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 "vm/statistics.hpp"
37 #include "future/unordered_map.hpp"
38 
39 namespace cacao {
40 namespace jit {
41 namespace compiler2 {
42 namespace memory {
43 
44 
45 STAT_DECLARE_SUM_GROUP(comp2_allocated)
46 STAT_DECLARE_SUM_GROUP(comp2_deallocated)
47 STAT_DECLARE_SUM_GROUP(comp2_max)
48 
49 inline unordered_map<void*,std::size_t>& mem_map() {
50  static unordered_map<void*,std::size_t> mm;
51  return mm;
52 }
53 
54 template<typename T>
55 inline std::size_t& current_heap_size() {
56  static std::size_t t = 0;
57  return t;
58 }
59 
60 template<typename T>
61 inline const char* get_class_name() {
62  return "other";
63 }
64 
65 // default stat access function template
66 template<typename T>
67 inline StatVar<std::size_t,0>& get_comp2_allocated() {
68  STAT_REGISTER_GROUP_VAR(std::size_t,comp2_allocated,0,get_class_name<T>(),get_class_name<T>(),comp2_allocated)
69  return comp2_allocated;
70 }
71 
72 template<typename T>
73 inline StatVar<std::size_t,0>& get_comp2_deallocated() {
74  STAT_REGISTER_GROUP_VAR(std::size_t,comp2_deallocated,0,get_class_name<T>(),get_class_name<T>(),comp2_deallocated)
75  return comp2_deallocated;
76 }
77 
78 template<typename T>
79 inline StatVar<std::size_t,0>& get_comp2_max() {
80  STAT_REGISTER_GROUP_VAR(std::size_t,comp2_max,0,get_class_name<T>(),get_class_name<T>(),comp2_max)
81  return comp2_max;
82 }
83 
84 template<typename T>
85 inline void stat_new(std::size_t size, void* p) {
86  current_heap_size<T>()+=size;
87  get_comp2_allocated<T>()+=size;
88  get_comp2_max<T>().max(current_heap_size<T>());
89  mem_map()[p] = size;
90 }
91 template<typename T>
92 inline void stat_delete(void* p) {
93  std::size_t size = mem_map()[p];
94  current_heap_size<T>() -= size;
95  get_comp2_deallocated<T>() += size;
96 }
97 
98 
99 } // end namespace memory
100 } // end namespace compiler2
101 } // end namespace jit
102 } // end namespace cacao
103 
104 #define MM_STAT(x) do { x; } while(0)
105 
106 #define MM_CLASS_NAME(x) \
107 namespace memory { \
108 template<> \
109 inline const char* get_class_name<x>() { \
110  return #x; \
111 } \
112 }
113 
114 #define MM_MAKE_NAME(x) \
115 namespace cacao { \
116 namespace jit { \
117 namespace compiler2 { \
118 class x; \
119 MM_CLASS_NAME(x) \
120 } \
121 } \
122 }
123 
124 #else
125 #define MM_STAT(x) /* nothing */
126 #define MM_CLASS_NAME(x) /* nothing */
127 #define MM_MAKE_NAME(x) /* nothing */
128 #endif /* ENABLE_MEMORY_MANAGER_STATISTICS */
129 
130 #endif /* _JIT_COMPILER2_MEMORY_MEMSTAT */
131 
132 
133 /*
134  * These are local overrides for various environment variables in Emacs.
135  * Please do not remove this and leave it at the end of the file, where
136  * Emacs will automagically detect them.
137  * ---------------------------------------------------------------------
138  * Local variables:
139  * mode: c++
140  * indent-tabs-mode: t
141  * c-basic-offset: 4
142  * tab-width: 4
143  * End:
144  * vim:noexpandtab:sw=4:ts=4:
145  */
#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