src/share/vm/memory/allocation.hpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File
*** old/src/share/vm/memory/allocation.hpp Mon Aug 2 14:26:19 2010
--- new/src/share/vm/memory/allocation.hpp Mon Aug 2 14:26:19 2010
*** 314,349 ****
--- 314,368 ----
// ResourceObj's can be allocated within other objects, but don't use
// new or delete (allocation_type is unknown). If new is used to allocate,
// use delete to deallocate.
class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
public:
! enum allocation_type { UNKNOWN = 0, C_HEAP, RESOURCE_AREA, ARENA };
! enum allocation_type { RESOURCE_AREA = 0, C_HEAP, ARENA, allocation_mask = 0x3 };
#ifdef ASSERT
private:
allocation_type _allocation;
+ // When this object is allocated on stack the new() operator is not
+ // called but garbage on stack may look like a valid allocation_type.
+ // Store negated 'this' pointer when new() is called to distinguish cases.
+ uintptr_t _allocation;
+ static void set_allocation_type(address res, allocation_type type) {
+ // Set allocation type in the resource object
+ uintptr_t allocation = (uintptr_t)res;
+ assert((allocation & allocation_mask) == 0, "");
+ assert(type < allocation_mask, "");
+ ((ResourceObj *)res)->_allocation = ~(allocation + type);
+ }
+ allocation_type get_allocation_type() {
+ return (allocation_type)((~_allocation) & allocation_mask);
+ }
public:
! bool allocated_on_C_heap() { return _allocation == C_HEAP; }
! bool allocated_on_stack() { return get_allocation_type() == RESOURCE_AREA; }
+ bool allocated_on_C_heap() { return get_allocation_type() == C_HEAP; }
+ bool allocated_on_arena() { return get_allocation_type() == ARENA; }
+ ResourceObj() {
+ if (~(_allocation | allocation_mask) != (uintptr_t)this) {
+ set_allocation_type((address)this, RESOURCE_AREA);
+ } else {
+ assert(allocated_on_stack() || allocated_on_C_heap() || allocated_on_arena(), "");
+ }
+ }
#endif // ASSERT
public:
void* operator new(size_t size, allocation_type type);
void* operator new(size_t size, Arena *arena) {
address res = (address)arena->Amalloc(size);
// Set allocation type in the resource object
DEBUG_ONLY(((ResourceObj *)res)->_allocation = ARENA;)
+ DEBUG_ONLY(set_allocation_type(res, ARENA);)
return res;
}
void* operator new(size_t size) {
address res = (address)resource_allocate_bytes(size);
// Set allocation type in the resource object
DEBUG_ONLY(((ResourceObj *)res)->_allocation = RESOURCE_AREA;)
+ DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
return res;
}
void* operator new(size_t size, void* where, allocation_type type) {
! void* res = where;
// Set allocation type in the resource object
DEBUG_ONLY(((ResourceObj *)res)->_allocation = type;)
! address res = (address)where;
+ DEBUG_ONLY(set_allocation_type(res, C_HEAP);)
return res;
}
void operator delete(void* p);
};
src/share/vm/memory/allocation.hpp
Index
Unified diffs
Context diffs
Sdiffs
Wdiffs
Patch
New
Old
Previous File
Next File