Skip to content

Commit 32986d1

Browse files
committed
consolidate JVMCI eager initialization
1 parent 7eb259b commit 32986d1

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

src/hotspot/share/jvmci/jvmci.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void* JVMCI::get_shared_library(char*& path, bool load) {
151151
return _shared_library_handle;
152152
}
153153

154-
void JVMCI::initialize_compiler(TRAPS) {
154+
void JVMCI::initialize_compiler_in_create_vm(TRAPS) {
155155
if (JVMCILibDumpJNIConfig) {
156156
JNIJVMCI::initialize_ids(nullptr);
157157
ShouldNotReachHere();
@@ -162,7 +162,24 @@ void JVMCI::initialize_compiler(TRAPS) {
162162
} else {
163163
runtime = JVMCI::java_runtime();
164164
}
165-
runtime->call_getCompiler(CHECK);
165+
166+
// Enter a JVMCI env, which will load libjvmci if it's in use
167+
JVMCIENV_FROM_THREAD(THREAD);
168+
int init_error = JVMCIENV->init_error();
169+
if (init_error != JNI_OK) {
170+
if (PrintCompilation) {
171+
const char* msg = JVMCIENV->init_error_msg();
172+
tty->print_cr("COMPILER INIT ERROR: Error creating or attaching to libjvmci (err: %d, description: %s)",
173+
init_error, msg == nullptr ? "unknown" : msg);
174+
}
175+
return;
176+
}
177+
178+
// Failures in the calls below will propagate to the caller
179+
// and cause VM to exit.
180+
JVMCIObject jvmciRuntime = runtime->get_HotSpotJVMCIRuntime(JVMCI_CHECK);
181+
runtime->initialize(JVMCI_CHECK);
182+
JVMCIENV->call_HotSpotJVMCIRuntime_getCompiler(jvmciRuntime, JVMCI_CHECK);
166183
}
167184

168185
void JVMCI::initialize_globals() {

src/hotspot/share/jvmci/jvmci.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ class JVMCI : public AllStatic {
191191

192192
static void initialize_globals();
193193

194-
// Called to force initialization of the JVMCI compiler
195-
// early in VM startup.
196-
static void initialize_compiler(TRAPS);
194+
// Called to initialize the JVMCI compiler during VM startup.
195+
static void initialize_compiler_in_create_vm(TRAPS);
197196

198197
// Ensures the boxing cache classes (e.g., java.lang.Integer.IntegerCache) are initialized.
199198
static void ensure_box_caches_initialized(TRAPS);

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -743,22 +743,6 @@ JVM_ENTRY_NO_ENV(jlong, JVM_ReadSystemPropertiesInfo(JNIEnv *env, jclass c, jint
743743
JVM_END
744744

745745

746-
void JVMCIRuntime::call_getCompiler(TRAPS) {
747-
JVMCIENV_FROM_THREAD(THREAD);
748-
int init_error = JVMCIENV->init_error();
749-
if (init_error != JNI_OK) {
750-
if (PrintCompilation) {
751-
const char* msg = JVMCIENV->init_error_msg();
752-
tty->print_cr("COMPILER INIT ERROR: Error creating or attaching to libjvmci (err: %d, description: %s)",
753-
init_error, msg == nullptr ? "unknown" : msg);
754-
}
755-
return;
756-
}
757-
JVMCIObject jvmciRuntime = JVMCIRuntime::get_HotSpotJVMCIRuntime(JVMCI_CHECK);
758-
initialize(JVMCI_CHECK);
759-
JVMCIENV->call_HotSpotJVMCIRuntime_getCompiler(jvmciRuntime, JVMCI_CHECK);
760-
}
761-
762746
void JVMCINMethodData::initialize(int nmethod_mirror_index,
763747
int nmethod_entry_patch_offset,
764748
const char* nmethod_mirror_name,

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,6 @@ class JVMCIRuntime: public CHeapObj<mtJVMCI> {
373373
// Explicitly initialize HotSpotJVMCIRuntime itself
374374
void initialize_HotSpotJVMCIRuntime(JVMCI_TRAPS);
375375

376-
void call_getCompiler(TRAPS);
377-
378376
// Shuts down this runtime by calling HotSpotJVMCIRuntime.shutdown().
379377
// If this is the last thread attached to this runtime, then
380378
// `_HotSpotJVMCIRuntime_instance` is set to null and `_init_state`

src/hotspot/share/runtime/threads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
835835

836836
#if INCLUDE_JVMCI
837837
if (force_JVMCI_initialization) {
838-
JVMCI::initialize_compiler(CHECK_JNI_ERR);
838+
JVMCI::initialize_compiler_in_create_vm(CHECK_JNI_ERR);
839839
}
840840
#endif
841841

0 commit comments

Comments
 (0)