559 // new or delete (allocation_type is unknown). If new is used to allocate,
560 // use delete to deallocate.
561 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
562 public:
563 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 };
564 static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN;
565 #ifdef ASSERT
566 private:
567 // When this object is allocated on stack the new() operator is not
568 // called but garbage on stack may look like a valid allocation_type.
569 // Store negated 'this' pointer when new() is called to distinguish cases.
570 // Use second array's element for verification value to distinguish garbage.
571 uintptr_t _allocation_t[2];
572 bool is_type_set() const;
573 public:
574 allocation_type get_allocation_type() const;
575 bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; }
576 bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; }
577 bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; }
578 bool allocated_on_arena() const { return get_allocation_type() == ARENA; }
579 ResourceObj(); // default construtor
580 ResourceObj(const ResourceObj& r); // default copy construtor
581 ResourceObj& operator=(const ResourceObj& r); // default copy assignment
582 ~ResourceObj();
583 #endif // ASSERT
584
585 public:
586 void* operator new(size_t size, allocation_type type, MEMFLAGS flags) throw();
587 void* operator new [](size_t size, allocation_type type, MEMFLAGS flags) throw();
588 void* operator new(size_t size, const std::nothrow_t& nothrow_constant,
589 allocation_type type, MEMFLAGS flags) throw();
590 void* operator new [](size_t size, const std::nothrow_t& nothrow_constant,
591 allocation_type type, MEMFLAGS flags) throw();
592
593 void* operator new(size_t size, Arena *arena) throw() {
594 address res = (address)arena->Amalloc(size);
595 DEBUG_ONLY(set_allocation_type(res, ARENA);)
596 return res;
597 }
598
599 void* operator new [](size_t size, Arena *arena) throw() {
600 address res = (address)arena->Amalloc(size);
|
559 // new or delete (allocation_type is unknown). If new is used to allocate,
560 // use delete to deallocate.
561 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
562 public:
563 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 };
564 static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN;
565 #ifdef ASSERT
566 private:
567 // When this object is allocated on stack the new() operator is not
568 // called but garbage on stack may look like a valid allocation_type.
569 // Store negated 'this' pointer when new() is called to distinguish cases.
570 // Use second array's element for verification value to distinguish garbage.
571 uintptr_t _allocation_t[2];
572 bool is_type_set() const;
573 public:
574 allocation_type get_allocation_type() const;
575 bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; }
576 bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; }
577 bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; }
578 bool allocated_on_arena() const { return get_allocation_type() == ARENA; }
579 ResourceObj(); // default constructor
580 ResourceObj(const ResourceObj& r); // default copy constructor
581 ResourceObj& operator=(const ResourceObj& r); // default copy assignment
582 ~ResourceObj();
583 #endif // ASSERT
584
585 public:
586 void* operator new(size_t size, allocation_type type, MEMFLAGS flags) throw();
587 void* operator new [](size_t size, allocation_type type, MEMFLAGS flags) throw();
588 void* operator new(size_t size, const std::nothrow_t& nothrow_constant,
589 allocation_type type, MEMFLAGS flags) throw();
590 void* operator new [](size_t size, const std::nothrow_t& nothrow_constant,
591 allocation_type type, MEMFLAGS flags) throw();
592
593 void* operator new(size_t size, Arena *arena) throw() {
594 address res = (address)arena->Amalloc(size);
595 DEBUG_ONLY(set_allocation_type(res, ARENA);)
596 return res;
597 }
598
599 void* operator new [](size_t size, Arena *arena) throw() {
600 address res = (address)arena->Amalloc(size);
|