Mercurial > hg > truffle
comparison src/share/vm/memory/allocation.hpp @ 20360:833b0f92429a
8046598: Scalable Native memory tracking development
Summary: Enhance scalability of native memory tracking
Reviewed-by: coleenp, ctornqvi, gtriantafill
author | zgu |
---|---|
date | Wed, 27 Aug 2014 08:19:12 -0400 |
parents | 752ba2e5f6d0 |
children | 6e0cb14ce59b |
comparison
equal
deleted
inserted
replaced
20359:4d3a43351904 | 20360:833b0f92429a |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
131 }; | 131 }; |
132 #endif | 132 #endif |
133 | 133 |
134 | 134 |
135 /* | 135 /* |
136 * MemoryType bitmap layout: | 136 * Memory types |
137 * | 16 15 14 13 12 11 10 09 | 08 07 06 05 | 04 03 02 01 | | |
138 * | memory type | object | reserved | | |
139 * | | type | | | |
140 */ | 137 */ |
141 enum MemoryType { | 138 enum MemoryType { |
142 // Memory type by sub systems. It occupies lower byte. | 139 // Memory type by sub systems. It occupies lower byte. |
143 mtNone = 0x0000, // undefined | 140 mtJavaHeap = 0x00, // Java heap |
144 mtClass = 0x0100, // memory class for Java classes | 141 mtClass = 0x01, // memory class for Java classes |
145 mtThread = 0x0200, // memory for thread objects | 142 mtThread = 0x02, // memory for thread objects |
146 mtThreadStack = 0x0300, | 143 mtThreadStack = 0x03, |
147 mtCode = 0x0400, // memory for generated code | 144 mtCode = 0x04, // memory for generated code |
148 mtGC = 0x0500, // memory for GC | 145 mtGC = 0x05, // memory for GC |
149 mtCompiler = 0x0600, // memory for compiler | 146 mtCompiler = 0x06, // memory for compiler |
150 mtInternal = 0x0700, // memory used by VM, but does not belong to | 147 mtInternal = 0x07, // memory used by VM, but does not belong to |
151 // any of above categories, and not used for | 148 // any of above categories, and not used for |
152 // native memory tracking | 149 // native memory tracking |
153 mtOther = 0x0800, // memory not used by VM | 150 mtOther = 0x08, // memory not used by VM |
154 mtSymbol = 0x0900, // symbol | 151 mtSymbol = 0x09, // symbol |
155 mtNMT = 0x0A00, // memory used by native memory tracking | 152 mtNMT = 0x0A, // memory used by native memory tracking |
156 mtChunk = 0x0B00, // chunk that holds content of arenas | 153 mtClassShared = 0x0B, // class data sharing |
157 mtJavaHeap = 0x0C00, // Java heap | 154 mtChunk = 0x0C, // chunk that holds content of arenas |
158 mtClassShared = 0x0D00, // class data sharing | 155 mtTest = 0x0D, // Test type for verifying NMT |
159 mtTest = 0x0E00, // Test type for verifying NMT | 156 mtTracing = 0x0E, // memory used for Tracing |
160 mtTracing = 0x0F00, // memory used for Tracing | 157 mtNone = 0x0F, // undefined |
161 mt_number_of_types = 0x000F, // number of memory types (mtDontTrack | 158 mt_number_of_types = 0x10 // number of memory types (mtDontTrack |
162 // is not included as validate type) | 159 // is not included as validate type) |
163 mtDontTrack = 0x0F00, // memory we do not or cannot track | 160 }; |
164 mt_masks = 0x7F00, | 161 |
165 | 162 typedef MemoryType MEMFLAGS; |
166 // object type mask | 163 |
167 otArena = 0x0010, // an arena object | |
168 otNMTRecorder = 0x0020, // memory recorder object | |
169 ot_masks = 0x00F0 | |
170 }; | |
171 | |
172 #define IS_MEMORY_TYPE(flags, type) ((flags & mt_masks) == type) | |
173 #define HAS_VALID_MEMORY_TYPE(flags)((flags & mt_masks) != mtNone) | |
174 #define FLAGS_TO_MEMORY_TYPE(flags) (flags & mt_masks) | |
175 | |
176 #define IS_ARENA_OBJ(flags) ((flags & ot_masks) == otArena) | |
177 #define IS_NMT_RECORDER(flags) ((flags & ot_masks) == otNMTRecorder) | |
178 #define NMT_CAN_TRACK(flags) (!IS_NMT_RECORDER(flags) && !(IS_MEMORY_TYPE(flags, mtDontTrack))) | |
179 | |
180 typedef unsigned short MEMFLAGS; | |
181 | 164 |
182 #if INCLUDE_NMT | 165 #if INCLUDE_NMT |
183 | 166 |
184 extern bool NMT_track_callsite; | 167 extern bool NMT_track_callsite; |
185 | 168 |
187 | 170 |
188 const bool NMT_track_callsite = false; | 171 const bool NMT_track_callsite = false; |
189 | 172 |
190 #endif // INCLUDE_NMT | 173 #endif // INCLUDE_NMT |
191 | 174 |
192 // debug build does not inline | 175 class NativeCallStack; |
193 #if defined(_NMT_NOINLINE_) | |
194 #define CURRENT_PC (NMT_track_callsite ? os::get_caller_pc(1) : 0) | |
195 #define CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) | |
196 #define CALLER_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(3) : 0) | |
197 #else | |
198 #define CURRENT_PC (NMT_track_callsite? os::get_caller_pc(0) : 0) | |
199 #define CALLER_PC (NMT_track_callsite ? os::get_caller_pc(1) : 0) | |
200 #define CALLER_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) | |
201 #endif | |
202 | |
203 | 176 |
204 | 177 |
205 template <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { | 178 template <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { |
206 public: | 179 public: |
207 _NOINLINE_ void* operator new(size_t size, address caller_pc = 0) throw(); | 180 _NOINLINE_ void* operator new(size_t size, const NativeCallStack& stack) throw(); |
181 _NOINLINE_ void* operator new(size_t size) throw(); | |
208 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant, | 182 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant, |
209 address caller_pc = 0) throw(); | 183 const NativeCallStack& stack) throw(); |
210 _NOINLINE_ void* operator new [](size_t size, address caller_pc = 0) throw(); | 184 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant) |
185 throw(); | |
186 _NOINLINE_ void* operator new [](size_t size, const NativeCallStack& stack) throw(); | |
187 _NOINLINE_ void* operator new [](size_t size) throw(); | |
211 _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, | 188 _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, |
212 address caller_pc = 0) throw(); | 189 const NativeCallStack& stack) throw(); |
190 _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) | |
191 throw(); | |
213 void operator delete(void* p); | 192 void operator delete(void* p); |
214 void operator delete [] (void* p); | 193 void operator delete [] (void* p); |
215 }; | 194 }; |
216 | 195 |
217 // Base class for objects allocated on the stack only. | 196 // Base class for objects allocated on the stack only. |
382 static void clean_chunk_pool(); | 361 static void clean_chunk_pool(); |
383 }; | 362 }; |
384 | 363 |
385 //------------------------------Arena------------------------------------------ | 364 //------------------------------Arena------------------------------------------ |
386 // Fast allocation of memory | 365 // Fast allocation of memory |
387 class Arena : public CHeapObj<mtNone|otArena> { | 366 class Arena : public CHeapObj<mtNone> { |
388 protected: | 367 protected: |
389 friend class ResourceMark; | 368 friend class ResourceMark; |
390 friend class HandleMark; | 369 friend class HandleMark; |
391 friend class NoHandleMark; | 370 friend class NoHandleMark; |
392 friend class VMStructs; | 371 friend class VMStructs; |
372 | |
373 MEMFLAGS _flags; // Memory tracking flags | |
393 | 374 |
394 Chunk *_first; // First chunk | 375 Chunk *_first; // First chunk |
395 Chunk *_chunk; // current chunk | 376 Chunk *_chunk; // current chunk |
396 char *_hwm, *_max; // High water mark and max in current chunk | 377 char *_hwm, *_max; // High water mark and max in current chunk |
397 // Get a new Chunk of at least size x | 378 // Get a new Chunk of at least size x |
416 } | 397 } |
417 return true; | 398 return true; |
418 } | 399 } |
419 | 400 |
420 public: | 401 public: |
421 Arena(); | 402 Arena(MEMFLAGS memflag); |
422 Arena(size_t init_size); | 403 Arena(MEMFLAGS memflag, size_t init_size); |
423 ~Arena(); | 404 ~Arena(); |
424 void destruct_contents(); | 405 void destruct_contents(); |
425 char* hwm() const { return _hwm; } | 406 char* hwm() const { return _hwm; } |
426 | 407 |
427 // new operators | 408 // new operators |
516 void set_size_in_bytes(size_t size); | 497 void set_size_in_bytes(size_t size); |
517 | 498 |
518 static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN; | 499 static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN; |
519 static void free_all(char** start, char** end) PRODUCT_RETURN; | 500 static void free_all(char** start, char** end) PRODUCT_RETURN; |
520 | 501 |
521 // how many arena instances | |
522 NOT_PRODUCT(static volatile jint _instance_count;) | |
523 private: | 502 private: |
524 // Reset this Arena to empty, access will trigger grow if necessary | 503 // Reset this Arena to empty, access will trigger grow if necessary |
525 void reset(void) { | 504 void reset(void) { |
526 _first = _chunk = NULL; | 505 _first = _chunk = NULL; |
527 _hwm = _max = NULL; | 506 _hwm = _max = NULL; |
679 | 658 |
680 #define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\ | 659 #define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\ |
681 NEW_C_HEAP_ARRAY3(type, (size), memflags, pc, AllocFailStrategy::RETURN_NULL) | 660 NEW_C_HEAP_ARRAY3(type, (size), memflags, pc, AllocFailStrategy::RETURN_NULL) |
682 | 661 |
683 #define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\ | 662 #define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\ |
684 NEW_C_HEAP_ARRAY3(type, (size), memflags, (address)0, AllocFailStrategy::RETURN_NULL) | 663 NEW_C_HEAP_ARRAY3(type, (size), memflags, CURRENT_PC, AllocFailStrategy::RETURN_NULL) |
685 | 664 |
686 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ | 665 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ |
687 (type*) (ReallocateHeap((char*)(old), (size) * sizeof(type), memflags)) | 666 (type*) (ReallocateHeap((char*)(old), (size) * sizeof(type), memflags)) |
688 | 667 |
689 #define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\ | 668 #define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\ |