Skip to content

Commit

Permalink
Separate Truffle source caches between multiple runs of the JPDA debu…
Browse files Browse the repository at this point in the history
…gger
  • Loading branch information
Jaroslav Tulach committed May 13, 2019
1 parent 2b84667 commit d9dad16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d9dad16

Please sign in to comment.