8012902: remove use of global operator new - take 2
Summary: The fix of 8010992, disable use of global operator new and new[] which caused failure on some tests. This takes two of the bugs also add ALLOW_OPERATOR_NEW_USAGE to prevent crash for third party code calling operator new of jvm on certain platforms.
Reviewed-by: coleenp, dholmes, zgu
Contributed-by: yumin.qi@oracle.com
--- a/hotspot/make/bsd/makefiles/fastdebug.make Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/make/bsd/makefiles/fastdebug.make Tue May 14 09:41:12 2013 -0700
@@ -58,6 +58,6 @@
# Linker mapfile
MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-debug
-VERSION = optimized
+VERSION = fastdebug
SYSDEFS += -DASSERT
PICFLAGS = DEFAULT
--- a/hotspot/make/bsd/makefiles/vm.make Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/make/bsd/makefiles/vm.make Tue May 14 09:41:12 2013 -0700
@@ -144,6 +144,9 @@
ifeq ($(OS_VENDOR), Darwin)
LIBJVM = lib$(JVM).dylib
CFLAGS += -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
+ ifeq (${VERSION}, $(filter ${VERSION}, debug fastdebug))
+ CFLAGS += -DALLOW_OPERATOR_NEW_USAGE
+ endif
else
LIBJVM = lib$(JVM).so
endif
--- a/hotspot/src/os/windows/vm/os_windows.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/os/windows/vm/os_windows.cpp Tue May 14 09:41:12 2013 -0700
@@ -3307,7 +3307,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/ci/ciReplay.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/ci/ciReplay.cpp Tue May 14 09:41:12 2013 -0700
@@ -492,7 +492,9 @@
}
Klass* k = parse_klass(CHECK);
rec->oops_offsets[i] = offset;
- rec->oops_handles[i] = (jobject)(new KlassHandle(THREAD, k));
+ KlassHandle *kh = NEW_C_HEAP_OBJ(KlassHandle, mtCompiler);
+ ::new ((void*)kh) KlassHandle(THREAD, k);
+ rec->oops_handles[i] = (jobject)kh;
}
}
--- a/hotspot/src/share/vm/classfile/altHashing.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/classfile/altHashing.cpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp Tue May 14 09:41:12 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, OOM_MALLOC_ERROR,
--- a/hotspot/src/share/vm/memory/allocation.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/allocation.cpp Tue May 14 09:41:12 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
@@ -49,10 +49,15 @@
# include "os_bsd.inline.hpp"
#endif
-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* 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 +86,6 @@
st->print(" {"INTPTR_FORMAT"}", this);
}
-
void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) {
address res;
switch (type) {
@@ -99,6 +103,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 +126,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 +138,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
@@ -215,8 +231,6 @@
tty->print_cr("Heap free " INTPTR_FORMAT, p);
}
-bool warn_new_operator = false; // see vm_main
-
//--------------------------------------------------------------------------------------
// ChunkPool implementation
@@ -360,7 +374,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 +683,40 @@
// 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
+// On certain platforms, such as Mac OS X (Darwin), in debug version, new is being called
+// from jdk source and causing data corruption. Such as
+// Java_sun_security_ec_ECKeyPairGenerator_generateECKeyPair
+// define ALLOW_OPERATOR_NEW_USAGE for platform on which global operator new allowed.
+//
+#ifndef ALLOW_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");
+ assert(false, "Should not call global operator new");
+ return 0;
+}
+
+void* operator new [](size_t size){
+ assert(false, "Should not call global operator new[]");
+ return 0;
+}
+
+void* operator new(size_t size, const std::nothrow_t& nothrow_constant){
+ assert(false, "Should not call global operator new");
+ return 0;
}
-#endif
+
+void* operator new [](size_t size, std::nothrow_t& nothrow_constant){
+ assert(false, "Should not call global operator new[]");
+ return 0;
+}
+
+void operator delete(void* p) {
+ assert(false, "Should not call global delete");
+}
+
+void operator delete [](void* p) {
+ assert(false, "Should not call global delete []");
+}
+#endif // ALLOW_OPERATOR_NEW_USAGE
void AllocatedObj::print() const { print_on(tty); }
void AllocatedObj::print_value() const { print_value_on(tty); }
--- a/hotspot/src/share/vm/memory/allocation.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/allocation.hpp Tue May 14 09:41:12 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,23 @@
// 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 _OBJ variants
+// of the NEW/FREE_C_HEAP macros are used for alloc/dealloc simple
+// objects which are not inherited from CHeapObj, note constructor and
+// destructor are not called. The preferable way to allocate objects
+// is using the new operator.
//
-// NEW_RESOURCE_ARRAY(type,size)
+// 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 must pay attention to calling destructors
+// at needed.
+//
+// NEW_RESOURCE_ARRAY(type, size)
// NEW_RESOURCE_OBJ(type)
-// NEW_C_HEAP_ARRAY(type,size)
-// NEW_C_HEAP_OBJ(type)
+// NEW_C_HEAP_ARRAY(type, size)
+// NEW_C_HEAP_OBJ(type, memflags)
+// FREE_C_HEAP_ARRAY(type, old, memflags)
+// FREE_C_HEAP_OBJ(objname, type, memflags)
// char* AllocateHeap(size_t size, const char* name);
// void FreeHeap(void* p);
//
@@ -195,8 +206,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 +220,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 +245,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 +528,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 +558,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
@@ -563,24 +605,25 @@
#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)
-#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)
+// allocate type in heap without calling ctor
+#define NEW_C_HEAP_OBJ(type, memflags)\
+ NEW_C_HEAP_ARRAY(type, 1, memflags)
-extern bool warn_new_operator;
+// deallocate obj of type in heap without calling dtor
+#define FREE_C_HEAP_OBJ(objname, memflags)\
+ FreeHeap((char*)objname, memflags);
// for statistics
#ifndef PRODUCT
--- a/hotspot/src/share/vm/memory/allocation.inline.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/allocation.inline.hpp Tue May 14 09:41:12 2013 -0700
@@ -86,30 +86,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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/cardTableModRefBS.cpp Tue May 14 09:41:12 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
@@ -80,15 +80,11 @@
_covered = new MemRegion[max_covered_regions];
_committed = new MemRegion[max_covered_regions];
- if (_covered == NULL || _committed == 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) {
+ delete[] _covered;
+ _covered = NULL;
+ }
+ if (_committed) {
+ delete[] _committed;
+ _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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/cardTableModRefBS.hpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/cardTableRS.cpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/cardTableRS.hpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/collectorPolicy.cpp Tue May 14 09:41:12 2013 -0700
@@ -856,7 +856,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/memory/memRegion.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/memRegion.cpp Tue May 14 09:41:12 2013 -0700
@@ -23,6 +23,8 @@
*/
#include "precompiled.hpp"
+#include "memory/allocation.hpp"
+#include "memory/allocation.inline.hpp"
#include "memory/memRegion.hpp"
#include "runtime/globals.hpp"
@@ -99,3 +101,19 @@
ShouldNotReachHere();
return MemRegion();
}
+
+void* MemRegion::operator new(size_t size) {
+ return (address)AllocateHeap(size, mtGC, 0, AllocFailStrategy::RETURN_NULL);
+}
+
+void* MemRegion::operator new [](size_t size) {
+ return (address)AllocateHeap(size, mtGC, 0, AllocFailStrategy::RETURN_NULL);
+}
+void MemRegion::operator delete(void* p) {
+ FreeHeap(p, mtGC);
+}
+
+void MemRegion::operator delete [](void* p) {
+ FreeHeap(p, mtGC);
+}
+
--- a/hotspot/src/share/vm/memory/memRegion.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/memory/memRegion.hpp Tue May 14 09:41:12 2013 -0700
@@ -34,7 +34,9 @@
// Note that MemRegions are passed by value, not by reference.
// The intent is that they remain very small and contain no
-// objects.
+// objects. _ValueObj should never be allocated in heap but we do
+// create MemRegions (in CardTableModRefBS) in heap so operator
+// new and operator new [] added for this special case.
class MetaWord;
@@ -92,6 +94,10 @@
size_t word_size() const { return _word_size; }
bool is_empty() const { return word_size() == 0; }
+ void* operator new(size_t size);
+ void* operator new [](size_t size);
+ void operator delete(void* p);
+ void operator delete [](void* p);
};
// For iteration over MemRegion's.
--- a/hotspot/src/share/vm/opto/idealGraphPrinter.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/opto/idealGraphPrinter.hpp Tue May 14 09:41:12 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.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/runtime/handles.cpp Tue May 14 09:41:12 2013 -0700
@@ -179,6 +179,22 @@
_thread->set_last_handle_mark(previous_handle_mark());
}
+void* HandleMark::operator new(size_t size) {
+ return AllocateHeap(size, mtThread);
+}
+
+void* HandleMark::operator new [] (size_t size) {
+ return AllocateHeap(size, mtThread);
+}
+
+void HandleMark::operator delete(void* p) {
+ FreeHeap(p, mtThread);
+}
+
+void HandleMark::operator delete[](void* p) {
+ FreeHeap(p, mtThread);
+}
+
#ifdef ASSERT
NoHandleMark::NoHandleMark() {
--- a/hotspot/src/share/vm/runtime/handles.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/runtime/handles.hpp Tue May 14 09:41:12 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
@@ -281,7 +281,7 @@
// 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.
+// a HandleMark when a thread is created. The operator new is for this special case.
class HandleMark {
private:
@@ -308,6 +308,11 @@
void push();
// called in the destructor of HandleMarkCleaner
void pop_and_restore();
+ // overloaded operators
+ void* operator new(size_t size);
+ void* operator new [](size_t size);
+ void operator delete(void* p);
+ void operator delete[](void* p);
};
//------------------------------------------------------------------------------------------------------------------------
--- a/hotspot/src/share/vm/runtime/objectMonitor.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/runtime/objectMonitor.hpp Tue May 14 09:41:12 2013 -0700
@@ -303,6 +303,18 @@
public:
static int Knob_Verbose;
static int Knob_SpinLimit;
+ void* operator new (size_t size) {
+ return AllocateHeap(size, mtInternal);
+ }
+ void* operator new[] (size_t size) {
+ return operator new (size);
+ }
+ void operator delete(void* p) {
+ FreeHeap(p, mtInternal);
+ }
+ void operator delete[] (void *p) {
+ operator delete(p);
+ }
};
#undef TEVENT
--- a/hotspot/src/share/vm/runtime/reflectionUtils.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/runtime/reflectionUtils.hpp Tue May 14 09:41:12 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/unhandledOops.hpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/runtime/unhandledOops.hpp Tue May 14 09:41:12 2013 -0700
@@ -48,7 +48,7 @@
class oop;
class Thread;
-class UnhandledOopEntry {
+class UnhandledOopEntry : public CHeapObj<mtThread> {
friend class UnhandledOops;
private:
oop* _oop_ptr;
@@ -62,7 +62,7 @@
};
-class UnhandledOops {
+class UnhandledOops : public CHeapObj<mtThread> {
friend class Thread;
private:
Thread* _thread;
--- a/hotspot/src/share/vm/runtime/vmStructs.cpp Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/runtime/vmStructs.cpp Tue May 14 09:41:12 2013 -0700
@@ -3119,15 +3119,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) {
@@ -3138,15 +3138,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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/utilities/events.hpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/utilities/quickSort.cpp Tue May 14 09:41:12 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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/utilities/workgroup.cpp Tue May 14 09:41:12 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
@@ -529,7 +529,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) {
@@ -549,6 +549,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 Tue May 14 11:34:30 2013 +0400
+++ b/hotspot/src/share/vm/utilities/workgroup.hpp Tue May 14 09:41:12 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