diff src/share/vm/memory/allocation.cpp @ 10130:6f817ce50129

8010992: Remove calls to global ::operator new[] and new Summary: disable use of global operator new and new[] which could cause unexpected exception and escape from NMT tracking. Reviewed-by: coleenp, dholmes, zgu Contributed-by: yumin.qi@oracle.com
author minqi
date Fri, 19 Apr 2013 11:08:52 -0700
parents 59c790074993
children 5a9fa2ba85f0
line wrap: on
line diff
--- a/src/share/vm/memory/allocation.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/src/share/vm/memory/allocation.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -51,8 +51,12 @@
 
 void* StackObj::operator new(size_t size)  { ShouldNotCallThis(); return 0; };
 void  StackObj::operator delete(void* p)   { ShouldNotCallThis(); };
+void* StackObj::operator new [](size_t size)  { ShouldNotCallThis(); return 0; };
+void  StackObj::operator delete [](void* p)   { ShouldNotCallThis(); };
 void* _ValueObj::operator new(size_t size)  { ShouldNotCallThis(); return 0; };
 void  _ValueObj::operator delete(void* p)   { ShouldNotCallThis(); };
+void* _ValueObj::operator new [](size_t size)  { ShouldNotCallThis(); return 0; };
+void  _ValueObj::operator delete [](void* p)   { ShouldNotCallThis(); };
 
 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
                                 size_t word_size, bool read_only, TRAPS) {
@@ -81,7 +85,6 @@
   st->print(" {"INTPTR_FORMAT"}", this);
 }
 
-
 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) {
   address res;
   switch (type) {
@@ -99,6 +102,10 @@
   return res;
 }
 
+void* ResourceObj::operator new [](size_t size, allocation_type type, MEMFLAGS flags) {
+  return (address) operator new(size, type, flags);
+}
+
 void* ResourceObj::operator new(size_t size, const std::nothrow_t&  nothrow_constant,
     allocation_type type, MEMFLAGS flags) {
   //should only call this with std::nothrow, use other operator new() otherwise
@@ -118,6 +125,10 @@
   return res;
 }
 
+void* ResourceObj::operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
+    allocation_type type, MEMFLAGS flags) {
+  return (address)operator new(size, nothrow_constant, type, flags);
+}
 
 void ResourceObj::operator delete(void* p) {
   assert(((ResourceObj *)p)->allocated_on_C_heap(),
@@ -126,6 +137,10 @@
   FreeHeap(p);
 }
 
+void ResourceObj::operator delete [](void* p) {
+  operator delete(p);
+}
+
 #ifdef ASSERT
 void ResourceObj::set_allocation_type(address res, allocation_type type) {
     // Set allocation type in the resource object
@@ -360,7 +375,7 @@
 void* Chunk::operator new(size_t requested_size, size_t length) {
   // requested_size is equal to sizeof(Chunk) but in order for the arena
   // allocations to come out aligned as expected the size must be aligned
-  // to expected arean alignment.
+  // to expected arena alignment.
   // expect requested_size but if sizeof(Chunk) doesn't match isn't proper size we must align it.
   assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment");
   size_t bytes = ARENA_ALIGN(requested_size) + length;
@@ -669,19 +684,21 @@
 // a memory leak.  Use CHeapObj as the base class of such objects to make it explicit
 // that they're allocated on the C heap.
 // Commented out in product version to avoid conflicts with third-party C++ native code.
-// %% note this is causing a problem on solaris debug build. the global
-// new is being called from jdk source and causing data corruption.
-// src/share/native/sun/awt/font/fontmanager/textcache/hsMemory.cpp::hsSoftNew
-// define CATCH_OPERATOR_NEW_USAGE if you want to use this.
-#ifdef CATCH_OPERATOR_NEW_USAGE
 void* operator new(size_t size){
-  static bool warned = false;
-  if (!warned && warn_new_operator)
-    warning("should not call global (default) operator new");
-  warned = true;
-  return (void *) AllocateHeap(size, "global operator new");
+  ShouldNotReachHere(); return 0;
+}
+
+void* operator new [](size_t size){
+  ShouldNotReachHere(); return 0;
 }
-#endif
+
+void* operator new(size_t size, const std::nothrow_t&  nothrow_constant){
+  ShouldNotReachHere(); return 0;
+}
+
+void* operator new [](size_t size, std::nothrow_t&  nothrow_constant){
+  ShouldNotReachHere(); return 0;
+}
 
 void AllocatedObj::print() const       { print_on(tty); }
 void AllocatedObj::print_value() const { print_value_on(tty); }