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
146146static 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
197198size_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