Skip to content

Commit

Permalink
8311946: add support for libgraal specific jtreg tests
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, thartmann
  • Loading branch information
Doug Simon committed Jul 14, 2023
1 parent 167d1c1 commit a63f865
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 14 deletions.
37 changes: 28 additions & 9 deletions src/hotspot/share/jvmci/jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/hotspot/share/jvmci/jvmci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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`.
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/oops/instanceKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3857,15 +3857,15 @@ 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) {
debug_stream.print(" interfaces:");
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))));
}
}

Expand All @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions src/hotspot/share/prims/whitebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 },
Expand Down
2 changes: 2 additions & 0 deletions test/hotspot/jtreg/TEST.ROOT
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
23 changes: 23 additions & 0 deletions test/jtreg-ext/requires/VMProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public Map<String, String> call() {
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);
Expand Down Expand Up @@ -486,6 +490,24 @@ protected String isGraalEnabled() {
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.
*
Expand Down Expand Up @@ -709,6 +731,7 @@ protected static void dump(Map<String, String> map) {
}
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);
Expand Down
3 changes: 3 additions & 0 deletions test/lib/jdk/test/whitebox/WhiteBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public Object[] parseCommandLine(String commandline, char delim, Dia
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();

Expand Down
19 changes: 19 additions & 0 deletions test/lib/jdk/test/whitebox/code/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ public static boolean isGraalEnabled() {
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.
*
Expand Down

1 comment on commit a63f865

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.