src/share/vm/memory/allocation.cpp

changeset 5249
ce9ecec70f99
parent 5247
7ee0d5c53c78
parent 5103
f9be75d21404
child 5251
eaf3742822ec
     1.1 --- a/src/share/vm/memory/allocation.cpp	Thu May 16 11:44:33 2013 +0100
     1.2 +++ b/src/share/vm/memory/allocation.cpp	Thu May 23 12:44:18 2013 +0100
     1.3 @@ -49,10 +49,15 @@
     1.4  # include "os_bsd.inline.hpp"
     1.5  #endif
     1.6  
     1.7 -void* StackObj::operator new(size_t size)  { ShouldNotCallThis(); return 0; };
     1.8 -void  StackObj::operator delete(void* p)   { ShouldNotCallThis(); };
     1.9 -void* _ValueObj::operator new(size_t size)  { ShouldNotCallThis(); return 0; };
    1.10 -void  _ValueObj::operator delete(void* p)   { ShouldNotCallThis(); };
    1.11 +void* StackObj::operator new(size_t size)       { ShouldNotCallThis(); return 0; }
    1.12 +void  StackObj::operator delete(void* p)        { ShouldNotCallThis(); }
    1.13 +void* StackObj::operator new [](size_t size)    { ShouldNotCallThis(); return 0; }
    1.14 +void  StackObj::operator delete [](void* p)     { ShouldNotCallThis(); }
    1.15 +
    1.16 +void* _ValueObj::operator new(size_t size)      { ShouldNotCallThis(); return 0; }
    1.17 +void  _ValueObj::operator delete(void* p)       { ShouldNotCallThis(); }
    1.18 +void* _ValueObj::operator new [](size_t size)   { ShouldNotCallThis(); return 0; }
    1.19 +void  _ValueObj::operator delete [](void* p)    { ShouldNotCallThis(); }
    1.20  
    1.21  void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
    1.22                                  size_t word_size, bool read_only, TRAPS) {
    1.23 @@ -81,7 +86,6 @@
    1.24    st->print(" {"INTPTR_FORMAT"}", this);
    1.25  }
    1.26  
    1.27 -
    1.28  void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) {
    1.29    address res;
    1.30    switch (type) {
    1.31 @@ -99,6 +103,10 @@
    1.32    return res;
    1.33  }
    1.34  
    1.35 +void* ResourceObj::operator new [](size_t size, allocation_type type, MEMFLAGS flags) {
    1.36 +  return (address) operator new(size, type, flags);
    1.37 +}
    1.38 +
    1.39  void* ResourceObj::operator new(size_t size, const std::nothrow_t&  nothrow_constant,
    1.40      allocation_type type, MEMFLAGS flags) {
    1.41    //should only call this with std::nothrow, use other operator new() otherwise
    1.42 @@ -118,6 +126,10 @@
    1.43    return res;
    1.44  }
    1.45  
    1.46 +void* ResourceObj::operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
    1.47 +    allocation_type type, MEMFLAGS flags) {
    1.48 +  return (address)operator new(size, nothrow_constant, type, flags);
    1.49 +}
    1.50  
    1.51  void ResourceObj::operator delete(void* p) {
    1.52    assert(((ResourceObj *)p)->allocated_on_C_heap(),
    1.53 @@ -126,6 +138,10 @@
    1.54    FreeHeap(p);
    1.55  }
    1.56  
    1.57 +void ResourceObj::operator delete [](void* p) {
    1.58 +  operator delete(p);
    1.59 +}
    1.60 +
    1.61  #ifdef ASSERT
    1.62  void ResourceObj::set_allocation_type(address res, allocation_type type) {
    1.63      // Set allocation type in the resource object
    1.64 @@ -215,8 +231,6 @@
    1.65    tty->print_cr("Heap free   " INTPTR_FORMAT, p);
    1.66  }
    1.67  
    1.68 -bool warn_new_operator = false; // see vm_main
    1.69 -
    1.70  //--------------------------------------------------------------------------------------
    1.71  // ChunkPool implementation
    1.72  
    1.73 @@ -360,7 +374,7 @@
    1.74  void* Chunk::operator new (size_t requested_size, AllocFailType alloc_failmode, size_t length) {
    1.75    // requested_size is equal to sizeof(Chunk) but in order for the arena
    1.76    // allocations to come out aligned as expected the size must be aligned
    1.77 -  // to expected arean alignment.
    1.78 +  // to expected arena alignment.
    1.79    // expect requested_size but if sizeof(Chunk) doesn't match isn't proper size we must align it.
    1.80    assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment");
    1.81    size_t bytes = ARENA_ALIGN(requested_size) + length;
    1.82 @@ -667,19 +681,40 @@
    1.83  // a memory leak.  Use CHeapObj as the base class of such objects to make it explicit
    1.84  // that they're allocated on the C heap.
    1.85  // Commented out in product version to avoid conflicts with third-party C++ native code.
    1.86 -// %% note this is causing a problem on solaris debug build. the global
    1.87 -// new is being called from jdk source and causing data corruption.
    1.88 -// src/share/native/sun/awt/font/fontmanager/textcache/hsMemory.cpp::hsSoftNew
    1.89 -// define CATCH_OPERATOR_NEW_USAGE if you want to use this.
    1.90 -#ifdef CATCH_OPERATOR_NEW_USAGE
    1.91 +// On certain platforms, such as Mac OS X (Darwin), in debug version, new is being called
    1.92 +// from jdk source and causing data corruption. Such as
    1.93 +//  Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair
    1.94 +// define ALLOW_OPERATOR_NEW_USAGE for platform on which global operator new allowed.
    1.95 +//
    1.96 +#ifndef ALLOW_OPERATOR_NEW_USAGE
    1.97  void* operator new(size_t size){
    1.98 -  static bool warned = false;
    1.99 -  if (!warned && warn_new_operator)
   1.100 -    warning("should not call global (default) operator new");
   1.101 -  warned = true;
   1.102 -  return (void *) AllocateHeap(size, "global operator new");
   1.103 +  assert(false, "Should not call global operator new");
   1.104 +  return 0;
   1.105  }
   1.106 -#endif
   1.107 +
   1.108 +void* operator new [](size_t size){
   1.109 +  assert(false, "Should not call global operator new[]");
   1.110 +  return 0;
   1.111 +}
   1.112 +
   1.113 +void* operator new(size_t size, const std::nothrow_t&  nothrow_constant){
   1.114 +  assert(false, "Should not call global operator new");
   1.115 +  return 0;
   1.116 +}
   1.117 +
   1.118 +void* operator new [](size_t size, std::nothrow_t&  nothrow_constant){
   1.119 +  assert(false, "Should not call global operator new[]");
   1.120 +  return 0;
   1.121 +}
   1.122 +
   1.123 +void operator delete(void* p) {
   1.124 +  assert(false, "Should not call global delete");
   1.125 +}
   1.126 +
   1.127 +void operator delete [](void* p) {
   1.128 +  assert(false, "Should not call global delete []");
   1.129 +}
   1.130 +#endif // ALLOW_OPERATOR_NEW_USAGE
   1.131  
   1.132  void AllocatedObj::print() const       { print_on(tty); }
   1.133  void AllocatedObj::print_value() const { print_value_on(tty); }

mercurial