Skip to content

Commit

Permalink
Cache JRT-FileSystem created for JrtFileSystem instances
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Apr 19, 2024
1 parent 8cc65a5 commit 7c3de8e
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class JRTUtil {
* Map from JDK home path to ct.sym file (located in /lib in the JDK)
*/
private static final Map<Path, CtSym> ctSymFiles = new ConcurrentHashMap<>();
private static final Map<String, FileSystem> JRT_FILE_SYSTEMS = new ConcurrentHashMap<>();

static final SoftClassCache classCache = new SoftClassCache();

Expand Down Expand Up @@ -166,6 +167,20 @@ public static JrtFileSystem getJrtSystem(File image, String release) throws IOEx
}
}

static FileSystem getJrtFileSystem(String path) throws IOException {
try {
return JRT_FILE_SYSTEMS.computeIfAbsent(path, p -> {
try {
return FileSystems.newFileSystem(JRTUtil.JRT_URI, Map.of("java.home", p)); //$NON-NLS-1$
} catch (IOException e) {
throw new RuntimeIOException(e);
}
});
} catch (RuntimeIOException e) {
throw e.getCause();
}
}

/**
* Convenient method to get access to the given archive as a {@link FileSystem}.
* <p>
Expand Down Expand Up @@ -531,9 +546,7 @@ public static JrtFileSystem getNewJrtFileSystem(Jdk jdk, String release) throws
this.jdk = jdkHome;
this.release = release;
JRTUtil.MODULE_TO_LOAD = System.getProperty("modules.to.load"); //$NON-NLS-1$
HashMap<String, String> env = new HashMap<>();
env.put("java.home", this.jdk.path); //$NON-NLS-1$
this.fs = FileSystems.newFileSystem(JRTUtil.JRT_URI, env);
this.fs = JRTUtil.getJrtFileSystem(this.jdk.path);
this.modRoot = this.fs.getPath(JRTUtil.MODULES_SUBDIR);
// Set up the root directory where modules are located
walkJrtForModules();
Expand Down

0 comments on commit 7c3de8e

Please sign in to comment.