allocation.hpp revision 1608
0N/A * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// All classes in the virtual machine must be subclassed 0N/A// by one of the following allocation classes: 0N/A// For objects allocated in the C-heap (managed by: free & malloc). 0N/A// For objects allocated on the stack. 0N/A// For embedded objects. 0N/A// For classes used as name spaces. // The printable subclasses are used for debugging and define virtual // member functions for printing. Classes that avoid allocating the // vtbl entries in the objects should therefore not be the printable // The following macros and function should be used to allocate memory // directly in the resource area or in the C-heap: // NEW_RESOURCE_ARRAY(type,size) // NEW_RESOURCE_OBJ(type) // NEW_C_HEAP_ARRAY(type,size) // char* AllocateHeap(size_t size, const char* name); // void FreeHeap(void* p); // C-heap allocation can be traced using +PrintHeapAllocation. // malloc and free should therefore never called directly. // Base class for objects allocated in the C-heap. // In non product mode we introduce a super class for all allocation classes // that supports printing. // We avoid the superclass in product mode since some C++ compilers add // a word overhead for empty super classes. void operator delete(
void* p);
// Base class for objects allocated on the stack only. // Calling new or delete will result in fatal error. void operator delete(
void* p);
// Base class for objects used as value objects. // Calling new or delete will result in fatal error. // Portability note: Certain compilers (e.g. gcc) will // always make classes bigger if it has a superclass, even // if the superclass does not have any virtual methods or // instance fields. The HotSpot implementation relies on this // not to happen. So never make a ValueObj class a direct subclass // of this object, but use the VALUE_OBJ_CLASS_SPEC class instead, e.g., // class A VALUE_OBJ_CLASS_SPEC { // With gcc and possible other compilers the VALUE_OBJ_CLASS_SPEC can // be defined as a an empty string "". void operator delete(
void* p);
// Base class for classes that constitute name spaces. //------------------------------Chunk------------------------------------------ // Linked list of raw memory chunks void operator delete(
void* p);
// default sizes; make them slightly smaller than 2**k to guard against // buddy-system style malloc implementations slack =
40,
// [RGV] Not sure if this is right, but make it slack =
20,
// suspected sizeof(Chunk) + internal malloc headers size =
32*K -
slack,
// Default size of an Arena chunk (following the first) void chop();
// Chop this chunk // Boundaries of data area (possibly unused) // Start the chunk_pool cleaner task //------------------------------Arena------------------------------------------ // Fast allocation of memory char *
_hwm, *
_max;
// High water mark and max in current chunk void*
grow(
size_t x);
// Get a new Chunk of at least size x // Fast allocate in the arena. Common case is: pointer test + increment. // Further assume size is padded out to words assert( (x&(
sizeof(
char*)-
1)) == 0,
"misaligned size" );
// Allocate with 'double' alignment. It is 8 bytes on sparc. // In other cases Amalloc_D() should be the same as Amalloc_4(). assert( (x&(
sizeof(
char*)-
1)) == 0,
"misaligned size" );
return grow(x);
// grow() returns a result aligned >= 8 bytes. // Fast delete in area. Common case is: NOP (except for storage reclaimed) // Move contents of this arena into an empty arena // Determine if pointer belongs to this Arena or not. // Total of all chunks in use (not thread-safe) // Reset this Arena to empty, access will trigger grow if necessary // One of the following macros must be used when allocating // an array or object from an arena //---------------------------------------------------------------------- // Base class for objects allocated in the resource area per default. // Optionally, objects may be allocated on the C heap with // new(ResourceObj::C_HEAP) Foo(...) or in an Arena with new (&arena) // ResourceObj's can be allocated within other objects, but don't use // new or delete (allocation_type is unknown). If new is used to allocate, // use delete to deallocate. // When this object is allocated on stack the new() operator is not // called but garbage on stack may look like a valid allocation_type. // Store negated 'this' pointer when new() is called to distinguish cases. void operator delete(
void* p);
// One of the following macros must be used when allocating an array // or object to determine whether it should reside in the C heap on in //------------------------------ReallocMark--------------------------------- // Code which uses REALLOC_RESOURCE_ARRAY should check an associated // ReallocMark, which is declared in the same scope as the reallocated // pointer. Any operation that could __potentially__ cause a reallocation // should check the ReallocMark.