Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/aarch64/gc/z/zGlobals_aarch64.cpp
41153 views
1
/*
2
* Copyright (c) 2017, 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
#include "precompiled.hpp"
25
#include "gc/shared/gcLogPrecious.hpp"
26
#include "gc/shared/gc_globals.hpp"
27
#include "gc/z/zGlobals.hpp"
28
#include "runtime/globals.hpp"
29
#include "runtime/os.hpp"
30
#include "utilities/globalDefinitions.hpp"
31
#include "utilities/powerOfTwo.hpp"
32
33
#ifdef LINUX
34
#include <sys/mman.h>
35
#endif // LINUX
36
37
//
38
// The heap can have three different layouts, depending on the max heap size.
39
//
40
// Address Space & Pointer Layout 1
41
// --------------------------------
42
//
43
// +--------------------------------+ 0x00007FFFFFFFFFFF (127TB)
44
// . .
45
// . .
46
// . .
47
// +--------------------------------+ 0x0000014000000000 (20TB)
48
// | Remapped View |
49
// +--------------------------------+ 0x0000010000000000 (16TB)
50
// . .
51
// +--------------------------------+ 0x00000c0000000000 (12TB)
52
// | Marked1 View |
53
// +--------------------------------+ 0x0000080000000000 (8TB)
54
// | Marked0 View |
55
// +--------------------------------+ 0x0000040000000000 (4TB)
56
// . .
57
// +--------------------------------+ 0x0000000000000000
58
//
59
// 6 4 4 4 4
60
// 3 6 5 2 1 0
61
// +--------------------+----+-----------------------------------------------+
62
// |00000000 00000000 00|1111|11 11111111 11111111 11111111 11111111 11111111|
63
// +--------------------+----+-----------------------------------------------+
64
// | | |
65
// | | * 41-0 Object Offset (42-bits, 4TB address space)
66
// | |
67
// | * 45-42 Metadata Bits (4-bits) 0001 = Marked0 (Address view 4-8TB)
68
// | 0010 = Marked1 (Address view 8-12TB)
69
// | 0100 = Remapped (Address view 16-20TB)
70
// | 1000 = Finalizable (Address view N/A)
71
// |
72
// * 63-46 Fixed (18-bits, always zero)
73
//
74
//
75
// Address Space & Pointer Layout 2
76
// --------------------------------
77
//
78
// +--------------------------------+ 0x00007FFFFFFFFFFF (127TB)
79
// . .
80
// . .
81
// . .
82
// +--------------------------------+ 0x0000280000000000 (40TB)
83
// | Remapped View |
84
// +--------------------------------+ 0x0000200000000000 (32TB)
85
// . .
86
// +--------------------------------+ 0x0000180000000000 (24TB)
87
// | Marked1 View |
88
// +--------------------------------+ 0x0000100000000000 (16TB)
89
// | Marked0 View |
90
// +--------------------------------+ 0x0000080000000000 (8TB)
91
// . .
92
// +--------------------------------+ 0x0000000000000000
93
//
94
// 6 4 4 4 4
95
// 3 7 6 3 2 0
96
// +------------------+-----+------------------------------------------------+
97
// |00000000 00000000 0|1111|111 11111111 11111111 11111111 11111111 11111111|
98
// +-------------------+----+------------------------------------------------+
99
// | | |
100
// | | * 42-0 Object Offset (43-bits, 8TB address space)
101
// | |
102
// | * 46-43 Metadata Bits (4-bits) 0001 = Marked0 (Address view 8-16TB)
103
// | 0010 = Marked1 (Address view 16-24TB)
104
// | 0100 = Remapped (Address view 32-40TB)
105
// | 1000 = Finalizable (Address view N/A)
106
// |
107
// * 63-47 Fixed (17-bits, always zero)
108
//
109
//
110
// Address Space & Pointer Layout 3
111
// --------------------------------
112
//
113
// +--------------------------------+ 0x00007FFFFFFFFFFF (127TB)
114
// . .
115
// . .
116
// . .
117
// +--------------------------------+ 0x0000500000000000 (80TB)
118
// | Remapped View |
119
// +--------------------------------+ 0x0000400000000000 (64TB)
120
// . .
121
// +--------------------------------+ 0x0000300000000000 (48TB)
122
// | Marked1 View |
123
// +--------------------------------+ 0x0000200000000000 (32TB)
124
// | Marked0 View |
125
// +--------------------------------+ 0x0000100000000000 (16TB)
126
// . .
127
// +--------------------------------+ 0x0000000000000000
128
//
129
// 6 4 4 4 4
130
// 3 8 7 4 3 0
131
// +------------------+----+-------------------------------------------------+
132
// |00000000 00000000 |1111|1111 11111111 11111111 11111111 11111111 11111111|
133
// +------------------+----+-------------------------------------------------+
134
// | | |
135
// | | * 43-0 Object Offset (44-bits, 16TB address space)
136
// | |
137
// | * 47-44 Metadata Bits (4-bits) 0001 = Marked0 (Address view 16-32TB)
138
// | 0010 = Marked1 (Address view 32-48TB)
139
// | 0100 = Remapped (Address view 64-80TB)
140
// | 1000 = Finalizable (Address view N/A)
141
// |
142
// * 63-48 Fixed (16-bits, always zero)
143
//
144
145
// Default value if probing is not implemented for a certain platform: 128TB
146
static const size_t DEFAULT_MAX_ADDRESS_BIT = 47;
147
// Minimum value returned, if probing fails: 64GB
148
static const size_t MINIMUM_MAX_ADDRESS_BIT = 36;
149
150
static size_t probe_valid_max_address_bit() {
151
#ifdef LINUX
152
size_t max_address_bit = 0;
153
const size_t page_size = os::vm_page_size();
154
for (size_t i = DEFAULT_MAX_ADDRESS_BIT; i > MINIMUM_MAX_ADDRESS_BIT; --i) {
155
const uintptr_t base_addr = ((uintptr_t) 1U) << i;
156
if (msync((void*)base_addr, page_size, MS_ASYNC) == 0) {
157
// msync suceeded, the address is valid, and maybe even already mapped.
158
max_address_bit = i;
159
break;
160
}
161
if (errno != ENOMEM) {
162
// Some error occured. This should never happen, but msync
163
// has some undefined behavior, hence ignore this bit.
164
#ifdef ASSERT
165
fatal("Received '%s' while probing the address space for the highest valid bit", os::errno_name(errno));
166
#else // ASSERT
167
log_warning_p(gc)("Received '%s' while probing the address space for the highest valid bit", os::errno_name(errno));
168
#endif // ASSERT
169
continue;
170
}
171
// Since msync failed with ENOMEM, the page might not be mapped.
172
// Try to map it, to see if the address is valid.
173
void* const result_addr = mmap((void*) base_addr, page_size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
174
if (result_addr != MAP_FAILED) {
175
munmap(result_addr, page_size);
176
}
177
if ((uintptr_t) result_addr == base_addr) {
178
// address is valid
179
max_address_bit = i;
180
break;
181
}
182
}
183
if (max_address_bit == 0) {
184
// probing failed, allocate a very high page and take that bit as the maximum
185
const uintptr_t high_addr = ((uintptr_t) 1U) << DEFAULT_MAX_ADDRESS_BIT;
186
void* const result_addr = mmap((void*) high_addr, page_size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
187
if (result_addr != MAP_FAILED) {
188
max_address_bit = BitsPerSize_t - count_leading_zeros((size_t) result_addr) - 1;
189
munmap(result_addr, page_size);
190
}
191
}
192
log_info_p(gc, init)("Probing address space for the highest valid bit: " SIZE_FORMAT, max_address_bit);
193
return MAX2(max_address_bit, MINIMUM_MAX_ADDRESS_BIT);
194
#else // LINUX
195
return DEFAULT_MAX_ADDRESS_BIT;
196
#endif // LINUX
197
}
198
199
size_t ZPlatformAddressOffsetBits() {
200
const static size_t valid_max_address_offset_bits = probe_valid_max_address_bit() + 1;
201
const size_t max_address_offset_bits = valid_max_address_offset_bits - 3;
202
const size_t min_address_offset_bits = max_address_offset_bits - 2;
203
const size_t address_offset = round_up_power_of_2(MaxHeapSize * ZVirtualToPhysicalRatio);
204
const size_t address_offset_bits = log2i_exact(address_offset);
205
return clamp(address_offset_bits, min_address_offset_bits, max_address_offset_bits);
206
}
207
208
size_t ZPlatformAddressMetadataShift() {
209
return ZPlatformAddressOffsetBits();
210
}
211
212