From 7c3de8e806fdcdb548db1a23658e838c840fd863 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Fri, 19 Apr 2024 19:19:05 +0200 Subject: [PATCH] Cache JRT-FileSystem created for JrtFileSystem instances --- .../jdt/internal/compiler/util/JRTUtil.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/JRTUtil.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/JRTUtil.java index 19de8fc6e4b..bce10356e79 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/JRTUtil.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/JRTUtil.java @@ -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 ctSymFiles = new ConcurrentHashMap<>(); + private static final Map JRT_FILE_SYSTEMS = new ConcurrentHashMap<>(); static final SoftClassCache classCache = new SoftClassCache(); @@ -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}. *

@@ -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 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();