[m-rev.] For review: Implementation of benchmarking library for Java
James Goddard
goddardjames at yahoo.com
Tue Jan 20 12:44:31 AEDT 2004
Estimated hours taken: 1
Branches: main
Implement some library procedures for the Java back-end.
library/benchmarking.m:
Implement the int_reference type as a new Java class.
Implement the following functions:
do_nothing/1
new_int_reference/2
ref_value/2
update_ref/2 <- this predicate was also change from being
polymorphic to only accepting ints.
Note that 3 procedures still have not been implemented for this class:
benchmarking.report_stats/0
benchmarking.report_full_memory_stats/0
benchmarking.get_user_cpu_miliseconds/1
This is because they will require use of JNI and will be implemented
at a later stage.
Index: benchmarking.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
retrieving revision 1.55
diff -u -d -r1.55 benchmarking.m
--- benchmarking.m 20 Oct 2003 07:29:26 -0000 1.55
+++ benchmarking.m 20 Jan 2004 01:35:06 -0000
@@ -734,6 +734,16 @@
").
*/
+:- pragma foreign_code("Java",
+"
+ static volatile Object ML_benchmarking_dummy_word;
+").
+:- pragma foreign_proc("Java",
+ do_nothing(X::in), [will_not_call_mercury, thread_safe],
+"
+ ML_benchmarking_dummy_word = X;
+").
+
%-----------------------------------------------------------------------------%
% Impure integer references.
@@ -741,6 +751,19 @@
% It is represented as a pointer to a single word on the heap.
:- type int_reference ---> int_reference(private_builtin__ref(int)).
+% In Java, this is implemented as a class to wrap the int.
+:- pragma foreign_code("Java",
+"
+ public static class IntRef {
+ public int value;
+
+ public IntRef(int init) {
+ value = init;
+ }
+ }
+").
+:- pragma foreign_type(java, int_reference, "mercury.benchmarking.IntRef").
+
% Create a new int_reference given a term for it to reference.
:- impure pred new_int_reference(int::in, int_reference::out) is det.
:- pragma inline(new_int_reference/2).
@@ -753,6 +776,12 @@
MR_define_size_slot(0, Ref, 1);
* (MR_Integer *) Ref = X;
").
+:- pragma foreign_proc("Java",
+ new_int_reference(X::in, Ref::out),
+ [will_not_call_mercury],
+"
+ Ref = new mercury.benchmarking.IntRef(X);
+").
:- impure pred incr_ref(int_reference::in) is det.
incr_ref(Ref) :-
@@ -768,14 +797,26 @@
"
X = * (MR_Integer *) Ref;
").
+:- pragma foreign_proc("Java",
+ ref_value(Ref::in, X::out),
+ [will_not_call_mercury],
+"
+ X = Ref.value;
+").
-:- impure pred update_ref(int_reference::in, T::in) is det.
+:- impure pred update_ref(int_reference::in, int::in) is det.
:- pragma inline(update_ref/2).
:- pragma foreign_proc("C",
update_ref(Ref::in, X::in),
[will_not_call_mercury],
"
* (MR_Integer *) Ref = X;
+").
+:- pragma foreign_proc("Java",
+ update_ref(Ref::in, X::in),
+ [will_not_call_mercury],
+"
+ Ref.value = X;
").
%-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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