1.1 --- a/src/share/vm/memory/allocation.hpp Thu May 16 11:44:33 2013 +0100 1.2 +++ b/src/share/vm/memory/allocation.hpp Thu May 23 12:44:18 2013 +0100 1.3 @@ -86,12 +86,23 @@ 1.4 // subclasses. 1.5 // 1.6 // The following macros and function should be used to allocate memory 1.7 -// directly in the resource area or in the C-heap: 1.8 +// directly in the resource area or in the C-heap, The _OBJ variants 1.9 +// of the NEW/FREE_C_HEAP macros are used for alloc/dealloc simple 1.10 +// objects which are not inherited from CHeapObj, note constructor and 1.11 +// destructor are not called. The preferable way to allocate objects 1.12 +// is using the new operator. 1.13 // 1.14 -// NEW_RESOURCE_ARRAY(type,size) 1.15 +// WARNING: The array variant must only be used for a homogenous array 1.16 +// where all objects are of the exact type specified. If subtypes are 1.17 +// stored in the array then must pay attention to calling destructors 1.18 +// at needed. 1.19 +// 1.20 +// NEW_RESOURCE_ARRAY(type, size) 1.21 // NEW_RESOURCE_OBJ(type) 1.22 -// NEW_C_HEAP_ARRAY(type,size) 1.23 -// NEW_C_HEAP_OBJ(type) 1.24 +// NEW_C_HEAP_ARRAY(type, size) 1.25 +// NEW_C_HEAP_OBJ(type, memflags) 1.26 +// FREE_C_HEAP_ARRAY(type, old, memflags) 1.27 +// FREE_C_HEAP_OBJ(objname, type, memflags) 1.28 // char* AllocateHeap(size_t size, const char* name); 1.29 // void FreeHeap(void* p); 1.30 // 1.31 @@ -195,8 +206,11 @@ 1.32 _NOINLINE_ void* operator new(size_t size, address caller_pc = 0); 1.33 _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant, 1.34 address caller_pc = 0); 1.35 - 1.36 + _NOINLINE_ void* operator new [](size_t size, address caller_pc = 0); 1.37 + _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, 1.38 + address caller_pc = 0); 1.39 void operator delete(void* p); 1.40 + void operator delete [] (void* p); 1.41 }; 1.42 1.43 // Base class for objects allocated on the stack only. 1.44 @@ -206,6 +220,8 @@ 1.45 private: 1.46 void* operator new(size_t size); 1.47 void operator delete(void* p); 1.48 + void* operator new [](size_t size); 1.49 + void operator delete [](void* p); 1.50 }; 1.51 1.52 // Base class for objects used as value objects. 1.53 @@ -229,7 +245,9 @@ 1.54 class _ValueObj { 1.55 private: 1.56 void* operator new(size_t size); 1.57 - void operator delete(void* p); 1.58 + void operator delete(void* p); 1.59 + void* operator new [](size_t size); 1.60 + void operator delete [](void* p); 1.61 }; 1.62 1.63 1.64 @@ -518,13 +536,24 @@ 1.65 1.66 public: 1.67 void* operator new(size_t size, allocation_type type, MEMFLAGS flags); 1.68 + void* operator new [](size_t size, allocation_type type, MEMFLAGS flags); 1.69 void* operator new(size_t size, const std::nothrow_t& nothrow_constant, 1.70 allocation_type type, MEMFLAGS flags); 1.71 + void* operator new [](size_t size, const std::nothrow_t& nothrow_constant, 1.72 + allocation_type type, MEMFLAGS flags); 1.73 + 1.74 void* operator new(size_t size, Arena *arena) { 1.75 address res = (address)arena->Amalloc(size); 1.76 DEBUG_ONLY(set_allocation_type(res, ARENA);) 1.77 return res; 1.78 } 1.79 + 1.80 + void* operator new [](size_t size, Arena *arena) { 1.81 + address res = (address)arena->Amalloc(size); 1.82 + DEBUG_ONLY(set_allocation_type(res, ARENA);) 1.83 + return res; 1.84 + } 1.85 + 1.86 void* operator new(size_t size) { 1.87 address res = (address)resource_allocate_bytes(size); 1.88 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) 1.89 @@ -537,7 +566,20 @@ 1.90 return res; 1.91 } 1.92 1.93 + void* operator new [](size_t size) { 1.94 + address res = (address)resource_allocate_bytes(size); 1.95 + DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) 1.96 + return res; 1.97 + } 1.98 + 1.99 + void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) { 1.100 + address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL); 1.101 + DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);) 1.102 + return res; 1.103 + } 1.104 + 1.105 void operator delete(void* p); 1.106 + void operator delete [](void* p); 1.107 }; 1.108 1.109 // One of the following macros must be used when allocating an array 1.110 @@ -571,24 +613,25 @@ 1.111 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ 1.112 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags)) 1.113 1.114 -#define FREE_C_HEAP_ARRAY(type,old,memflags) \ 1.115 +#define FREE_C_HEAP_ARRAY(type, old, memflags) \ 1.116 FreeHeap((char*)(old), memflags) 1.117 1.118 -#define NEW_C_HEAP_OBJ(type, memflags)\ 1.119 - NEW_C_HEAP_ARRAY(type, 1, memflags) 1.120 - 1.121 - 1.122 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\ 1.123 (type*) (AllocateHeap((size) * sizeof(type), memflags, pc)) 1.124 1.125 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\ 1.126 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc)) 1.127 1.128 -#define NEW_C_HEAP_OBJ2(type, memflags, pc)\ 1.129 - NEW_C_HEAP_ARRAY2(type, 1, memflags, pc) 1.130 +#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail) \ 1.131 + (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail) 1.132 1.133 +// allocate type in heap without calling ctor 1.134 +#define NEW_C_HEAP_OBJ(type, memflags)\ 1.135 + NEW_C_HEAP_ARRAY(type, 1, memflags) 1.136 1.137 -extern bool warn_new_operator; 1.138 +// deallocate obj of type in heap without calling dtor 1.139 +#define FREE_C_HEAP_OBJ(objname, memflags)\ 1.140 + FreeHeap((char*)objname, memflags); 1.141 1.142 // for statistics 1.143 #ifndef PRODUCT