src/share/classes/java/lang/ClassLoader.java
Print this page
@@ -1740,24 +1740,31 @@
private int jniVersion;
// the class from which the library is loaded, also indicates
// the loader this native library belongs.
private Class<?> fromClass;
// the canonicalized name of the native library.
+ // or static library name
String name;
+ // Indicates if the native library is linked into the VM
+ boolean isBuiltin;
+ // Indicates if the native library is loaded
+ boolean loaded;
+ native void load(String name, boolean isBuiltin);
- native void load(String name);
native long find(String name);
- native void unload();
+ native void unload(String name, boolean isBuiltin);
+ static native String findBuiltinLib(String name);
- public NativeLibrary(Class<?> fromClass, String name) {
+ public NativeLibrary(Class<?> fromClass, String name, boolean isBuiltin) {
this.name = name;
this.fromClass = fromClass;
+ this.isBuiltin = isBuiltin;
}
protected void finalize() {
synchronized (loadedLibraryNames) {
- if (fromClass.getClassLoader() != null && handle != 0) {
+ if (fromClass.getClassLoader() != null && loaded) {
/* remove the native library name */
int size = loadedLibraryNames.size();
for (int i = 0; i < size; i++) {
if (name.equals(loadedLibraryNames.elementAt(i))) {
loadedLibraryNames.removeElementAt(i);
@@ -1765,11 +1772,11 @@
}
}
/* unload the library. */
ClassLoader.nativeLibraryContext.push(this);
try {
- unload();
+ unload(name, isBuiltin);
} finally {
ClassLoader.nativeLibraryContext.pop();
}
}
}
@@ -1885,25 +1892,31 @@
// Oops, it failed
throw new UnsatisfiedLinkError("no " + name + " in java.library.path");
}
private static boolean loadLibrary0(Class<?> fromClass, final File file) {
+ // Check to see if we're attempting to access a static library
+ // System.out.println("loadLibrary0: filename: " + file.getName());
+ String name = NativeLibrary.findBuiltinLib(file.getName());
+ // System.out.println("loadLibrary0: name: " + name);
+ boolean isBuiltin = (name != null);
+ if (!isBuiltin) {
boolean exists = AccessController.doPrivileged(
new PrivilegedAction<Object>() {
public Object run() {
return file.exists() ? Boolean.TRUE : null;
}})
!= null;
if (!exists) {
return false;
}
- String name;
try {
name = file.getCanonicalPath();
} catch (IOException e) {
return false;
}
+ }
ClassLoader loader =
(fromClass == null) ? null : fromClass.getClassLoader();
Vector<NativeLibrary> libs =
loader != null ? loader.nativeLibraries : systemNativeLibraries;
synchronized (libs) {
@@ -1946,18 +1959,18 @@
name +
" is being loaded in another classloader");
}
}
}
- NativeLibrary lib = new NativeLibrary(fromClass, name);
+ NativeLibrary lib = new NativeLibrary(fromClass, name, isBuiltin);
nativeLibraryContext.push(lib);
try {
- lib.load(name);
+ lib.load(name, isBuiltin);
} finally {
nativeLibraryContext.pop();
}
- if (lib.handle != 0) {
+ if (lib.loaded) {
loadedLibraryNames.addElement(name);
libs.addElement(lib);
return true;
}
return false;