Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/arena.hpp
32285 views
/*1* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_ADLC_ARENA_HPP25#define SHARE_VM_ADLC_ARENA_HPP2627// All classes in the virtual machine must be subclassed28// by one of the following allocation classes:29//30//31// For objects allocated in the C-heap (managed by: free & malloc).32// - CHeapObj33//34//35// For embedded objects.36// - ValueObj37//38// For classes used as name spaces.39// - AllStatic40//4142class CHeapObj {43public:44void* operator new(size_t size) throw();45void operator delete(void* p);46void* new_array(size_t size);47};484950// Base class for objects used as value objects.51// Calling new or delete will result in fatal error.5253class ValueObj {54public:55void* operator new(size_t size) throw();56void operator delete(void* p);57};5859// Base class for classes that constitute name spaces.6061class AllStatic {62public:63void* operator new(size_t size) throw();64void operator delete(void* p);65};666768//------------------------------Chunk------------------------------------------69// Linked list of raw memory chunks70class Chunk: public CHeapObj {71private:72// This ordinary operator delete is needed even though not used, so the73// below two-argument operator delete will be treated as a placement74// delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.75void operator delete(void* p);76public:77void* operator new(size_t size, size_t length) throw();78void operator delete(void* p, size_t length);79Chunk(size_t length);8081enum {82init_size = 1*1024, // Size of first chunk83size = 32*1024 // Default size of an Arena chunk (following the first)84};85Chunk* _next; // Next Chunk in list86size_t _len; // Size of this Chunk8788void chop(); // Chop this chunk89void next_chop(); // Chop next chunk9091// Boundaries of data area (possibly unused)92char* bottom() const { return ((char*) this) + sizeof(Chunk); }93char* top() const { return bottom() + _len; }94};959697//------------------------------Arena------------------------------------------98// Fast allocation of memory99class Arena: public CHeapObj {100protected:101friend class ResourceMark;102friend class HandleMark;103friend class NoHandleMark;104Chunk *_first; // First chunk105Chunk *_chunk; // current chunk106char *_hwm, *_max; // High water mark and max in current chunk107void* grow(size_t x); // Get a new Chunk of at least size x108size_t _size_in_bytes; // Size of arena (used for memory usage tracing)109public:110Arena();111Arena(size_t init_size);112Arena(Arena *old);113~Arena() { _first->chop(); }114char* hwm() const { return _hwm; }115116// Fast allocate in the arena. Common case is: pointer test + increment.117void* Amalloc(size_t x) {118#ifdef _LP64119x = (x + (8-1)) & ((unsigned)(-8));120#else121x = (x + (4-1)) & ((unsigned)(-4));122#endif123if (_hwm + x > _max) {124return grow(x);125} else {126char *old = _hwm;127_hwm += x;128return old;129}130}131// Further assume size is padded out to words132// Warning: in LP64, Amalloc_4 is really Amalloc_8133void *Amalloc_4(size_t x) {134assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );135if (_hwm + x > _max) {136return grow(x);137} else {138char *old = _hwm;139_hwm += x;140return old;141}142}143144// Fast delete in area. Common case is: NOP (except for storage reclaimed)145void Afree(void *ptr, size_t size) {146if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr;147}148149void *Acalloc( size_t items, size_t x );150void *Arealloc( void *old_ptr, size_t old_size, size_t new_size );151152// Reset this Arena to empty, and return this Arenas guts in a new Arena.153Arena *reset(void);154155// Determine if pointer belongs to this Arena or not.156bool contains( const void *ptr ) const;157158// Total of all chunks in use (not thread-safe)159size_t used() const;160161// Total # of bytes used162size_t size_in_bytes() const { return _size_in_bytes; }163void set_size_in_bytes(size_t size) { _size_in_bytes = size; }164};165166#endif // SHARE_VM_ADLC_ARENA_HPP167168169