0N/A/*
4565N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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 *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_MEMORY_ALLOCATION_HPP
1879N/A#define SHARE_VM_MEMORY_ALLOCATION_HPP
1879N/A
1879N/A#include "runtime/globals.hpp"
1879N/A#include "utilities/globalDefinitions.hpp"
1879N/A#ifdef COMPILER1
1879N/A#include "c1/c1_globals.hpp"
1879N/A#endif
1879N/A#ifdef COMPILER2
1879N/A#include "opto/c2_globals.hpp"
1879N/A#endif
1879N/A
2399N/A#include <new>
2399N/A
0N/A#define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1)
0N/A#define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1))
0N/A#define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK)
0N/A
3863N/A
3863N/A// noinline attribute
3863N/A#ifdef _WINDOWS
3863N/A #define _NOINLINE_ __declspec(noinline)
3863N/A#else
3863N/A #if __GNUC__ < 3 // gcc 2.x does not support noinline attribute
3863N/A #define _NOINLINE_
3863N/A #else
3863N/A #define _NOINLINE_ __attribute__ ((noinline))
3863N/A #endif
3863N/A#endif
3863N/A
4565N/Aclass AllocFailStrategy {
4565N/Apublic:
4565N/A enum AllocFailEnum { EXIT_OOM, RETURN_NULL };
4565N/A};
4565N/Atypedef AllocFailStrategy::AllocFailEnum AllocFailType;
4565N/A
0N/A// All classes in the virtual machine must be subclassed
0N/A// by one of the following allocation classes:
0N/A//
0N/A// For objects allocated in the resource area (see resourceArea.hpp).
0N/A// - ResourceObj
0N/A//
0N/A// For objects allocated in the C-heap (managed by: free & malloc).
0N/A// - CHeapObj
0N/A//
0N/A// For objects allocated on the stack.
0N/A// - StackObj
0N/A//
0N/A// For embedded objects.
0N/A// - ValueObj
0N/A//
0N/A// For classes used as name spaces.
0N/A// - AllStatic
0N/A//
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// subclasses.
0N/A//
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//
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//
0N/A// C-heap allocation can be traced using +PrintHeapAllocation.
0N/A// malloc and free should therefore never called directly.
0N/A
0N/A// Base class for objects allocated in the C-heap.
0N/A
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
0N/A#ifdef PRODUCT
0N/A#define ALLOCATION_SUPER_CLASS_SPEC
0N/A#else
0N/A#define ALLOCATION_SUPER_CLASS_SPEC : public AllocatedObj
0N/Aclass AllocatedObj {
0N/A public:
0N/A // Printing support
0N/A void print() const;
0N/A void print_value() const;
0N/A
0N/A virtual void print_on(outputStream* st) const;
0N/A virtual void print_value_on(outputStream* st) const;
0N/A};
0N/A#endif
0N/A
3863N/A
3863N/A/*
3863N/A * MemoryType bitmap layout:
3863N/A * | 16 15 14 13 12 11 10 09 | 08 07 06 05 | 04 03 02 01 |
3863N/A * | memory type | object | reserved |
3863N/A * | | type | |
3863N/A */
3863N/Aenum MemoryType {
3863N/A // Memory type by sub systems. It occupies lower byte.
3863N/A mtNone = 0x0000, // undefined
3863N/A mtClass = 0x0100, // memory class for Java classes
3863N/A mtThread = 0x0200, // memory for thread objects
3863N/A mtThreadStack = 0x0300,
3863N/A mtCode = 0x0400, // memory for generated code
3863N/A mtGC = 0x0500, // memory for GC
3863N/A mtCompiler = 0x0600, // memory for compiler
3863N/A mtInternal = 0x0700, // memory used by VM, but does not belong to
3863N/A // any of above categories, and not used for
3863N/A // native memory tracking
3863N/A mtOther = 0x0800, // memory not used by VM
3863N/A mtSymbol = 0x0900, // symbol
3863N/A mtNMT = 0x0A00, // memory used by native memory tracking
3863N/A mtChunk = 0x0B00, // chunk that holds content of arenas
3863N/A mtJavaHeap = 0x0C00, // Java heap
4064N/A mtClassShared = 0x0D00, // class data sharing
4186N/A mtTest = 0x0E00, // Test type for verifying NMT
4186N/A mtTracing = 0x0F00, // memory used for Tracing
4186N/A mt_number_of_types = 0x000F, // number of memory types (mtDontTrack
4064N/A // is not included as validate type)
4186N/A mtDontTrack = 0x1000, // memory we do not or cannot track
3863N/A mt_masks = 0x7F00,
3863N/A
3863N/A // object type mask
3863N/A otArena = 0x0010, // an arena object
3863N/A otNMTRecorder = 0x0020, // memory recorder object
3863N/A ot_masks = 0x00F0
3863N/A};
3863N/A
3863N/A#define IS_MEMORY_TYPE(flags, type) ((flags & mt_masks) == type)
3863N/A#define HAS_VALID_MEMORY_TYPE(flags)((flags & mt_masks) != mtNone)
3863N/A#define FLAGS_TO_MEMORY_TYPE(flags) (flags & mt_masks)
3863N/A
3863N/A#define IS_ARENA_OBJ(flags) ((flags & ot_masks) == otArena)
3863N/A#define IS_NMT_RECORDER(flags) ((flags & ot_masks) == otNMTRecorder)
3863N/A#define NMT_CAN_TRACK(flags) (!IS_NMT_RECORDER(flags) && !(IS_MEMORY_TYPE(flags, mtDontTrack)))
3863N/A
3863N/Atypedef unsigned short MEMFLAGS;
3863N/A
3863N/Aextern bool NMT_track_callsite;
3863N/A
3863N/A// debug build does not inline
3863N/A#if defined(_DEBUG_)
3863N/A #define CURRENT_PC (NMT_track_callsite ? os::get_caller_pc(1) : 0)
3863N/A #define CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0)
3863N/A #define CALLER_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(3) : 0)
3863N/A#else
3863N/A #define CURRENT_PC (NMT_track_callsite? os::get_caller_pc(0) : 0)
3863N/A #define CALLER_PC (NMT_track_callsite ? os::get_caller_pc(1) : 0)
3863N/A #define CALLER_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0)
3863N/A#endif
3863N/A
3863N/A
3863N/A
3863N/Atemplate <MEMFLAGS F> class CHeapObj ALLOCATION_SUPER_CLASS_SPEC {
0N/A public:
3863N/A _NOINLINE_ void* operator new(size_t size, address caller_pc = 0);
3863N/A _NOINLINE_ void* operator new (size_t size, const std::nothrow_t& nothrow_constant,
3863N/A address caller_pc = 0);
3863N/A
0N/A void operator delete(void* p);
0N/A};
0N/A
0N/A// Base class for objects allocated on the stack only.
0N/A// Calling new or delete will result in fatal error.
0N/A
0N/Aclass StackObj ALLOCATION_SUPER_CLASS_SPEC {
0N/A public:
0N/A void* operator new(size_t size);
0N/A void operator delete(void* p);
0N/A};
0N/A
0N/A// Base class for objects used as value objects.
0N/A// Calling new or delete will result in fatal error.
0N/A//
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.,
0N/A// like this:
0N/A//
0N/A// class A VALUE_OBJ_CLASS_SPEC {
0N/A// ...
0N/A// }
0N/A//
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//
0N/Aclass _ValueObj {
0N/A public:
0N/A void* operator new(size_t size);
0N/A void operator delete(void* p);
0N/A};
0N/A
0N/A// Base class for classes that constitute name spaces.
0N/A
0N/Aclass AllStatic {
0N/A public:
0N/A AllStatic() { ShouldNotCallThis(); }
0N/A ~AllStatic() { ShouldNotCallThis(); }
0N/A};
0N/A
0N/A
0N/A//------------------------------Chunk------------------------------------------
0N/A// Linked list of raw memory chunks
3863N/Aclass Chunk: CHeapObj<mtChunk> {
2772N/A friend class VMStructs;
2772N/A
0N/A protected:
0N/A Chunk* _next; // Next Chunk in list
0N/A const size_t _len; // Size of this Chunk
0N/A public:
4565N/A void* operator new(size_t size, AllocFailType alloc_failmode, size_t length);
0N/A void operator delete(void* p);
0N/A Chunk(size_t length);
0N/A
0N/A enum {
0N/A // default sizes; make them slightly smaller than 2**k to guard against
0N/A // buddy-system style malloc implementations
0N/A#ifdef _LP64
0N/A slack = 40, // [RGV] Not sure if this is right, but make it
0N/A // a multiple of 8.
0N/A#else
0N/A slack = 20, // suspected sizeof(Chunk) + internal malloc headers
0N/A#endif
0N/A
0N/A init_size = 1*K - slack, // Size of first chunk
0N/A medium_size= 10*K - slack, // Size of medium-sized chunk
0N/A size = 32*K - slack, // Default size of an Arena chunk (following the first)
0N/A non_pool_size = init_size + 32 // An initial size which is not one of above
0N/A };
0N/A
0N/A void chop(); // Chop this chunk
0N/A void next_chop(); // Chop next chunk
0N/A static size_t aligned_overhead_size(void) { return ARENA_ALIGN(sizeof(Chunk)); }
0N/A
0N/A size_t length() const { return _len; }
0N/A Chunk* next() const { return _next; }
0N/A void set_next(Chunk* n) { _next = n; }
0N/A // Boundaries of data area (possibly unused)
0N/A char* bottom() const { return ((char*) this) + aligned_overhead_size(); }
0N/A char* top() const { return bottom() + _len; }
0N/A bool contains(char* p) const { return bottom() <= p && p <= top(); }
0N/A
0N/A // Start the chunk_pool cleaner task
0N/A static void start_chunk_pool_cleaner_task();
1601N/A
1601N/A static void clean_chunk_pool();
0N/A};
0N/A
0N/A//------------------------------Arena------------------------------------------
0N/A// Fast allocation of memory
3863N/Aclass Arena : public CHeapObj<mtNone|otArena> {
0N/Aprotected:
0N/A friend class ResourceMark;
0N/A friend class HandleMark;
0N/A friend class NoHandleMark;
2772N/A friend class VMStructs;
2772N/A
0N/A Chunk *_first; // First chunk
0N/A Chunk *_chunk; // current chunk
0N/A char *_hwm, *_max; // High water mark and max in current chunk
3863N/A size_t _size_in_bytes; // Size of arena (used for native memory tracking)
3863N/A
4565N/A // Get a new Chunk of at least size x
4565N/A void* grow(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
2122N/A NOT_PRODUCT(static julong _bytes_allocated;) // total #bytes allocated since start
0N/A friend class AllocStats;
0N/A debug_only(void* malloc(size_t size);)
0N/A debug_only(void* internal_malloc_4(size_t x);)
2122N/A NOT_PRODUCT(void inc_bytes_allocated(size_t x);)
2154N/A
2154N/A void signal_out_of_memory(size_t request, const char* whence) const;
2154N/A
4565N/A bool check_for_overflow(size_t request, const char* whence,
4565N/A AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) const {
2154N/A if (UINTPTR_MAX - request < (uintptr_t)_hwm) {
4565N/A if (alloc_failmode == AllocFailStrategy::RETURN_NULL) {
4565N/A return false;
4565N/A }
2154N/A signal_out_of_memory(request, whence);
2154N/A }
4565N/A return true;
2154N/A }
2154N/A
0N/A public:
0N/A Arena();
0N/A Arena(size_t init_size);
0N/A ~Arena();
0N/A void destruct_contents();
0N/A char* hwm() const { return _hwm; }
0N/A
3863N/A // new operators
3863N/A void* operator new (size_t size);
3863N/A void* operator new (size_t size, const std::nothrow_t& nothrow_constant);
3863N/A
3863N/A // dynamic memory type tagging
3863N/A void* operator new(size_t size, MEMFLAGS flags);
3863N/A void* operator new(size_t size, const std::nothrow_t& nothrow_constant, MEMFLAGS flags);
3863N/A void operator delete(void* p);
3863N/A
0N/A // Fast allocate in the arena. Common case is: pointer test + increment.
4565N/A void* Amalloc(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
0N/A assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2");
0N/A x = ARENA_ALIGN(x);
0N/A debug_only(if (UseMallocOnly) return malloc(x);)
4565N/A if (!check_for_overflow(x, "Arena::Amalloc", alloc_failmode))
4565N/A return NULL;
2122N/A NOT_PRODUCT(inc_bytes_allocated(x);)
0N/A if (_hwm + x > _max) {
4565N/A return grow(x, alloc_failmode);
0N/A } else {
0N/A char *old = _hwm;
0N/A _hwm += x;
0N/A return old;
0N/A }
0N/A }
0N/A // Further assume size is padded out to words
4565N/A void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
0N/A assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
0N/A debug_only(if (UseMallocOnly) return malloc(x);)
4565N/A if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode))
4565N/A return NULL;
2122N/A NOT_PRODUCT(inc_bytes_allocated(x);)
0N/A if (_hwm + x > _max) {
4565N/A return grow(x, alloc_failmode);
0N/A } else {
0N/A char *old = _hwm;
0N/A _hwm += x;
0N/A return old;
0N/A }
0N/A }
0N/A
0N/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().
4565N/A void* Amalloc_D(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
0N/A assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
0N/A debug_only(if (UseMallocOnly) return malloc(x);)
0N/A#if defined(SPARC) && !defined(_LP64)
0N/A#define DALIGN_M1 7
0N/A size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm;
0N/A x += delta;
0N/A#endif
4565N/A if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode))
4565N/A return NULL;
2122N/A NOT_PRODUCT(inc_bytes_allocated(x);)
0N/A if (_hwm + x > _max) {
4565N/A return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes.
0N/A } else {
0N/A char *old = _hwm;
0N/A _hwm += x;
0N/A#if defined(SPARC) && !defined(_LP64)
0N/A old += delta; // align to 8-bytes
0N/A#endif
0N/A return old;
0N/A }
0N/A }
0N/A
0N/A // Fast delete in area. Common case is: NOP (except for storage reclaimed)
0N/A void Afree(void *ptr, size_t size) {
0N/A#ifdef ASSERT
0N/A if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
0N/A if (UseMallocOnly) return;
0N/A#endif
0N/A if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr;
0N/A }
0N/A
4565N/A void *Arealloc( void *old_ptr, size_t old_size, size_t new_size,
4565N/A AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
0N/A
0N/A // Move contents of this arena into an empty arena
0N/A Arena *move_contents(Arena *empty_arena);
0N/A
0N/A // Determine if pointer belongs to this Arena or not.
0N/A bool contains( const void *ptr ) const;
0N/A
0N/A // Total of all chunks in use (not thread-safe)
0N/A size_t used() const;
0N/A
0N/A // Total # of bytes used
3863N/A size_t size_in_bytes() const { return _size_in_bytes; };
3863N/A void set_size_in_bytes(size_t size);
3863N/A
0N/A static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN;
0N/A static void free_all(char** start, char** end) PRODUCT_RETURN;
0N/A
3863N/A // how many arena instances
3863N/A NOT_PRODUCT(static volatile jint _instance_count;)
0N/Aprivate:
0N/A // Reset this Arena to empty, access will trigger grow if necessary
0N/A void reset(void) {
0N/A _first = _chunk = NULL;
0N/A _hwm = _max = NULL;
3863N/A set_size_in_bytes(0);
0N/A }
0N/A};
0N/A
0N/A// One of the following macros must be used when allocating
0N/A// an array or object from an arena
1756N/A#define NEW_ARENA_ARRAY(arena, type, size) \
1756N/A (type*) (arena)->Amalloc((size) * sizeof(type))
0N/A
1756N/A#define REALLOC_ARENA_ARRAY(arena, type, old, old_size, new_size) \
1756N/A (type*) (arena)->Arealloc((char*)(old), (old_size) * sizeof(type), \
1756N/A (new_size) * sizeof(type) )
0N/A
1756N/A#define FREE_ARENA_ARRAY(arena, type, old, size) \
1756N/A (arena)->Afree((char*)(old), (size) * sizeof(type))
0N/A
1756N/A#define NEW_ARENA_OBJ(arena, type) \
0N/A NEW_ARENA_ARRAY(arena, type, 1)
0N/A
0N/A
0N/A//%note allocation_1
4565N/Aextern char* resource_allocate_bytes(size_t size,
4565N/A AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
4565N/Aextern char* resource_allocate_bytes(Thread* thread, size_t size,
4565N/A AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
4565N/Aextern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size,
4565N/A AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
0N/Aextern void resource_free_bytes( char *old, size_t size );
0N/A
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/Aclass ResourceObj ALLOCATION_SUPER_CLASS_SPEC {
0N/A public:
1605N/A enum allocation_type { STACK_OR_EMBEDDED = 0, RESOURCE_AREA, C_HEAP, ARENA, allocation_mask = 0x3 };
1608N/A static void set_allocation_type(address res, allocation_type type) NOT_DEBUG_RETURN;
0N/A#ifdef ASSERT
0N/A private:
1605N/A // When this object is allocated on stack the new() operator is not
1605N/A // called but garbage on stack may look like a valid allocation_type.
1605N/A // Store negated 'this' pointer when new() is called to distinguish cases.
1922N/A // Use second array's element for verification value to distinguish garbage.
1922N/A uintptr_t _allocation_t[2];
1922N/A bool is_type_set() const;
0N/A public:
1608N/A allocation_type get_allocation_type() const;
1608N/A bool allocated_on_stack() const { return get_allocation_type() == STACK_OR_EMBEDDED; }
1608N/A bool allocated_on_res_area() const { return get_allocation_type() == RESOURCE_AREA; }
1608N/A bool allocated_on_C_heap() const { return get_allocation_type() == C_HEAP; }
1608N/A bool allocated_on_arena() const { return get_allocation_type() == ARENA; }
1605N/A ResourceObj(); // default construtor
1605N/A ResourceObj(const ResourceObj& r); // default copy construtor
1605N/A ResourceObj& operator=(const ResourceObj& r); // default copy assignment
1605N/A ~ResourceObj();
0N/A#endif // ASSERT
0N/A
0N/A public:
3863N/A void* operator new(size_t size, allocation_type type, MEMFLAGS flags);
0N/A void* operator new(size_t size, Arena *arena) {
0N/A address res = (address)arena->Amalloc(size);
1605N/A DEBUG_ONLY(set_allocation_type(res, ARENA);)
0N/A return res;
0N/A }
0N/A void* operator new(size_t size) {
0N/A address res = (address)resource_allocate_bytes(size);
1605N/A DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
0N/A return res;
0N/A }
4565N/A
4565N/A void* operator new(size_t size, const std::nothrow_t& nothrow_constant) {
4565N/A address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL);
4565N/A DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);)
4565N/A return res;
4565N/A }
4565N/A
0N/A void operator delete(void* p);
0N/A};
0N/A
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
0N/A#define NEW_RESOURCE_ARRAY(type, size)\
0N/A (type*) resource_allocate_bytes((size) * sizeof(type))
0N/A
4565N/A#define NEW_RESOURCE_ARRAY_RETURN_NULL(type, size)\
4565N/A (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL)
4565N/A
0N/A#define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\
0N/A (type*) resource_allocate_bytes(thread, (size) * sizeof(type))
0N/A
0N/A#define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\
0N/A (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type) )
0N/A
0N/A#define FREE_RESOURCE_ARRAY(type, old, size)\
0N/A resource_free_bytes((char*)(old), (size) * sizeof(type))
0N/A
0N/A#define FREE_FAST(old)\
0N/A /* nop */
0N/A
0N/A#define NEW_RESOURCE_OBJ(type)\
0N/A NEW_RESOURCE_ARRAY(type, 1)
0N/A
3863N/A#define NEW_C_HEAP_ARRAY(type, size, memflags)\
3863N/A (type*) (AllocateHeap((size) * sizeof(type), memflags))
0N/A
3863N/A#define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\
3863N/A (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags))
3863N/A
3863N/A#define FREE_C_HEAP_ARRAY(type,old,memflags) \
3863N/A FreeHeap((char*)(old), memflags)
0N/A
3863N/A#define NEW_C_HEAP_OBJ(type, memflags)\
3863N/A NEW_C_HEAP_ARRAY(type, 1, memflags)
3863N/A
3863N/A
3863N/A#define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\
3863N/A (type*) (AllocateHeap((size) * sizeof(type), memflags, pc))
0N/A
3863N/A#define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\
3863N/A (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc))
3863N/A
3863N/A#define NEW_C_HEAP_OBJ2(type, memflags, pc)\
3863N/A NEW_C_HEAP_ARRAY2(type, 1, memflags, pc)
3863N/A
0N/A
0N/Aextern bool warn_new_operator;
0N/A
0N/A// for statistics
0N/A#ifndef PRODUCT
0N/Aclass AllocStats : StackObj {
2122N/A julong start_mallocs, start_frees;
2122N/A julong start_malloc_bytes, start_mfree_bytes, start_res_bytes;
0N/A public:
0N/A AllocStats();
0N/A
2122N/A julong num_mallocs(); // since creation of receiver
2122N/A julong alloc_bytes();
2122N/A julong num_frees();
2122N/A julong free_bytes();
2122N/A julong resource_bytes();
0N/A void print();
0N/A};
0N/A#endif
0N/A
0N/A
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/Aclass ReallocMark: public StackObj {
0N/Aprotected:
0N/A NOT_PRODUCT(int _nesting;)
0N/A
0N/Apublic:
0N/A ReallocMark() PRODUCT_RETURN;
0N/A void check() PRODUCT_RETURN;
0N/A};
1879N/A
4523N/A// Helper class to allocate arrays that may become large.
4523N/A// Uses the OS malloc for allocations smaller than ArrayAllocatorMallocLimit
4523N/A// and uses mapped memory for larger allocations.
4523N/A// Most OS mallocs do something similar but Solaris malloc does not revert
4523N/A// to mapped memory for large allocations. By default ArrayAllocatorMallocLimit
4523N/A// is set so that we always use malloc except for Solaris where we set the
4523N/A// limit to get mapped memory.
4523N/Atemplate <class E, MEMFLAGS F>
4573N/Aclass ArrayAllocator VALUE_OBJ_CLASS_SPEC {
4523N/A char* _addr;
4523N/A bool _use_malloc;
4523N/A size_t _size;
4573N/A bool _free_in_destructor;
4523N/A public:
4573N/A ArrayAllocator(bool free_in_destructor = true) :
4573N/A _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
4573N/A
4573N/A ~ArrayAllocator() {
4573N/A if (_free_in_destructor) {
4573N/A free();
4573N/A }
4573N/A }
4573N/A
4523N/A E* allocate(size_t length);
4523N/A void free();
4523N/A};
4523N/A
1879N/A#endif // SHARE_VM_MEMORY_ALLOCATION_HPP