@Override public void duringSetup(DuringSetupAccess access) { NativeLibrarySupport.singleton().registerLibraryInitializer(new JNILibraryInitializer()); } }
@Override public void afterRegistration(AfterRegistrationAccess access) { NativeLibrarySupport.initialize(); } }
@Substitute @SuppressWarnings("unused") static void loadLibrary(Class<?> fromClass, String name, boolean isAbsolute) { NativeLibrarySupport.singleton().loadLibrary(name, isAbsolute); }
/** * Gets the native address for the {@code native} method represented by this object, attempting * to resolve it if it is currently 0. */ public PointerBase getOrFindEntryPoint() { if (entryPoint.isNull()) { String shortName = getShortName(); entryPoint = NativeLibrarySupport.singleton().findSymbol(shortName); if (entryPoint.isNull()) { String longName = shortName + "__" + getSignature(); entryPoint = NativeLibrarySupport.singleton().findSymbol(longName); if (entryPoint.isNull()) { throw new UnsatisfiedLinkError(toString()); } } } return entryPoint; }
static void initialize() { ImageSingletons.add(NativeLibrarySupport.class, new NativeLibrarySupport()); }
public void loadLibrary(String name, boolean isAbsolute) { if (paths == null) { String[] tokens = SubstrateUtil.split(System.getProperty("java.library.path", ""), File.pathSeparator); paths = Arrays.stream(tokens).map(t -> t.isEmpty() ? "." : t).toArray(String[]::new); } if (isAbsolute) { if (loadLibrary0(new File(name), false)) { return; } throw new UnsatisfiedLinkError("Can't load library: " + name); } // Test if this is a built-in library if (loadLibrary0(new File(name), true)) { return; } String libname = System.mapLibraryName(name); for (String path : paths) { File libpath = new File(path, libname); if (loadLibrary0(libpath, false)) { return; } File altpath = Target_java_lang_ClassLoaderHelper.mapAlternativeName(libpath); if (altpath != null && loadLibrary0(libpath, false)) { return; } } throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); }