Path: blob/master/src/hotspot/cpu/aarch64/gc/z/zGlobals_aarch64.cpp
41153 views
/*1* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/shared/gcLogPrecious.hpp"25#include "gc/shared/gc_globals.hpp"26#include "gc/z/zGlobals.hpp"27#include "runtime/globals.hpp"28#include "runtime/os.hpp"29#include "utilities/globalDefinitions.hpp"30#include "utilities/powerOfTwo.hpp"3132#ifdef LINUX33#include <sys/mman.h>34#endif // LINUX3536//37// The heap can have three different layouts, depending on the max heap size.38//39// Address Space & Pointer Layout 140// --------------------------------41//42// +--------------------------------+ 0x00007FFFFFFFFFFF (127TB)43// . .44// . .45// . .46// +--------------------------------+ 0x0000014000000000 (20TB)47// | Remapped View |48// +--------------------------------+ 0x0000010000000000 (16TB)49// . .50// +--------------------------------+ 0x00000c0000000000 (12TB)51// | Marked1 View |52// +--------------------------------+ 0x0000080000000000 (8TB)53// | Marked0 View |54// +--------------------------------+ 0x0000040000000000 (4TB)55// . .56// +--------------------------------+ 0x000000000000000057//58// 6 4 4 4 459// 3 6 5 2 1 060// +--------------------+----+-----------------------------------------------+61// |00000000 00000000 00|1111|11 11111111 11111111 11111111 11111111 11111111|62// +--------------------+----+-----------------------------------------------+63// | | |64// | | * 41-0 Object Offset (42-bits, 4TB address space)65// | |66// | * 45-42 Metadata Bits (4-bits) 0001 = Marked0 (Address view 4-8TB)67// | 0010 = Marked1 (Address view 8-12TB)68// | 0100 = Remapped (Address view 16-20TB)69// | 1000 = Finalizable (Address view N/A)70// |71// * 63-46 Fixed (18-bits, always zero)72//73//74// Address Space & Pointer Layout 275// --------------------------------76//77// +--------------------------------+ 0x00007FFFFFFFFFFF (127TB)78// . .79// . .80// . .81// +--------------------------------+ 0x0000280000000000 (40TB)82// | Remapped View |83// +--------------------------------+ 0x0000200000000000 (32TB)84// . .85// +--------------------------------+ 0x0000180000000000 (24TB)86// | Marked1 View |87// +--------------------------------+ 0x0000100000000000 (16TB)88// | Marked0 View |89// +--------------------------------+ 0x0000080000000000 (8TB)90// . .91// +--------------------------------+ 0x000000000000000092//93// 6 4 4 4 494// 3 7 6 3 2 095// +------------------+-----+------------------------------------------------+96// |00000000 00000000 0|1111|111 11111111 11111111 11111111 11111111 11111111|97// +-------------------+----+------------------------------------------------+98// | | |99// | | * 42-0 Object Offset (43-bits, 8TB address space)100// | |101// | * 46-43 Metadata Bits (4-bits) 0001 = Marked0 (Address view 8-16TB)102// | 0010 = Marked1 (Address view 16-24TB)103// | 0100 = Remapped (Address view 32-40TB)104// | 1000 = Finalizable (Address view N/A)105// |106// * 63-47 Fixed (17-bits, always zero)107//108//109// Address Space & Pointer Layout 3110// --------------------------------111//112// +--------------------------------+ 0x00007FFFFFFFFFFF (127TB)113// . .114// . .115// . .116// +--------------------------------+ 0x0000500000000000 (80TB)117// | Remapped View |118// +--------------------------------+ 0x0000400000000000 (64TB)119// . .120// +--------------------------------+ 0x0000300000000000 (48TB)121// | Marked1 View |122// +--------------------------------+ 0x0000200000000000 (32TB)123// | Marked0 View |124// +--------------------------------+ 0x0000100000000000 (16TB)125// . .126// +--------------------------------+ 0x0000000000000000127//128// 6 4 4 4 4129// 3 8 7 4 3 0130// +------------------+----+-------------------------------------------------+131// |00000000 00000000 |1111|1111 11111111 11111111 11111111 11111111 11111111|132// +------------------+----+-------------------------------------------------+133// | | |134// | | * 43-0 Object Offset (44-bits, 16TB address space)135// | |136// | * 47-44 Metadata Bits (4-bits) 0001 = Marked0 (Address view 16-32TB)137// | 0010 = Marked1 (Address view 32-48TB)138// | 0100 = Remapped (Address view 64-80TB)139// | 1000 = Finalizable (Address view N/A)140// |141// * 63-48 Fixed (16-bits, always zero)142//143144// Default value if probing is not implemented for a certain platform: 128TB145static const size_t DEFAULT_MAX_ADDRESS_BIT = 47;146// Minimum value returned, if probing fails: 64GB147static const size_t MINIMUM_MAX_ADDRESS_BIT = 36;148149static size_t probe_valid_max_address_bit() {150#ifdef LINUX151size_t max_address_bit = 0;152const size_t page_size = os::vm_page_size();153for (size_t i = DEFAULT_MAX_ADDRESS_BIT; i > MINIMUM_MAX_ADDRESS_BIT; --i) {154const uintptr_t base_addr = ((uintptr_t) 1U) << i;155if (msync((void*)base_addr, page_size, MS_ASYNC) == 0) {156// msync suceeded, the address is valid, and maybe even already mapped.157max_address_bit = i;158break;159}160if (errno != ENOMEM) {161// Some error occured. This should never happen, but msync162// has some undefined behavior, hence ignore this bit.163#ifdef ASSERT164fatal("Received '%s' while probing the address space for the highest valid bit", os::errno_name(errno));165#else // ASSERT166log_warning_p(gc)("Received '%s' while probing the address space for the highest valid bit", os::errno_name(errno));167#endif // ASSERT168continue;169}170// Since msync failed with ENOMEM, the page might not be mapped.171// Try to map it, to see if the address is valid.172void* const result_addr = mmap((void*) base_addr, page_size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);173if (result_addr != MAP_FAILED) {174munmap(result_addr, page_size);175}176if ((uintptr_t) result_addr == base_addr) {177// address is valid178max_address_bit = i;179break;180}181}182if (max_address_bit == 0) {183// probing failed, allocate a very high page and take that bit as the maximum184const uintptr_t high_addr = ((uintptr_t) 1U) << DEFAULT_MAX_ADDRESS_BIT;185void* const result_addr = mmap((void*) high_addr, page_size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0);186if (result_addr != MAP_FAILED) {187max_address_bit = BitsPerSize_t - count_leading_zeros((size_t) result_addr) - 1;188munmap(result_addr, page_size);189}190}191log_info_p(gc, init)("Probing address space for the highest valid bit: " SIZE_FORMAT, max_address_bit);192return MAX2(max_address_bit, MINIMUM_MAX_ADDRESS_BIT);193#else // LINUX194return DEFAULT_MAX_ADDRESS_BIT;195#endif // LINUX196}197198size_t ZPlatformAddressOffsetBits() {199const static size_t valid_max_address_offset_bits = probe_valid_max_address_bit() + 1;200const size_t max_address_offset_bits = valid_max_address_offset_bits - 3;201const size_t min_address_offset_bits = max_address_offset_bits - 2;202const size_t address_offset = round_up_power_of_2(MaxHeapSize * ZVirtualToPhysicalRatio);203const size_t address_offset_bits = log2i_exact(address_offset);204return clamp(address_offset_bits, min_address_offset_bits, max_address_offset_bits);205}206207size_t ZPlatformAddressMetadataShift() {208return ZPlatformAddressOffsetBits();209}210211212