< prev index next >
src/java.base/share/classes/jdk/internal/nicl/LdLoader.java
Print this page
@@ -35,16 +35,20 @@
public class LdLoader extends LibraryLoader {
private static final boolean DEBUG = Boolean.parseBoolean(
privilegedGetProperty("jdk.internal.nicl.LdLoader.DEBUG"));
+ // copy of ClassLoader.usr_paths field
private final String[] usr_paths;
// preloaded/built-in library
private final UnixLibrary defaultLibrary;
- private String[] getUserClassPath() {
+ private String[] getUserLibraryPaths() {
+ // ClassLoader.usr_paths is initialized from "java.library.path" System property.
+ // FIXME: we should define and use a private API rather than reading a
+ // private static non-final lazily initialized field from ClassLoader.
return AccessController.doPrivileged((PrivilegedAction<String[]>)() -> {
try {
Field f = ClassLoader.class.getDeclaredField("usr_paths");
f.setAccessible(true);
return (String[])f.get(null);
@@ -53,11 +57,11 @@
}
});
}
public LdLoader() {
- this.usr_paths = getUserClassPath();
+ this.usr_paths = getUserLibraryPaths();
this.defaultLibrary = new UnixLibrary(null);
}
@Override
public Library getDefaultLibrary() {
@@ -84,12 +88,14 @@
System.err.println(Pointer.toString(err));
}
}
throw new UnsatisfiedLinkError("Can't load library: " + libPath);
- } catch (Throwable t) {
- throw new RuntimeException(t);
+ } catch (RuntimeException re) {
+ throw re;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}
}
@Override
@@ -104,11 +110,14 @@
for (String usr_path : usr_paths) {
String libPath = usr_path + File.separator + name;
try {
return tryLoadLibrary(libPath);
- } catch (UnsatisfiedLinkError e) {
+ } catch (RuntimeException | UnsatisfiedLinkError e) {
+ if (DEBUG) {
+ System.err.println(e);
+ }
// ignore and try next path
}
}
throw new UnsatisfiedLinkError(name);
< prev index next >