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