src/share/vm/memory/allocation.hpp

changeset 2043
2dfd013a7465
parent 2040
0e35fa8ebccd
child 2044
f4f596978298
equal deleted inserted replaced
2042:fb8abd207dbe 2043:2dfd013a7465
315 // new or delete (allocation_type is unknown). If new is used to allocate, 315 // new or delete (allocation_type is unknown). If new is used to allocate,
316 // use delete to deallocate. 316 // use delete to deallocate.
317 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC { 317 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
318 public: 318 public:
319 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 }; 319 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 };
320 static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN;
320 #ifdef ASSERT 321 #ifdef ASSERT
321 private: 322 private:
322 // When this object is allocated on stack the new() operator is not 323 // When this object is allocated on stack the new() operator is not
323 // called but garbage on stack may look like a valid allocation_type. 324 // called but garbage on stack may look like a valid allocation_type.
324 // Store negated 'this' pointer when new() is called to distinguish cases. 325 // Store negated 'this' pointer when new() is called to distinguish cases.
325 uintptr_t _allocation; 326 uintptr_t _allocation;
326 public: 327 public:
327 static void set_allocation_type(address res, allocation_type type); 328 allocation_type get_allocation_type() const;
328 allocation_type get_allocation_type(); 329 bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; }
329 bool allocated_on_stack() { return get_allocation_type() == STACK_OR_EMBEDDED; } 330 bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; }
330 bool allocated_on_res_area() { return get_allocation_type() == RESOURCE_AREA; } 331 bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; }
331 bool allocated_on_C_heap() { return get_allocation_type() == C_HEAP; } 332 bool allocated_on_arena() const { return get_allocation_type() == ARENA; }
332 bool allocated_on_arena() { return get_allocation_type() == ARENA; }
333 ResourceObj(); // default construtor 333 ResourceObj(); // default construtor
334 ResourceObj(const ResourceObj& r); // default copy construtor 334 ResourceObj(const ResourceObj& r); // default copy construtor
335 ResourceObj& operator=(const ResourceObj& r); // default copy assignment 335 ResourceObj& operator=(const ResourceObj& r); // default copy assignment
336 ~ResourceObj(); 336 ~ResourceObj();
337 #endif // ASSERT 337 #endif // ASSERT
344 return res; 344 return res;
345 } 345 }
346 void* operator new(size_t size) { 346 void* operator new(size_t size) {
347 address res = (address)resource_allocate_bytes(size); 347 address res = (address)resource_allocate_bytes(size);
348 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) 348 DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
349 return res;
350 }
351 void* operator new(size_t size, void* where, allocation_type type) {
352 address res = (address)where;
353 DEBUG_ONLY(set_allocation_type(res, type);)
354 return res; 349 return res;
355 } 350 }
356 void operator delete(void* p); 351 void operator delete(void* p);
357 }; 352 };
358 353

mercurial