Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/virtualspace.hpp
40949 views
1
/*
2
* Copyright (c) 1997, 2021, 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_MEMORY_VIRTUALSPACE_HPP
26
#define SHARE_MEMORY_VIRTUALSPACE_HPP
27
28
#include "memory/memRegion.hpp"
29
#include "utilities/globalDefinitions.hpp"
30
31
class outputStream;
32
33
// ReservedSpace is a data structure for reserving a contiguous address range.
34
35
class ReservedSpace {
36
friend class VMStructs;
37
protected:
38
char* _base;
39
size_t _size;
40
size_t _noaccess_prefix;
41
size_t _alignment;
42
size_t _page_size;
43
bool _special;
44
int _fd_for_heap;
45
private:
46
bool _executable;
47
48
// ReservedSpace
49
ReservedSpace(char* base, size_t size, size_t alignment,
50
size_t page_size, bool special, bool executable);
51
protected:
52
// Helpers to clear and set members during initialization. Two members
53
// require special treatment:
54
// * _fd_for_heap - The fd is set once and should not be cleared
55
// even if the reservation has to be retried.
56
// * _noaccess_prefix - Used for compressed heaps and updated after
57
// the reservation is initialized. Always set to
58
// 0 during initialization.
59
void clear_members();
60
void initialize_members(char* base, size_t size, size_t alignment,
61
size_t page_size, bool special, bool executable);
62
63
void initialize(size_t size, size_t alignment, size_t page_size,
64
char* requested_address, bool executable);
65
66
void reserve(size_t size, size_t alignment, size_t page_size,
67
char* requested_address, bool executable);
68
public:
69
// Constructor
70
ReservedSpace();
71
// Initialize the reserved space with the given size. Depending on the size
72
// a suitable page size and alignment will be used.
73
explicit ReservedSpace(size_t size);
74
// Initialize the reserved space with the given size. The preferred_page_size
75
// is used as the minimum page size/alignment. This may waste some space if
76
// the given size is not aligned to that value, as the reservation will be
77
// aligned up to the final alignment in this case.
78
ReservedSpace(size_t size, size_t preferred_page_size);
79
ReservedSpace(size_t size, size_t alignment, size_t page_size,
80
char* requested_address = NULL);
81
82
// Accessors
83
char* base() const { return _base; }
84
size_t size() const { return _size; }
85
char* end() const { return _base + _size; }
86
size_t alignment() const { return _alignment; }
87
size_t page_size() const { return _page_size; }
88
bool special() const { return _special; }
89
bool executable() const { return _executable; }
90
size_t noaccess_prefix() const { return _noaccess_prefix; }
91
bool is_reserved() const { return _base != NULL; }
92
void release();
93
94
// Splitting
95
// This splits the space into two spaces, the first part of which will be returned.
96
ReservedSpace first_part(size_t partition_size, size_t alignment);
97
ReservedSpace last_part (size_t partition_size, size_t alignment);
98
99
// These simply call the above using the default alignment.
100
inline ReservedSpace first_part(size_t partition_size);
101
inline ReservedSpace last_part (size_t partition_size);
102
103
// Alignment
104
static size_t page_align_size_up(size_t size);
105
static size_t page_align_size_down(size_t size);
106
static size_t allocation_align_size_up(size_t size);
107
bool contains(const void* p) const {
108
return (base() <= ((char*)p)) && (((char*)p) < (base() + size()));
109
}
110
};
111
112
ReservedSpace
113
ReservedSpace::first_part(size_t partition_size)
114
{
115
return first_part(partition_size, alignment());
116
}
117
118
ReservedSpace ReservedSpace::last_part(size_t partition_size)
119
{
120
return last_part(partition_size, alignment());
121
}
122
123
// Class encapsulating behavior specific of memory space reserved for Java heap.
124
class ReservedHeapSpace : public ReservedSpace {
125
private:
126
void try_reserve_heap(size_t size, size_t alignment, size_t page_size,
127
char *requested_address);
128
void try_reserve_range(char *highest_start, char *lowest_start,
129
size_t attach_point_alignment, char *aligned_HBMA,
130
char *upper_bound, size_t size, size_t alignment, size_t page_size);
131
void initialize_compressed_heap(const size_t size, size_t alignment, size_t page_size);
132
// Create protection page at the beginning of the space.
133
void establish_noaccess_prefix();
134
public:
135
// Constructor. Tries to find a heap that is good for compressed oops.
136
// heap_allocation_directory is the path to the backing memory for Java heap. When set, Java heap will be allocated
137
// on the device which is managed by the file system where the directory resides.
138
ReservedHeapSpace(size_t size, size_t forced_base_alignment, size_t page_size, const char* heap_allocation_directory = NULL);
139
// Returns the base to be used for compression, i.e. so that null can be
140
// encoded safely and implicit null checks can work.
141
char *compressed_oop_base() const { return _base - _noaccess_prefix; }
142
MemRegion region() const;
143
};
144
145
// Class encapsulating behavior specific memory space for Code
146
class ReservedCodeSpace : public ReservedSpace {
147
public:
148
// Constructor
149
ReservedCodeSpace(size_t r_size, size_t rs_align, size_t page_size);
150
};
151
152
// VirtualSpace is data structure for committing a previously reserved address range in smaller chunks.
153
154
class VirtualSpace {
155
friend class VMStructs;
156
private:
157
// Reserved area
158
char* _low_boundary;
159
char* _high_boundary;
160
161
// Committed area
162
char* _low;
163
char* _high;
164
165
// The entire space has been committed and pinned in memory, no
166
// os::commit_memory() or os::uncommit_memory().
167
bool _special;
168
169
// Need to know if commit should be executable.
170
bool _executable;
171
172
// MPSS Support
173
// Each virtualspace region has a lower, middle, and upper region.
174
// Each region has an end boundary and a high pointer which is the
175
// high water mark for the last allocated byte.
176
// The lower and upper unaligned to LargePageSizeInBytes uses default page.
177
// size. The middle region uses large page size.
178
char* _lower_high;
179
char* _middle_high;
180
char* _upper_high;
181
182
char* _lower_high_boundary;
183
char* _middle_high_boundary;
184
char* _upper_high_boundary;
185
186
size_t _lower_alignment;
187
size_t _middle_alignment;
188
size_t _upper_alignment;
189
190
// MPSS Accessors
191
char* lower_high() const { return _lower_high; }
192
char* middle_high() const { return _middle_high; }
193
char* upper_high() const { return _upper_high; }
194
195
char* lower_high_boundary() const { return _lower_high_boundary; }
196
char* middle_high_boundary() const { return _middle_high_boundary; }
197
char* upper_high_boundary() const { return _upper_high_boundary; }
198
199
size_t lower_alignment() const { return _lower_alignment; }
200
size_t middle_alignment() const { return _middle_alignment; }
201
size_t upper_alignment() const { return _upper_alignment; }
202
203
public:
204
// Committed area
205
char* low() const { return _low; }
206
char* high() const { return _high; }
207
208
// Reserved area
209
char* low_boundary() const { return _low_boundary; }
210
char* high_boundary() const { return _high_boundary; }
211
212
bool special() const { return _special; }
213
214
public:
215
// Initialization
216
VirtualSpace();
217
bool initialize_with_granularity(ReservedSpace rs, size_t committed_byte_size, size_t max_commit_ganularity);
218
bool initialize(ReservedSpace rs, size_t committed_byte_size);
219
220
// Destruction
221
~VirtualSpace();
222
223
// Reserved memory
224
size_t reserved_size() const;
225
// Actually committed OS memory
226
size_t actual_committed_size() const;
227
// Memory used/expanded in this virtual space
228
size_t committed_size() const;
229
// Memory left to use/expand in this virtual space
230
size_t uncommitted_size() const;
231
232
bool contains(const void* p) const;
233
234
// Operations
235
// returns true on success, false otherwise
236
bool expand_by(size_t bytes, bool pre_touch = false);
237
void shrink_by(size_t bytes);
238
void release();
239
240
void check_for_contiguity() PRODUCT_RETURN;
241
242
// Debugging
243
void print_on(outputStream* out) PRODUCT_RETURN;
244
void print();
245
};
246
247
#endif // SHARE_MEMORY_VIRTUALSPACE_HPP
248
249