Mercurial > hg > truffle
comparison src/share/vm/memory/allocation.hpp @ 11017:ce9ecec70f99
Merge
author | chegar |
---|---|
date | Thu, 23 May 2013 12:44:18 +0100 |
parents | 7ee0d5c53c78 f9be75d21404 |
children | eaf3742822ec |
comparison
equal
deleted
inserted
replaced
11016:cb92413c6934 | 11017:ce9ecec70f99 |
---|---|
84 // member functions for printing. Classes that avoid allocating the | 84 // member functions for printing. Classes that avoid allocating the |
85 // vtbl entries in the objects should therefore not be the printable | 85 // vtbl entries in the objects should therefore not be the printable |
86 // subclasses. | 86 // subclasses. |
87 // | 87 // |
88 // The following macros and function should be used to allocate memory | 88 // The following macros and function should be used to allocate memory |
89 // directly in the resource area or in the C-heap: | 89 // directly in the resource area or in the C-heap, The _OBJ variants |
90 // | 90 // of the NEW/FREE_C_HEAP macros are used for alloc/dealloc simple |
91 // NEW_RESOURCE_ARRAY(type,size) | 91 // objects which are not inherited from CHeapObj, note constructor and |
92 // destructor are not called. The preferable way to allocate objects | |
93 // is using the new operator. | |
94 // | |
95 // WARNING: The array variant must only be used for a homogenous array | |
96 // where all objects are of the exact type specified. If subtypes are | |
97 // stored in the array then must pay attention to calling destructors | |
98 // at needed. | |
99 // | |
100 // NEW_RESOURCE_ARRAY(type, size) | |
92 // NEW_RESOURCE_OBJ(type) | 101 // NEW_RESOURCE_OBJ(type) |
93 // NEW_C_HEAP_ARRAY(type,size) | 102 // NEW_C_HEAP_ARRAY(type, size) |
94 // NEW_C_HEAP_OBJ(type) | 103 // NEW_C_HEAP_OBJ(type, memflags) |
104 // FREE_C_HEAP_ARRAY(type, old, memflags) | |
105 // FREE_C_HEAP_OBJ(objname, type, memflags) | |
95 // char* AllocateHeap(size_t size, const char* name); | 106 // char* AllocateHeap(size_t size, const char* name); |
96 // void FreeHeap(void* p); | 107 // void FreeHeap(void* p); |
97 // | 108 // |
98 // C-heap allocation can be traced using +PrintHeapAllocation. | 109 // C-heap allocation can be traced using +PrintHeapAllocation. |
99 // malloc and free should therefore never called directly. | 110 // malloc and free should therefore never called directly. |
193 template <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { | 204 template <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC { |
194 public: | 205 public: |
195 _NOINLINE_ void* operator new(size_t size, address caller_pc = 0); | 206 _NOINLINE_ void* operator new(size_t size, address caller_pc = 0); |
196 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant, | 207 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant, |
197 address caller_pc = 0); | 208 address caller_pc = 0); |
198 | 209 _NOINLINE_ void* operator new [](size_t size, address caller_pc = 0); |
210 _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, | |
211 address caller_pc = 0); | |
199 void operator delete(void* p); | 212 void operator delete(void* p); |
213 void operator delete [] (void* p); | |
200 }; | 214 }; |
201 | 215 |
202 // Base class for objects allocated on the stack only. | 216 // Base class for objects allocated on the stack only. |
203 // Calling new or delete will result in fatal error. | 217 // Calling new or delete will result in fatal error. |
204 | 218 |
205 class StackObj ALLOCATION_SUPER_CLASS_SPEC { | 219 class StackObj ALLOCATION_SUPER_CLASS_SPEC { |
206 private: | 220 private: |
207 void* operator new(size_t size); | 221 void* operator new(size_t size); |
208 void operator delete(void* p); | 222 void operator delete(void* p); |
223 void* operator new [](size_t size); | |
224 void operator delete [](void* p); | |
209 }; | 225 }; |
210 | 226 |
211 // Base class for objects used as value objects. | 227 // Base class for objects used as value objects. |
212 // Calling new or delete will result in fatal error. | 228 // Calling new or delete will result in fatal error. |
213 // | 229 // |
227 // be defined as a an empty string "". | 243 // be defined as a an empty string "". |
228 // | 244 // |
229 class _ValueObj { | 245 class _ValueObj { |
230 private: | 246 private: |
231 void* operator new(size_t size); | 247 void* operator new(size_t size); |
232 void operator delete(void* p); | 248 void operator delete(void* p); |
249 void* operator new [](size_t size); | |
250 void operator delete [](void* p); | |
233 }; | 251 }; |
234 | 252 |
235 | 253 |
236 // Base class for objects stored in Metaspace. | 254 // Base class for objects stored in Metaspace. |
237 // Calling delete will result in fatal error. | 255 // Calling delete will result in fatal error. |
516 ~ResourceObj(); | 534 ~ResourceObj(); |
517 #endif // ASSERT | 535 #endif // ASSERT |
518 | 536 |
519 public: | 537 public: |
520 void* operator new(size_t size, allocation_type type, MEMFLAGS flags); | 538 void* operator new(size_t size, allocation_type type, MEMFLAGS flags); |
539 void* operator new [](size_t size, allocation_type type, MEMFLAGS flags); | |
521 void* operator new(size_t size, const std::nothrow_t& nothrow_constant, | 540 void* operator new(size_t size, const std::nothrow_t& nothrow_constant, |
522 allocation_type type, MEMFLAGS flags); | 541 allocation_type type, MEMFLAGS flags); |
542 void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, | |
543 allocation_type type, MEMFLAGS flags); | |
544 | |
523 void* operator new(size_t size, Arena *arena) { | 545 void* operator new(size_t size, Arena *arena) { |
524 address res = (address)arena->Amalloc(size); | 546 address res = (address)arena->Amalloc(size); |
525 DEBUG_ONLY(set_allocation_type(res, ARENA);) | 547 DEBUG_ONLY(set_allocation_type(res, ARENA);) |
526 return res; | 548 return res; |
527 } | 549 } |
550 | |
551 void* operator new [](size_t size, Arena *arena) { | |
552 address res = (address)arena->Amalloc(size); | |
553 DEBUG_ONLY(set_allocation_type(res, ARENA);) | |
554 return res; | |
555 } | |
556 | |
528 void* operator new(size_t size) { | 557 void* operator new(size_t size) { |
529 address res = (address)resource_allocate_bytes(size); | 558 address res = (address)resource_allocate_bytes(size); |
530 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) | 559 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) |
531 return res; | 560 return res; |
532 } | 561 } |
535 address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL); | 564 address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL); |
536 DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);) | 565 DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);) |
537 return res; | 566 return res; |
538 } | 567 } |
539 | 568 |
569 void* operator new [](size_t size) { | |
570 address res = (address)resource_allocate_bytes(size); | |
571 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) | |
572 return res; | |
573 } | |
574 | |
575 void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) { | |
576 address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL); | |
577 DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);) | |
578 return res; | |
579 } | |
580 | |
540 void operator delete(void* p); | 581 void operator delete(void* p); |
582 void operator delete [](void* p); | |
541 }; | 583 }; |
542 | 584 |
543 // One of the following macros must be used when allocating an array | 585 // One of the following macros must be used when allocating an array |
544 // or object to determine whether it should reside in the C heap on in | 586 // or object to determine whether it should reside in the C heap on in |
545 // the resource area. | 587 // the resource area. |
569 (type*) (AllocateHeap((size) * sizeof(type), memflags)) | 611 (type*) (AllocateHeap((size) * sizeof(type), memflags)) |
570 | 612 |
571 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ | 613 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ |
572 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags)) | 614 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags)) |
573 | 615 |
574 #define FREE_C_HEAP_ARRAY(type,old,memflags) \ | 616 #define FREE_C_HEAP_ARRAY(type, old, memflags) \ |
575 FreeHeap((char*)(old), memflags) | 617 FreeHeap((char*)(old), memflags) |
576 | 618 |
619 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\ | |
620 (type*) (AllocateHeap((size) * sizeof(type), memflags, pc)) | |
621 | |
622 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\ | |
623 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc)) | |
624 | |
625 #define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail) \ | |
626 (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail) | |
627 | |
628 // allocate type in heap without calling ctor | |
577 #define NEW_C_HEAP_OBJ(type, memflags)\ | 629 #define NEW_C_HEAP_OBJ(type, memflags)\ |
578 NEW_C_HEAP_ARRAY(type, 1, memflags) | 630 NEW_C_HEAP_ARRAY(type, 1, memflags) |
579 | 631 |
580 | 632 // deallocate obj of type in heap without calling dtor |
581 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\ | 633 #define FREE_C_HEAP_OBJ(objname, memflags)\ |
582 (type*) (AllocateHeap((size) * sizeof(type), memflags, pc)) | 634 FreeHeap((char*)objname, memflags); |
583 | |
584 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\ | |
585 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc)) | |
586 | |
587 #define NEW_C_HEAP_OBJ2(type, memflags, pc)\ | |
588 NEW_C_HEAP_ARRAY2(type, 1, memflags, pc) | |
589 | |
590 | |
591 extern bool warn_new_operator; | |
592 | 635 |
593 // for statistics | 636 // for statistics |
594 #ifndef PRODUCT | 637 #ifndef PRODUCT |
595 class AllocStats : StackObj { | 638 class AllocStats : StackObj { |
596 julong start_mallocs, start_frees; | 639 julong start_mallocs, start_frees; |