Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/hotspot/share/classfile/classLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,18 @@ void ClassLoader::setup_bootstrap_search_path_impl(JavaThread* current, const ch
}
}

// Gets the exploded path for the named module. The memory for the path
// is allocated on the C heap if `c_heap` is true otherwise in the resource area.
static const char* get_exploded_module_path(const char* module_name, bool c_heap) {
const char *home = Arguments::get_java_home();
const char file_sep = os::file_separator()[0];
// 10 represents the length of "modules" + 2 file separators + \0
size_t len = strlen(home) + strlen(module_name) + 10;
char *path = c_heap ? NEW_C_HEAP_ARRAY(char, len, mtModule) : NEW_RESOURCE_ARRAY(char, len);
jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
return path;
}

// During an exploded modules build, each module defined to the boot loader
// will be added to the ClassLoader::_exploded_entries array.
void ClassLoader::add_to_exploded_build_list(JavaThread* current, Symbol* module_sym) {
Expand All @@ -680,12 +692,7 @@ void ClassLoader::add_to_exploded_build_list(JavaThread* current, Symbol* module
// Find the module's symbol
ResourceMark rm(current);
const char *module_name = module_sym->as_C_string();
const char *home = Arguments::get_java_home();
const char file_sep = os::file_separator()[0];
// 10 represents the length of "modules" + 2 file separators + \0
size_t len = strlen(home) + strlen(module_name) + 10;
char *path = NEW_RESOURCE_ARRAY(char, len);
jio_snprintf(path, len, "%s%cmodules%c%s", home, file_sep, file_sep, module_name);
const char *path = get_exploded_module_path(module_name, false);

struct stat st;
if (os::stat(path, &st) == 0) {
Expand Down Expand Up @@ -1415,6 +1422,20 @@ char* ClassLoader::lookup_vm_options() {
return options;
}

bool ClassLoader::is_module_observable(const char* module_name) {
assert(JImageOpen != NULL, "jimage library should have been opened");
if (JImage_file == NULL) {
struct stat st;
const char *path = get_exploded_module_path(module_name, true);
bool res = os::stat(path, &st) == 0;
FREE_C_HEAP_ARRAY(char, path);
return res;
}
jlong size;
const char *jimage_version = get_jimage_version_string();
return (*JImageFindResource)(JImage_file, module_name, jimage_version, "module-info.class", &size) != 0;
}

#if INCLUDE_CDS
void ClassLoader::initialize_shared_path(JavaThread* current) {
if (Arguments::is_dumping_archive()) {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/classfile/classLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ class ClassLoader: AllStatic {

static char* lookup_vm_options();

// Determines if the named module is present in the
// modules jimage file or in the exploded modules directory.
static bool is_module_observable(const char* module_name);

static JImageLocationRef jimage_find_resource(JImageFile* jf, const char* module_name,
const char* file_name, jlong &size);

Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/classfile/vmSymbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@
do_alias(appendToClassPathForInstrumentation_signature, string_void_signature) \
template(serializePropertiesToByteArray_name, "serializePropertiesToByteArray") \
template(serializeAgentPropertiesToByteArray_name, "serializeAgentPropertiesToByteArray") \
template(serializeSavedPropertiesToByteArray_name, "serializeSavedPropertiesToByteArray") \
template(encodeThrowable_name, "encodeThrowable") \
template(encodeThrowable_signature, "(Ljava/lang/Throwable;JI)I") \
template(decodeAndThrowThrowable_name, "decodeAndThrowThrowable") \
template(classRedefinedCount_name, "classRedefinedCount") \
template(classLoader_name, "classLoader") \
template(componentType_name, "componentType") \
Expand Down
15 changes: 12 additions & 3 deletions src/hotspot/share/jvmci/jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "memory/universe.hpp"
#include "runtime/arguments.hpp"
#include "runtime/atomic.hpp"
#include "runtime/javaThread.inline.hpp"
#include "runtime/os.hpp"
#include "utilities/events.hpp"

Expand Down Expand Up @@ -228,9 +229,17 @@ void JVMCI::vlog(int level, const char* format, va_list ap) {
void JVMCI::vtrace(int level, const char* format, va_list ap) {
if (JVMCITraceLevel >= level) {
Thread* thread = Thread::current_or_null_safe();
if (thread != nullptr) {
ResourceMark rm;
tty->print("JVMCITrace-%d[%s]:%*c", level, thread->name(), level, ' ');
if (thread != nullptr && thread->is_Java_thread()) {
ResourceMark rm(thread);
JavaThreadState state = JavaThread::cast(thread)->thread_state();
if (state == _thread_in_vm || state == _thread_in_Java || state == _thread_new) {
tty->print("JVMCITrace-%d[%s]:%*c", level, thread->name(), level, ' ');
} else {
// According to check_access_thread_state, it's unsafe to
// resolve the j.l.Thread object unless the thread is in
// one of the states above.
tty->print("JVMCITrace-%d[%s@" PTR_FORMAT "]:%*c", level, thread->type_name(), p2i(thread), level, ' ');
}
} else {
tty->print("JVMCITrace-%d[?]:%*c", level, level, ' ');
}
Expand Down
17 changes: 8 additions & 9 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ static JavaThread* get_current_thread(bool allow_null=true) {
err_msg("Cannot call into HotSpot from JVMCI shared library without attaching current thread")); \
return; \
} \
JVMCITraceMark jtm("CompilerToVM::" #name); \
C2V_BLOCK(result_type, name, signature)
C2V_BLOCK(result_type, name, signature) \
JVMCITraceMark jtm("CompilerToVM::" #name);

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

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

if (resolve) {
Expand Down Expand Up @@ -2312,9 +2312,9 @@ C2V_VMENTRY_PREFIX(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject c2vm
// Called from unattached JVMCI shared library thread
return false;
}
JVMCITraceMark jtm("isCurrentThreadAttached");
if (thread->jni_environment() == env) {
C2V_BLOCK(jboolean, isCurrentThreadAttached, (JNIEnv* env, jobject))
JVMCITraceMark jtm("isCurrentThreadAttached");
requireJVMCINativeLibrary(JVMCI_CHECK_0);
JVMCIRuntime* runtime = thread->libjvmci_runtime();
if (runtime == nullptr || !runtime->has_shared_library_javavm()) {
Expand All @@ -2331,7 +2331,6 @@ C2V_VMENTRY_PREFIX(jlong, getCurrentJavaThread, (JNIEnv* env, jobject c2vm))
// Called from unattached JVMCI shared library thread
return 0L;
}
JVMCITraceMark jtm("getCurrentJavaThread");
return (jlong) p2i(thread);
C2V_END

Expand Down Expand Up @@ -2377,10 +2376,10 @@ C2V_VMENTRY_PREFIX(jboolean, attachCurrentThread, (JNIEnv* env, jobject c2vm, jb
attachSharedLibraryThread(env, name, as_daemon);
return true;
}
JVMCITraceMark jtm("attachCurrentThread");
if (thread->jni_environment() == env) {
// Called from HotSpot
C2V_BLOCK(jboolean, attachCurrentThread, (JNIEnv* env, jobject, jboolean))
JVMCITraceMark jtm("attachCurrentThread");
requireJVMCINativeLibrary(JVMCI_CHECK_0);

JVMCIRuntime* runtime = JVMCI::compiler_runtime(thread);
Expand Down Expand Up @@ -2435,10 +2434,10 @@ C2V_VMENTRY_PREFIX(jboolean, detachCurrentThread, (JNIEnv* env, jobject c2vm, jb
// Called from unattached JVMCI shared library thread
JNI_THROW_("detachCurrentThread", IllegalStateException, "Cannot detach non-attached thread", false);
}
JVMCITraceMark jtm("detachCurrentThread");
if (thread->jni_environment() == env) {
// Called from HotSpot
C2V_BLOCK(void, detachCurrentThread, (JNIEnv* env, jobject))
JVMCITraceMark jtm("detachCurrentThread");
requireJVMCINativeLibrary(JVMCI_CHECK_0);
requireInHotSpot("detachCurrentThread", JVMCI_CHECK_0);
JVMCIRuntime* runtime = thread->libjvmci_runtime();
Expand Down
Loading