26 # include "incls/_allocation.cpp.incl" 27 28 void* CHeapObj::operator new(size_t size){ 29 return (void *) AllocateHeap(size, "CHeapObj-new"); 30 } 31 32 void CHeapObj::operator delete(void* p){ 33 FreeHeap(p); 34 } 35 36 void* StackObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; 37 void StackObj::operator delete(void* p) { ShouldNotCallThis(); }; 38 void* _ValueObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; 39 void _ValueObj::operator delete(void* p) { ShouldNotCallThis(); }; 40 41 void* ResourceObj::operator new(size_t size, allocation_type type) { 42 address res; 43 switch (type) { 44 case C_HEAP: 45 res = (address)AllocateHeap(size, "C_Heap: ResourceOBJ"); 46 break; 47 case RESOURCE_AREA: 48 res = (address)operator new(size); 49 break; 50 default: 51 ShouldNotReachHere(); 52 } 53 // Set allocation type in the resource object for assertion checks. 54 DEBUG_ONLY(((ResourceObj *)res)->_allocation = type;) 55 return res; 56 } 57 58 void ResourceObj::operator delete(void* p) { 59 assert(((ResourceObj *)p)->allocated_on_C_heap(), 60 "delete only allowed for C_HEAP objects"); 61 FreeHeap(p); 62 } 63 64 void trace_heap_malloc(size_t size, const char* name, void* p) { 65 // A lock is not needed here - tty uses a lock internally 66 tty->print_cr("Heap malloc " INTPTR_FORMAT " %7d %s", p, size, name == NULL ? "" : name); 67 } 68 69 70 void trace_heap_free(void* p) { 71 // A lock is not needed here - tty uses a lock internally 72 tty->print_cr("Heap free " INTPTR_FORMAT, p); 73 } 74 75 bool warn_new_operator = false; // see vm_main 76 77 //-------------------------------------------------------------------------------------- 78 // ChunkPool implementation 79 80 // MT-safe pool of chunks to reduce malloc/free thrashing 81 // NB: not using Mutex because pools are used before Threads are initialized 82 class ChunkPool { 83 Chunk* _first; // first cached Chunk; its first word points to next chunk | 26 # include "incls/_allocation.cpp.incl" 27 28 void* CHeapObj::operator new(size_t size){ 29 return (void *) AllocateHeap(size, "CHeapObj-new"); 30 } 31 32 void CHeapObj::operator delete(void* p){ 33 FreeHeap(p); 34 } 35 36 void* StackObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; 37 void StackObj::operator delete(void* p) { ShouldNotCallThis(); }; 38 void* _ValueObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; 39 void _ValueObj::operator delete(void* p) { ShouldNotCallThis(); }; 40 41 void* ResourceObj::operator new(size_t size, allocation_type type) { 42 address res; 43 switch (type) { 44 case C_HEAP: 45 res = (address)AllocateHeap(size, "C_Heap: ResourceOBJ"); 46 DEBUG_ONLY(set_allocation_type(res, C_HEAP);) 47 break; 48 case RESOURCE_AREA: 49 // Will set allocation type in the resource object. 50 res = (address)operator new(size); 51 break; 52 default: 53 ShouldNotReachHere(); 54 } 55 return res; 56 } 57 58 void ResourceObj::operator delete(void* p) { 59 assert(((ResourceObj *)p)->allocated_on_C_heap(), 60 "delete only allowed for C_HEAP objects"); 61 DEBUG_ONLY(((ResourceObj *)p)->_allocation = badHeapOopVal;) 62 FreeHeap(p); 63 } 64 65 #ifdef ASSERT 66 void ResourceObj::set_allocation_type(address res, allocation_type type) { 67 // Set allocation type in the resource object 68 uintptr_t allocation = (uintptr_t)res; 69 assert((allocation & allocation_mask) == 0, "address should be aligned ot 4 bytes at least"); 70 assert(type <= allocation_mask, "incorrect allocation type"); 71 ((ResourceObj *)res)->_allocation = ~(allocation + type); 72 } 73 74 ResourceObj::allocation_type ResourceObj::get_allocation_type() { 75 assert(~(_allocation | allocation_mask) == (uintptr_t)this, "lost resource object"); 76 return (allocation_type)((~_allocation) & allocation_mask); 77 } 78 79 ResourceObj::ResourceObj() { // default construtor 80 if (~(_allocation | allocation_mask) != (uintptr_t)this) { 81 set_allocation_type((address)this, STACK_OR_EMBEDDED); 82 } else { 83 assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena(), 84 "allocation_type should be set by operator new()"); 85 } 86 } 87 88 ResourceObj::ResourceObj(const ResourceObj& r) { // default copy construtor 89 // Used in ClassFileParser::parse_constant_pool_entries() for ClassFileStream. 90 set_allocation_type((address)this, STACK_OR_EMBEDDED); 91 } 92 93 ResourceObj& ResourceObj::operator=(const ResourceObj& r) { // default copy assignment 94 // Used in InlineTree::ok_to_inline() for WarmCallInfo. 95 assert(allocated_on_stack(), "copy only into local"); 96 // Keep current _allocation value; 97 return *this; 98 } 99 100 ResourceObj::~ResourceObj() { 101 if (!allocated_on_C_heap()) { // operator delete() checks C_heap allocation_type. 102 _allocation = badHeapOopVal; 103 } 104 } 105 #endif // ASSERT 106 107 108 void trace_heap_malloc(size_t size, const char* name, void* p) { 109 // A lock is not needed here - tty uses a lock internally 110 tty->print_cr("Heap malloc " INTPTR_FORMAT " %7d %s", p, size, name == NULL ? "" : name); 111 } 112 113 114 void trace_heap_free(void* p) { 115 // A lock is not needed here - tty uses a lock internally 116 tty->print_cr("Heap free " INTPTR_FORMAT, p); 117 } 118 119 bool warn_new_operator = false; // see vm_main 120 121 //-------------------------------------------------------------------------------------- 122 // ChunkPool implementation 123 124 // MT-safe pool of chunks to reduce malloc/free thrashing 125 // NB: not using Mutex because pools are used before Threads are initialized 126 class ChunkPool { 127 Chunk* _first; // first cached Chunk; its first word points to next chunk |