hotspot/src/share/vm/memory/allocation.hpp
changeset 18109 c4a4f293ad06
parent 18066 b4b1f65075e5
parent 18094 1856e0a7879d
child 18453 4056af328b00
equal deleted inserted replaced
18067:916d656dadf8 18109:c4a4f293ad06
   641   (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
   641   (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
   642 
   642 
   643 #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\
   643 #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\
   644   (type*) resource_allocate_bytes(thread, (size) * sizeof(type))
   644   (type*) resource_allocate_bytes(thread, (size) * sizeof(type))
   645 
   645 
       
   646 #define NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(thread, type, size)\
       
   647   (type*) resource_allocate_bytes(thread, (size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
       
   648 
   646 #define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\
   649 #define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\
   647   (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type) )
   650   (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type))
       
   651 
       
   652 #define REALLOC_RESOURCE_ARRAY_RETURN_NULL(type, old, old_size, new_size)\
       
   653   (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type),\
       
   654                                     (new_size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
   648 
   655 
   649 #define FREE_RESOURCE_ARRAY(type, old, size)\
   656 #define FREE_RESOURCE_ARRAY(type, old, size)\
   650   resource_free_bytes((char*)(old), (size) * sizeof(type))
   657   resource_free_bytes((char*)(old), (size) * sizeof(type))
   651 
   658 
   652 #define FREE_FAST(old)\
   659 #define FREE_FAST(old)\
   653     /* nop */
   660     /* nop */
   654 
   661 
   655 #define NEW_RESOURCE_OBJ(type)\
   662 #define NEW_RESOURCE_OBJ(type)\
   656   NEW_RESOURCE_ARRAY(type, 1)
   663   NEW_RESOURCE_ARRAY(type, 1)
   657 
   664 
       
   665 #define NEW_RESOURCE_OBJ_RETURN_NULL(type)\
       
   666   NEW_RESOURCE_ARRAY_RETURN_NULL(type, 1)
       
   667 
       
   668 #define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)\
       
   669   (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
       
   670 
       
   671 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
       
   672   (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
       
   673 
   658 #define NEW_C_HEAP_ARRAY(type, size, memflags)\
   674 #define NEW_C_HEAP_ARRAY(type, size, memflags)\
   659   (type*) (AllocateHeap((size) * sizeof(type), memflags))
   675   (type*) (AllocateHeap((size) * sizeof(type), memflags))
   660 
   676 
       
   677 #define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\
       
   678   NEW_C_HEAP_ARRAY3(type, size, memflags, pc, AllocFailStrategy::RETURN_NULL)
       
   679 
       
   680 #define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\
       
   681   NEW_C_HEAP_ARRAY3(type, size, memflags, (address)0, AllocFailStrategy::RETURN_NULL)
       
   682 
   661 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
   683 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
   662   (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
   684   (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
   663 
   685 
       
   686 #define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\
       
   687    (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, AllocFailStrategy::RETURN_NULL))
       
   688 
   664 #define FREE_C_HEAP_ARRAY(type, old, memflags) \
   689 #define FREE_C_HEAP_ARRAY(type, old, memflags) \
   665   FreeHeap((char*)(old), memflags)
   690   FreeHeap((char*)(old), memflags)
   666 
       
   667 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
       
   668   (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
       
   669 
       
   670 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\
       
   671   (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc))
       
   672 
       
   673 #define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)         \
       
   674   (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
       
   675 
   691 
   676 // allocate type in heap without calling ctor
   692 // allocate type in heap without calling ctor
   677 #define NEW_C_HEAP_OBJ(type, memflags)\
   693 #define NEW_C_HEAP_OBJ(type, memflags)\
   678   NEW_C_HEAP_ARRAY(type, 1, memflags)
   694   NEW_C_HEAP_ARRAY(type, 1, memflags)
       
   695 
       
   696 #define NEW_C_HEAP_OBJ_RETURN_NULL(type, memflags)\
       
   697   NEW_C_HEAP_ARRAY_RETURN_NULL(type, 1, memflags)
   679 
   698 
   680 // deallocate obj of type in heap without calling dtor
   699 // deallocate obj of type in heap without calling dtor
   681 #define FREE_C_HEAP_OBJ(objname, memflags)\
   700 #define FREE_C_HEAP_OBJ(objname, memflags)\
   682   FreeHeap((char*)objname, memflags);
   701   FreeHeap((char*)objname, memflags);
   683 
   702 
   719 // Most OS mallocs do something similar but Solaris malloc does not revert
   738 // Most OS mallocs do something similar but Solaris malloc does not revert
   720 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
   739 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
   721 // is set so that we always use malloc except for Solaris where we set the
   740 // is set so that we always use malloc except for Solaris where we set the
   722 // limit to get mapped memory.
   741 // limit to get mapped memory.
   723 template <class E, MEMFLAGS F>
   742 template <class E, MEMFLAGS F>
   724 class ArrayAllocator : StackObj {
   743 class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
   725   char* _addr;
   744   char* _addr;
   726   bool _use_malloc;
   745   bool _use_malloc;
   727   size_t _size;
   746   size_t _size;
   728  public:
   747   bool _free_in_destructor;
   729   ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { }
   748  public:
   730   ~ArrayAllocator() { free(); }
   749   ArrayAllocator(bool free_in_destructor = true) :
       
   750     _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
       
   751 
       
   752   ~ArrayAllocator() {
       
   753     if (_free_in_destructor) {
       
   754       free();
       
   755     }
       
   756   }
       
   757 
   731   E* allocate(size_t length);
   758   E* allocate(size_t length);
   732   void free();
   759   void free();
   733 };
   760 };
   734 
   761 
   735 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP
   762 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP