< prev index next >

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

Print this page

        

*** 20,34 **** --- 20,37 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ #include "precompiled.hpp" + #include "gc/shared/gcLogPrecious.hpp" #include "gc/z/zGlobals.hpp" #include "runtime/globals.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/powerOfTwo.hpp" + #include <sys/mman.h> + // // The heap can have three different layouts, depending on the max heap size. // // Address Space & Pointer Layout 1 // --------------------------------
*** 133,145 **** // | 1000 = Finalizable (Address view N/A) // | // * 63-48 Fixed (16-bits, always zero) // size_t ZPlatformAddressOffsetBits() { ! const size_t min_address_offset_bits = 42; // 4TB ! const size_t max_address_offset_bits = 44; // 16TB const size_t address_offset = round_up_power_of_2(MaxHeapSize * ZVirtualToPhysicalRatio); const size_t address_offset_bits = log2_intptr(address_offset); return clamp(address_offset_bits, min_address_offset_bits, max_address_offset_bits); } --- 136,181 ---- // | 1000 = Finalizable (Address view N/A) // | // * 63-48 Fixed (16-bits, always zero) // + static size_t probe_valid_max_address_bit() { + const size_t page_size = (size_t) sysconf(_SC_PAGE_SIZE); + size_t max_address_bits = 0; + // TODO: Iterate from high to low addresses and stop at the first valid one, should be faster. + for (size_t i = 1; i <= sizeof(uintptr_t) * CHAR_BIT; ++i) { + const uintptr_t base_addr = ((uintptr_t) 1U) << i; + if (msync((void*)base_addr, page_size, MS_ASYNC) == 0) { + // msync suceeded, the address is valid, and maybe even already mapped. + max_address_bits = i; + continue; + } + if (errno != ENOMEM) { + // Some error occured. This should never happen, but msync + // has some undefined behavior, hence ignore this bit. + continue; + } + // Since msync failed with ENOMEM, the page might not be mapped. + // Try to map it, to see if the address is valid. + void* result_addr = mmap((void*) base_addr, page_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if ((uintptr_t) result_addr == base_addr) { + // address is valid + max_address_bits = i; + } + if (result_addr != MAP_FAILED) { + munmap(result_addr, page_size); + } + } + max_address_bits += 1; + log_info_p(gc, init)("Probing address space for the number of valid bits: %zu", max_address_bits); + return max_address_bits; + } + size_t ZPlatformAddressOffsetBits() { ! const static size_t ZAddressBits = probe_valid_max_address_bit(); ! const size_t max_address_offset_bits = ZAddressBits - 3; ! const size_t min_address_offset_bits = max_address_offset_bits - 2; const size_t address_offset = round_up_power_of_2(MaxHeapSize * ZVirtualToPhysicalRatio); const size_t address_offset_bits = log2_intptr(address_offset); return clamp(address_offset_bits, min_address_offset_bits, max_address_offset_bits); }
< prev index next >