Skip to content

Commit 8b69a2e

Browse files
author
Doug Simon
committed
8298099: [JVMCI] decouple libgraal from JVMCI module at runtime
Reviewed-by: never
1 parent 8a9911e commit 8b69a2e

File tree

18 files changed

+377
-463
lines changed

18 files changed

+377
-463
lines changed

src/hotspot/share/classfile/classLoader.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,18 @@ void ClassLoader::setup_bootstrap_search_path_impl(JavaThread* current, const ch
671671
}
672672
}
673673

674+
// Gets the exploded path for the named module. The memory for the path
675+
// is allocated on the C heap if `c_heap` is true otherwise in the resource area.
676+
static const char* get_exploded_module_path(const char* module_name, bool c_heap) {
677+
const char *home = Arguments::get_java_home();
678+
const char file_sep = os::file_separator()[0];
679+
// 10 represents the length of "modules" + 2 file separators + \0
680+
size_t len = strlen(home) + strlen(module_name) + 10;
681+
char *path = c_heap ? NEW_C_HEAP_ARRAY(char, len, mtModule) : NEW_RESOURCE_ARRAY(char, len);
682+
jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
683+
return path;
684+
}
685+
674686
// During an exploded modules build, each module defined to the boot loader
675687
// will be added to the ClassLoader::_exploded_entries array.
676688
void ClassLoader::add_to_exploded_build_list(JavaThread* current, Symbol* module_sym) {
@@ -680,12 +692,7 @@ void ClassLoader::add_to_exploded_build_list(JavaThread* current, Symbol* module
680692
// Find the module's symbol
681693
ResourceMark rm(current);
682694
const char *module_name = module_sym->as_C_string();
683-
const char *home = Arguments::get_java_home();
684-
const char file_sep = os::file_separator()[0];
685-
// 10 represents the length of "modules" + 2 file separators + \0
686-
size_t len = strlen(home) + strlen(module_name) + 10;
687-
char *path = NEW_RESOURCE_ARRAY(char, len);
688-
jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
695+
const char *path = get_exploded_module_path(module_name, false);
689696

690697
struct stat st;
691698
if (os::stat(path, &st) == 0) {
@@ -1415,6 +1422,20 @@ char* ClassLoader::lookup_vm_options() {
14151422
return options;
14161423
}
14171424

1425+
bool ClassLoader::is_module_observable(const char* module_name) {
1426+
assert(JImageOpen != NULL, "jimage library should have been opened");
1427+
if (JImage_file == NULL) {
1428+
struct stat st;
1429+
const char *path = get_exploded_module_path(module_name, true);
1430+
bool res = os::stat(path, &st) == 0;
1431+
FREE_C_HEAP_ARRAY(char, path);
1432+
return res;
1433+
}
1434+
jlong size;
1435+
const char *jimage_version = get_jimage_version_string();
1436+
return (*JImageFindResource)(JImage_file, module_name, jimage_version, "module-info.class", &size) != 0;
1437+
}
1438+
14181439
#if INCLUDE_CDS
14191440
void ClassLoader::initialize_shared_path(JavaThread* current) {
14201441
if (Arguments::is_dumping_archive()) {

src/hotspot/share/classfile/classLoader.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ class ClassLoader: AllStatic {
374374

375375
static char* lookup_vm_options();
376376

377+
// Determines if the named module is present in the
378+
// modules jimage file or in the exploded modules directory.
379+
static bool is_module_observable(const char* module_name);
380+
377381
static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
378382
const char* file_name, jlong &size);
379383

src/hotspot/share/classfile/vmSymbols.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@
745745
do_alias(appendToClassPathForInstrumentation_signature, string_void_signature) \
746746
template(serializePropertiesToByteArray_name, "serializePropertiesToByteArray") \
747747
template(serializeAgentPropertiesToByteArray_name, "serializeAgentPropertiesToByteArray") \
748+
template(serializeSavedPropertiesToByteArray_name, "serializeSavedPropertiesToByteArray") \
749+
template(encodeThrowable_name, "encodeThrowable") \
750+
template(encodeThrowable_signature, "(Ljava/lang/Throwable;JI)I") \
751+
template(decodeAndThrowThrowable_name, "decodeAndThrowThrowable") \
748752
template(classRedefinedCount_name, "classRedefinedCount") \
749753
template(classLoader_name, "classLoader") \
750754
template(componentType_name, "componentType") \

src/hotspot/share/jvmci/jvmci.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "memory/universe.hpp"
3636
#include "runtime/arguments.hpp"
3737
#include "runtime/atomic.hpp"
38+
#include "runtime/javaThread.inline.hpp"
3839
#include "runtime/os.hpp"
3940
#include "utilities/events.hpp"
4041

@@ -228,9 +229,17 @@ void JVMCI::vlog(int level, const char* format, va_list ap) {
228229
void JVMCI::vtrace(int level, const char* format, va_list ap) {
229230
if (JVMCITraceLevel >= level) {
230231
Thread* thread = Thread::current_or_null_safe();
231-
if (thread != nullptr) {
232-
ResourceMark rm;
233-
tty->print("JVMCITrace-%d[%s]:%*c", level, thread->name(), level, ' ');
232+
if (thread != nullptr && thread->is_Java_thread()) {
233+
ResourceMark rm(thread);
234+
JavaThreadState state = JavaThread::cast(thread)->thread_state();
235+
if (state == _thread_in_vm || state == _thread_in_Java || state == _thread_new) {
236+
tty->print("JVMCITrace-%d[%s]:%*c", level, thread->name(), level, ' ');
237+
} else {
238+
// According to check_access_thread_state, it's unsafe to
239+
// resolve the j.l.Thread object unless the thread is in
240+
// one of the states above.
241+
tty->print("JVMCITrace-%d[%s@" PTR_FORMAT "]:%*c", level, thread->type_name(), p2i(thread), level, ' ');
242+
}
234243
} else {
235244
tty->print("JVMCITrace-%d[?]:%*c", level, level, ' ');
236245
}

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ static JavaThread* get_current_thread(bool allow_null=true) {
142142
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
143143
return; \
144144
} \
145-
JVMCITraceMark jtm("CompilerToVM::" #name); \
146-
C2V_BLOCK(result_type, name, signature)
145+
C2V_BLOCK(result_type, name, signature) \
146+
JVMCITraceMark jtm("CompilerToVM::" #name);
147147

148148
#define C2V_VMENTRY_(result_type, name, signature, result) \
149149
JNIEXPORT result_type JNICALL c2v_ ## name signature { \
@@ -153,8 +153,8 @@ static JavaThread* get_current_thread(bool allow_null=true) {
153153
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
154154
return result; \
155155
} \
156-
JVMCITraceMark jtm("CompilerToVM::" #name); \
157-
C2V_BLOCK(result_type, name, signature)
156+
C2V_BLOCK(result_type, name, signature) \
157+
JVMCITraceMark jtm("CompilerToVM::" #name);
158158

159159
#define C2V_VMENTRY_NULL(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, NULL)
160160
#define C2V_VMENTRY_0(result_type, name, signature) C2V_VMENTRY_(result_type, name, signature, 0)
@@ -503,7 +503,7 @@ C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, ARGU
503503
} else {
504504
// Use the System class loader
505505
class_loader = Handle(THREAD, SystemDictionary::java_system_loader());
506-
JVMCIENV->runtime()->initialize(JVMCIENV);
506+
JVMCIENV->runtime()->initialize(JVMCI_CHECK_NULL);
507507
}
508508

509509
if (resolve) {
@@ -2312,9 +2312,9 @@ C2V_VMENTRY_PREFIX(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject c2vm
23122312
// Called from unattached JVMCI shared library thread
23132313
return false;
23142314
}
2315-
JVMCITraceMark jtm("isCurrentThreadAttached");
23162315
if (thread->jni_environment() == env) {
23172316
C2V_BLOCK(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject))
2317+
JVMCITraceMark jtm("isCurrentThreadAttached");
23182318
requireJVMCINativeLibrary(JVMCI_CHECK_0);
23192319
JVMCIRuntime* runtime = thread->libjvmci_runtime();
23202320
if (runtime == nullptr || !runtime->has_shared_library_javavm()) {
@@ -2331,7 +2331,6 @@ C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
23312331
// Called from unattached JVMCI shared library thread
23322332
return 0L;
23332333
}
2334-
JVMCITraceMark jtm("getCurrentJavaThread");
23352334
return (jlong) p2i(thread);
23362335
C2V_END
23372336

@@ -2377,10 +2376,10 @@ C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jb
23772376
attachSharedLibraryThread(env, name, as_daemon);
23782377
return true;
23792378
}
2380-
JVMCITraceMark jtm("attachCurrentThread");
23812379
if (thread->jni_environment() == env) {
23822380
// Called from HotSpot
23832381
C2V_BLOCK(jboolean, attachCurrentThread, (JNIEnv* env, jobject, jboolean))
2382+
JVMCITraceMark jtm("attachCurrentThread");
23842383
requireJVMCINativeLibrary(JVMCI_CHECK_0);
23852384

23862385
JVMCIRuntime* runtime = JVMCI::compiler_runtime(thread);
@@ -2435,10 +2434,10 @@ C2V_VMENTRY_PREFIX(jboolean, detachCurrentThread, (JNIEnv* env, jobject c2vm, jb
24352434
// Called from unattached JVMCI shared library thread
24362435
JNI_THROW_("detachCurrentThread", IllegalStateException, "Cannot detach non-attached thread", false);
24372436
}
2438-
JVMCITraceMark jtm("detachCurrentThread");
24392437
if (thread->jni_environment() == env) {
24402438
// Called from HotSpot
24412439
C2V_BLOCK(void, detachCurrentThread, (JNIEnv* env, jobject))
2440+
JVMCITraceMark jtm("detachCurrentThread");
24422441
requireJVMCINativeLibrary(JVMCI_CHECK_0);
24432442
requireInHotSpot("detachCurrentThread", JVMCI_CHECK_0);
24442443
JVMCIRuntime* runtime = thread->libjvmci_runtime();

0 commit comments

Comments
 (0)