Skip to content

Commit 5b1030b

Browse files
committed
Changed constants from #define to typed static const variables.
Changed the log_warning to a log_warning_p, so it is reported in hs_err file. mummap the result of mmap directly after the mmap call to be able to break out of the loop, instead of check the max_address_bit == 0 precondition. Fixed an 'off by one' mistake.
1 parent 5bc71d4 commit 5b1030b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/hotspot/cpu/aarch64/gc/z/zGlobals_aarch64.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@
139139
//
140140

141141
// Default value if probing is not implemented for a certain platform: 128TB
142-
#define DEFAULT_MAX_ADDRESS_BIT 47
142+
static const size_t DEFAULT_MAX_ADDRESS_BIT = 47;
143143
// Minimum value returned, if probing fails: 64GB
144-
#define MINIMUM_MAX_ADDRESS_BIT 36
144+
static const size_t MINIMUM_MAX_ADDRESS_BIT = 36;
145145

146146
static size_t probe_valid_max_address_bit() {
147147
#ifdef LINUX
148148
size_t max_address_bit = 0;
149149
const size_t page_size = os::vm_page_size();
150-
for (int i = DEFAULT_MAX_ADDRESS_BIT; i > MINIMUM_MAX_ADDRESS_BIT && max_address_bit == 0; --i) {
150+
for (size_t i = DEFAULT_MAX_ADDRESS_BIT; i > MINIMUM_MAX_ADDRESS_BIT; --i) {
151151
const uintptr_t base_addr = ((uintptr_t) 1U) << i;
152152
if (msync((void*)base_addr, page_size, MS_ASYNC) == 0) {
153153
// msync suceeded, the address is valid, and maybe even already mapped.
@@ -160,19 +160,20 @@ static size_t probe_valid_max_address_bit() {
160160
#ifdef ASSERT
161161
fatal("Received %s while probing the address space for the highest valid bit", os::errno_name(errno));
162162
#else // ASSERT
163-
log_warning(gc)("Received %s while probing the address space for the highest valid bit", os::errno_name(errno));
163+
log_warning_p(gc)("Received %s while probing the address space for the highest valid bit", os::errno_name(errno));
164164
#endif // ASSERT
165165
continue;
166166
}
167167
// Since msync failed with ENOMEM, the page might not be mapped.
168168
// Try to map it, to see if the address is valid.
169169
void* result_addr = mmap((void*) base_addr, page_size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);
170+
if (result_addr != MAP_FAILED) {
171+
munmap(result_addr, page_size);
172+
}
170173
if ((uintptr_t) result_addr == base_addr) {
171174
// address is valid
172175
max_address_bit = i;
173-
}
174-
if (result_addr != MAP_FAILED) {
175-
munmap(result_addr, page_size);
176+
break;
176177
}
177178
}
178179
if (max_address_bit == 0) {
@@ -195,8 +196,8 @@ static size_t probe_valid_max_address_bit() {
195196
}
196197

197198
size_t ZPlatformAddressOffsetBits() {
198-
const static size_t valid_max_address_bit = probe_valid_max_address_bit();
199-
const size_t max_address_offset_bits = valid_max_address_bit - 3;
199+
const static size_t valid_max_address_offset_bits = probe_valid_max_address_bit() + 1;
200+
const size_t max_address_offset_bits = valid_max_address_offset_bits - 3;
200201
const size_t min_address_offset_bits = max_address_offset_bits - 2;
201202
const size_t address_offset = round_up_power_of_2(MaxHeapSize * ZVirtualToPhysicalRatio);
202203
const size_t address_offset_bits = log2_intptr(address_offset);

0 commit comments

Comments
 (0)