8010992: Remove calls to global ::operator new[] and new
authorminqi
Fri, 19 Apr 2013 11:08:52 -0700
changeset 17026 72b2233861f1
parent 17025 1cabc279ba46
child 17028 8972029d19a0
child 17031 9a576749065b
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
hotspot/src/os/windows/vm/os_windows.cpp
hotspot/src/share/vm/classfile/altHashing.cpp
hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
hotspot/src/share/vm/memory/allocation.cpp
hotspot/src/share/vm/memory/allocation.hpp
hotspot/src/share/vm/memory/allocation.inline.hpp
hotspot/src/share/vm/memory/cardTableModRefBS.cpp
hotspot/src/share/vm/memory/cardTableModRefBS.hpp
hotspot/src/share/vm/memory/cardTableRS.cpp
hotspot/src/share/vm/memory/cardTableRS.hpp
hotspot/src/share/vm/memory/collectorPolicy.cpp
hotspot/src/share/vm/opto/idealGraphPrinter.hpp
hotspot/src/share/vm/runtime/handles.hpp
hotspot/src/share/vm/runtime/reflectionUtils.hpp
hotspot/src/share/vm/runtime/synchronizer.cpp
hotspot/src/share/vm/runtime/thread.cpp
hotspot/src/share/vm/runtime/vmStructs.cpp
hotspot/src/share/vm/utilities/events.hpp
hotspot/src/share/vm/utilities/quickSort.cpp
hotspot/src/share/vm/utilities/workgroup.cpp
hotspot/src/share/vm/utilities/workgroup.hpp
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -3305,7 +3305,7 @@
   assert(ret != SYS_THREAD_ERROR, "StartThread failed"); // should propagate back
 }
 
-class HighResolutionInterval {
+class HighResolutionInterval : public CHeapObj<mtThread> {
   // The default timer resolution seems to be 10 milliseconds.
   // (Where is this written down?)
   // If someone wants to sleep for only a fraction of the default,
--- a/hotspot/src/share/vm/classfile/altHashing.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/classfile/altHashing.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -242,8 +242,8 @@
 void AltHashing::testMurmur3_32_ByteArray() {
   // printf("testMurmur3_32_ByteArray\n");
 
-  jbyte* vector = new jbyte[256];
-  jbyte* hashes = new jbyte[4 * 256];
+  jbyte vector[256];
+  jbyte hashes[4 * 256];
 
   for (int i = 0; i < 256; i++) {
     vector[i] = (jbyte) i;
--- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -52,7 +52,7 @@
 }
 
 void ConcurrentMarkSweepPolicy::initialize_generations() {
-  _generations = new GenerationSpecPtr[number_of_generations()];
+  _generations = NEW_C_HEAP_ARRAY3(GenerationSpecPtr, number_of_generations(), mtGC, 0, AllocFailStrategy::RETURN_NULL);
   if (_generations == NULL)
     vm_exit_during_initialization("Unable to allocate gen spec");
 
--- a/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -282,7 +282,8 @@
     _fine_eviction_stride = _max_fine_entries / _fine_eviction_sample_size;
   }
 
-  _fine_grain_regions = new PerRegionTablePtr[_max_fine_entries];
+  _fine_grain_regions = NEW_C_HEAP_ARRAY3(PerRegionTablePtr, _max_fine_entries,
+                        mtGC, 0, AllocFailStrategy::RETURN_NULL);
 
   if (_fine_grain_regions == NULL) {
     vm_exit_out_of_memory(sizeof(void*)*_max_fine_entries,
--- a/hotspot/src/share/vm/memory/allocation.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/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); }
--- a/hotspot/src/share/vm/memory/allocation.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/allocation.hpp	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
@@ -86,12 +86,24 @@
 // subclasses.
 //
 // The following macros and function should be used to allocate memory
-// directly in the resource area or in the C-heap:
+// directly in the resource area or in the C-heap, The _OBJECT variants
+// of the NEW_C_HEAP macros are used when a constructor and destructor
+// must be invoked for the object(s) and the objects are not inherited
+// from CHeapObj. The preferable way to allocate objects is using the
+// new operator.
+//
+// WARNING: The array variant must only be used for a homogenous array
+// where all objects are of the exact type specified. If subtypes are
+// stored in the array then the incorrect destructor might be called.
 //
 //   NEW_RESOURCE_ARRAY(type,size)
 //   NEW_RESOURCE_OBJ(type)
 //   NEW_C_HEAP_ARRAY(type,size)
 //   NEW_C_HEAP_OBJ(type)
+//   NEW_C_HEAP_OBJECT(type, memflags, pc, allocfail)
+//   NEW_C_HEAP_OBJECT_ARRAY(type, size, memflags, pc, allocfail)
+//   FREE_C_HEAP_OBJECT(type, objname, memflags)
+//   FREE_C_HEAP_OBJECT_ARRAY(type, size, arrayname, memflags)
 //   char* AllocateHeap(size_t size, const char* name);
 //   void  FreeHeap(void* p);
 //
@@ -195,8 +207,11 @@
   _NOINLINE_ void* operator new(size_t size, address caller_pc = 0);
   _NOINLINE_ void* operator new (size_t size, const std::nothrow_t&  nothrow_constant,
                                address caller_pc = 0);
-
+  _NOINLINE_ void* operator new [](size_t size, address caller_pc = 0);
+  _NOINLINE_ void* operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
+                               address caller_pc = 0);
   void  operator delete(void* p);
+  void  operator delete [] (void* p);
 };
 
 // Base class for objects allocated on the stack only.
@@ -206,6 +221,8 @@
  private:
   void* operator new(size_t size);
   void  operator delete(void* p);
+  void* operator new [](size_t size);
+  void  operator delete [](void* p);
 };
 
 // Base class for objects used as value objects.
