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/04/28 05:16:40 UTC

[netbeans-html4j] branch master updated: Prevent GC of JsCallbacks in case there are multiple of them and the JS VM doesn't keep strong reference to them

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-html4j.git


The following commit(s) were added to refs/heads/master by this push:
     new fdbe294  Prevent GC of JsCallbacks in case there are multiple of them and the JS VM doesn't keep strong reference to them
fdbe294 is described below

commit fdbe294044177bda335a62670e99c3806508f27f
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Sun Apr 28 07:16:09 2019 +0200

    Prevent GC of JsCallbacks in case there are multiple of them and the JS VM doesn't keep strong reference to them
---
 .../org/netbeans/html/boot/impl/JavaScriptProcesor.java   | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java
index bf97dde..7e13130 100644
--- a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java
+++ b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java
@@ -401,15 +401,20 @@ public final class JavaScriptProcesor extends AbstractProcessor {
             source.append("public final class $JsCallbacks$ {\n");
             source.append("  static final $JsCallbacks$ VM = new $JsCallbacks$(null);\n");
             source.append("  private final org.netbeans.html.boot.spi.Fn.Presenter p;\n");
-            source.append("  private $JsCallbacks$ last;\n");
+            source.append("  private $JsCallbacks$ next;\n");
             source.append("  private $JsCallbacks$(org.netbeans.html.boot.spi.Fn.Presenter p) {\n");
             source.append("    this.p = p;\n");
             source.append("  }\n");
-            source.append("  final $JsCallbacks$ current() {\n");
+            source.append("  synchronized final $JsCallbacks$ current() {\n");
             source.append("    org.netbeans.html.boot.spi.Fn.Presenter now = org.netbeans.html.boot.spi.Fn.activePresenter();\n");
-            source.append("    if (now == p) return this;\n");
-            source.append("    if (last != null && now == last.p) return last;\n");
-            source.append("    return last = new $JsCallbacks$(now);\n");
+            source.append("    $JsCallbacks$ thiz = this;\n");
+            source.append("    for (;;) {\n");
+            source.append("      if (now == thiz.p) return thiz;\n");
+            source.append("      if (thiz.next == null) {\n");
+            source.append("        return thiz.next = new $JsCallbacks$(now);\n");
+            source.append("      }\n");
+            source.append("      thiz = thiz.next;\n");
+            source.append("    }\n");
             source.append("  }\n");
             for (Map.Entry<String, ExecutableElement> entry : map.entrySet()) {
                 final String mangled = entry.getKey();


---------------------------------------------------------------------
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