Patch: JNI_OnLoad
Tom Tromey
tromey@cygnus.com
Mon Feb 7 16:27:00 GMT 2000
I'm committing the appended patch. It unifies Runtime.load and
Runtime.loadLibrary, so they are easier to maintain. It also adds
preliminary (aka broken) support for JNI_OnLoad.
2000-02-07 Tom Tromey <tromey@cygnus.com>
* java/lang/Runtime.java (_load): Declare.
(load, loadLibrary): Wrote in terms of _load.
* java/lang/natRuntime.cc (load): Call JNI_OnLoad if it appears in
library.
(loadLibrary): Likewise.
Include <jni.h>.
(_load): New method.
(loadLibrary, load): Removed.
Tom
Index: java/lang/Runtime.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Runtime.java,v
retrieving revision 1.6
diff -u -r1.6 Runtime.java
--- Runtime.java 2000/01/19 18:39:26 1.6
+++ Runtime.java 2000/02/08 00:19:14
@@ -23,8 +23,7 @@
/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
* "The Java Language Specification", ISBN 0-201-63451-1
* plus online API docs for JDK 1.2 beta from http://www.javasoft.com .
- * Status: All 1.1 methods exist. exec(), load(), and loadLibrary()
- * are not fully implemented.
+ * Status: All 1.1 methods exist. exec() is not fully implemented.
*/
public class Runtime
@@ -94,8 +93,17 @@
s.checkLink(lib);
}
- public native void load (String pathname);
- public native void loadLibrary (String libname);
+ private native void _load (String pathname, boolean do_search);
+
+ public void load (String pathname)
+ {
+ _load (pathname, false);
+ }
+
+ public void loadLibrary (String libname)
+ {
+ _load (libname, true);
+ }
// This is a helper function for the ClassLoader which can load
// compiled libraries. Returns true if library (which is just the
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.6
diff -u -r1.6 natRuntime.cc
--- natRuntime.cc 2000/02/04 20:49:27 1.6
+++ natRuntime.cc 2000/02/08 00:19:14
@@ -18,6 +18,8 @@
#include <java/lang/UnknownError.h>
#include <java/lang/UnsatisfiedLinkError.h>
+#include <jni.h>
+
#ifdef USE_LTDL
#include <ltdl.h>
@@ -99,7 +101,7 @@
}
void
-java::lang::Runtime::load (jstring path)
+java::lang::Runtime::_load (jstring path, jboolean do_search)
{
JvSynchronize sync (this);
checkLink (path);
@@ -110,39 +112,29 @@
jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
buf[total] = '\0';
// FIXME: make sure path is absolute.
- lt_dlhandle h = lt_dlopen (buf);
+ lt_dlhandle h = do_search ? lt_dlopenext (buf) : lt_dlopen (buf);
if (h == NULL)
{
const char *msg = lt_dlerror ();
_Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
}
-#else
- _Jv_Throw (new UnknownError
- (JvNewStringLatin1 ("Runtime.load not implemented")));
-#endif /* USE_LTDL */
-}
-void
-java::lang::Runtime::loadLibrary (jstring lib)
-{
- JvSynchronize sync (this);
- checkLink (lib);
- using namespace java::lang;
-#ifdef USE_LTDL
- jint len = _Jv_GetStringUTFLength (lib);
- char buf[len + 1];
- jsize total = JvGetStringUTFRegion (lib, 0, lib->length(), buf);
- buf[total] = '\0';
- // FIXME: make sure path is absolute.
- lt_dlhandle h = lt_dlopenext (buf);
- if (h == NULL)
+ void *onload = lt_dlsym (h, "JNI_OnLoad");
+ if (onload != NULL)
{
- const char *msg = lt_dlerror ();
- _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 (msg)));
+ // FIXME: need invocation API to get JavaVM.
+ jint vers = ((jint (*) (...)) onload) (NULL, NULL);
+ if (vers != JNI_VERSION_1_1 && vers != JNI_VERSION_1_2)
+ {
+ // FIXME: unload the library.
+ _Jv_Throw (new UnsatisfiedLinkError (JvNewStringLatin1 ("unrecognized version from JNI_OnLoad")));
+ }
}
#else
_Jv_Throw (new UnknownError
- (JvNewStringLatin1 ("Runtime.loadLibrary not implemented")));
+ (JvNewStringLatin1 (do_search
+ ? "Runtime.loadLibrary not implemented"
+ : "Runtime.load not implemented")));
#endif /* USE_LTDL */
}
More information about the Java-patches
mailing list