Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/adlc/arena.hpp
32285 views
1
/*
2
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_VM_ADLC_ARENA_HPP
26
#define SHARE_VM_ADLC_ARENA_HPP
27
28
// All classes in the virtual machine must be subclassed
29
// by one of the following allocation classes:
30
//
31
//
32
// For objects allocated in the C-heap (managed by: free & malloc).
33
// - CHeapObj
34
//
35
//
36
// For embedded objects.
37
// - ValueObj
38
//
39
// For classes used as name spaces.
40
// - AllStatic
41
//
42
43
class CHeapObj {
44
public:
45
void* operator new(size_t size) throw();
46
void operator delete(void* p);
47
void* new_array(size_t size);
48
};
49
50
51
// Base class for objects used as value objects.
52
// Calling new or delete will result in fatal error.
53
54
class ValueObj {
55
public:
56
void* operator new(size_t size) throw();
57
void operator delete(void* p);
58
};
59
60
// Base class for classes that constitute name spaces.
61
62
class AllStatic {
63
public:
64
void* operator new(size_t size) throw();
65
void operator delete(void* p);
66
};
67
68
69
//------------------------------Chunk------------------------------------------
70
// Linked list of raw memory chunks
71
class Chunk: public CHeapObj {
72
private:
73
// This ordinary operator delete is needed even though not used, so the
74
// below two-argument operator delete will be treated as a placement
75
// delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
76
void operator delete(void* p);
77
public:
78
void* operator new(size_t size, size_t length) throw();
79
void operator delete(void* p, size_t length);
80
Chunk(size_t length);
81
82
enum {
83
init_size = 1*1024, // Size of first chunk
84
size = 32*1024 // Default size of an Arena chunk (following the first)
85
};
86
Chunk* _next; // Next Chunk in list
87
size_t _len; // Size of this Chunk
88
89
void chop(); // Chop this chunk
90
void next_chop(); // Chop next chunk
91
92
// Boundaries of data area (possibly unused)
93
char* bottom() const { return ((char*) this) + sizeof(Chunk); }
94
char* top() const { return bottom() + _len; }
95
};
96
97
98
//------------------------------Arena------------------------------------------
99
// Fast allocation of memory
100
class Arena: public CHeapObj {
101
protected:
102
friend class ResourceMark;
103
friend class HandleMark;
104
friend class NoHandleMark;
105
Chunk *_first; // First chunk
106
Chunk *_chunk; // current chunk
107
char *_hwm, *_max; // High water mark and max in current chunk
108
void* grow(size_t x); // Get a new Chunk of at least size x
109
size_t _size_in_bytes; // Size of arena (used for memory usage tracing)
110
public:
111
Arena();
112
Arena(size_t init_size);
113
Arena(Arena *old);
114
~Arena() { _first->chop(); }
115
char* hwm() const { return _hwm; }
116
117
// Fast allocate in the arena. Common case is: pointer test + increment.
118
void* Amalloc(size_t x) {
119
#ifdef _LP64
120
x = (x + (8-1)) & ((unsigned)(-8));
121
#else
122
x = (x + (4-1)) & ((unsigned)(-4));
123
#endif
124
if (_hwm + x > _max) {
125
return grow(x);
126
} else {
127
char *old = _hwm;
128
_hwm += x;
129
return old;
130
}
131
}
132
// Further assume size is padded out to words
133
// Warning: in LP64, Amalloc_4 is really Amalloc_8
134
void *Amalloc_4(size_t x) {
135
assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
136
if (_hwm + x > _max) {
137
return grow(x);
138
} else {
139
char *old = _hwm;
140
_hwm += x;
141
return old;
142
}
143
}
144
145
// Fast delete in area. Common case is: NOP (except for storage reclaimed)
146
void Afree(void *ptr, size_t size) {
147
if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr;
148
}
149
150
void *Acalloc( size_t items, size_t x );
151
void *Arealloc( void *old_ptr, size_t old_size, size_t new_size );
152
153
// Reset this Arena to empty, and return this Arenas guts in a new Arena.
154
Arena *reset(void);
155
156
// Determine if pointer belongs to this Arena or not.
157
bool contains( const void *ptr ) const;
158
159
// Total of all chunks in use (not thread-safe)
160
size_t used() const;
161
162
// Total # of bytes used
163
size_t size_in_bytes() const { return _size_in_bytes; }
164
void set_size_in_bytes(size_t size) { _size_in_bytes = size; }
165
};
166
167
#endif // SHARE_VM_ADLC_ARENA_HPP
168
169