8012902: remove use of global operator new - take 2

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
This commit is contained in:
Yumin Qi 2013-05-14 09:41:12 -07:00 committed by Yumin Qi
parent b3675a00d9
commit 98151c30c8
28 changed files with 287 additions and 101 deletions

View file

@ -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