comparison src/share/vm/memory/allocation.cpp @ 1688:2dfd013a7465

6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena() Summary: Pass the check in ResourceObj() if _allocation value is already set and object is allocated on stack. Reviewed-by: dholmes, johnc
author kvn
date Mon, 09 Aug 2010 15:17:05 -0700
parents 0e35fa8ebccd
children f4f596978298
comparison
equal deleted inserted replaced
1687:fb8abd207dbe 1688:2dfd013a7465
44 case C_HEAP: 44 case C_HEAP:
45 res = (address)AllocateHeap(size, "C_Heap: ResourceOBJ"); 45 res = (address)AllocateHeap(size, "C_Heap: ResourceOBJ");
46 DEBUG_ONLY(set_allocation_type(res, C_HEAP);) 46 DEBUG_ONLY(set_allocation_type(res, C_HEAP);)
47 break; 47 break;
48 case RESOURCE_AREA: 48 case RESOURCE_AREA:
49 // Will set allocation type in the resource object. 49 // new(size) sets allocation type RESOURCE_AREA.
50 res = (address)operator new(size); 50 res = (address)operator new(size);
51 break; 51 break;
52 default: 52 default:
53 ShouldNotReachHere(); 53 ShouldNotReachHere();
54 } 54 }
64 64
65 #ifdef ASSERT 65 #ifdef ASSERT
66 void ResourceObj::set_allocation_type(address res, allocation_type type) { 66 void ResourceObj::set_allocation_type(address res, allocation_type type) {
67 // Set allocation type in the resource object 67 // Set allocation type in the resource object
68 uintptr_t allocation = (uintptr_t)res; 68 uintptr_t allocation = (uintptr_t)res;
69 assert((allocation & allocation_mask) == 0, "address should be aligned ot 4 bytes at least"); 69 assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least");
70 assert(type <= allocation_mask, "incorrect allocation type"); 70 assert(type <= allocation_mask, "incorrect allocation type");
71 ((ResourceObj *)res)->_allocation = ~(allocation + type); 71 ((ResourceObj *)res)->_allocation = ~(allocation + type);
72 } 72 }
73 73
74 ResourceObj::allocation_type ResourceObj::get_allocation_type() { 74 ResourceObj::allocation_type ResourceObj::get_allocation_type() const {
75 assert(~(_allocation | allocation_mask) == (uintptr_t)this, "lost resource object"); 75 assert(~(_allocation | allocation_mask) == (uintptr_t)this, "lost resource object");
76 return (allocation_type)((~_allocation) & allocation_mask); 76 return (allocation_type)((~_allocation) & allocation_mask);
77 } 77 }
78 78
79 ResourceObj::ResourceObj() { // default construtor 79 ResourceObj::ResourceObj() { // default constructor
80 if (~(_allocation | allocation_mask) != (uintptr_t)this) { 80 if (~(_allocation | allocation_mask) != (uintptr_t)this) {
81 set_allocation_type((address)this, STACK_OR_EMBEDDED); 81 set_allocation_type((address)this, STACK_OR_EMBEDDED);
82 } else if (allocated_on_stack()) {
83 // For some reason we got a value which looks like an allocation on stack.
84 // Pass if it is really allocated on stack.
85 assert(Thread::current()->on_local_stack((address)this),"should be on stack");
82 } else { 86 } else {
83 assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena(), 87 assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena(),
84 "allocation_type should be set by operator new()"); 88 "allocation_type should be set by operator new()");
85 } 89 }
86 } 90 }
87 91
88 ResourceObj::ResourceObj(const ResourceObj& r) { // default copy construtor 92 ResourceObj::ResourceObj(const ResourceObj& r) { // default copy constructor
89 // Used in ClassFileParser::parse_constant_pool_entries() for ClassFileStream. 93 // Used in ClassFileParser::parse_constant_pool_entries() for ClassFileStream.
90 set_allocation_type((address)this, STACK_OR_EMBEDDED); 94 set_allocation_type((address)this, STACK_OR_EMBEDDED);
91 } 95 }
92 96
93 ResourceObj& ResourceObj::operator=(const ResourceObj& r) { // default copy assignment 97 ResourceObj& ResourceObj::operator=(const ResourceObj& r) { // default copy assignment
96 // Keep current _allocation value; 100 // Keep current _allocation value;
97 return *this; 101 return *this;
98 } 102 }
99 103
100 ResourceObj::~ResourceObj() { 104 ResourceObj::~ResourceObj() {
101 if (!allocated_on_C_heap()) { // operator delete() checks C_heap allocation_type. 105 // allocated_on_C_heap() also checks that encoded (in _allocation) address == this.
102 _allocation = badHeapOopVal; 106 if (!allocated_on_C_heap()) { // ResourceObj::delete() zaps _allocation for C_heap.
107 _allocation = badHeapOopVal; // zap type
103 } 108 }
104 } 109 }
105 #endif // ASSERT 110 #endif // ASSERT
106 111
107 112