aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorminqi <none@none>2013-05-14 09:41:12 -0700
committerminqi <none@none>2013-05-14 09:41:12 -0700
commitcb5be34076df87331eaa9788afcccdce98e27e07 (patch)
treeec3eec28a631b1c6c60d3667c05d3d40c860a49d
parent132d94fcbfc7014e997f4b3d897d02a5d24f76a8 (diff)
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
-rw-r--r--make/bsd/makefiles/fastdebug.make2
-rw-r--r--make/bsd/makefiles/vm.make3
-rw-r--r--src/os/windows/vm/os_windows.cpp2
-rw-r--r--src/share/vm/ci/ciReplay.cpp4
-rw-r--r--src/share/vm/classfile/altHashing.cpp6
-rw-r--r--src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp4
-rw-r--r--src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp5
-rw-r--r--src/share/vm/memory/allocation.cpp75
-rw-r--r--src/share/vm/memory/allocation.hpp73
-rw-r--r--src/share/vm/memory/allocation.inline.hpp29
-rw-r--r--src/share/vm/memory/cardTableModRefBS.cpp39
-rw-r--r--src/share/vm/memory/cardTableModRefBS.hpp3
-rw-r--r--src/share/vm/memory/cardTableRS.cpp17
-rw-r--r--src/share/vm/memory/cardTableRS.hpp3
-rw-r--r--src/share/vm/memory/collectorPolicy.cpp2
-rw-r--r--src/share/vm/memory/memRegion.cpp18
-rw-r--r--src/share/vm/memory/memRegion.hpp8
-rw-r--r--src/share/vm/opto/idealGraphPrinter.hpp11
-rw-r--r--src/share/vm/runtime/handles.cpp16
-rw-r--r--src/share/vm/runtime/handles.hpp9
-rw-r--r--src/share/vm/runtime/objectMonitor.hpp12
-rw-r--r--src/share/vm/runtime/reflectionUtils.hpp6
-rw-r--r--src/share/vm/runtime/unhandledOops.hpp4
-rw-r--r--src/share/vm/runtime/vmStructs.cpp12
-rw-r--r--src/share/vm/utilities/events.hpp4
-rw-r--r--src/share/vm/utilities/quickSort.cpp12
-rw-r--r--src/share/vm/utilities/workgroup.cpp5
-rw-r--r--src/share/vm/utilities/workgroup.hpp4
28 files changed, 287 insertions, 101 deletions
diff --git a/make/bsd/makefiles/fastdebug.make b/make/bsd/makefiles/fastdebug.make
index d79139340..f2f5dcfb8 100644
--- a/make/bsd/makefiles/fastdebug.make
+++ b/make/bsd/makefiles/fastdebug.make
@@ -58,6 +58,6 @@ CFLAGS$(HOTSPARC_GENERIC) += $(OPT_CFLAGS/BYFILE)
# Linker mapfile
MAPFILE = $(GAMMADIR)/make/bsd/makefiles/mapfile-vers-debug
-VERSION = optimized
+VERSION = fastdebug
SYSDEFS += -DASSERT
PICFLAGS = DEFAULT
diff --git a/make/bsd/makefiles/vm.make b/make/bsd/makefiles/vm.make
index b9528e101..d247031a6 100644
--- a/make/bsd/makefiles/vm.make
+++ b/make/bsd/makefiles/vm.make
@@ -144,6 +144,9 @@ JVM = jvm
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
diff --git a/src/os/windows/vm/os_windows.cpp b/src/os/windows/vm/os_windows.cpp
index dfcb64dd9..5a05d416a 100644
--- a/src/os/windows/vm/os_windows.cpp
+++ b/src/os/windows/vm/os_windows.cpp
@@ -3307,7 +3307,7 @@ void os::pd_start_thread(Thread* thread) {
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,
diff --git a/src/share/vm/ci/ciReplay.cpp b/src/share/vm/ci/ciReplay.cpp
index a314f35f8..71813b8f3 100644
--- a/src/share/vm/ci/ciReplay.cpp
+++ b/src/share/vm/ci/ciReplay.cpp
@@ -492,7 +492,9 @@ class CompileReplay : public StackObj {
}
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;
}
}
diff --git a/src/share/vm/classfile/altHashing.cpp b/src/share/vm/classfile/altHashing.cpp
index df2c53e55..8dfc3153c 100644
--- a/src/share/vm/classfile/altHashing.cpp
+++ b/src/share/vm/classfile/altHashing.cpp
@@ -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 @@ static const juint MURMUR3_32_X86_CHECK_VALUE = 0xB0F57EE3;
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;
diff --git a/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp b/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
index e57d405e5..c2aafb7bc 100644
--- a/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
+++ b/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
@@ -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 @@ ConcurrentMarkSweepPolicy::ConcurrentMarkSweepPolicy() {
}
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");
diff --git a/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp b/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
index 1e005a26e..34339b25e 100644
--- a/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
+++ b/src/share/vm/gc_implementation/g1/heapRegionRemSet.cpp
@@ -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 @@ OtherRegionsTable::OtherRegionsTable(HeapRegion* hr) :
_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,
diff --git a/src/share/vm/memory/allocation.cpp b/src/share/vm/memory/allocation.cpp
index 1c1bf7ab4..a6721c9e7 100644
--- a/src/share/vm/memory/allocation.cpp
+++ b/src/share/vm/memory/allocation.cpp
@@ -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 @@ void MetaspaceObj::print_address_on(outputStream* st) const {
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 @@ void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flag
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 @@ void* ResourceObj::operator new(size_t size, const std::nothrow_t& nothrow_cons
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 @@ void ResourceObj::operator delete(void* p) {
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 @@ void trace_heap_free(void* p) {
tty->print_cr("Heap free " INTPTR_FORMAT, p);
}
-bool warn_new_operator = false; // see vm_main
-
//--------------------------------------------------------------------------------------
// ChunkPool implementation
@@ -360,7 +374,7 @@ class ChunkPoolCleaner : public PeriodicTask {
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 @@ void* Arena::internal_malloc_4(size_t x) {
// 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;
}
-#endif
+
+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;
+}
+
+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); }
diff --git a/src/share/vm/memory/allocation.hpp b/src/share/vm/memory/allocation.hpp
index b65b2979c..2955943b3 100644
--- a/src/share/vm/memory/allocation.hpp
+++ b/src/share/vm/memory/allocation.hpp
@@ -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 @@ typedef AllocFailStrategy::AllocFailEnum AllocFailType;
// 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 @@ template <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC {
_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 @@ class StackObj ALLOCATION_SUPER_CLASS_SPEC {
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 StackObj ALLOCATION_SUPER_CLASS_SPEC {
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 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
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 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
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 @@ class ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
#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
diff --git a/src/share/vm/memory/allocation.inline.hpp b/src/share/vm/memory/allocation.inline.hpp
index d55695bdc..138dd660a 100644
--- a/src/share/vm/memory/allocation.inline.hpp
+++ b/src/share/vm/memory/allocation.inline.hpp
@@ -86,30 +86,39 @@ inline void FreeHeap(void* p, MEMFLAGS memflags = mtInternal) {
template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size,
address caller_pc){
-#ifdef ASSERT
void* p = (void*)AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
+#ifdef ASSERT
if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
- return p;
-#else
- return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC));
#endif
+ return p;
}
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);
- return p;
-#else
- return (void *) AllocateHeap(size, F, (caller_pc != 0 ? caller_pc : CALLER_PC),
- AllocFailStrategy::RETURN_NULL);
#endif
+ return p;
+}
+
+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>
diff --git a/src/share/vm/memory/cardTableModRefBS.cpp b/src/share/vm/memory/cardTableModRefBS.cpp
index cbe3654cc..7cc68debf 100644
--- a/src/share/vm/memory/cardTableModRefBS.cpp
+++ b/src/share/vm/memory/cardTableModRefBS.cpp
@@ -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 @@ CardTableModRefBS::CardTableModRefBS(MemRegion whole_heap,
_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;
+ _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 @@ CardTableModRefBS::CardTableModRefBS(MemRegion whole_heap,
|| _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(MemRegion whole_heap,
}
}
+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++) {
diff --git a/src/share/vm/memory/cardTableModRefBS.hpp b/src/share/vm/memory/cardTableModRefBS.hpp
index 69af2daa8..6b5de2a44 100644
--- a/src/share/vm/memory/cardTableModRefBS.hpp
+++ b/src/share/vm/memory/cardTableModRefBS.hpp
@@ -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 @@ public:
}
CardTableModRefBS(MemRegion whole_heap, int max_covered_regions);
+ ~CardTableModRefBS();
// *** Barrier set functions.
diff --git a/src/share/vm/memory/cardTableRS.cpp b/src/share/vm/memory/cardTableRS.cpp
index bd1cd9dd2..7c2186994 100644
--- a/src/share/vm/memory/cardTableRS.cpp
+++ b/src/share/vm/memory/cardTableRS.cpp
@@ -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 @@ CardTableRS::CardTableRS(MemRegion whole_heap,
_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 @@ CardTableRS::CardTableRS(MemRegion whole_heap,
_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);
}
diff --git a/src/share/vm/memory/cardTableRS.hpp b/src/share/vm/memory/cardTableRS.hpp
index 7ac9e4162..234b3972d 100644
--- a/src/share/vm/memory/cardTableRS.hpp
+++ b/src/share/vm/memory/cardTableRS.hpp
@@ -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 @@ class CardTableRS: public GenRemSet {
public:
CardTableRS(MemRegion whole_heap, int max_covered_regions);
+ ~CardTableRS();
// *** GenRemSet functions.
GenRemSet::Name rs_kind() { return GenRemSet::CardTable; }
diff --git a/src/share/vm/memory/collectorPolicy.cpp b/src/share/vm/memory/collectorPolicy.cpp
index c8543d943..0ac674a32 100644
--- a/src/share/vm/memory/collectorPolicy.cpp
+++ b/src/share/vm/memory/collectorPolicy.cpp
@@ -856,7 +856,7 @@ MarkSweepPolicy::MarkSweepPolicy() {
}
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");
diff --git a/src/share/vm/memory/memRegion.cpp b/src/share/vm/memory/memRegion.cpp
index 70483f9ad..baabdb878 100644
--- a/src/share/vm/memory/memRegion.cpp
+++ b/src/share/vm/memory/memRegion.cpp
@@ -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 @@ MemRegion MemRegion::minus(const MemRegion mr2) const {
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);
+}
+
diff --git a/src/share/vm/memory/memRegion.hpp b/src/share/vm/memory/memRegion.hpp
index 66f90f3bc..600d27533 100644
--- a/src/share/vm/memory/memRegion.hpp
+++ b/src/share/vm/memory/memRegion.hpp
@@ -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 @@ public:
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.
diff --git a/src/share/vm/opto/idealGraphPrinter.hpp b/src/share/vm/opto/idealGraphPrinter.hpp
index 7d1863f4a..f2892d5a9 100644
--- a/src/share/vm/opto/idealGraphPrinter.hpp
+++ b/src/share/vm/opto/idealGraphPrinter.hpp
@@ -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 Node;
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 @@ private:
IdealGraphPrinter();
~IdealGraphPrinter();
-public:
+ public:
static void clean_up();
static IdealGraphPrinter *printer();
@@ -135,8 +134,6 @@ public:
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
diff --git a/src/share/vm/runtime/handles.cpp b/src/share/vm/runtime/handles.cpp
index a62ff177d..ebbdd9d74 100644
--- a/src/share/vm/runtime/handles.cpp
+++ b/src/share/vm/runtime/handles.cpp
@@ -179,6 +179,22 @@ HandleMark::~HandleMark() {
_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() {
diff --git a/src/share/vm/runtime/handles.hpp b/src/share/vm/runtime/handles.hpp
index 8c643d7c2..82506bd70 100644
--- a/src/share/vm/runtime/handles.hpp
+++ b/src/share/vm/runtime/handles.hpp
@@ -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 @@ class HandleArea: public Arena {
// 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 @@ class HandleMark {
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);
};
//------------------------------------------------------------------------------------------------------------------------
diff --git a/src/share/vm/runtime/objectMonitor.hpp b/src/share/vm/runtime/objectMonitor.hpp
index e4236f490..df4b0279c 100644
--- a/src/share/vm/runtime/objectMonitor.hpp
+++ b/src/share/vm/runtime/objectMonitor.hpp
@@ -303,6 +303,18 @@ public:
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
diff --git a/src/share/vm/runtime/reflectionUtils.hpp b/src/share/vm/runtime/reflectionUtils.hpp
index 7641fa769..d51b2ab78 100644
--- a/src/share/vm/runtime/reflectionUtils.hpp
+++ b/src/share/vm/runtime/reflectionUtils.hpp
@@ -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 FieldStream : public KlassStream {
}
};
-class FilteredField {
+class FilteredField : public CHeapObj<mtInternal> {
private:
Klass* _klass;
- int _field_offset;
+ int _field_offset;
public:
FilteredField(Klass* klass, int field_offset) {
diff --git a/src/share/vm/runtime/unhandledOops.hpp b/src/share/vm/runtime/unhandledOops.hpp
index 97fd85431..5f65d1536 100644
--- a/src/share/vm/runtime/unhandledOops.hpp
+++ b/src/share/vm/runtime/unhandledOops.hpp
@@ -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 UnhandledOopEntry {
};
-class UnhandledOops {
+class UnhandledOops : public CHeapObj<mtThread> {
friend class Thread;
private:
Thread* _thread;
diff --git a/src/share/vm/runtime/vmStructs.cpp b/src/share/vm/runtime/vmStructs.cpp
index b281d7ac3..aacc63b5e 100644
--- a/src/share/vm/runtime/vmStructs.cpp
+++ b/src/share/vm/runtime/vmStructs.cpp
@@ -3119,15 +3119,15 @@ static int recursiveFindType(VMTypeEntry* origtypes, const char* typeName, bool
// 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 @@ static int recursiveFindType(VMTypeEntry* origtypes, const char* typeName, bool
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 ");
diff --git a/src/share/vm/utilities/events.hpp b/src/share/vm/utilities/events.hpp
index c2e543da9..804fe77df 100644
--- a/src/share/vm/utilities/events.hpp
+++ b/src/share/vm/utilities/events.hpp
@@ -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 @@ class EventLog : public CHeapObj<mtInternal> {
// 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;
diff --git a/src/share/vm/utilities/quickSort.cpp b/src/share/vm/utilities/quickSort.cpp
index e3cfa1efa..86c33a208 100644
--- a/src/share/vm/utilities/quickSort.cpp
+++ b/src/share/vm/utilities/quickSort.cpp
@@ -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 @@ void QuickSort::test_quick_sort() {
// 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 @@ void QuickSort::test_quick_sort() {
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);
}
}
diff --git a/src/share/vm/utilities/workgroup.cpp b/src/share/vm/utilities/workgroup.cpp
index 5db6344fd..479cd0402 100644
--- a/src/share/vm/utilities/workgroup.cpp
+++ b/src/share/vm/utilities/workgroup.cpp
@@ -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 @@ bool FreeIdSet::_safepoint;
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(int sz, Monitor* mon) :
FreeIdSet::~FreeIdSet() {
_sets[_index] = NULL;
+ FREE_C_HEAP_ARRAY(int, _ids, mtInternal);
}
void FreeIdSet::set_safepoint(bool b) {
diff --git a/src/share/vm/utilities/workgroup.hpp b/src/share/vm/utilities/workgroup.hpp
index 6a9353624..e1184a679 100644
--- a/src/share/vm/utilities/workgroup.hpp
+++ b/src/share/vm/utilities/workgroup.hpp
@@ -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 @@ public:
};
// Represents a set of free small integer ids.
-class FreeIdSet {
+class FreeIdSet : public CHeapObj<mtInternal> {
enum {
end_of_list = -1,
claimed = -2