comparison src/share/vm/memory/allocation.hpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 6e0cb14ce59b
children
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
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.
284 f(ConstMethod) \ 263 f(ConstMethod) \
285 f(MethodData) \ 264 f(MethodData) \
286 f(ConstantPool) \ 265 f(ConstantPool) \
287 f(ConstantPoolCache) \ 266 f(ConstantPoolCache) \
288 f(Annotation) \ 267 f(Annotation) \
289 f(MethodCounters) 268 f(MethodCounters) \
269 f(Deallocated)
290 270
291 #define METASPACE_OBJ_TYPE_DECLARE(name) name ## Type, 271 #define METASPACE_OBJ_TYPE_DECLARE(name) name ## Type,
292 #define METASPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name; 272 #define METASPACE_OBJ_TYPE_NAME_CASE(name) case name ## Type: return #name;
293 273
294 enum Type { 274 enum Type {
382 static void clean_chunk_pool(); 362 static void clean_chunk_pool();
383 }; 363 };
384 364
385 //------------------------------Arena------------------------------------------ 365 //------------------------------Arena------------------------------------------
386 // Fast allocation of memory 366 // Fast allocation of memory
387 class Arena : public CHeapObj<mtNone|otArena> { 367 class Arena : public CHeapObj<mtNone> {
388 protected: 368 protected:
389 friend class ResourceMark; 369 friend class ResourceMark;
390 friend class HandleMark; 370 friend class HandleMark;
391 friend class NoHandleMark; 371 friend class NoHandleMark;
392 friend class VMStructs; 372 friend class VMStructs;
373
374 MEMFLAGS _flags; // Memory tracking flags
393 375
394 Chunk *_first; // First chunk 376 Chunk *_first; // First chunk
395 Chunk *_chunk; // current chunk 377 Chunk *_chunk; // current chunk
396 char *_hwm, *_max; // High water mark and max in current chunk 378 char *_hwm, *_max; // High water mark and max in current chunk
397 // Get a new Chunk of at least size x 379 // Get a new Chunk of at least size x
416 } 398 }
417 return true; 399 return true;
418 } 400 }
419 401
420 public: 402 public:
421 Arena(); 403 Arena(MEMFLAGS memflag);
422 Arena(size_t init_size); 404 Arena(MEMFLAGS memflag, size_t init_size);
423 ~Arena(); 405 ~Arena();
424 void destruct_contents(); 406 void destruct_contents();
425 char* hwm() const { return _hwm; } 407 char* hwm() const { return _hwm; }
426 408
427 // new operators 409 // new operators
516 void set_size_in_bytes(size_t size); 498 void set_size_in_bytes(size_t size);
517 499
518 static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN; 500 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; 501 static void free_all(char** start, char** end) PRODUCT_RETURN;
520 502
521 // how many arena instances
522 NOT_PRODUCT(static volatile jint _instance_count;)
523 private: 503 private:
524 // Reset this Arena to empty, access will trigger grow if necessary 504 // Reset this Arena to empty, access will trigger grow if necessary
525 void reset(void) { 505 void reset(void) {
526 _first = _chunk = NULL; 506 _first = _chunk = NULL;
527 _hwm = _max = NULL; 507 _hwm = _max = NULL;
679 659
680 #define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\ 660 #define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\
681 NEW_C_HEAP_ARRAY3(type, (size), memflags, pc, AllocFailStrategy::RETURN_NULL) 661 NEW_C_HEAP_ARRAY3(type, (size), memflags, pc, AllocFailStrategy::RETURN_NULL)
682 662
683 #define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\ 663 #define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\
684 NEW_C_HEAP_ARRAY3(type, (size), memflags, (address)0, AllocFailStrategy::RETURN_NULL) 664 NEW_C_HEAP_ARRAY3(type, (size), memflags, CURRENT_PC, AllocFailStrategy::RETURN_NULL)
685 665
686 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ 666 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
687 (type*) (ReallocateHeap((char*)(old), (size) * sizeof(type), memflags)) 667 (type*) (ReallocateHeap((char*)(old), (size) * sizeof(type), memflags))
688 668
689 #define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\ 669 #define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\