提交 6c473ca1 编写于 作者: M minqi

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
上级 da58dd31
......@@ -3305,7 +3305,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,
......
/*
* 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;
......
/*
* 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");
......
/*
* 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,
......
/*
* 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 @@ 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 +102,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 +125,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 +137,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
......@@ -360,7 +375,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 +684,21 @@ 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
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;
}
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;
}
#endif
void AllocatedObj::print() const { print_on(tty); }
void AllocatedObj::print_value() const { print_value_on(tty); }
......
/*
* 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 @@ 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 _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 @@ 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 +221,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 +246,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 +529,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 +559,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
......@@ -560,22 +603,60 @@ 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)
// 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;
......
......@@ -82,30 +82,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>
......
/*
* 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 @@ CardTableModRefBS::CardTableModRefBS(MemRegion whole_heap,
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;
_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) {
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++) {
......
/*
* 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.
......
/*
* 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);
}
......
/*
* 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; }
......
......@@ -842,7 +842,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");
......
/*
* 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
......
/*
* 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 @@ class HandleArea: public Arena {
// 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 @@ class HandleMark {
// 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 @@ class HandleMark {
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();
......
/*
* 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) {
......
......@@ -1012,7 +1012,8 @@ ObjectMonitor * ATTR ObjectSynchronizer::omAlloc (Thread * Self) {
// 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
......
......@@ -228,8 +228,8 @@ Thread::Thread() {
_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 @@ Thread::~Thread() {
// 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.
......
......@@ -3116,15 +3116,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) {
......@@ -3135,15 +3135,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 ");
......
/*
* 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;
......
/*
* 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);
}
}
......
/*
* 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 @@ 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) {
......@@ -548,6 +548,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) {
......
/*
* 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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册