allocation.hpp revision 4573
2120N/A * Copyright (c) 1997, 2012, 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. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// noinline attribute 0N/A #
if __GNUC__ <
3 // gcc 2.x does not support noinline attribute 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. 0N/A// The printable subclasses are used for debugging and define virtual 0N/A// member functions for printing. Classes that avoid allocating the 0N/A// vtbl entries in the objects should therefore not be the printable 0N/A// The following macros and function should be used to allocate memory 0N/A// directly in the resource area or in the C-heap: 0N/A// NEW_RESOURCE_ARRAY(type,size) 0N/A// NEW_RESOURCE_OBJ(type) 0N/A// NEW_C_HEAP_ARRAY(type,size) 0N/A// NEW_C_HEAP_OBJ(type) 0N/A// char* AllocateHeap(size_t size, const char* name); 0N/A// void FreeHeap(void* p); 0N/A// C-heap allocation can be traced using +PrintHeapAllocation. 0N/A// malloc and free should therefore never called directly. 0N/A// Base class for objects allocated in the C-heap. 0N/A// In non product mode we introduce a super class for all allocation classes 0N/A// that supports printing. 0N/A// We avoid the superclass in product mode since some C++ compilers add 0N/A// a word overhead for empty super classes. 0N/A * MemoryType bitmap layout: 0N/A * | 16 15 14 13 12 11 10 09 | 08 07 06 05 | 04 03 02 01 | 0N/A * | memory type | object | reserved | 0N/A // Memory type by sub systems. It occupies lower byte. 0N/A mtClass =
0x0100,
// memory class for Java classes 0N/A mtCode =
0x0400,
// memory for generated code 0N/A mtInternal =
0x0700,
// memory used by VM, but does not belong to 0N/A // any of above categories, and not used for 0N/A // native memory tracking 0N/A mtNMT =
0x0A00,
// memory used by native memory tracking 0N/A mtChunk =
0x0B00,
// chunk that holds content of arenas 0N/A mtTest =
0x0E00,
// Test type for verifying NMT 0N/A // is not included as validate type) 0N/A// debug build does not inline 0N/A void operator delete(
void* p);
0N/A// Base class for objects allocated on the stack only. 0N/A// Calling new or delete will result in fatal error. 0N/A void operator delete(
void* p);
0N/A// Base class for objects used as value objects. 0N/A// Calling new or delete will result in fatal error. 0N/A// Portability note: Certain compilers (e.g. gcc) will 0N/A// always make classes bigger if it has a superclass, even 0N/A// if the superclass does not have any virtual methods or 0N/A// instance fields. The HotSpot implementation relies on this 0N/A// not to happen. So never make a ValueObj class a direct subclass 0N/A// of this object, but use the VALUE_OBJ_CLASS_SPEC class instead, e.g., 367N/A// class A VALUE_OBJ_CLASS_SPEC { 0N/A// With gcc and possible other compilers the VALUE_OBJ_CLASS_SPEC can 0N/A// be defined as a an empty string "". 0N/A void operator delete(
void* p);
0N/A// Base class for classes that constitute name spaces. 0N/A//------------------------------Chunk------------------------------------------ 0N/A// Linked list of raw memory chunks 0N/A void operator delete(
void* p);
0N/A // default sizes; make them slightly smaller than 2**k to guard against 0N/A // buddy-system style malloc implementations 0N/A slack =
40,
// [RGV] Not sure if this is right, but make it 0N/A slack =
20,
// suspected sizeof(Chunk) + internal malloc headers 0N/A size =
32*K -
slack,
// Default size of an Arena chunk (following the first) 0N/A // Boundaries of data area (possibly unused) 0N/A // Start the chunk_pool cleaner task 0N/A//------------------------------Arena------------------------------------------ 0N/A// Fast allocation of memory 0N/A char *
_hwm, *
_max;
// High water mark and max in current chunk 0N/A // dynamic memory type tagging 0N/A void operator delete(
void* p);
0N/A // Fast allocate in the arena. Common case is: pointer test + increment. 0N/A // Further assume size is padded out to words 0N/A assert( (x&(
sizeof(
char*)-
1)) == 0,
"misaligned size" );
401N/A // Allocate with 'double' alignment. It is 8 bytes on sparc. 0N/A // In other cases Amalloc_D() should be the same as Amalloc_4(). 0N/A assert( (x&(
sizeof(
char*)-
1)) == 0,
"misaligned size" );
0N/A return grow(x);
// grow() returns a result aligned >= 8 bytes. 0N/A // Fast delete in area. Common case is: NOP (except for storage reclaimed) 0N/A // Move contents of this arena into an empty arena 0N/A // Determine if pointer belongs to this Arena or not. 0N/A // Total of all chunks in use (not thread-safe) 0N/A // Total # of bytes used 0N/A // how many arena instances 0N/A // Reset this Arena to empty, access will trigger grow if necessary 0N/A// One of the following macros must be used when allocating 1172N/A// an array or object from an arena 0N/A//---------------------------------------------------------------------- 0N/A// Base class for objects allocated in the resource area per default. 0N/A// Optionally, objects may be allocated on the C heap with 0N/A// new(ResourceObj::C_HEAP) Foo(...) or in an Arena with new (&arena) 0N/A// ResourceObj's can be allocated within other objects, but don't use 0N/A// new or delete (allocation_type is unknown). If new is used to allocate, 0N/A// use delete to deallocate. 0N/A // When this object is allocated on stack the new() operator is not 0N/A // called but garbage on stack may look like a valid allocation_type. 0N/A // Store negated 'this' pointer when new() is called to distinguish cases. 0N/A // Use second array's element for verification value to distinguish garbage. 0N/A void operator delete(
void* p);
0N/A// One of the following macros must be used when allocating an array 0N/A// or object to determine whether it should reside in the C heap on in 0N/A// the resource area. 0N/A//------------------------------ReallocMark--------------------------------- 0N/A// Code which uses REALLOC_RESOURCE_ARRAY should check an associated 0N/A// ReallocMark, which is declared in the same scope as the reallocated 0N/A// pointer. Any operation that could __potentially__ cause a reallocation 0N/A// should check the ReallocMark. 0N/A// Helper class to allocate arrays that may become large. 0N/A// Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit 0N/A// and uses mapped memory for larger allocations. 0N/A// Most OS mallocs do something similar but Solaris malloc does not revert 0N/A// to mapped memory for large allocations. By default ArrayAllocatorMallocLimit 0N/A// is set so that we always use malloc except for Solaris where we set the 0N/A// limit to get mapped memory. 0N/A#
endif // SHARE_VM_MEMORY_ALLOCATION_HPP