2352 * Every classloader contains a vector of loaded native libraries in the
2353 * private field {@code nativeLibraries}. The native libraries loaded
2354 * into the system are entered into the {@code systemNativeLibraries}
2355 * vector.
2356 *
2357 * <p> Every native library requires a particular version of JNI. This is
2358 * denoted by the private {@code jniVersion} field. This field is set by
2359 * the VM when it loads the library, and used by the VM to pass the correct
2360 * version of JNI to the native methods. </p>
2361 *
2362 * @see ClassLoader
2363 * @since 1.2
2364 */
2365 static class NativeLibrary {
2366 // opaque handle to native library, used in native code.
2367 long handle;
2368 // the version of JNI environment the native library requires.
2369 private int jniVersion;
2370 // the class from which the library is loaded, also indicates
2371 // the loader this native library belongs.
2372 private final Class<?> fromClass;
2373 // the canonicalized name of the native library.
2374 // or static library name
2375 String name;
2376 // Indicates if the native library is linked into the VM
2377 boolean isBuiltin;
2378 // Indicates if the native library is loaded
2379 boolean loaded;
2380 native void load(String name, boolean isBuiltin);
2381
2382 native long find(String name);
2383 native void unload(String name, boolean isBuiltin);
2384
2385 public NativeLibrary(Class<?> fromClass, String name, boolean isBuiltin) {
2386 this.name = name;
2387 this.fromClass = fromClass;
2388 this.isBuiltin = isBuiltin;
2389 }
2390
2391 @SuppressWarnings("deprecation")
2392 protected void finalize() {
2393 synchronized (loadedLibraryNames) {
2394 if (fromClass.getClassLoader() != null && loaded) {
2395 /* remove the native library name */
2396 int size = loadedLibraryNames.size();
2397 for (int i = 0; i < size; i++) {
2398 if (name.equals(loadedLibraryNames.elementAt(i))) {
2399 loadedLibraryNames.removeElementAt(i);
2400 break;
2401 }
2402 }
2403 /* unload the library. */
2404 ClassLoader.nativeLibraryContext.push(this);
2405 try {
2406 unload(name, isBuiltin);
2407 } finally {
2408 ClassLoader.nativeLibraryContext.pop();
2409 }
2410 }
2411 }
2412 }
2413 // Invoked in the VM to determine the context class in
2414 // JNI_Load/JNI_Unload
|
2352 * Every classloader contains a vector of loaded native libraries in the
2353 * private field {@code nativeLibraries}. The native libraries loaded
2354 * into the system are entered into the {@code systemNativeLibraries}
2355 * vector.
2356 *
2357 * <p> Every native library requires a particular version of JNI. This is
2358 * denoted by the private {@code jniVersion} field. This field is set by
2359 * the VM when it loads the library, and used by the VM to pass the correct
2360 * version of JNI to the native methods. </p>
2361 *
2362 * @see ClassLoader
2363 * @since 1.2
2364 */
2365 static class NativeLibrary {
2366 // opaque handle to native library, used in native code.
2367 long handle;
2368 // the version of JNI environment the native library requires.
2369 private int jniVersion;
2370 // the class from which the library is loaded, also indicates
2371 // the loader this native library belongs.
2372 private Class<?> fromClass;
2373 // the canonicalized name of the native library.
2374 // or static library name
2375 String name;
2376 // Indicates if the native library is linked into the VM
2377 boolean isBuiltin;
2378 // Indicates if the native library is loaded
2379 boolean loaded;
2380 native void load(String name, boolean isBuiltin);
2381
2382 native long find(String name);
2383 native void unload(String name, boolean isBuiltin);
2384
2385 public NativeLibrary(Class<?> fromClass, String name, boolean isBuiltin) {
2386 this.name = name;
2387 this.fromClass = fromClass;
2388 this.isBuiltin = isBuiltin;
2389 }
2390
2391 @SuppressWarnings("deprecation")
2392 protected void finalize() {
2393 synchronized (loadedLibraryNames) {
2394 if (fromClass.getClassLoader() != null && loaded) {
2395 this.fromClass = null; // no context when unloaded
2396
2397 /* remove the native library name */
2398 int size = loadedLibraryNames.size();
2399 for (int i = 0; i < size; i++) {
2400 if (name.equals(loadedLibraryNames.elementAt(i))) {
2401 loadedLibraryNames.removeElementAt(i);
2402 break;
2403 }
2404 }
2405 /* unload the library. */
2406 ClassLoader.nativeLibraryContext.push(this);
2407 try {
2408 unload(name, isBuiltin);
2409 } finally {
2410 ClassLoader.nativeLibraryContext.pop();
2411 }
2412 }
2413 }
2414 }
2415 // Invoked in the VM to determine the context class in
2416 // JNI_Load/JNI_Unload
|