aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java')
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/DynamicLinker.java1
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/MacOSXDynamicLinkerImpl.java11
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/NativeLibrary.java25
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/UnixDynamicLinkerImpl.java10
-rwxr-xr-xsrc/java/com/sun/gluegen/runtime/WindowsDynamicLinkerImpl.java5
5 files changed, 50 insertions, 2 deletions
diff --git a/src/java/com/sun/gluegen/runtime/DynamicLinker.java b/src/java/com/sun/gluegen/runtime/DynamicLinker.java
index d0ee39b..c67c526 100755
--- a/src/java/com/sun/gluegen/runtime/DynamicLinker.java
+++ b/src/java/com/sun/gluegen/runtime/DynamicLinker.java
@@ -44,6 +44,7 @@ package com.sun.gluegen.runtime;
interface DynamicLinker {
public long openLibrary(String pathname);
+ public long openLibraryLocal(String pathname);
public long lookupSymbol(long libraryHandle, String symbolName);
public void closeLibrary(long libraryHandle);
}
diff --git a/src/java/com/sun/gluegen/runtime/MacOSXDynamicLinkerImpl.java b/src/java/com/sun/gluegen/runtime/MacOSXDynamicLinkerImpl.java
index f998d07..2568050 100755
--- a/src/java/com/sun/gluegen/runtime/MacOSXDynamicLinkerImpl.java
+++ b/src/java/com/sun/gluegen/runtime/MacOSXDynamicLinkerImpl.java
@@ -26,6 +26,17 @@ public class MacOSXDynamicLinkerImpl implements DynamicLinker
// --- Begin CustomJavaCode .cfg declarations
+ public long openLibraryLocal(String pathname) {
+ // Note we use RTLD_LOCAL visibility to _NOT_ allow this functionality to
+ // be used to pre-resolve dependent libraries of JNI code without
+ // requiring that all references to symbols in those libraries be
+ // looked up dynamically via the ProcAddressTable mechanism; in
+ // other words, one can actually link against the library instead of
+ // having to dlsym all entry points. System.loadLibrary() uses
+ // RTLD_LOCAL visibility so can't be used for this purpose.
+ return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL);
+ }
+
public long openLibrary(String pathname) {
// Note we use RTLD_GLOBAL visibility to allow this functionality to
// be used to pre-resolve dependent libraries of JNI code without
diff --git a/src/java/com/sun/gluegen/runtime/NativeLibrary.java b/src/java/com/sun/gluegen/runtime/NativeLibrary.java
index 1341012..e939de4 100755
--- a/src/java/com/sun/gluegen/runtime/NativeLibrary.java
+++ b/src/java/com/sun/gluegen/runtime/NativeLibrary.java
@@ -126,7 +126,15 @@ public class NativeLibrary {
path, and in the context of the specified ClassLoader, which is
used to help find the library in the case of e.g. Java Web Start. */
public static NativeLibrary open(String libName, ClassLoader loader) {
- return open(libName, libName, libName, true, loader);
+ return open(libName, libName, libName, true, loader, false);
+ }
+
+ /** Opens the given native library, assuming it has the same base
+ name on all platforms, looking first in the system's search
+ path, and in the context of the specified ClassLoader, which is
+ used to help find the library in the case of e.g. Java Web Start. */
+ public static NativeLibrary open(String libName, ClassLoader loader, boolean local) {
+ return open(libName, libName, libName, true, loader, local);
}
/** Opens the given native library, assuming it has the given base
@@ -149,6 +157,14 @@ public class NativeLibrary {
String macOSXLibName,
boolean searchSystemPathFirst,
ClassLoader loader) {
+ return open(windowsLibName, unixLibName, macOSXLibName, searchSystemPathFirst, loader, false);
+ }
+
+ public static NativeLibrary open(String windowsLibName,
+ String unixLibName,
+ String macOSXLibName,
+ boolean searchSystemPathFirst,
+ ClassLoader loader, boolean local) {
List possiblePaths = enumerateLibraryPaths(windowsLibName,
unixLibName,
macOSXLibName,
@@ -161,7 +177,12 @@ public class NativeLibrary {
System.out.println("Trying to load " + path);
}
ensureNativeLibLoaded();
- long res = dynLink.openLibrary(path);
+ long res;
+ if(local) {
+ res = dynLink.openLibraryLocal(path);
+ } else {
+ res = dynLink.openLibrary(path);
+ }
if (res != 0) {
if (DEBUG) {
System.out.println("Successfully loaded " + path + ": res = 0x" + Long.toHexString(res));
diff --git a/src/java/com/sun/gluegen/runtime/UnixDynamicLinkerImpl.java b/src/java/com/sun/gluegen/runtime/UnixDynamicLinkerImpl.java
index b6a79be..e4c3818 100755
--- a/src/java/com/sun/gluegen/runtime/UnixDynamicLinkerImpl.java
+++ b/src/java/com/sun/gluegen/runtime/UnixDynamicLinkerImpl.java
@@ -32,6 +32,16 @@ public class UnixDynamicLinkerImpl implements DynamicLinker
// --- Begin CustomJavaCode .cfg declarations
+ public long openLibraryLocal(String pathname) {
+ // Note we use RTLD_GLOBAL visibility to _NOT_ allow this functionality to
+ // be used to pre-resolve dependent libraries of JNI code without
+ // requiring that all references to symbols in those libraries be
+ // looked up dynamically via the ProcAddressTable mechanism; in
+ // other words, one can actually link against the library instead of
+ // having to dlsym all entry points. System.loadLibrary() uses
+ // RTLD_LOCAL visibility so can't be used for this purpose.
+ return dlopen(pathname, RTLD_LAZY | RTLD_LOCAL);
+ }
public long openLibrary(String pathname) {
// Note we use RTLD_GLOBAL visibility to allow this functionality to
// be used to pre-resolve dependent libraries of JNI code without
diff --git a/src/java/com/sun/gluegen/runtime/WindowsDynamicLinkerImpl.java b/src/java/com/sun/gluegen/runtime/WindowsDynamicLinkerImpl.java
index 553c2f2..3690041 100755
--- a/src/java/com/sun/gluegen/runtime/WindowsDynamicLinkerImpl.java
+++ b/src/java/com/sun/gluegen/runtime/WindowsDynamicLinkerImpl.java
@@ -22,6 +22,11 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker
// --- Begin CustomJavaCode .cfg declarations
+ public long openLibraryLocal(String libraryName) {
+ // How does that work under Windows ?
+ return LoadLibraryW(libraryName);
+ }
+
public long openLibrary(String libraryName) {
return LoadLibraryW(libraryName);
}