[m-rev.] For review: library predicates for Java using JNI

James Goddard goddardjames at yahoo.com
Mon Feb 2 17:17:47 AEDT 2004


For review by Fergus:

This is the relative diff for the code which incorporates JNI into the
Java implementation.  Is this what you had in mind for the Makefile?

Thanks,

James

diff -u java/runtime/Native.java java/runtime/Native.java
--- java/runtime/Native.java	29 Jan 2004 00:48:02 -0000
+++ java/runtime/Native.java	2 Feb 2004 06:04:40 -0000
@@ -18,13 +18,13 @@
 	** SHARED_OBJ is the name of the shared object which contains all the
 	** compiled native code.
 	*/
-	private	static final java.lang.String	SHARED_OBJ	= "Native.so";
+	private	static final java.lang.String	SHARED_OBJ = "Native.pic_o";
 
 	/*
 	** available and isAvailable() are true when native functionality
 	** is available. (ie SHARED_OBJ was loaded successfully)
 	*/
-	private	static boolean			available	= false;
+	private	static boolean			available  = false;
 
 	public static boolean isAvailable() {
 		return available;
@@ -40,6 +40,7 @@
 	** 	(including the directories containing each jar file) for
 	** 	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.
 	*/
 	private static boolean load_library() {
@@ -64,19 +65,17 @@
 					dir = new java.io.File("");
 				}
 
-				java.io.File[] match = dir.listFiles(
-						new java.io.FilenameFilter() {
-						public boolean accept(
-							java.io.File dir,
-							java.lang.String name)
-						{
-						return name.equals(SHARED_OBJ);
-						}
-						});
-
-				java.lang.System.load(
-						match[0].getAbsolutePath());
-				System.out.println(match[0].getAbsolutePath());
+				java.io.File match = new java.io.File(dir,
+						SHARED_OBJ);
+				if (match.exists() == false) {
+					dir = new java.io.File(dir,
+						mercury.runtime.Constants.
+						MR_FULLARCH);
+					match = new java.io.File(dir,
+						SHARED_OBJ);
+				}
+
+				java.lang.System.load(match.getAbsolutePath());
 				return true;
 			}
 			catch (java.lang.Exception e) {
diff -u java/runtime/Native.c java/runtime/Native.c
--- java/runtime/Native.c	29 Jan 2004 00:14:12 -0000
+++ java/runtime/Native.c	2 Feb 2004 04:08:17 -0000
@@ -41,8 +41,8 @@
 JNIEXPORT jint JNICALL Java_mercury_runtime_Native_get_1user_1cpu_1miliseconds(
 		JNIEnv *, jclass);
 
-#include "../../runtime/mercury_imp.h"
-#include "../../runtime/mercury_timing.h"
+#include "mercury_imp.h"
+#include "mercury_timing.h"
 
 #include <time.h>
 #ifdef MR_HAVE_SYS_TYPES_H
diff -u java/runtime/Mmakefile java/runtime/Mmakefile
--- java/runtime/Mmakefile	29 Jan 2004 00:21:15 -0000
+++ java/runtime/Mmakefile	2 Feb 2004 05:42:20 -0000
@@ -8,17 +8,27 @@
 
+MERCURY_DIR	= ../..
+RUNTIME_DIR	= $(MERCURY_DIR)/runtime
 
-MAIN_TARGET=Native.so
+include $(MERCURY_DIR)/Mmake.common
 
 
-Native.so:	Native.o ../../runtime/mercury_timing.o
-		gcc -shared Native.o ../../runtime/mercury_timing.o \
-				-o Native.so
+MAIN_TARGET	= Native.pic_o
+
+OBJ		= $(RUNTIME_DIR)/mercury_timing.o Native.o
+
+CC		= $(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS)
+CFLAGS		= -I$(RUNTIME_DIR)
+
+
+Native.pic_o:	$(OBJ)
+		$(LINK_SHARED_OBJ) $(CFLAGS) $(CFLAGS_FOR_PIC) $(OBJ) \
+		-o Native.pic_o
 
 Native.o:	Native.c
-		gcc -c Native.c
+		$(CC) $(CFLAGS) -c Native.c
 
 realclean_local: clean
 
 clean:
-		rm -f Native.o Native.so
+		rm -f Native.o Native.pic_o
 
--- configure.in	20 Jan 2004 23:02:16 -0000	1.384
+++ configure.in	2 Feb 2004 05:10:01 -0000
@@ -3701,6 +3701,7 @@
 scripts/mkfifo_using_mknod bindist/bindist.INSTALL bindist/bindist.Makefile
 scripts/mercury_config scripts/Mercury.config scripts/Mercury.config.bootstrap
 tools/lmc tools/dotime runtime/mercury_dotnet.cs java/runtime/Constants.java
+library/Mmakefile
 ,
 [
 # Only do this when compiling the source, not when reconfiguring
only in patch2:
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ library/Mmakefile.in	2 Feb 2004 05:49:15 -0000
+
+FULLARCH=@FULLARCH@


+jars:	classes
+	jar cf $(STD_LIB_NAME).jar mercury/*.class
+	jar cf $(STD_LIB_NAME).runtime.jar mercury/runtime/*.class
+	-+cd mercury/runtime && mmake $(NATIVE_SO)
+	-cp mercury/runtime/$(NATIVE_SO) .
+
+# This shared object is needed to run some of the standard library methods.
+NATIVE_SO = Native.pic_o
+


+# Copy the jars and NATIVE_SO to INSTALL_JAVA_LIBRARY_DIR.
+
+.PHONY: install_library
+install_library: jars
+	mkdir -p $(INSTALL_JAVA_LIBRARY_DIR)
+	cp $(JARS) $(INSTALL_JAVA_LIBRARY_DIR)
+	cp $(NATIVE_SO) $(INSTALL_JAVA_LIBRARY_DIR)/$(FULLARCH)
+
--------------------------------------------------------------------------
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