@@ -229,7 +246,9 @@
 class _ValueObj {
  private:
   void* operator new(size_t size);
-  void operator delete(void* p);
+  void  operator delete(void* p);
+  void* operator new [](size_t size);
+  void  operator delete [](void* p);
 };
 
 
@@ -510,13 +529,24 @@
 
  public:
   void* operator new(size_t size, allocation_type type, MEMFLAGS flags);
+  void* operator new [](size_t size, allocation_type type, MEMFLAGS flags);
   void* operator new(size_t size, const std::nothrow_t&  nothrow_constant,
       allocation_type type, MEMFLAGS flags);
+  void* operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
+      allocation_type type, MEMFLAGS flags);
+
   void* operator new(size_t size, Arena *arena) {
       address res = (address)arena->Amalloc(size);
       DEBUG_ONLY(set_allocation_type(res, ARENA);)
       return res;
   }
+
+  void* operator new [](size_t size, Arena *arena) {
+      address res = (address)arena->Amalloc(size);
+      DEBUG_ONLY(set_allocation_type(res, ARENA);)
+      return res;
+  }
+
   void* operator new(size_t size) {
       address res = (address)resource_allocate_bytes(size);
       DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
@@ -529,7 +559,20 @@
       return res;
   }
 
+  void* operator new [](size_t size) {
+      address res = (address)resource_allocate_bytes(size);
+      DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
+      return res;
+  }
+
+  void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) {
+      address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL);
+      DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);)
+      return res;
+  }
+
   void  operator delete(void* p);
+  void  operator delete [](void* p);
 };
 
 // One of the following macros must be used when allocating an array
