[m-rev.] For review: More Java implementations for the benchmarking library
James Goddard
goddardjames at yahoo.com
Tue Feb 10 18:16:29 AEDT 2004
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.
Index: benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.57
diff -u -d -r1.57 benchmarking.m
--- benchmarking.m 5 Feb 2004 03:56:04 -0000 1.57
+++ benchmarking.m 10 Feb 2004 07:05:05 -0000
@@ -93,6 +93,18 @@
#endif
").
+:- pragma foreign_proc("Java", report_stats,
+ [may_call_mercury],
+"
+ ML_report_stats();
+").
+
+:- pragma foreign_proc("Java", report_full_memory_stats,
+ [will_not_call_mercury],
+"
+ ML_report_full_memory_stats();
+").
+
%-----------------------------------------------------------------------------%
:- pragma foreign_code("C", "
@@ -579,6 +591,52 @@
}
#endif /* MR_MPROF_PROFILE_MEMORY */
+").
+
+:- pragma foreign_code("Java",
+"
+private static int time_at_start = 0;
+private static int time_at_last_stat = 0;
+
+static {
+ if (mercury.runtime.Native.isAvailable()) {
+ time_at_start = mercury.runtime.Native.
+ get_user_cpu_miliseconds();
+ time_at_last_stat = time_at_start;
+ }
+}
+
+private static void
+ML_report_stats() {
+ int time_at_prev_stat = time_at_last_stat;
+ time_at_last_stat = get_user_cpu_miliseconds_1_p_0();
+
+ System.err.print(""[Time: "" +
+ ((time_at_last_stat - time_at_prev_stat) / 1000.0) +
+ "", "" +
+ ((time_at_last_stat - time_at_start) / 1000.0)
+ );
+
+ /*
+ ** XXX At this point there should be a whole bunch of memory usage
+ ** statistics. Unfortunately the Java back-end does not yet
+ ** support this amount of profiling, so cpu time is all you get.
+ */
+
+ System.err.println(""]"");
+}
+
+private static void
+ML_report_full_memory_stats() {
+ /*
+ ** XXX The support for this predicate is even worse. Since we don't
+ ** have access to memory usage statistics, all you get here is an
+ ** apology. But at least it doesn't just crash with an error.
+ */
+
+ System.err.println(""Sorry, report_full_memory_stats is not yet "" +
+ ""implemented for the Java back-end."");
+}
").
%-----------------------------------------------------------------------------%
Index: ../java/runtime/Native.java.in
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/Native.java.in,v
retrieving revision 1.1
diff -u -d -r1.1 Native.java.in
--- ../java/runtime/Native.java.in 5 Feb 2004 03:56:00 -0000 1.1
+++ ../java/runtime/Native.java.in 10 Feb 2004 06:14:49 -0000
@@ -22,17 +22,30 @@
"Native. at 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 @@
** 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 @@
}
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()
/*
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list