CACAO
memstats.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/memory/Memorymemstat.hpp - Custom new/delete handler statistics
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #ifndef _JIT_COMPILER2_MEMORY_MEMSTAT
26 #define _JIT_COMPILER2_MEMORY_MEMSTAT
27 
28 #include "config.h"
29 
30 #if defined(ENABLE_STATISTICS)
31 #define ENABLE_MEMORY_MANAGER_STATISTICS
32 #endif
33 
34 #if defined(ENABLE_MEMORY_MANAGER_STATISTICS)
35 
36 #include <unordered_map>
37 
38 #include "vm/statistics.hpp"
39 
40 namespace cacao {
41 namespace jit {
42 namespace compiler2 {
43 namespace memory {
44 
45 
46 STAT_DECLARE_SUM_GROUP(comp2_allocated)
47 STAT_DECLARE_SUM_GROUP(comp2_deallocated)
48 STAT_DECLARE_SUM_GROUP(comp2_max)
49 
50 inline std::unordered_map<void*,std::size_t>& mem_map() {
51  static std::unordered_map<void*,std::size_t> mm;
52  return mm;
53 }
54 
55 template<typename T>
56 inline std::size_t& current_heap_size() {
57  static std::size_t t = 0;
58  return t;
59 }
60 
61 template<typename T>
62 inline const char* get_class_name() {
63  return "other";
64 }
65 
66 // default stat access function template
67 template<typename T>
68 inline StatVar<std::size_t,0>& get_comp2_allocated() {
69  STAT_REGISTER_GROUP_VAR(std::size_t,comp2_allocated,0,get_class_name<T>(),get_class_name<T>(),comp2_allocated)
70  return comp2_allocated;
71 }
72 
73 template<typename T>
74 inline StatVar<std::size_t,0>& get_comp2_deallocated() {
75  STAT_REGISTER_GROUP_VAR(std::size_t,comp2_deallocated,0,get_class_name<T>(),get_class_name<T>(),comp2_deallocated)
76  return comp2_deallocated;
77 }
78 
79 template<typename T>
80 inline StatVar<std::size_t,0>& get_comp2_max() {
81  STAT_REGISTER_GROUP_VAR(std::size_t,comp2_max,0,get_class_name<T>(),get_class_name<T>(),comp2_max)
82  return comp2_max;
83 }
84 
85 template<typename T>
86 inline void stat_new(std::size_t size, void* p) {
87  current_heap_size<T>()+=size;
88  get_comp2_allocated<T>()+=size;
89  get_comp2_max<T>().max(current_heap_size<T>());
90  mem_map()[p] = size;
91 }
92 template<typename T>
93 inline void stat_delete(void* p) {
94  std::size_t size = mem_map()[p];
95  current_heap_size<T>() -= size;
96  get_comp2_deallocated<T>() += size;
97 }
98 
99 
100 } // end namespace memory
101 } // end namespace compiler2
102 } // end namespace jit
103 } // end namespace cacao
104 
105 #define MM_STAT(x) do { x; } while(0)
106 
107 #define MM_CLASS_NAME(x) \
108 namespace memory { \
109 template<> \
110 inline const char* get_class_name<x>() { \
111  return #x; \
112 } \
113 }
114 
115 #define MM_MAKE_NAME(x) \
116 namespace cacao { \
117 namespace jit { \
118 namespace compiler2 { \
119 class x; \
120 MM_CLASS_NAME(x) \
121 } \
122 } \
123 }
124 
125 #else
126 #define MM_STAT(x) /* nothing */
127 #define MM_CLASS_NAME(x) /* nothing */
128 #define MM_MAKE_NAME(x) /* nothing */
129 #endif /* ENABLE_MEMORY_MANAGER_STATISTICS */
130 
131 #endif /* _JIT_COMPILER2_MEMORY_MEMSTAT */
132 
133 
134 /*
135  * These are local overrides for various environment variables in Emacs.
136  * Please do not remove this and leave it at the end of the file, where
137  * Emacs will automagically detect them.
138  * ---------------------------------------------------------------------
139  * Local variables:
140  * mode: c++
141  * indent-tabs-mode: t
142  * c-basic-offset: 4
143  * tab-width: 4
144  * End:
145  * vim:noexpandtab:sw=4:ts=4:
146  */
#define max(a, b)
Definition: lsra.hpp:80
JNIEnv jthread jobject jclass jlong size
Definition: jvmti.h:387
This file contains the statistics framework.
#define STAT_REGISTER_GROUP_VAR(type, var, init, name, description, group)
Register an statistics variable and add it to a group.
Definition: statistics.hpp:967
#define return
std::size_t & current_heap_size()
Definition: Allocator.cpp:37