Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jvmci/jvmci.cpp
40949 views
1
/*
2
* Copyright (c) 2019, 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
#include "precompiled.hpp"
25
#include "classfile/systemDictionary.hpp"
26
#include "compiler/compileTask.hpp"
27
#include "compiler/compilerThread.hpp"
28
#include "gc/shared/collectedHeap.hpp"
29
#include "jvmci/jvmci.hpp"
30
#include "jvmci/jvmciJavaClasses.hpp"
31
#include "jvmci/jvmciEnv.hpp"
32
#include "jvmci/jvmciRuntime.hpp"
33
#include "jvmci/metadataHandles.hpp"
34
#include "memory/resourceArea.hpp"
35
#include "memory/universe.hpp"
36
#include "runtime/arguments.hpp"
37
#include "utilities/events.hpp"
38
39
JVMCIRuntime* JVMCI::_compiler_runtime = NULL;
40
JVMCIRuntime* JVMCI::_java_runtime = NULL;
41
volatile bool JVMCI::_is_initialized = false;
42
bool JVMCI::_box_caches_initialized = false;
43
void* JVMCI::_shared_library_handle = NULL;
44
char* JVMCI::_shared_library_path = NULL;
45
volatile bool JVMCI::_in_shutdown = false;
46
StringEventLog* JVMCI::_events = NULL;
47
StringEventLog* JVMCI::_verbose_events = NULL;
48
49
void jvmci_vmStructs_init() NOT_DEBUG_RETURN;
50
51
bool JVMCI::can_initialize_JVMCI() {
52
// Initializing JVMCI requires the module system to be initialized past phase 3.
53
// The JVMCI API itself isn't available until phase 2 and ServiceLoader (which
54
// JVMCI initialization requires) isn't usable until after phase 3. Testing
55
// whether the system loader is initialized satisfies all these invariants.
56
if (SystemDictionary::java_system_loader() == NULL) {
57
return false;
58
}
59
assert(Universe::is_module_initialized(), "must be");
60
return true;
61
}
62
63
void* JVMCI::get_shared_library(char*& path, bool load) {
64
void* sl_handle = _shared_library_handle;
65
if (sl_handle != NULL || !load) {
66
path = _shared_library_path;
67
return sl_handle;
68
}
69
assert(JVMCI_lock->owner() == Thread::current(), "must be");
70
path = NULL;
71
if (_shared_library_handle == NULL) {
72
char path[JVM_MAXPATHLEN];
73
char ebuf[1024];
74
if (JVMCILibPath != NULL) {
75
if (!os::dll_locate_lib(path, sizeof(path), JVMCILibPath, JVMCI_SHARED_LIBRARY_NAME)) {
76
fatal("Unable to create path to JVMCI shared library based on value of JVMCILibPath (%s)", JVMCILibPath);
77
}
78
} else {
79
if (!os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) {
80
fatal("Unable to create path to JVMCI shared library");
81
}
82
}
83
84
void* handle = os::dll_load(path, ebuf, sizeof ebuf);
85
if (handle == NULL) {
86
fatal("Unable to load JVMCI shared library from %s: %s", path, ebuf);
87
}
88
_shared_library_handle = handle;
89
_shared_library_path = strdup(path);
90
91
JVMCI_event_1("loaded JVMCI shared library from %s", path);
92
}
93
path = _shared_library_path;
94
return _shared_library_handle;
95
}
96
97
void JVMCI::initialize_compiler(TRAPS) {
98
if (JVMCILibDumpJNIConfig) {
99
JNIJVMCI::initialize_ids(NULL);
100
ShouldNotReachHere();
101
}
102
103
JVMCI::compiler_runtime()->call_getCompiler(CHECK);
104
}
105
106
void JVMCI::initialize_globals() {
107
jvmci_vmStructs_init();
108
if (LogEvents) {
109
if (JVMCIEventLogLevel > 0) {
110
_events = new StringEventLog("JVMCI Events", "jvmci");
111
if (JVMCIEventLogLevel > 1) {
112
int count = LogEventsBufferEntries;
113
for (int i = 1; i < JVMCIEventLogLevel && i < max_EventLog_level; i++) {
114
// Expand event buffer by 10x for each level above 1
115
count = count * 10;
116
}
117
_verbose_events = new StringEventLog("Verbose JVMCI Events", "verbose-jvmci", count);
118
}
119
}
120
}
121
if (UseJVMCINativeLibrary) {
122
// There are two runtimes.
123
_compiler_runtime = new JVMCIRuntime(0);
124
_java_runtime = new JVMCIRuntime(-1);
125
} else {
126
// There is only a single runtime
127
_java_runtime = _compiler_runtime = new JVMCIRuntime(0);
128
}
129
}
130
131
void JVMCI::ensure_box_caches_initialized(TRAPS) {
132
if (_box_caches_initialized) {
133
return;
134
}
135
136
// While multiple threads may reach here, that's fine
137
// since class initialization is synchronized.
138
Symbol* box_classes[] = {
139
java_lang_Boolean::symbol(),
140
java_lang_Byte_ByteCache::symbol(),
141
java_lang_Short_ShortCache::symbol(),
142
java_lang_Character_CharacterCache::symbol(),
143
java_lang_Integer_IntegerCache::symbol(),
144
java_lang_Long_LongCache::symbol()
145
};
146
147
for (unsigned i = 0; i < sizeof(box_classes) / sizeof(Symbol*); i++) {
148
Klass* k = SystemDictionary::resolve_or_fail(box_classes[i], true, CHECK);
149
InstanceKlass* ik = InstanceKlass::cast(k);
150
if (ik->is_not_initialized()) {
151
ik->initialize(CHECK);
152
}
153
}
154
_box_caches_initialized = true;
155
}
156
157
JavaThread* JVMCI::compilation_tick(JavaThread* thread) {
158
if (thread->is_Compiler_thread()) {
159
CompileTask *task = CompilerThread::cast(thread)->task();
160
if (task != NULL) {
161
JVMCICompileState *state = task->blocking_jvmci_compile_state();
162
if (state != NULL) {
163
state->inc_compilation_ticks();
164
}
165
}
166
}
167
return thread;
168
}
169
170
void JVMCI::metadata_do(void f(Metadata*)) {
171
if (_java_runtime != NULL) {
172
_java_runtime->_metadata_handles->metadata_do(f);
173
}
174
if (_compiler_runtime != NULL && _compiler_runtime != _java_runtime) {
175
_compiler_runtime->_metadata_handles->metadata_do(f);
176
}
177
}
178
179
void JVMCI::do_unloading(bool unloading_occurred) {
180
if (unloading_occurred) {
181
if (_java_runtime != NULL) {
182
_java_runtime->_metadata_handles->do_unloading();
183
}
184
if (_compiler_runtime != NULL && _compiler_runtime != _java_runtime) {
185
_compiler_runtime->_metadata_handles->do_unloading();
186
}
187
}
188
}
189
190
bool JVMCI::is_compiler_initialized() {
191
return _is_initialized;
192
}
193
194
void JVMCI::shutdown() {
195
ResourceMark rm;
196
{
197
MutexLocker locker(JVMCI_lock);
198
_in_shutdown = true;
199
JVMCI_event_1("shutting down JVMCI");
200
}
201
JVMCIRuntime* java_runtime = _java_runtime;
202
if (java_runtime != compiler_runtime()) {
203
java_runtime->shutdown();
204
}
205
if (compiler_runtime() != NULL) {
206
compiler_runtime()->shutdown();
207
}
208
}
209
210
bool JVMCI::in_shutdown() {
211
return _in_shutdown;
212
}
213
214
void JVMCI::vlog(int level, const char* format, va_list ap) {
215
if (LogEvents && JVMCIEventLogLevel >= level) {
216
StringEventLog* events = level == 1 ? _events : _verbose_events;
217
guarantee(events != NULL, "JVMCI event log not yet initialized");
218
Thread* thread = Thread::current_or_null_safe();
219
if (thread != NULL) {
220
events->logv(thread, format, ap);
221
}
222
}
223
}
224
225
void JVMCI::vtrace(int level, const char* format, va_list ap) {
226
if (JVMCITraceLevel >= level) {
227
Thread* thread = Thread::current_or_null_safe();
228
if (thread != NULL) {
229
ResourceMark rm;
230
tty->print("JVMCITrace-%d[%s]:%*c", level, thread->name(), level, ' ');
231
} else {
232
tty->print("JVMCITrace-%d[?]:%*c", level, level, ' ');
233
}
234
tty->vprint_cr(format, ap);
235
}
236
}
237
238
#define LOG_TRACE(level) { va_list ap; \
239
va_start(ap, format); vlog(level, format, ap); va_end(ap); \
240
va_start(ap, format); vtrace(level, format, ap); va_end(ap); \
241
}
242
243
void JVMCI::event(int level, const char* format, ...) LOG_TRACE(level)
244
void JVMCI::event1(const char* format, ...) LOG_TRACE(1)
245
void JVMCI::event2(const char* format, ...) LOG_TRACE(2)
246
void JVMCI::event3(const char* format, ...) LOG_TRACE(3)
247
void JVMCI::event4(const char* format, ...) LOG_TRACE(4)
248
249
#undef LOG_TRACE
250
251