Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os/aix/safepointMechanism_aix.cpp
40930 views
1
/*
2
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. 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 it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 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 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "logging/log.hpp"
27
#include "runtime/globals.hpp"
28
#include "runtime/os.hpp"
29
#include "runtime/safepointMechanism.hpp"
30
#include "services/memTracker.hpp"
31
#include <sys/mman.h>
32
33
void SafepointMechanism::pd_initialize() {
34
// No special code needed if we can use SIGTRAP
35
if (USE_POLL_BIT_ONLY) {
36
default_initialize();
37
return;
38
}
39
40
// Poll bit values
41
_poll_word_armed_value = poll_bit();
42
_poll_word_disarmed_value = ~_poll_word_armed_value;
43
44
// Allocate one protected page
45
char* map_address = (char*)MAP_FAILED;
46
const size_t page_size = os::vm_page_size();
47
const size_t map_size = 2 * page_size;
48
const int prot = PROT_READ;
49
const int flags = MAP_PRIVATE | MAP_ANONYMOUS;
50
51
// Use optimized addresses for the polling page,
52
// e.g. map it to a special 32-bit address.
53
if (OptimizePollingPageLocation) {
54
// architecture-specific list of address wishes:
55
char* address_wishes[] = {
56
// AIX: addresses lower than 0x30000000 don't seem to work on AIX.
57
// PPC64: all address wishes are non-negative 32 bit values where
58
// the lower 16 bits are all zero. we can load these addresses
59
// with a single ppc_lis instruction.
60
(char*) 0x30000000, (char*) 0x31000000,
61
(char*) 0x32000000, (char*) 0x33000000,
62
(char*) 0x40000000, (char*) 0x41000000,
63
(char*) 0x42000000, (char*) 0x43000000,
64
(char*) 0x50000000, (char*) 0x51000000,
65
(char*) 0x52000000, (char*) 0x53000000,
66
(char*) 0x60000000, (char*) 0x61000000,
67
(char*) 0x62000000, (char*) 0x63000000
68
};
69
int address_wishes_length = sizeof(address_wishes)/sizeof(char*);
70
71
// iterate over the list of address wishes:
72
for (int i = 0; i < address_wishes_length; i++) {
73
// Try to map with current address wish.
74
// AIX: AIX needs MAP_FIXED if we provide an address and mmap will
75
// fail if the address is already mapped.
76
map_address = (char*) ::mmap(address_wishes[i],
77
map_size, prot,
78
flags | MAP_FIXED,
79
-1, 0);
80
log_debug(os)("SafePoint Polling Page address: %p (wish) => %p",
81
address_wishes[i], map_address);
82
83
if (map_address == address_wishes[i]) {
84
// Map succeeded and map_address is at wished address, exit loop.
85
break;
86
}
87
88
if (map_address != (char*)MAP_FAILED) {
89
// Map succeeded, but polling_page is not at wished address, unmap and continue.
90
::munmap(map_address, map_size);
91
map_address = (char*)MAP_FAILED;
92
}
93
// Map failed, continue loop.
94
}
95
}
96
if (map_address == (char*)MAP_FAILED) {
97
map_address = (char*) ::mmap(NULL, map_size, prot, flags, -1, 0);
98
}
99
guarantee(map_address != (char*)MAP_FAILED && map_address != NULL,
100
"SafepointMechanism::pd_initialize: failed to allocate polling page");
101
log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(map_address));
102
_polling_page = (address)(map_address);
103
104
// Register polling page with NMT.
105
MemTracker::record_virtual_memory_reserve_and_commit(map_address, map_size, CALLER_PC, mtSafepoint);
106
107
// Use same page for thread local handshakes without SIGTRAP
108
if (!os::guard_memory((char*)_polling_page, page_size)) {
109
fatal("Could not protect polling page");
110
}
111
uintptr_t bad_page_val = reinterpret_cast<uintptr_t>(map_address),
112
good_page_val = bad_page_val + os::vm_page_size();
113
_poll_page_armed_value = bad_page_val;
114
_poll_page_disarmed_value = good_page_val;
115
}
116
117