Path: blob/master/src/hotspot/cpu/ppc/gc/z/zGlobals_ppc.cpp
66646 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2021 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324#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#include <cstddef>3334#ifdef LINUX35#include <sys/mman.h>36#endif // LINUX3738//39// The overall memory layouts across different power platforms are similar and only differ with regards to40// the position of the highest addressable bit; the position of the metadata bits and the size of the actual41// addressable heap address space are adjusted accordingly.42//43// The following memory schema shows an exemplary layout in which bit '45' is the highest addressable bit.44// It is assumed that this virtual memroy address space layout is predominant on the power platform.45//46// Standard Address Space & Pointer Layout47// ---------------------------------------48//49// +--------------------------------+ 0x00007FFFFFFFFFFF (127 TiB - 1)50// . .51// . .52// . .53// +--------------------------------+ 0x0000140000000000 (20 TiB)54// | Remapped View |55// +--------------------------------+ 0x0000100000000000 (16 TiB)56// . .57// +--------------------------------+ 0x00000c0000000000 (12 TiB)58// | Marked1 View |59// +--------------------------------+ 0x0000080000000000 (8 TiB)60// | Marked0 View |61// +--------------------------------+ 0x0000040000000000 (4 TiB)62// . .63// +--------------------------------+ 0x000000000000000064//65// 6 4 4 4 466// 3 6 5 2 1 067// +--------------------+----+-----------------------------------------------+68// |00000000 00000000 00|1111|11 11111111 11111111 11111111 11111111 11111111|69// +--------------------+----+-----------------------------------------------+70// | | |71// | | * 41-0 Object Offset (42-bits, 4TB address space)72// | |73// | * 45-42 Metadata Bits (4-bits) 0001 = Marked0 (Address view 4-8TB)74// | 0010 = Marked1 (Address view 8-12TB)75// | 0100 = Remapped (Address view 16-20TB)76// | 1000 = Finalizable (Address view N/A)77// |78// * 63-46 Fixed (18-bits, always zero)79//8081// Maximum value as per spec (Power ISA v2.07): 2 ^ 60 bytes, i.e. 1 EiB (exbibyte)82static const unsigned int MAXIMUM_MAX_ADDRESS_BIT = 60;8384// Most modern power processors provide an address space with not more than 45 bit addressable bit,85// that is an address space of 32 TiB in size.86static const unsigned int DEFAULT_MAX_ADDRESS_BIT = 45;8788// Minimum value returned, if probing fails: 64 GiB89static const unsigned int MINIMUM_MAX_ADDRESS_BIT = 36;9091// Determines the highest addressable bit of the virtual address space (depends on platform)92// by trying to interact with memory in that address range,93// i.e. by syncing existing mappings (msync) or by temporarily mapping the memory area (mmap).94// If one of those operations succeeds, it is proven that the targeted memory area is within the virtual address space.95//96// To reduce the number of required system calls to a bare minimum, the DEFAULT_MAX_ADDRESS_BIT is intentionally set97// lower than what the ABI would theoretically permit.98// Such an avoidance strategy, however, might impose unnecessary limits on processors that exceed this limit.99// If DEFAULT_MAX_ADDRESS_BIT is addressable, the next higher bit will be tested as well to ensure that100// the made assumption does not artificially restrict the memory availability.101static unsigned int probe_valid_max_address_bit(size_t init_bit, size_t min_bit) {102assert(init_bit >= min_bit, "Sanity");103assert(init_bit <= MAXIMUM_MAX_ADDRESS_BIT, "Test bit is outside the assumed address space range");104105#ifdef LINUX106unsigned int max_valid_address_bit = 0;107void* last_allocatable_address = nullptr;108109const unsigned int page_size = os::vm_page_size();110111for (size_t i = init_bit; i >= min_bit; --i) {112void* base_addr = (void*) (((unsigned long) 1U) << i);113114/* ==== Try msync-ing already mapped memory page ==== */115if (msync(base_addr, page_size, MS_ASYNC) == 0) {116// The page of the given address was synced by the linux kernel and must thus be both, mapped and valid.117max_valid_address_bit = i;118break;119}120if (errno != ENOMEM) {121// An unexpected error occurred, i.e. an error not indicating that the targeted memory page is unmapped,122// but pointing out another type of issue.123// Even though this should never happen, those issues may come up due to undefined behavior.124#ifdef ASSERT125fatal("Received '%s' while probing the address space for the highest valid bit", os::errno_name(errno));126#else // ASSERT127log_warning_p(gc)("Received '%s' while probing the address space for the highest valid bit", os::errno_name(errno));128#endif // ASSERT129continue;130}131132/* ==== Try mapping memory page on our own ==== */133last_allocatable_address = mmap(base_addr, page_size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);134if (last_allocatable_address != MAP_FAILED) {135munmap(last_allocatable_address, page_size);136}137138if (last_allocatable_address == base_addr) {139// As the linux kernel mapped exactly the page we have requested, the address must be valid.140max_valid_address_bit = i;141break;142}143144log_info_p(gc, init)("Probe failed for bit '%zu'", i);145}146147if (max_valid_address_bit == 0) {148// Probing did not bring up any usable address bit.149// As an alternative, the VM evaluates the address returned by mmap as it is expected that the reserved page150// will be close to the probed address that was out-of-range.151// As per mmap(2), "the kernel [will take] [the address] as a hint about where to152// place the mapping; on Linux, the mapping will be created at a nearby page boundary".153// It should thus be a "close enough" approximation to the real virtual memory address space limit.154//155// This recovery strategy is only applied in production builds.156// In debug builds, an assertion in 'ZPlatformAddressOffsetBits' will bail out the VM to indicate that157// the assumed address space is no longer up-to-date.158if (last_allocatable_address != MAP_FAILED) {159const unsigned int bitpos = BitsPerSize_t - count_leading_zeros((size_t) last_allocatable_address) - 1;160log_info_p(gc, init)("Did not find any valid addresses within the range, using address '%u' instead", bitpos);161return bitpos;162}163164#ifdef ASSERT165fatal("Available address space can not be determined");166#else // ASSERT167log_warning_p(gc)("Cannot determine available address space. Falling back to default value.");168return DEFAULT_MAX_ADDRESS_BIT;169#endif // ASSERT170} else {171if (max_valid_address_bit == init_bit) {172// An usable address bit has been found immediately.173// To ensure that the entire virtual address space is exploited, the next highest bit will be tested as well.174log_info_p(gc, init)("Hit valid address '%u' on first try, retrying with next higher bit", max_valid_address_bit);175return MAX2(max_valid_address_bit, probe_valid_max_address_bit(init_bit + 1, init_bit + 1));176}177}178179log_info_p(gc, init)("Found valid address '%u'", max_valid_address_bit);180return max_valid_address_bit;181#else // LINUX182return DEFAULT_MAX_ADDRESS_BIT;183#endif // LINUX184}185186size_t ZPlatformAddressOffsetBits() {187const static unsigned int valid_max_address_offset_bits =188probe_valid_max_address_bit(DEFAULT_MAX_ADDRESS_BIT, MINIMUM_MAX_ADDRESS_BIT) + 1;189assert(valid_max_address_offset_bits >= MINIMUM_MAX_ADDRESS_BIT,190"Highest addressable bit is outside the assumed address space range");191192const size_t max_address_offset_bits = valid_max_address_offset_bits - 3;193const size_t min_address_offset_bits = max_address_offset_bits - 2;194const size_t address_offset = round_up_power_of_2(MaxHeapSize * ZVirtualToPhysicalRatio);195const size_t address_offset_bits = log2i_exact(address_offset);196197return clamp(address_offset_bits, min_address_offset_bits, max_address_offset_bits);198}199200size_t ZPlatformAddressMetadataShift() {201return ZPlatformAddressOffsetBits();202}203204205