From d9dad16626fbde630374920f889a4902e045cf53 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Mon, 13 May 2019 15:36:50 +0200 Subject: [PATCH] Separate Truffle source caches between multiple runs of the JPDA debugger --- .../debugger/jpda/truffle/source/Source.java | 6 +++--- .../jpda/truffle/source/SourceFilesCache.java | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java index 40ff60b2eb6c..74c59ed603bb 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java @@ -54,13 +54,13 @@ public final class Source { private final long hash; private String content; - private Source(String name, URI uri, long hash, StringReference codeRef) { + private Source(JPDADebugger jpda, String name, URI uri, long hash, StringReference codeRef) { this.name = name; this.codeRef = codeRef; URL url = null; if (uri == null || !"file".equalsIgnoreCase(uri.getScheme())) { try { - url = SourceFilesCache.getDefault().getSourceFile(name, hash, uri, getContent()); + url = SourceFilesCache.get(jpda).getSourceFile(name, hash, uri, getContent()); } catch (IOException ex) { Exceptions.printStackTrace(ex); } @@ -135,7 +135,7 @@ private static Source getTheSource(JPDADebugger debugger, long id, URI uri, StringReference codeRef) { - Source src = new Source(name, uri, id, codeRef); + Source src = new Source(debugger, name, uri, id, codeRef); synchronized (KNOWN_SOURCES) { Map dbgSources = KNOWN_SOURCES.get(debugger); if (dbgSources == null) { diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/SourceFilesCache.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/SourceFilesCache.java index 42db88974fc0..a1bf24b5a8e4 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/SourceFilesCache.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/SourceFilesCache.java @@ -22,12 +22,15 @@ import java.io.IOException; import java.net.URI; import java.net.URL; +import java.util.Map; +import java.util.WeakHashMap; +import org.netbeans.api.debugger.jpda.JPDADebugger; import org.openide.filesystems.FileObject; final class SourceFilesCache { - private static final SourceFilesCache DEFAULT = new SourceFilesCache(); + private static final Map MAP = new WeakHashMap<>(); private final SourceFS fs; @@ -35,8 +38,13 @@ private SourceFilesCache() { fs = new SourceFS(); } - public static SourceFilesCache getDefault() { - return DEFAULT; + public static synchronized SourceFilesCache get(JPDADebugger jpda) { + SourceFilesCache sfc = MAP.get(jpda); + if (sfc == null) { + sfc = new SourceFilesCache(); + MAP.put(jpda, sfc); + } + return sfc; } public URL getSourceFile(String name, long hash, URI uri, String content) throws IOException {