You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2019/05/15 12:24:24 UTC

[netbeans] branch master updated: Separate Truffle source caches between multiple runs of the JPDA debugger

This is an automated email from the ASF dual-hosted git repository.

jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new d9dad16  Separate Truffle source caches between multiple runs of the JPDA debugger
     new 5f9a953  Merge pull request #1252 from JaroslavTulach/jtulach/TruffleSourceCachePerSession
d9dad16 is described below

commit d9dad16626fbde630374920f889a4902e045cf53
Author: Jaroslav Tulach <ja...@oracle.com>
AuthorDate: Mon May 13 15:36:50 2019 +0200

    Separate Truffle source caches between multiple runs of the JPDA debugger
---
 .../modules/debugger/jpda/truffle/source/Source.java       |  6 +++---
 .../debugger/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 40ff60b..74c59ed 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 @@ public final class Source {
                                        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) {
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 42db889..a1bf24b 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 @@ package org.netbeans.modules.debugger.jpda.truffle.source;
 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;
     
@@ -35,8 +38,13 @@ final class 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 {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists