mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
Implement some library procedures for Java.
Estimated hours taken: 1.5 Branches: main Implement some library procedures for Java. library/benchmarking.m: Implement the following predicates in Java: report_stats/0 report_full_memory_stats/0 java/runtime/Native.java.in: Record whether or not there has yet been an attempt to load the library. Add the side effect of loading the library to isAvailable(), in case the static code for benchmarking.java is run before the static code for Native.java.
This commit is contained in:
@@ -21,18 +21,31 @@ public class Native {
|
||||
private static final java.lang.String SHARED_OBJ =
|
||||
"Native.@EXT_FOR_SHARED_LIB@";
|
||||
|
||||
/*
|
||||
** attemptedLoad records whether or not the user has yet attempted to
|
||||
** load the shared library.
|
||||
*/
|
||||
private static boolean attemptedLoad = false;
|
||||
|
||||
/*
|
||||
** available and isAvailable() are true when native functionality
|
||||
** is available. (ie SHARED_OBJ was loaded successfully)
|
||||
*/
|
||||
private static boolean available = false;
|
||||
|
||||
/*
|
||||
** isAvailable() as the side effect of attempting to load the library
|
||||
** if this has not already been done.
|
||||
*/
|
||||
public static boolean isAvailable() {
|
||||
if (!attemptedLoad) {
|
||||
load_library();
|
||||
}
|
||||
return available;
|
||||
}
|
||||
|
||||
static {
|
||||
available = load_library();
|
||||
load_library();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -42,9 +55,11 @@ public class Native {
|
||||
** the shared object SHARED_OBJ and attempts to load this file
|
||||
** if found.
|
||||
** Also searches in the subdirectory Constants.MR_FULLARCH.
|
||||
** Returns true if successful, false otherwise.
|
||||
** Sets available to true if successful, false otherwise.
|
||||
*/
|
||||
private static boolean load_library() {
|
||||
private static void load_library() {
|
||||
attemptedLoad = true;
|
||||
|
||||
java.util.StringTokenizer classpath =
|
||||
new java.util.StringTokenizer(
|
||||
java.lang.System.getProperty("java.class.path")
|
||||
@@ -77,14 +92,15 @@ public class Native {
|
||||
}
|
||||
|
||||
java.lang.System.load(match.getAbsolutePath());
|
||||
return true;
|
||||
available = true;
|
||||
return;
|
||||
}
|
||||
catch (java.lang.Exception e) {
|
||||
continue;
|
||||
}
|
||||
} // while classpath.hasMoreTokens()
|
||||
|
||||
return false;
|
||||
return;
|
||||
} // load_library()
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user