@@ -560,22 +603,60 @@
 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
   (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
 
-#define FREE_C_HEAP_ARRAY(type,old,memflags) \
+#define FREE_C_HEAP_ARRAY(type, old, memflags) \
   FreeHeap((char*)(old), memflags)
 
+// allocate type in heap without calling ctor
+// WARNING: type must not have virtual functions!!! There is no way to initialize vtable.
 #define NEW_C_HEAP_OBJ(type, memflags)\
   NEW_C_HEAP_ARRAY(type, 1, memflags)
 
-
 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
   (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
 
 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\
   (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc))
 
-#define NEW_C_HEAP_OBJ2(type, memflags, pc)\
-  NEW_C_HEAP_ARRAY2(type, 1, memflags, pc)
+#define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)         \
+  (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail);
+
+// !!! Attention, see comments above about the usage !!!
+
+// allocate type in heap and call ctor
+#define NEW_C_HEAP_OBJECT(objname, type, memflags, pc, allocfail)\
+  {                                                                                 \
+    objname = (type*)AllocateHeap(sizeof(type), memflags, pc, allocfail);           \
+    if (objname != NULL) ::new ((void *)objname) type();                            \
+  }
 
+// allocate array of type, call ctor for every element in the array
+#define NEW_C_HEAP_OBJECT_ARRAY(array_name, type, size, memflags, pc, allocfail)    \
+  {                                                                                 \
+    array_name = (type*)AllocateHeap(size * sizeof(type), memflags, pc, allocfail); \
+    if (array_name != NULL) {                                                       \
+      for (int index = 0; index < size; index++) {                                  \
+        ::new ((void*)&array_name[index]) type();                                   \
+      }                                                                             \
+    }                                                                               \
+  }
+
+// deallocate type in heap, call dtor
+#define FREE_C_HEAP_OBJECT(type, objname, memflags)                                 \
+  if (objname != NULL) {                                                            \
+    ((type*)objname)->~type();                                                      \
+    FREE_C_HEAP_ARRAY(type, objname, memflags);                                     \
+  }
+
+// deallocate array of type with size, call dtor for every element in the array
+#define FREE_C_HEAP_OBJECT_ARRAY(type, array_name, size, memflags)                  \
+  {                                                                                 \
+    if (array_name != NULL) {                                                       \
+      for (int index = 0; index < size; index++) {                                  \
+        ((type*)&array_name[index])->~type();                                       \
+      }                                                                             \
+      FREE_C_HEAP_ARRAY(type, array_name, memflags);                                \
+    }                                                                               \
+  }
 
 extern bool warn_new_operator;
 
--- a/hotspot/src/share/vm/memory/allocation.inline.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/allocation.inline.hpp	Fri Apr 19 11:08:52 2013 -0700
@@ -82,30 +82,39 @@
 
 template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size,
       address caller_pc){
+    void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
 #ifdef ASSERT
-    void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
     if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
+#endif
     return p;
-#else
-    return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
-#endif
   }
 
 template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
   const std::nothrow_t&  nothrow_constant, address caller_pc) {
-#ifdef ASSERT
   void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
       AllocFailStrategy::RETURN_NULL);
+#ifdef ASSERT
     if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
+#endif
     return p;
-#else
-  return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
-      AllocFailStrategy::RETURN_NULL);
-#endif
+}
+
+template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
+      address caller_pc){
+    return CHeapObj<F>::operator new(size, caller_pc);
+}
+
+template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
+  const std::nothrow_t&  nothrow_constant, address caller_pc) {
+    return CHeapObj<F>::operator new(size, nothrow_constant, caller_pc);
 }
 
 template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){
-   FreeHeap(p, F);
+    FreeHeap(p, F);
+}
+
+template <MEMFLAGS F> void CHeapObj<F>::operator delete [](void* p){
+    FreeHeap(p, F);
 }
 
 template <class E, MEMFLAGS F>
--- a/hotspot/src/share/vm/memory/cardTableModRefBS.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/cardTableModRefBS.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -78,17 +78,13 @@
 
   assert(card_size <= 512, "card_size must be less than 512"); // why?
 
-  _covered   = new MemRegion[max_covered_regions];
-  _committed = new MemRegion[max_covered_regions];
-  if (_covered == NULL || _committed == NULL)
+  NEW_C_HEAP_OBJECT_ARRAY(_covered, MemRegion, max_covered_regions, mtGC, 0, AllocFailStrategy::RETURN_NULL);
+  NEW_C_HEAP_OBJECT_ARRAY(_committed, MemRegion, max_covered_regions, mtGC, 0, AllocFailStrategy::RETURN_NULL);
+  if (_covered == NULL || _committed == NULL) {
     vm_exit_during_initialization("couldn't alloc card table covered region set.");
-  int i;
-  for (i = 0; i < max_covered_regions; i++) {
-    _covered[i].set_word_size(0);
-    _committed[i].set_word_size(0);
   }
+
   _cur_covered_regions = 0;
-
   const size_t rs_align = _page_size == (size_t) os::vm_page_size() ? 0 :
     MAX2(_page_size, (size_t) os::vm_allocation_granularity());
   ReservedSpace heap_rs(_byte_map_size, rs_align, false);
@@ -134,7 +130,7 @@
       || _lowest_non_clean_base_chunk_index == NULL
       || _last_LNC_resizing_collection == NULL)
     vm_exit_during_initialization("couldn't allocate an LNC array.");
-  for (i = 0; i < max_covered_regions; i++) {
+  for (int i = 0; i < max_covered_regions; i++) {
     _lowest_non_clean[i] = NULL;
     _lowest_non_clean_chunk_size[i] = 0;
     _last_LNC_resizing_collection[i] = -1;
@@ -153,6 +149,33 @@
   }
 }
 
