src/share/vm/memory/allocation.hpp

changeset 5103
f9be75d21404
parent 4987
f258c5828eb8
child 5208
a1ebd310d5c1
child 5249
ce9ecec70f99
     1.1 --- a/src/share/vm/memory/allocation.hpp	Tue May 14 11:34:30 2013 +0400
     1.2 +++ b/src/share/vm/memory/allocation.hpp	Tue May 14 09:41:12 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -86,12 +86,23 @@
    1.11  // subclasses.
    1.12  //
    1.13  // The following macros and function should be used to allocate memory
    1.14 -// directly in the resource area or in the C-heap:
    1.15 +// directly in the resource area or in the C-heap, The _OBJ variants
    1.16 +// of the NEW/FREE_C_HEAP macros are used for alloc/dealloc simple
    1.17 +// objects which are not inherited from CHeapObj, note constructor and
    1.18 +// destructor are not called. The preferable way to allocate objects
    1.19 +// is using the new operator.
    1.20  //
    1.21 -//   NEW_RESOURCE_ARRAY(type,size)
    1.22 +// WARNING: The array variant must only be used for a homogenous array
    1.23 +// where all objects are of the exact type specified. If subtypes are
    1.24 +// stored in the array then must pay attention to calling destructors
    1.25 +// at needed.
    1.26 +//
    1.27 +//   NEW_RESOURCE_ARRAY(type, size)
    1.28  //   NEW_RESOURCE_OBJ(type)
    1.29 -//   NEW_C_HEAP_ARRAY(type,size)
    1.30 -//   NEW_C_HEAP_OBJ(type)
    1.31 +//   NEW_C_HEAP_ARRAY(type, size)
    1.32 +//   NEW_C_HEAP_OBJ(type, memflags)
    1.33 +//   FREE_C_HEAP_ARRAY(type, old, memflags)
    1.34 +//   FREE_C_HEAP_OBJ(objname, type, memflags)
    1.35  //   char* AllocateHeap(size_t size, const char* name);
    1.36  //   void  FreeHeap(void* p);
    1.37  //
    1.38 @@ -195,8 +206,11 @@
    1.39    _NOINLINE_ void* operator new(size_t size, address caller_pc = 0);
    1.40    _NOINLINE_ void* operator new (size_t size, const std::nothrow_t&  nothrow_constant,
    1.41                                 address caller_pc = 0);
    1.42 -
    1.43 +  _NOINLINE_ void* operator new [](size_t size, address caller_pc = 0);
    1.44 +  _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
    1.45 +                               address caller_pc = 0);
    1.46    void  operator delete(void* p);
    1.47 +  void  operator delete [] (void* p);
    1.48  };
    1.49  
    1.50  // Base class for objects allocated on the stack only.
    1.51 @@ -206,6 +220,8 @@
    1.52   private:
    1.53    void* operator new(size_t size);
    1.54    void  operator delete(void* p);
    1.55 +  void* operator new [](size_t size);
    1.56 +  void  operator delete [](void* p);
    1.57  };
    1.58  
    1.59  // Base class for objects used as value objects.
    1.60 @@ -229,7 +245,9 @@
    1.61  class _ValueObj {
    1.62   private:
    1.63    void* operator new(size_t size);
    1.64 -  void operator delete(void* p);
    1.65 +  void  operator delete(void* p);
    1.66 +  void* operator new [](size_t size);
    1.67 +  void  operator delete [](void* p);
    1.68  };
    1.69  
    1.70  
    1.71 @@ -510,13 +528,24 @@
    1.72  
    1.73   public:
    1.74    void* operator new(size_t size, allocation_type type, MEMFLAGS flags);
    1.75 +  void* operator new [](size_t size, allocation_type type, MEMFLAGS flags);
    1.76    void* operator new(size_t size, const std::nothrow_t&  nothrow_constant,
    1.77        allocation_type type, MEMFLAGS flags);
    1.78 +  void* operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
    1.79 +      allocation_type type, MEMFLAGS flags);
    1.80 +
    1.81    void* operator new(size_t size, Arena *arena) {
    1.82        address res = (address)arena->Amalloc(size);
    1.83        DEBUG_ONLY(set_allocation_type(res, ARENA);)
    1.84        return res;
    1.85    }
    1.86 +
    1.87 +  void* operator new [](size_t size, Arena *arena) {
    1.88 +      address res = (address)arena->Amalloc(size);
    1.89 +      DEBUG_ONLY(set_allocation_type(res, ARENA);)
    1.90 +      return res;
    1.91 +  }
    1.92 +
    1.93    void* operator new(size_t size) {
    1.94        address res = (address)resource_allocate_bytes(size);
    1.95        DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
    1.96 @@ -529,7 +558,20 @@
    1.97        return res;
    1.98    }
    1.99  
   1.100 +  void* operator new [](size_t size) {
   1.101 +      address res = (address)resource_allocate_bytes(size);
   1.102 +      DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
   1.103 +      return res;
   1.104 +  }
   1.105 +
   1.106 +  void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) {
   1.107 +      address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL);
   1.108 +      DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);)
   1.109 +      return res;
   1.110 +  }
   1.111 +
   1.112    void  operator delete(void* p);
   1.113 +  void  operator delete [](void* p);
   1.114  };
   1.115  
   1.116  // One of the following macros must be used when allocating an array
   1.117 @@ -563,24 +605,25 @@
   1.118  #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
   1.119    (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
   1.120  
   1.121 -#define FREE_C_HEAP_ARRAY(type,old,memflags) \
   1.122 +#define FREE_C_HEAP_ARRAY(type, old, memflags) \
   1.123    FreeHeap((char*)(old), memflags)
   1.124  
   1.125 -#define NEW_C_HEAP_OBJ(type, memflags)\
   1.126 -  NEW_C_HEAP_ARRAY(type, 1, memflags)
   1.127 -
   1.128 -
   1.129  #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
   1.130    (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
   1.131  
   1.132  #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\
   1.133    (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc))
   1.134  
   1.135 -#define NEW_C_HEAP_OBJ2(type, memflags, pc)\
   1.136 -  NEW_C_HEAP_ARRAY2(type, 1, memflags, pc)
   1.137 +#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)         \
   1.138 +  (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail)
   1.139  
   1.140 +// allocate type in heap without calling ctor
   1.141 +#define NEW_C_HEAP_OBJ(type, memflags)\
   1.142 +  NEW_C_HEAP_ARRAY(type, 1, memflags)
   1.143  
   1.144 -extern bool warn_new_operator;
   1.145 +// deallocate obj of type in heap without calling dtor
   1.146 +#define FREE_C_HEAP_OBJ(objname, memflags)\
   1.147 +  FreeHeap((char*)objname, memflags);
   1.148  
   1.149  // for statistics
   1.150  #ifndef PRODUCT

mercurial