1.1 --- a/src/share/vm/memory/allocation.cpp Fri Aug 06 11:53:28 2010 -0700 1.2 +++ b/src/share/vm/memory/allocation.cpp Mon Aug 09 15:17:05 2010 -0700 1.3 @@ -46,7 +46,7 @@ 1.4 DEBUG_ONLY(set_allocation_type(res, C_HEAP);) 1.5 break; 1.6 case RESOURCE_AREA: 1.7 - // Will set allocation type in the resource object. 1.8 + // new(size) sets allocation type RESOURCE_AREA. 1.9 res = (address)operator new(size); 1.10 break; 1.11 default: 1.12 @@ -66,26 +66,30 @@ 1.13 void ResourceObj::set_allocation_type(address res, allocation_type type) { 1.14 // Set allocation type in the resource object 1.15 uintptr_t allocation = (uintptr_t)res; 1.16 - assert((allocation & allocation_mask) == 0, "address should be aligned ot 4 bytes at least"); 1.17 + assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least"); 1.18 assert(type <= allocation_mask, "incorrect allocation type"); 1.19 ((ResourceObj *)res)->_allocation = ~(allocation + type); 1.20 } 1.21 1.22 -ResourceObj::allocation_type ResourceObj::get_allocation_type() { 1.23 +ResourceObj::allocation_type ResourceObj::get_allocation_type() const { 1.24 assert(~(_allocation | allocation_mask) == (uintptr_t)this, "lost resource object"); 1.25 return (allocation_type)((~_allocation) & allocation_mask); 1.26 } 1.27 1.28 -ResourceObj::ResourceObj() { // default construtor 1.29 +ResourceObj::ResourceObj() { // default constructor 1.30 if (~(_allocation | allocation_mask) != (uintptr_t)this) { 1.31 set_allocation_type((address)this, STACK_OR_EMBEDDED); 1.32 + } else if (allocated_on_stack()) { 1.33 + // For some reason we got a value which looks like an allocation on stack. 1.34 + // Pass if it is really allocated on stack. 1.35 + assert(Thread::current()->on_local_stack((address)this),"should be on stack"); 1.36 } else { 1.37 assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena(), 1.38 "allocation_type should be set by operator new()"); 1.39 } 1.40 } 1.41 1.42 -ResourceObj::ResourceObj(const ResourceObj& r) { // default copy construtor 1.43 +ResourceObj::ResourceObj(const ResourceObj& r) { // default copy constructor 1.44 // Used in ClassFileParser::parse_constant_pool_entries() for ClassFileStream. 1.45 set_allocation_type((address)this, STACK_OR_EMBEDDED); 1.46 } 1.47 @@ -98,8 +102,9 @@ 1.48 } 1.49 1.50 ResourceObj::~ResourceObj() { 1.51 - if (!allocated_on_C_heap()) { // operator delete() checks C_heap allocation_type. 1.52 - _allocation = badHeapOopVal; 1.53 + // allocated_on_C_heap() also checks that encoded (in _allocation) address == this. 1.54 + if (!allocated_on_C_heap()) { // ResourceObj::delete() zaps _allocation for C_heap. 1.55 + _allocation = badHeapOopVal; // zap type 1.56 } 1.57 } 1.58 #endif // ASSERT