Skip to content

Commit

Permalink
Merge pull request #1252 from JaroslavTulach/jtulach/TruffleSourceCac…
Browse files Browse the repository at this point in the history
…hePerSession

Separate Truffle source caches between multiple debugging sessions.
  • Loading branch information
Jaroslav Tulach committed May 15, 2019
2 parents 3a9cdc8 + d9dad16 commit 5f9a953
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger);
if (dbgSources == null) {
Expand Down
Expand Up @@ -22,21 +22,29 @@
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<JPDADebugger, SourceFilesCache> MAP = new WeakHashMap<>();

private final SourceFS fs;

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 {
Expand Down

0 comments on commit 5f9a953

Please sign in to comment.