4040final class RandomXLibraryLoader {
4141
4242 private static boolean isLoaded = false ;
43- private static String loadedLibraryPath = null ; // Store the path of the loaded library for logging
43+ private static Path loadedLibraryPath = null ; // Store the path of the loaded library
4444
4545 // Private constructor to prevent instantiation
4646 private RandomXLibraryLoader () {}
@@ -53,16 +53,19 @@ private RandomXLibraryLoader() {}
5353 *
5454 * @throws UnsatisfiedLinkError if the library cannot be loaded for any reason.
5555 * @throws Exception for other unexpected errors during loading.
56+ * @return Path to the loaded native library file, or null if already loaded or failed before critical point.
5657 */
57- public static synchronized void load () throws Exception {
58+ public static synchronized Path load () throws Exception {
5859 if (isLoaded ) {
5960 log .info ("Native library already loaded from: {}" , loadedLibraryPath );
60- return ;
61+ return loadedLibraryPath ; // Return cached path
6162 }
6263
64+ Path tempLibFilePath = null ;
6365 try {
64- File tempFile = extractAndLoadNativeLibrary ();
65- loadedLibraryPath = tempFile .getAbsolutePath ();
66+ File tempFile = extractAndLoadNativeLibrary (); // This method now returns File
67+ tempLibFilePath = tempFile .toPath ();
68+ loadedLibraryPath = tempLibFilePath ; // Cache the path
6669
6770 String tempLibDir = tempFile .getParent ();
6871 if (tempLibDir != null ) {
@@ -79,10 +82,12 @@ public static synchronized void load() throws Exception {
7982
8083 isLoaded = true ;
8184 log .info ("RandomX native library loaded successfully via RandomXLibraryLoader from: {}" , loadedLibraryPath );
85+ return loadedLibraryPath ;
8286
8387 } catch (UnsatisfiedLinkError ule ) { // Catch specifically from System.load()
8488 log .error ("Failed to load native library (UnsatisfiedLinkError from System.load()): {}: {}" ,
85- (loadedLibraryPath != null ? loadedLibraryPath : "<path not determined>" ), ule .getMessage (), ule );
89+ (loadedLibraryPath != null ? loadedLibraryPath : (tempLibFilePath != null ? tempLibFilePath : "<path not determined>" )),
90+ ule .getMessage (), ule );
8691 logLibraryPaths (); // Log paths for diagnostics
8792 throw ule ; // Re-throw to be handled by RandomXNative's static block
8893 } catch (Exception e ) {
0 commit comments