src/share/vm/memory/allocation.hpp

changeset 5295
9f3e3245b50f
parent 5252
3a0774193f71
parent 5280
9f9c0a163cc5
child 5321
2b9380b0bf0b
     1.1 --- a/src/share/vm/memory/allocation.hpp	Mon Jun 24 14:27:24 2013 -0700
     1.2 +++ b/src/share/vm/memory/allocation.hpp	Tue Jun 25 12:46:21 2013 -0700
     1.3 @@ -643,8 +643,15 @@
     1.4  #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\
     1.5    (type*) resource_allocate_bytes(thread, (size) * sizeof(type))
     1.6  
     1.7 +#define NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(thread, type, size)\
     1.8 +  (type*) resource_allocate_bytes(thread, (size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
     1.9 +
    1.10  #define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\
    1.11 -  (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type) )
    1.12 +  (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type))
    1.13 +
    1.14 +#define REALLOC_RESOURCE_ARRAY_RETURN_NULL(type, old, old_size, new_size)\
    1.15 +  (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type),\
    1.16 +                                    (new_size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
    1.17  
    1.18  #define FREE_RESOURCE_ARRAY(type, old, size)\
    1.19    resource_free_bytes((char*)(old), (size) * sizeof(type))
    1.20 @@ -655,28 +662,40 @@
    1.21  #define NEW_RESOURCE_OBJ(type)\
    1.22    NEW_RESOURCE_ARRAY(type, 1)
    1.23  
    1.24 +#define NEW_RESOURCE_OBJ_RETURN_NULL(type)\
    1.25 +  NEW_RESOURCE_ARRAY_RETURN_NULL(type, 1)
    1.26 +
    1.27 +#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)\
    1.28 +  (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
    1.29 +
    1.30 +#define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
    1.31 +  (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
    1.32 +
    1.33  #define NEW_C_HEAP_ARRAY(type, size, memflags)\
    1.34    (type*) (AllocateHeap((size) * sizeof(type), memflags))
    1.35  
    1.36 +#define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\
    1.37 +  NEW_C_HEAP_ARRAY3(type, size, memflags, pc, AllocFailStrategy::RETURN_NULL)
    1.38 +
    1.39 +#define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\
    1.40 +  NEW_C_HEAP_ARRAY3(type, size, memflags, (address)0, AllocFailStrategy::RETURN_NULL)
    1.41 +
    1.42  #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
    1.43    (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
    1.44  
    1.45 +#define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\
    1.46 +   (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, AllocFailStrategy::RETURN_NULL))
    1.47 +
    1.48  #define FREE_C_HEAP_ARRAY(type, old, memflags) \
    1.49    FreeHeap((char*)(old), memflags)
    1.50  
    1.51 -#define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
    1.52 -  (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
    1.53 -
    1.54 -#define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\
    1.55 -  (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc))
    1.56 -
    1.57 -#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)         \
    1.58 -  (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
    1.59 -
    1.60  // allocate type in heap without calling ctor
    1.61  #define NEW_C_HEAP_OBJ(type, memflags)\
    1.62    NEW_C_HEAP_ARRAY(type, 1, memflags)
    1.63  
    1.64 +#define NEW_C_HEAP_OBJ_RETURN_NULL(type, memflags)\
    1.65 +  NEW_C_HEAP_ARRAY_RETURN_NULL(type, 1, memflags)
    1.66 +
    1.67  // deallocate obj of type in heap without calling dtor
    1.68  #define FREE_C_HEAP_OBJ(objname, memflags)\
    1.69    FreeHeap((char*)objname, memflags);
    1.70 @@ -721,13 +740,21 @@
    1.71  // is set so that we always use malloc except for Solaris where we set the
    1.72  // limit to get mapped memory.
    1.73  template <class E, MEMFLAGS F>
    1.74 -class ArrayAllocator : StackObj {
    1.75 +class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
    1.76    char* _addr;
    1.77    bool _use_malloc;
    1.78    size_t _size;
    1.79 +  bool _free_in_destructor;
    1.80   public:
    1.81 -  ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { }
    1.82 -  ~ArrayAllocator() { free(); }
    1.83 +  ArrayAllocator(bool free_in_destructor = true) :
    1.84 +    _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
    1.85 +
    1.86 +  ~ArrayAllocator() {
    1.87 +    if (_free_in_destructor) {
    1.88 +      free();
    1.89 +    }
    1.90 +  }
    1.91 +
    1.92    E* allocate(size_t length);
    1.93    void free();
    1.94  };

mercurial