+CardTableModRefBS::~CardTableModRefBS() {
+  if (_covered) {
+    FREE_C_HEAP_OBJECT_ARRAY(MemRegion, _covered, _max_covered_regions, mtGC);
+    _covered = NULL;
+  }
+  if (_committed) {
+    FREE_C_HEAP_OBJECT_ARRAY(MemRegion, _committed, _max_covered_regions, mtGC);
+    _committed = NULL;
+  }
+  if (_lowest_non_clean) {
+    FREE_C_HEAP_ARRAY(CardArr, _lowest_non_clean, mtGC);
+    _lowest_non_clean = NULL;
+  }
+  if (_lowest_non_clean_chunk_size) {
+    FREE_C_HEAP_ARRAY(size_t, _lowest_non_clean_chunk_size, mtGC);
+    _lowest_non_clean_chunk_size = NULL;
+  }
+  if (_lowest_non_clean_base_chunk_index) {
+    FREE_C_HEAP_ARRAY(uintptr_t, _lowest_non_clean_base_chunk_index, mtGC);
+    _lowest_non_clean_base_chunk_index = NULL;
+  }
+  if (_last_LNC_resizing_collection) {
+    FREE_C_HEAP_ARRAY(int, _last_LNC_resizing_collection, mtGC);
+    _last_LNC_resizing_collection = NULL;
+  }
+}
+
 int CardTableModRefBS::find_covering_region_by_base(HeapWord* base) {
   int i;
   for (i = 0; i < _cur_covered_regions; i++) {
--- a/hotspot/src/share/vm/memory/cardTableModRefBS.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/cardTableModRefBS.hpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 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
@@ -280,6 +280,7 @@
   }
 
   CardTableModRefBS(MemRegion whole_heap, int max_covered_regions);
+  ~CardTableModRefBS();
 
   // *** Barrier set functions.
 
--- a/hotspot/src/share/vm/memory/cardTableRS.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/cardTableRS.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -54,9 +54,10 @@
   _ct_bs = new CardTableModRefBSForCTRS(whole_heap, max_covered_regions);
 #endif
   set_bs(_ct_bs);
-  _last_cur_val_in_gen = new jbyte[GenCollectedHeap::max_gens + 1];
+  _last_cur_val_in_gen = NEW_C_HEAP_ARRAY3(jbyte, GenCollectedHeap::max_gens + 1,
+                         mtGC, 0, AllocFailStrategy::RETURN_NULL);
   if (_last_cur_val_in_gen == NULL) {
-    vm_exit_during_initialization("Could not last_cur_val_in_gen array.");
+    vm_exit_during_initialization("Could not create last_cur_val_in_gen array.");
   }
   for (int i = 0; i < GenCollectedHeap::max_gens + 1; i++) {
     _last_cur_val_in_gen[i] = clean_card_val();
@@ -64,6 +65,16 @@
   _ct_bs->set_CTRS(this);
 }
 
+CardTableRS::~CardTableRS() {
+  if (_ct_bs) {
+    delete _ct_bs;
+    _ct_bs = NULL;
+  }
+  if (_last_cur_val_in_gen) {
+    FREE_C_HEAP_ARRAY(jbyte, _last_cur_val_in_gen, mtInternal);
+  }
+}
+
 void CardTableRS::resize_covered_region(MemRegion new_region) {
   _ct_bs->resize_covered_region(new_region);
 }
--- a/hotspot/src/share/vm/memory/cardTableRS.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/cardTableRS.hpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -102,6 +102,7 @@
 
 public:
   CardTableRS(MemRegion whole_heap, int max_covered_regions);
+  ~CardTableRS();
 
   // *** GenRemSet functions.
   GenRemSet::Name rs_kind() { return GenRemSet::CardTable; }
--- a/hotspot/src/share/vm/memory/collectorPolicy.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -842,7 +842,7 @@
 }
 
 void MarkSweepPolicy::initialize_generations() {
-  _generations = new GenerationSpecPtr[number_of_generations()];
+  _generations = NEW_C_HEAP_ARRAY3(GenerationSpecPtr, number_of_generations(), mtGC, 0, AllocFailStrategy::RETURN_NULL);
   if (_generations == NULL)
     vm_exit_during_initialization("Unable to allocate gen spec");
 
--- a/hotspot/src/share/vm/opto/idealGraphPrinter.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/opto/idealGraphPrinter.hpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 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
@@ -41,9 +41,8 @@
 class InlineTree;
 class ciMethod;
 
-class IdealGraphPrinter
-{
-private:
+class IdealGraphPrinter : public CHeapObj<mtCompiler> {
+ private:
 
   static const char *INDENT;
   static const char *TOP_ELEMENT;
@@ -121,7 +120,7 @@
   IdealGraphPrinter();
   ~IdealGraphPrinter();
 
-public:
+ public:
 
   static void clean_up();
   static IdealGraphPrinter *printer();
@@ -135,8 +134,6 @@
   void print_method(Compile* compile, const char *name, int level=1, bool clear_nodes = false);
   void print(Compile* compile, const char *name, Node *root, int level=1, bool clear_nodes = false);
   void print_xml(const char *name);
-
-
 };
 
 #endif
--- a/hotspot/src/share/vm/runtime/handles.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/runtime/handles.hpp	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
@@ -280,10 +280,10 @@
 // If h has to be preserved, it can be converted to an oop or a local JNI handle
 // across the HandleMark boundary.
 
-// The base class of HandleMark should have been StackObj but we also heap allocate
-// a HandleMark when a thread is created.
+// The only special case for HandleMark is when a Thread is created, the first
+// HandleMark of the Thread is allocated in heap.
 
-class HandleMark {
+class HandleMark : public StackObj {
  private:
   Thread *_thread;              // thread that owns this mark
   HandleArea *_area;            // saved handle area
@@ -293,7 +293,6 @@
   // Link to previous active HandleMark in thread
   HandleMark* _previous_handle_mark;
 
-  void initialize(Thread* thread);                // common code for constructors
   void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; }
   HandleMark* previous_handle_mark() const        { return _previous_handle_mark; }
 
@@ -303,6 +302,7 @@
   HandleMark(Thread* thread)                      { initialize(thread); }
   ~HandleMark();
 
+  void initialize(Thread* thread);                // common code for constructors
   // Functions used by HandleMarkCleaner
   // called in the constructor of HandleMarkCleaner
   void push();
--- a/hotspot/src/share/vm/runtime/reflectionUtils.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/runtime/reflectionUtils.hpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 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
@@ -136,10 +136,10 @@
   }
 };
 
-class FilteredField {
+class FilteredField : public CHeapObj<mtInternal>  {
  private:
   Klass* _klass;
-  int      _field_offset;
+  int    _field_offset;
 
  public:
   FilteredField(Klass* klass, int field_offset) {
--- a/hotspot/src/share/vm/runtime/synchronizer.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/runtime/synchronizer.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1012,7 +1012,8 @@
         // Both the local and global free lists are empty -- resort to malloc().
         // In the current implementation objectMonitors are TSM - immortal.
         assert (_BLOCKSIZE > 1, "invariant") ;
-        ObjectMonitor * temp = new ObjectMonitor[_BLOCKSIZE];
+        ObjectMonitor * temp;
+        NEW_C_HEAP_OBJECT_ARRAY(temp, ObjectMonitor, _BLOCKSIZE, mtInternal, 0, AllocFailStrategy::RETURN_NULL);
 
         // NOTE: (almost) no way to recover if allocation failed.
         // We might be able to induce a STW safepoint and scavenge enough
--- a/hotspot/src/share/vm/runtime/thread.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -228,8 +228,8 @@
   _oops_do_parity = 0;
 
   // the handle mark links itself to last_handle_mark
-  new HandleMark(this);
-
+  HandleMark *hm = NEW_C_HEAP_OBJ(HandleMark, mtThread);
+  hm->initialize(this);
   // plain initialization
   debug_only(_owned_locks = NULL;)
   debug_only(_allow_allocation_count = 0;)
@@ -352,8 +352,8 @@
   // since the handle marks are using the handle area, we have to deallocated the root
   // handle mark before deallocating the thread's handle area,
   assert(last_handle_mark() != NULL, "check we have an element");
-  delete last_handle_mark();
-  assert(last_handle_mark() == NULL, "check we have reached the end");
+  FREE_C_HEAP_OBJECT(HandleMark, last_handle_mark(), mtThread);
+  set_last_handle_mark(NULL);
 
   // It's possible we can encounter a null _ParkEvent, etc., in stillborn threads.
   // We NULL out the fields for good hygiene.
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -3116,15 +3116,15 @@
   // Search for the base type by peeling off const and *
   size_t len = strlen(typeName);
   if (typeName[len-1] == '*') {
-    char * s = new char[len];
+    char * s = NEW_C_HEAP_ARRAY(char, len, mtInternal);
     strncpy(s, typeName, len - 1);
     s[len-1] = '\0';
     // tty->print_cr("checking \"%s\" for \"%s\"", s, typeName);
     if (recursiveFindType(origtypes, s, true) == 1) {
-      delete [] s;
+      FREE_C_HEAP_ARRAY(char, s, mtInternal);
       return 1;
     }
-    delete [] s;
+    FREE_C_HEAP_ARRAY(char, s, mtInternal);
   }
   const char* start = NULL;
   if (strstr(typeName, "GrowableArray<") == typeName) {
@@ -3135,15 +3135,15 @@
   if (start != NULL) {
     const char * end = strrchr(typeName, '>');
     int len = end - start + 1;
-    char * s = new char[len];
+    char * s = NEW_C_HEAP_ARRAY(char, len, mtInternal);
     strncpy(s, start, len - 1);
     s[len-1] = '\0';
     // tty->print_cr("checking \"%s\" for \"%s\"", s, typeName);
     if (recursiveFindType(origtypes, s, true) == 1) {
-      delete [] s;
+      FREE_C_HEAP_ARRAY(char, s, mtInternal);
       return 1;
     }
-    delete [] s;
+    FREE_C_HEAP_ARRAY(char, s, mtInternal);
   }
   if (strstr(typeName, "const ") == typeName) {
     const char * s = typeName + strlen("const ");
--- a/hotspot/src/share/vm/utilities/events.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/utilities/events.hpp	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
@@ -69,7 +69,7 @@
 // semantics aren't appropriate.  The name is used as the label of the
 // log when it is dumped during a crash.
 template <class T> class EventLogBase : public EventLog {
-  template <class X> class EventRecord {
+  template <class X> class EventRecord : public CHeapObj<mtInternal> {
    public:
     double  timestamp;
     Thread* thread;
--- a/hotspot/src/share/vm/utilities/quickSort.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/utilities/quickSort.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 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
@@ -30,6 +30,8 @@
 
 #include "runtime/os.hpp"
 #include "utilities/quickSort.hpp"
+#include "memory/allocation.hpp"
+#include "memory/allocation.inline.hpp"
 #include <stdlib.h>
 
 static int test_comparator(int a, int b) {
@@ -187,8 +189,8 @@
   // test sorting random arrays
   for (int i = 0; i < 1000; i++) {
     int length = os::random() % 100;
-    int* test_array = new int[length];
-    int* expected_array = new int[length];
+    int* test_array = NEW_C_HEAP_ARRAY(int, length, mtInternal);
+    int* expected_array = NEW_C_HEAP_ARRAY(int, length, mtInternal);
     for (int j = 0; j < length; j++) {
         // Choose random values, but get a chance of getting duplicates
         test_array[j] = os::random() % (length * 2);
@@ -210,8 +212,8 @@
     sort(test_array, length, test_even_odd_comparator, true);
     assert(compare_arrays(test_array, expected_array, length), "Sorting already sorted array changed order of elements - not idempotent");
 
-    delete[] test_array;
-    delete[] expected_array;
+    FREE_C_HEAP_ARRAY(int, test_array, mtInternal);
+    FREE_C_HEAP_ARRAY(int, expected_array, mtInternal);
   }
 }
 
--- a/hotspot/src/share/vm/utilities/workgroup.cpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/utilities/workgroup.cpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -528,7 +528,7 @@
 FreeIdSet::FreeIdSet(int sz, Monitor* mon) :
   _sz(sz), _mon(mon), _hd(0), _waiters(0), _index(-1), _claimed(0)
 {
-  _ids = new int[sz];
+  _ids = NEW_C_HEAP_ARRAY(int, sz, mtInternal);
   for (int i = 0; i < sz; i++) _ids[i] = i+1;
   _ids[sz-1] = end_of_list; // end of list.
   if (_stat_init) {
@@ -548,6 +548,7 @@
 
 FreeIdSet::~FreeIdSet() {
   _sets[_index] = NULL;
+  FREE_C_HEAP_ARRAY(int, _ids, mtInternal);
 }
 
 void FreeIdSet::set_safepoint(bool b) {
--- a/hotspot/src/share/vm/utilities/workgroup.hpp	Thu Apr 18 14:03:37 2013 -0400
+++ b/hotspot/src/share/vm/utilities/workgroup.hpp	Fri Apr 19 11:08:52 2013 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 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
@@ -494,7 +494,7 @@
 };
 
 // Represents a set of free small integer ids.
-class FreeIdSet {
+class FreeIdSet : public CHeapObj<mtInternal> {
   enum {
     end_of_list = -1,
     claimed = -2