Path: blob/master/src/hotspot/os/aix/safepointMechanism_aix.cpp
40930 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*22*/2324#include "precompiled.hpp"25#include "logging/log.hpp"26#include "runtime/globals.hpp"27#include "runtime/os.hpp"28#include "runtime/safepointMechanism.hpp"29#include "services/memTracker.hpp"30#include <sys/mman.h>3132void SafepointMechanism::pd_initialize() {33// No special code needed if we can use SIGTRAP34if (USE_POLL_BIT_ONLY) {35default_initialize();36return;37}3839// Poll bit values40_poll_word_armed_value = poll_bit();41_poll_word_disarmed_value = ~_poll_word_armed_value;4243// Allocate one protected page44char* map_address = (char*)MAP_FAILED;45const size_t page_size = os::vm_page_size();46const size_t map_size = 2 * page_size;47const int prot = PROT_READ;48const int flags = MAP_PRIVATE | MAP_ANONYMOUS;4950// Use optimized addresses for the polling page,51// e.g. map it to a special 32-bit address.52if (OptimizePollingPageLocation) {53// architecture-specific list of address wishes:54char* address_wishes[] = {55// AIX: addresses lower than 0x30000000 don't seem to work on AIX.56// PPC64: all address wishes are non-negative 32 bit values where57// the lower 16 bits are all zero. we can load these addresses58// with a single ppc_lis instruction.59(char*) 0x30000000, (char*) 0x31000000,60(char*) 0x32000000, (char*) 0x33000000,61(char*) 0x40000000, (char*) 0x41000000,62(char*) 0x42000000, (char*) 0x43000000,63(char*) 0x50000000, (char*) 0x51000000,64(char*) 0x52000000, (char*) 0x53000000,65(char*) 0x60000000, (char*) 0x61000000,66(char*) 0x62000000, (char*) 0x6300000067};68int address_wishes_length = sizeof(address_wishes)/sizeof(char*);6970// iterate over the list of address wishes:71for (int i = 0; i < address_wishes_length; i++) {72// Try to map with current address wish.73// AIX: AIX needs MAP_FIXED if we provide an address and mmap will74// fail if the address is already mapped.75map_address = (char*) ::mmap(address_wishes[i],76map_size, prot,77flags | MAP_FIXED,78-1, 0);79log_debug(os)("SafePoint Polling Page address: %p (wish) => %p",80address_wishes[i], map_address);8182if (map_address == address_wishes[i]) {83// Map succeeded and map_address is at wished address, exit loop.84break;85}8687if (map_address != (char*)MAP_FAILED) {88// Map succeeded, but polling_page is not at wished address, unmap and continue.89::munmap(map_address, map_size);90map_address = (char*)MAP_FAILED;91}92// Map failed, continue loop.93}94}95if (map_address == (char*)MAP_FAILED) {96map_address = (char*) ::mmap(NULL, map_size, prot, flags, -1, 0);97}98guarantee(map_address != (char*)MAP_FAILED && map_address != NULL,99"SafepointMechanism::pd_initialize: failed to allocate polling page");100log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(map_address));101_polling_page = (address)(map_address);102103// Register polling page with NMT.104MemTracker::record_virtual_memory_reserve_and_commit(map_address, map_size, CALLER_PC, mtSafepoint);105106// Use same page for thread local handshakes without SIGTRAP107if (!os::guard_memory((char*)_polling_page, page_size)) {108fatal("Could not protect polling page");109}110uintptr_t bad_page_val = reinterpret_cast<uintptr_t>(map_address),111good_page_val = bad_page_val + os::vm_page_size();112_poll_page_armed_value = bad_page_val;113_poll_page_disarmed_value = good_page_val;114}115116117