348
349 //----------------------------------------------------------------------
350 // Base class for objects allocated in the resource area per default.
351 // Optionally, objects may be allocated on the C heap with
352 // new(ResourceObj::C_HEAP) Foo(...) or in an Arena with new (&arena)
353 // ResourceObj's can be allocated within other objects, but don't use
354 // new or delete (allocation_type is unknown). If new is used to allocate,
355 // use delete to deallocate.
356 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
357 public:
358 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 };
359 static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN;
360 #ifdef ASSERT
361 private:
362 // When this object is allocated on stack the new() operator is not
363 // called but garbage on stack may look like a valid allocation_type.
364 // Store negated 'this' pointer when new() is called to distinguish cases.
365 // Use second array's element for verification value to distinguish garbage.
366 uintptr_t _allocation_t[2];
367 bool is_type_set() const;
368 public:
369 allocation_type get_allocation_type() const;
370 bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; }
371 bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; }
372 bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; }
373 bool allocated_on_arena() const { return get_allocation_type() == ARENA; }
374 ResourceObj(); // default constructor
375 ResourceObj(const ResourceObj& r); // default copy constructor
376 ResourceObj& operator=(const ResourceObj& r); // default copy assignment
377 ~ResourceObj();
378 #endif // ASSERT
379
380 public:
381 void* operator new(size_t size, allocation_type type, MEMFLAGS flags) throw();
382 void* operator new [](size_t size, allocation_type type, MEMFLAGS flags) throw();
383 void* operator new(size_t size, const std::nothrow_t& nothrow_constant,
384 allocation_type type, MEMFLAGS flags) throw();
385 void* operator new [](size_t size, const std::nothrow_t& nothrow_constant,
386 allocation_type type, MEMFLAGS flags) throw();
387
388 void* operator new(size_t size, Arena *arena) throw();
389
390 void* operator new [](size_t size, Arena *arena) throw();
391
392 void* operator new(size_t size) throw() {
393 address res = (address)resource_allocate_bytes(size);
|
348
349 //----------------------------------------------------------------------
350 // Base class for objects allocated in the resource area per default.
351 // Optionally, objects may be allocated on the C heap with
352 // new(ResourceObj::C_HEAP) Foo(...) or in an Arena with new (&arena)
353 // ResourceObj's can be allocated within other objects, but don't use
354 // new or delete (allocation_type is unknown). If new is used to allocate,
355 // use delete to deallocate.
356 class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
357 public:
358 enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 };
359 static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN;
360 #ifdef ASSERT
361 private:
362 // When this object is allocated on stack the new() operator is not
363 // called but garbage on stack may look like a valid allocation_type.
364 // Store negated 'this' pointer when new() is called to distinguish cases.
365 // Use second array's element for verification value to distinguish garbage.
366 uintptr_t _allocation_t[2];
367 bool is_type_set() const;
368 void initialize_allocation_info();
369 public:
370 allocation_type get_allocation_type() const;
371 bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; }
372 bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; }
373 bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; }
374 bool allocated_on_arena() const { return get_allocation_type() == ARENA; }
375 protected:
376 ResourceObj(); // default constructor
377 ResourceObj(const ResourceObj& r); // default copy constructor
378 ResourceObj& operator=(const ResourceObj& r); // default copy assignment
379 ~ResourceObj();
380 #endif // ASSERT
381
382 public:
383 void* operator new(size_t size, allocation_type type, MEMFLAGS flags) throw();
384 void* operator new [](size_t size, allocation_type type, MEMFLAGS flags) throw();
385 void* operator new(size_t size, const std::nothrow_t& nothrow_constant,
386 allocation_type type, MEMFLAGS flags) throw();
387 void* operator new [](size_t size, const std::nothrow_t& nothrow_constant,
388 allocation_type type, MEMFLAGS flags) throw();
389
390 void* operator new(size_t size, Arena *arena) throw();
391
392 void* operator new [](size_t size, Arena *arena) throw();
393
394 void* operator new(size_t size) throw() {
395 address res = (address)resource_allocate_bytes(size);
|