Mercurial > hg > truffle
annotate src/share/vm/memory/allocation.hpp @ 6292:b679a28208fd
disabled failing BigBangTests: helloWorldTest, formattedOutputTest, arrayListTestWithCalls
made BigBangTest less verbose unless "BigBang.verbose" system property is set to "true"
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 28 Aug 2012 11:43:06 +0200 |
parents | d2a62e0f25eb |
children | da91efe96a93 |
rev | line source |
---|---|
0 | 1 /* |
6197 | 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
342
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
342
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
342
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_MEMORY_ALLOCATION_HPP |
26 #define SHARE_VM_MEMORY_ALLOCATION_HPP | |
27 | |
28 #include "runtime/globals.hpp" | |
29 #include "utilities/globalDefinitions.hpp" | |
30 #ifdef COMPILER1 | |
31 #include "c1/c1_globals.hpp" | |
32 #endif | |
33 #ifdef COMPILER2 | |
34 #include "opto/c2_globals.hpp" | |
35 #endif | |
36 | |
3302
2a3da7eaf4a6
7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents:
2307
diff
changeset
|
37 #include <new> |
2a3da7eaf4a6
7036747: 7017009 reappeared, problem with ElfStringTable
zgu
parents:
2307
diff
changeset
|
38 |
0 | 39 #define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1) |
40 #define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1)) | |
41 #define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK) | |
42 | |
6197 | 43 |
44 // noinline attribute | |
45 #ifdef _WINDOWS | |
46 #define _NOINLINE_ __declspec(noinline) | |
47 #else | |
48 #if __GNUC__ < 3 // gcc 2.x does not support noinline attribute | |
49 #define _NOINLINE_ | |
50 #else | |
51 #define _NOINLINE_ __attribute__ ((noinline)) | |
52 #endif | |
53 #endif | |
54 | |
0 | 55 // All classes in the virtual machine must be subclassed |
56 // by one of the following allocation classes: | |
57 // | |
58 // For objects allocated in the resource area (see resourceArea.hpp). | |
59 // - ResourceObj | |
60 // | |
61 // For objects allocated in the C-heap (managed by: free & malloc). | |
62 // - CHeapObj | |
63 // | |
64 // For objects allocated on the stack. | |
65 // - StackObj | |
66 // | |
67 // For embedded objects. | |
68 // - ValueObj | |
69 // | |
70 // For classes used as name spaces. | |
71 // - AllStatic | |
72 // | |
73 // The printable subclasses are used for debugging and define virtual | |
74 // member functions for printing. Classes that avoid allocating the | |
75 // vtbl entries in the objects should therefore not be the printable | |
76 // subclasses. | |
77 // | |
78 // The following macros and function should be used to allocate memory | |
79 // directly in the resource area or in the C-heap: | |
80 // | |
81 // NEW_RESOURCE_ARRAY(type,size) | |
82 // NEW_RESOURCE_OBJ(type) | |
83 // NEW_C_HEAP_ARRAY(type,size) | |
84 // NEW_C_HEAP_OBJ(type) | |
85 // char* AllocateHeap(size_t size, const char* name); | |
86 // void FreeHeap(void* p); | |
87 // | |
88 // C-heap allocation can be traced using +PrintHeapAllocation. | |
89 // malloc and free should therefore never called directly. | |
90 | |
91 // Base class for objects allocated in the C-heap. | |
92 | |
93 // In non product mode we introduce a super class for all allocation classes | |
94 // that supports printing. | |
95 // We avoid the superclass in product mode since some C++ compilers add | |
96 // a word overhead for empty super classes. | |
97 | |
98 #ifdef PRODUCT | |
99 #define ALLOCATION_SUPER_CLASS_SPEC | |
100 #else | |
101 #define ALLOCATION_SUPER_CLASS_SPEC : public AllocatedObj | |
102 class AllocatedObj { | |
103 public: | |
104 // Printing support | |
105 void print() const; | |
106 void print_value() const; | |
107 | |
108 virtual void print_on(outputStream* st) const; | |
109 virtual void print_value_on(outputStream* st) const; | |
110 }; | |
111 #endif | |
112 | |
6197 | 113 |
114 /* | |
115 * MemoryType bitmap layout: | |
116 * | 16 15 14 13 12 11 10 09 | 08 07 06 05 | 04 03 02 01 | | |
117 * | memory type | object | reserved | | |
118 * | | type | | | |
119 */ | |
120 enum MemoryType { | |
121 // Memory type by sub systems. It occupies lower byte. | |
122 mtNone = 0x0000, // undefined | |
123 mtClass = 0x0100, // memory class for Java classes | |
124 mtThread = 0x0200, // memory for thread objects | |
125 mtThreadStack = 0x0300, | |
126 mtCode = 0x0400, // memory for generated code | |
127 mtGC = 0x0500, // memory for GC | |
128 mtCompiler = 0x0600, // memory for compiler | |
129 mtInternal = 0x0700, // memory used by VM, but does not belong to | |
130 // any of above categories, and not used for | |
131 // native memory tracking | |
132 mtOther = 0x0800, // memory not used by VM | |
133 mtSymbol = 0x0900, // symbol | |
134 mtNMT = 0x0A00, // memory used by native memory tracking | |
135 mtChunk = 0x0B00, // chunk that holds content of arenas | |
136 mtJavaHeap = 0x0C00, // Java heap | |
137 mtDontTrack = 0x0D00, // memory we donot or cannot track | |
138 mt_number_of_types = 0x000C, // number of memory types | |
139 mt_masks = 0x7F00, | |
140 | |
141 // object type mask | |
142 otArena = 0x0010, // an arena object | |
143 otNMTRecorder = 0x0020, // memory recorder object | |
144 ot_masks = 0x00F0 | |
145 }; | |
146 | |
147 #define IS_MEMORY_TYPE(flags, type) ((flags & mt_masks) == type) | |
148 #define HAS_VALID_MEMORY_TYPE(flags)((flags & mt_masks) != mtNone) | |
149 #define FLAGS_TO_MEMORY_TYPE(flags) (flags & mt_masks) | |
150 | |
151 #define IS_ARENA_OBJ(flags) ((flags & ot_masks) == otArena) | |
152 #define IS_NMT_RECORDER(flags) ((flags & ot_masks) == otNMTRecorder) | |
153 #define NMT_CAN_TRACK(flags) (!IS_NMT_RECORDER(flags) && !(IS_MEMORY_TYPE(flags, mtDontTrack))) | |
154 | |
155 typedef unsigned short MEMFLAGS; | |
156 | |
157 extern bool NMT_track_callsite; | |
158 | |
159 // debug build does not inline | |
160 #if defined(_DEBUG_) | |
161 #define CURRENT_PC (NMT_track_callsite ? os::get_caller_pc(1) : 0) | |
162 #define CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) | |
163 #define CALLER_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(3) : 0) | |
164 #else | |
165 #define CURRENT_PC (NMT_track_callsite? os::get_caller_pc(0) : 0) | |
166 #define CALLER_PC (NMT_track_callsite ? os::get_caller_pc(1) : 0) | |
167 #define CALLER_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) | |
168 #endif | |
169 | |
170 | |
171 | |
172 template <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { | |
0 | 173 public: |
6197 | 174 _NOINLINE_ void* operator new(size_t size, address caller_pc = 0); |
175 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant, | |
176 address caller_pc = 0); | |
177 | |
0 | 178 void operator delete(void* p); |
179 }; | |
180 | |
181 // Base class for objects allocated on the stack only. | |
182 // Calling new or delete will result in fatal error. | |
183 | |
184 class StackObj ALLOCATION_SUPER_CLASS_SPEC { | |
185 public: | |
186 void* operator new(size_t size); | |
187 void operator delete(void* p); | |
188 }; | |
189 | |
190 // Base class for objects used as value objects. | |
191 // Calling new or delete will result in fatal error. | |
192 // | |
193 // Portability note: Certain compilers (e.g. gcc) will | |
194 // always make classes bigger if it has a superclass, even | |
195 // if the superclass does not have any virtual methods or | |
196 // instance fields. The HotSpot implementation relies on this | |
197 // not to happen. So never make a ValueObj class a direct subclass | |
198 // of this object, but use the VALUE_OBJ_CLASS_SPEC class instead, e.g., | |
199 // like this: | |
200 // | |
201 // class A VALUE_OBJ_CLASS_SPEC { | |
202 // ... | |
203 // } | |
204 // | |
205 // With gcc and possible other compilers the VALUE_OBJ_CLASS_SPEC can | |
206 // be defined as a an empty string "". | |
207 // | |
208 class _ValueObj { | |
209 public: | |
210 void* operator new(size_t size); | |
211 void operator delete(void* p); | |
212 }; | |
213 | |
214 // Base class for classes that constitute name spaces. | |
215 | |
216 class AllStatic { | |
217 public: | |
218 AllStatic() { ShouldNotCallThis(); } | |
219 ~AllStatic() { ShouldNotCallThis(); } | |
220 }; | |
221 | |
222 | |
223 //------------------------------Chunk------------------------------------------ | |
224 // Linked list of raw memory chunks | |
6197 | 225 class Chunk: CHeapObj<mtChunk> { |
3939 | 226 friend class VMStructs; |
227 | |
0 | 228 protected: |
229 Chunk* _next; // Next Chunk in list | |
230 const size_t _len; // Size of this Chunk | |
231 public: | |
232 void* operator new(size_t size, size_t length); | |
233 void operator delete(void* p); | |
234 Chunk(size_t length); | |
235 | |
236 enum { | |
237 // default sizes; make them slightly smaller than 2**k to guard against | |
238 // buddy-system style malloc implementations | |
239 #ifdef _LP64 | |
240 slack = 40, // [RGV] Not sure if this is right, but make it | |
241 // a multiple of 8. | |
242 #else | |
243 slack = 20, // suspected sizeof(Chunk) + internal malloc headers | |
244 #endif | |
245 | |
246 init_size = 1*K - slack, // Size of first chunk | |
247 medium_size= 10*K - slack, // Size of medium-sized chunk | |
248 size = 32*K - slack, // Default size of an Arena chunk (following the first) | |
249 non_pool_size = init_size + 32 // An initial size which is not one of above | |
250 }; | |
251 | |
252 void chop(); // Chop this chunk | |
253 void next_chop(); // Chop next chunk | |
254 static size_t aligned_overhead_size(void) { return ARENA_ALIGN(sizeof(Chunk)); } | |
255 | |
256 size_t length() const { return _len; } | |
257 Chunk* next() const { return _next; } | |
258 void set_next(Chunk* n) { _next = n; } | |
259 // Boundaries of data area (possibly unused) | |
260 char* bottom() const { return ((char*) this) + aligned_overhead_size(); } | |
261 char* top() const { return bottom() + _len; } | |
262 bool contains(char* p) const { return bottom() <= p && p <= top(); } | |
263 | |
264 // Start the chunk_pool cleaner task | |
265 static void start_chunk_pool_cleaner_task(); | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
266 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
267 static void clean_chunk_pool(); |
0 | 268 }; |
269 | |
270 //------------------------------Arena------------------------------------------ | |
271 // Fast allocation of memory | |
6197 | 272 class Arena : public CHeapObj<mtNone|otArena> { |
0 | 273 protected: |
274 friend class ResourceMark; | |
275 friend class HandleMark; | |
276 friend class NoHandleMark; | |
3939 | 277 friend class VMStructs; |
278 | |
0 | 279 Chunk *_first; // First chunk |
280 Chunk *_chunk; // current chunk | |
281 char *_hwm, *_max; // High water mark and max in current chunk | |
282 void* grow(size_t x); // Get a new Chunk of at least size x | |
6197 | 283 size_t _size_in_bytes; // Size of arena (used for native memory tracking) |
284 | |
2250 | 285 NOT_PRODUCT(static julong _bytes_allocated;) // total #bytes allocated since start |
0 | 286 friend class AllocStats; |
287 debug_only(void* malloc(size_t size);) | |
288 debug_only(void* internal_malloc_4(size_t x);) | |
2250 | 289 NOT_PRODUCT(void inc_bytes_allocated(size_t x);) |
2307
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
290 |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
291 void signal_out_of_memory(size_t request, const char* whence) const; |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
292 |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
293 void check_for_overflow(size_t request, const char* whence) const { |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
294 if (UINTPTR_MAX - request < (uintptr_t)_hwm) { |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
295 signal_out_of_memory(request, whence); |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
296 } |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
297 } |
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
298 |
0 | 299 public: |
300 Arena(); | |
301 Arena(size_t init_size); | |
302 Arena(Arena *old); | |
303 ~Arena(); | |
304 void destruct_contents(); | |
305 char* hwm() const { return _hwm; } | |
306 | |
6197 | 307 // new operators |
308 void* operator new (size_t size); | |
309 void* operator new (size_t size, const std::nothrow_t& nothrow_constant); | |
310 | |
311 // dynamic memory type tagging | |
312 void* operator new(size_t size, MEMFLAGS flags); | |
313 void* operator new(size_t size, const std::nothrow_t& nothrow_constant, MEMFLAGS flags); | |
314 void operator delete(void* p); | |
315 | |
0 | 316 // Fast allocate in the arena. Common case is: pointer test + increment. |
317 void* Amalloc(size_t x) { | |
318 assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); | |
319 x = ARENA_ALIGN(x); | |
320 debug_only(if (UseMallocOnly) return malloc(x);) | |
2307
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
321 check_for_overflow(x, "Arena::Amalloc"); |
2250 | 322 NOT_PRODUCT(inc_bytes_allocated(x);) |
0 | 323 if (_hwm + x > _max) { |
324 return grow(x); | |
325 } else { | |
326 char *old = _hwm; | |
327 _hwm += x; | |
328 return old; | |
329 } | |
330 } | |
331 // Further assume size is padded out to words | |
332 void *Amalloc_4(size_t x) { | |
333 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); | |
334 debug_only(if (UseMallocOnly) return malloc(x);) | |
2307
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
335 check_for_overflow(x, "Arena::Amalloc_4"); |
2250 | 336 NOT_PRODUCT(inc_bytes_allocated(x);) |
0 | 337 if (_hwm + x > _max) { |
338 return grow(x); | |
339 } else { | |
340 char *old = _hwm; | |
341 _hwm += x; | |
342 return old; | |
343 } | |
344 } | |
345 | |
346 // Allocate with 'double' alignment. It is 8 bytes on sparc. | |
347 // In other cases Amalloc_D() should be the same as Amalloc_4(). | |
348 void* Amalloc_D(size_t x) { | |
349 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); | |
350 debug_only(if (UseMallocOnly) return malloc(x);) | |
351 #if defined(SPARC) && !defined(_LP64) | |
352 #define DALIGN_M1 7 | |
353 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; | |
354 x += delta; | |
355 #endif | |
2307
4a9604cd7c5f
6878713: Verifier heap corruption, relating to backward jsrs
kamg
parents:
2250
diff
changeset
|
356 check_for_overflow(x, "Arena::Amalloc_D"); |
2250 | 357 NOT_PRODUCT(inc_bytes_allocated(x);) |
0 | 358 if (_hwm + x > _max) { |
359 return grow(x); // grow() returns a result aligned >= 8 bytes. | |
360 } else { | |
361 char *old = _hwm; | |
362 _hwm += x; | |
363 #if defined(SPARC) && !defined(_LP64) | |
364 old += delta; // align to 8-bytes | |
365 #endif | |
366 return old; | |
367 } | |
368 } | |
369 | |
370 // Fast delete in area. Common case is: NOP (except for storage reclaimed) | |
371 void Afree(void *ptr, size_t size) { | |
372 #ifdef ASSERT | |
373 if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory | |
374 if (UseMallocOnly) return; | |
375 #endif | |
376 if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr; | |
377 } | |
378 | |
379 void *Arealloc( void *old_ptr, size_t old_size, size_t new_size ); | |
380 | |
381 // Move contents of this arena into an empty arena | |
382 Arena *move_contents(Arena *empty_arena); | |
383 | |
384 // Determine if pointer belongs to this Arena or not. | |
385 bool contains( const void *ptr ) const; | |
386 | |
387 // Total of all chunks in use (not thread-safe) | |
388 size_t used() const; | |
389 | |
390 // Total # of bytes used | |
6197 | 391 size_t size_in_bytes() const { return _size_in_bytes; }; |
392 void set_size_in_bytes(size_t size); | |
393 | |
0 | 394 static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN; |
395 static void free_all(char** start, char** end) PRODUCT_RETURN; | |
396 | |
6197 | 397 // how many arena instances |
398 NOT_PRODUCT(static volatile jint _instance_count;) | |
0 | 399 private: |
400 // Reset this Arena to empty, access will trigger grow if necessary | |
401 void reset(void) { | |
402 _first = _chunk = NULL; | |
403 _hwm = _max = NULL; | |
6197 | 404 set_size_in_bytes(0); |
0 | 405 } |
406 }; | |
407 | |
408 // One of the following macros must be used when allocating | |
409 // an array or object from an arena | |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
410 #define NEW_ARENA_ARRAY(arena, type, size) \ |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
411 (type*) (arena)->Amalloc((size) * sizeof(type)) |
0 | 412 |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
413 #define REALLOC_ARENA_ARRAY(arena, type, old, old_size, new_size) \ |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
414 (type*) (arena)->Arealloc((char*)(old), (old_size) * sizeof(type), \ |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
415 (new_size) * sizeof(type) ) |
0 | 416 |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
417 #define FREE_ARENA_ARRAY(arena, type, old, size) \ |
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
418 (arena)->Afree((char*)(old), (size) * sizeof(type)) |
0 | 419 |
1836
894b1d7c7e01
6423256: GC stacks should use a better data structure
jcoomes
parents:
1689
diff
changeset
|
420 #define NEW_ARENA_OBJ(arena, type) \ |
0 | 421 NEW_ARENA_ARRAY(arena, type, 1) |
422 | |
423 | |
424 //%note allocation_1 | |
425 extern char* resource_allocate_bytes(size_t size); | |
426 extern char* resource_allocate_bytes(Thread* thread, size_t size); | |
427 extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size); | |
428 extern void resource_free_bytes( char *old, size_t size ); | |
429 | |
430 //---------------------------------------------------------------------- | |
431 // Base class for objects allocated in the resource area per default. | |
432 // Optionally, objects may be allocated on the C heap with | |
433 // new(ResourceObj::C_HEAP) Foo(...) or in an Arena with new (&arena) | |
434 // ResourceObj's can be allocated within other objects, but don't use | |
435 // new or delete (allocation_type is unknown). If new is used to allocate, | |
436 // use delete to deallocate. | |
437 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC { | |
438 public: | |
1685 | 439 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 }; |
1688
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1685
diff
changeset
|
440 static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN; |
0 | 441 #ifdef ASSERT |
442 private: | |
1685 | 443 // When this object is allocated on stack the new() operator is not |
444 // called but garbage on stack may look like a valid allocation_type. | |
445 // Store negated 'this' pointer when new() is called to distinguish cases. | |
2015
79d8657be916
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
1972
diff
changeset
|
446 // Use second array's element for verification value to distinguish garbage. |
79d8657be916
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
1972
diff
changeset
|
447 uintptr_t _allocation_t[2]; |
79d8657be916
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
1972
diff
changeset
|
448 bool is_type_set() const; |
0 | 449 public: |
1688
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1685
diff
changeset
|
450 allocation_type get_allocation_type() const; |
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1685
diff
changeset
|
451 bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; } |
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1685
diff
changeset
|
452 bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; } |
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1685
diff
changeset
|
453 bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; } |
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1685
diff
changeset
|
454 bool allocated_on_arena() const { return get_allocation_type() == ARENA; } |
1685 | 455 ResourceObj(); // default construtor |
456 ResourceObj(const ResourceObj& r); // default copy construtor | |
457 ResourceObj& operator=(const ResourceObj& r); // default copy assignment | |
458 ~ResourceObj(); | |
0 | 459 #endif // ASSERT |
460 | |
461 public: | |
6197 | 462 void* operator new(size_t size, allocation_type type, MEMFLAGS flags); |
0 | 463 void* operator new(size_t size, Arena *arena) { |
464 address res = (address)arena->Amalloc(size); | |
1685 | 465 DEBUG_ONLY(set_allocation_type(res, ARENA);) |
0 | 466 return res; |
467 } | |
468 void* operator new(size_t size) { | |
469 address res = (address)resource_allocate_bytes(size); | |
1685 | 470 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) |
0 | 471 return res; |
472 } | |
473 void operator delete(void* p); | |
474 }; | |
475 | |
476 // One of the following macros must be used when allocating an array | |
477 // or object to determine whether it should reside in the C heap on in | |
478 // the resource area. | |
479 | |
480 #define NEW_RESOURCE_ARRAY(type, size)\ | |
481 (type*) resource_allocate_bytes((size) * sizeof(type)) | |
482 | |
483 #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\ | |
484 (type*) resource_allocate_bytes(thread, (size) * sizeof(type)) | |
485 | |
486 #define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\ | |
487 (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type) ) | |
488 | |
489 #define FREE_RESOURCE_ARRAY(type, old, size)\ | |
490 resource_free_bytes((char*)(old), (size) * sizeof(type)) | |
491 | |
492 #define FREE_FAST(old)\ | |
493 /* nop */ | |
494 | |
495 #define NEW_RESOURCE_OBJ(type)\ | |
496 NEW_RESOURCE_ARRAY(type, 1) | |
497 | |
6197 | 498 #define NEW_C_HEAP_ARRAY(type, size, memflags)\ |
499 (type*) (AllocateHeap((size) * sizeof(type), memflags)) | |
0 | 500 |
6197 | 501 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ |
502 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags)) | |
503 | |
504 #define FREE_C_HEAP_ARRAY(type,old,memflags) \ | |
505 FreeHeap((char*)(old), memflags) | |
0 | 506 |
6197 | 507 #define NEW_C_HEAP_OBJ(type, memflags)\ |
508 NEW_C_HEAP_ARRAY(type, 1, memflags) | |
509 | |
510 | |
511 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\ | |
512 (type*) (AllocateHeap((size) * sizeof(type), memflags, pc)) | |
0 | 513 |
6197 | 514 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\ |
515 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc)) | |
516 | |
517 #define NEW_C_HEAP_OBJ2(type, memflags, pc)\ | |
518 NEW_C_HEAP_ARRAY2(type, 1, memflags, pc) | |
519 | |
0 | 520 |
521 extern bool warn_new_operator; | |
522 | |
523 // for statistics | |
524 #ifndef PRODUCT | |
525 class AllocStats : StackObj { | |
2250 | 526 julong start_mallocs, start_frees; |
527 julong start_malloc_bytes, start_mfree_bytes, start_res_bytes; | |
0 | 528 public: |
529 AllocStats(); | |
530 | |
2250 | 531 julong num_mallocs(); // since creation of receiver |
532 julong alloc_bytes(); | |
533 julong num_frees(); | |
534 julong free_bytes(); | |
535 julong resource_bytes(); | |
0 | 536 void print(); |
537 }; | |
538 #endif | |
539 | |
540 | |
541 //------------------------------ReallocMark--------------------------------- | |
542 // Code which uses REALLOC_RESOURCE_ARRAY should check an associated | |
543 // ReallocMark, which is declared in the same scope as the reallocated | |
544 // pointer. Any operation that could __potentially__ cause a reallocation | |
545 // should check the ReallocMark. | |
546 class ReallocMark: public StackObj { | |
547 protected: | |
548 NOT_PRODUCT(int _nesting;) | |
549 | |
550 public: | |
551 ReallocMark() PRODUCT_RETURN; | |
552 void check() PRODUCT_RETURN; | |
553 }; | |
1972 | 554 |
555 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP |