src/share/classes/java/lang/ClassLoader.java

Print this page

        

*** 1740,1763 **** 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. String name; - native void load(String name); native long find(String name); ! native void unload(); ! public NativeLibrary(Class<?> fromClass, String name) { this.name = name; this.fromClass = fromClass; } protected void finalize() { synchronized (loadedLibraryNames) { ! if (fromClass.getClassLoader() != null && handle != 0) { /* 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); --- 1740,1770 ---- 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 long find(String name); ! native void unload(String name, boolean isBuiltin); ! static native String findBuiltinLib(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 && 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,1775 **** } } /* unload the library. */ ClassLoader.nativeLibraryContext.push(this); try { ! unload(); } finally { ClassLoader.nativeLibraryContext.pop(); } } } --- 1772,1782 ---- } } /* unload the library. */ ClassLoader.nativeLibraryContext.push(this); try { ! unload(name, isBuiltin); } finally { ClassLoader.nativeLibraryContext.pop(); } } }
*** 1885,1909 **** // Oops, it failed throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); } private static boolean loadLibrary0(Class<?> fromClass, final File file) { 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) { --- 1892,1922 ---- // 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; } 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,1963 **** name + " is being loaded in another classloader"); } } } ! NativeLibrary lib = new NativeLibrary(fromClass, name); nativeLibraryContext.push(lib); try { ! lib.load(name); } finally { nativeLibraryContext.pop(); } ! if (lib.handle != 0) { loadedLibraryNames.addElement(name); libs.addElement(lib); return true; } return false; --- 1959,1976 ---- name + " is being loaded in another classloader"); } } } ! NativeLibrary lib = new NativeLibrary(fromClass, name, isBuiltin); nativeLibraryContext.push(lib); try { ! lib.load(name, isBuiltin); } finally { nativeLibraryContext.pop(); } ! if (lib.loaded) { loadedLibraryNames.addElement(name); libs.addElement(lib); return true; } return false;