diff --git a/src/hotspot/share/jvmci/jvmci.cpp b/src/hotspot/share/jvmci/jvmci.cpp index 87cb431dd74..78b3e3004df 100644 --- a/src/hotspot/share/jvmci/jvmci.cpp +++ b/src/hotspot/share/jvmci/jvmci.cpp @@ -67,6 +67,33 @@ bool JVMCI::can_initialize_JVMCI() { return true; } +bool JVMCI::get_shared_library_path(char* pathbuf, size_t pathlen, bool fail_is_fatal) { + if (JVMCILibPath != nullptr) { + if (!os::dll_locate_lib(pathbuf, pathlen, JVMCILibPath, JVMCI_SHARED_LIBRARY_NAME)) { + if (!fail_is_fatal) { + return false; + } + fatal("Unable to create path to JVMCI shared library based on value of JVMCILibPath (%s)", JVMCILibPath); + } + } else { + if (!os::dll_locate_lib(pathbuf, pathlen, Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) { + if (!fail_is_fatal) { + return false; + } + fatal("Unable to create path to JVMCI shared library"); + } + } + return true; +} + +bool JVMCI::shared_library_exists() { + if (_shared_library_handle != nullptr) { + return true; + } + char path[JVM_MAXPATHLEN]; + return get_shared_library_path(path, sizeof(path), false); +} + void* JVMCI::get_shared_library(char*& path, bool load) { void* sl_handle = _shared_library_handle; if (sl_handle != nullptr || !load) { @@ -78,15 +105,7 @@ void* JVMCI::get_shared_library(char*& path, bool load) { if (_shared_library_handle == nullptr) { char path[JVM_MAXPATHLEN]; char ebuf[1024]; - if (JVMCILibPath != nullptr) { - if (!os::dll_locate_lib(path, sizeof(path), JVMCILibPath, JVMCI_SHARED_LIBRARY_NAME)) { - fatal("Unable to create path to JVMCI shared library based on value of JVMCILibPath (%s)", JVMCILibPath); - } - } else { - if (!os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) { - fatal("Unable to create path to JVMCI shared library"); - } - } + get_shared_library_path(path, sizeof(path), true); void* handle = os::dll_load(path, ebuf, sizeof ebuf); if (handle == nullptr) { diff --git a/src/hotspot/share/jvmci/jvmci.hpp b/src/hotspot/share/jvmci/jvmci.hpp index 848cf0d4f21..200046906f6 100644 --- a/src/hotspot/share/jvmci/jvmci.hpp +++ b/src/hotspot/share/jvmci/jvmci.hpp @@ -101,6 +101,12 @@ class JVMCI : public AllStatic { // Gets the Thread* value for the current thread or null if it's not available. static Thread* current_thread_or_null(); + // Writes into `pathbuf` the path to the existing JVMCI shared library file. + // If the file cannot be found and `fail_is_fatal` is true, then + // a fatal error occurs. + // Returns whether the path to an existing file was written into `pathbuf`. + static bool get_shared_library_path(char* pathbuf, size_t pathlen, bool fail_is_fatal); + public: enum CodeInstallResult { @@ -122,6 +128,11 @@ class JVMCI : public AllStatic { return JVMCIThreadsPerNativeLibraryRuntime == 1 && JVMCICompilerIdleDelay == 0; } + // Determines if the JVMCI shared library exists. This does not + // take into account whether loading the library would succeed + // if it's not already loaded. + static bool shared_library_exists(); + // Gets the handle to the loaded JVMCI shared library, loading it // first if not yet loaded and `load` is true. The path from // which the library is loaded is returned in `path`. diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index e1eed0e1272..8fd4eaefb12 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -3857,7 +3857,7 @@ void InstanceKlass::print_class_load_helper(ClassLoaderData* loader_data, // Class hierarchy info debug_stream.print(" klass: " PTR_FORMAT " super: " PTR_FORMAT, - p2i(this), p2i(superklass())); + p2i(this), p2i(superklass())); // Interfaces if (local_interfaces() != nullptr && local_interfaces()->length() > 0) { @@ -3865,7 +3865,7 @@ void InstanceKlass::print_class_load_helper(ClassLoaderData* loader_data, int length = local_interfaces()->length(); for (int i = 0; i < length; i++) { debug_stream.print(" " PTR_FORMAT, - p2i(InstanceKlass::cast(local_interfaces()->at(i)))); + p2i(InstanceKlass::cast(local_interfaces()->at(i)))); } } @@ -3877,9 +3877,9 @@ void InstanceKlass::print_class_load_helper(ClassLoaderData* loader_data, // Classfile checksum if (cfs) { debug_stream.print(" bytes: %d checksum: %08x", - cfs->length(), - ClassLoader::crc32(0, (const char*)cfs->buffer(), - cfs->length())); + cfs->length(), + ClassLoader::crc32(0, (const char*)cfs->buffer(), + cfs->length())); } msg.debug("%s", debug_stream.as_string()); diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 9303bf4c946..5451126169a 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -366,6 +366,13 @@ WB_ENTRY(jboolean, WB_IsGCSupported(JNIEnv* env, jobject o, jint name)) return GCConfig::is_gc_supported((CollectedHeap::Name)name); WB_END +WB_ENTRY(jboolean, WB_HasLibgraal(JNIEnv* env, jobject o)) +#if INCLUDE_JVMCI + return JVMCI::shared_library_exists(); +#endif + return false; +WB_END + WB_ENTRY(jboolean, WB_IsGCSupportedByJVMCICompiler(JNIEnv* env, jobject o, jint name)) #if INCLUDE_JVMCI if (EnableJVMCI) { @@ -2803,6 +2810,7 @@ static JNINativeMethod methods[] = { {CC"isCDSIncluded", CC"()Z", (void*)&WB_IsCDSIncluded }, {CC"isJFRIncluded", CC"()Z", (void*)&WB_IsJFRIncluded }, {CC"isDTraceIncluded", CC"()Z", (void*)&WB_IsDTraceIncluded }, + {CC"hasLibgraal", CC"()Z", (void*)&WB_HasLibgraal }, {CC"isC2OrJVMCIIncluded", CC"()Z", (void*)&WB_isC2OrJVMCIIncluded }, {CC"isJVMCISupportedByGC", CC"()Z", (void*)&WB_IsJVMCISupportedByGC}, {CC"canWriteJavaHeapArchive", CC"()Z", (void*)&WB_CanWriteJavaHeapArchive }, diff --git a/test/hotspot/jtreg/TEST.ROOT b/test/hotspot/jtreg/TEST.ROOT index 30b83f79383..51be81c48bc 100644 --- a/test/hotspot/jtreg/TEST.ROOT +++ b/test/hotspot/jtreg/TEST.ROOT @@ -78,6 +78,8 @@ requires.properties= \ vm.continuations \ vm.jvmti \ vm.graal.enabled \ + jdk.hasLibgraal \ + vm.libgraal.enabled \ vm.compiler1.enabled \ vm.compiler2.enabled \ vm.musl \ diff --git a/test/jtreg-ext/requires/VMProps.java b/test/jtreg-ext/requires/VMProps.java index 447b4133cc3..8a78e644a65 100644 --- a/test/jtreg-ext/requires/VMProps.java +++ b/test/jtreg-ext/requires/VMProps.java @@ -123,6 +123,10 @@ public class VMProps implements Callable> { map.put("vm.continuations", this::vmContinuations); // vm.graal.enabled is true if Graal is used as JIT map.put("vm.graal.enabled", this::isGraalEnabled); + // jdk.hasLibgraal is true if the libgraal shared library file is present + map.put("jdk.hasLibgraal", this::hasLibgraal); + // vm.libgraal.enabled is true if libgraal is used as JIT + map.put("vm.libgraal.enabled", this::isLibgraalEnabled); map.put("vm.compiler1.enabled", this::isCompiler1Enabled); map.put("vm.compiler2.enabled", this::isCompiler2Enabled); map.put("docker.support", this::dockerSupport); @@ -486,6 +490,24 @@ public class VMProps implements Callable> { return "" + Compiler.isGraalEnabled(); } + /** + * Check if the libgraal shared library file is present. + * + * @return true if the libgraal shared library file is present. + */ + protected String hasLibgraal() { + return "" + WB.hasLibgraal(); + } + + /** + * Check if libgraal is used as JIT compiler. + * + * @return true if libgraal is used as JIT compiler. + */ + protected String isLibgraalEnabled() { + return "" + Compiler.isLibgraalEnabled(); + } + /** * Check if Compiler1 is present. * @@ -709,6 +731,7 @@ public class VMProps implements Callable> { } List lines = new ArrayList<>(); map.forEach((k, v) -> lines.add(k + ":" + v)); + Collections.sort(lines); try { Files.write(Paths.get(dumpFileName), lines, StandardOpenOption.APPEND, StandardOpenOption.CREATE); diff --git a/test/lib/jdk/test/whitebox/WhiteBox.java b/test/lib/jdk/test/whitebox/WhiteBox.java index 66cd7567af0..15519d3dbcf 100644 --- a/test/lib/jdk/test/whitebox/WhiteBox.java +++ b/test/lib/jdk/test/whitebox/WhiteBox.java @@ -303,6 +303,9 @@ public class WhiteBox { public native void NMTArenaMalloc(long arena, long size); // Compiler + + // Determines if the libgraal shared library file is present. + public native boolean hasLibgraal(); public native boolean isC2OrJVMCIIncluded(); public native boolean isJVMCISupportedByGC(); diff --git a/test/lib/jdk/test/whitebox/code/Compiler.java b/test/lib/jdk/test/whitebox/code/Compiler.java index 7c37770a5ec..2f8447700d5 100644 --- a/test/lib/jdk/test/whitebox/code/Compiler.java +++ b/test/lib/jdk/test/whitebox/code/Compiler.java @@ -88,6 +88,25 @@ public class Compiler { return true; } + /** + * Check if libgraal is used as JIT compiler. + * + * libraal is enabled if isGraalEnabled is true and: + * - UseJVMCINativeLibrary flag is true + * + * @return true if libgraal is used as JIT compiler. + */ + public static boolean isLibgraalEnabled() { + if (!isGraalEnabled()) { + return false; + } + Boolean useJvmciNativeLibrary = WB.getBooleanVMFlag("UseJVMCINativeLibrary"); + if (useJvmciNativeLibrary == null || !useJvmciNativeLibrary) { + return false; + } + return true; + } + /** * Check if C2 is used as JIT compiler. *