8311946: add support for libgraal specific jtreg tests

Reviewed-by: kvn, thartmann
This commit is contained in:
Doug Simon 2023-07-14 14:10:10 +00:00
parent 167d1c1835
commit a63f865feb
8 changed files with 99 additions and 14 deletions

View File

@ -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) {

View File

@ -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`.

View File

@ -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());

View File

@ -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 },

View File

@ -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 \

View File

@ -123,6 +123,10 @@ public class VMProps implements Callable<Map<String, String>> {
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<Map<String, String>> {
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<Map<String, String>> {
}
List<String> 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);

View File

@ -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();

View File

@ -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.
*