changeset 1420:bbe835067b89

8135337: NativeDebug.dumpCounters with incorrect scope count Reviewed-by: hannesw, sundar
author attila
date Thu, 10 Sep 2015 15:28:05 +0200
parents c62b95b20e60
children 882bbbfcaf03
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Scope.java
diffstat 2 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java	Thu Sep 10 15:24:39 2015 +0200
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java	Thu Sep 10 15:28:05 2015 +0200
@@ -26,6 +26,7 @@
 package jdk.nashorn.internal.objects;
 
 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
+
 import java.io.PrintWriter;
 import java.util.LinkedList;
 import java.util.Objects;
@@ -246,7 +247,7 @@
         final PrintWriter out = Context.getCurrentErr();
 
         out.println("ScriptObject count " + ScriptObject.getCount());
-        out.println("Scope count " + Scope.getCount());
+        out.println("Scope count " + Scope.getScopeCount());
         out.println("ScriptObject listeners added " + PropertyListeners.getListenersAdded());
         out.println("ScriptObject listeners removed " + PropertyListeners.getListenersRemoved());
         out.println("ScriptFunction constructor calls " + ScriptFunction.getConstructorCount());
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Scope.java	Thu Sep 10 15:24:39 2015 +0200
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Scope.java	Thu Sep 10 15:28:05 2015 +0200
@@ -27,6 +27,7 @@
 
 import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup;
 
+import java.util.concurrent.atomic.LongAdder;
 import jdk.nashorn.internal.codegen.CompilerConstants;
 
 /**
@@ -38,7 +39,7 @@
     private int splitState = -1;
 
     /** This is updated only in debug mode - counts number of {@code ScriptObject} instances created that are scope */
-    private static int count;
+    private static final LongAdder count = Context.DEBUG ? new LongAdder() : null;
 
     /** Method handle that points to {@link Scope#getSplitState}. */
     public static final CompilerConstants.Call GET_SPLIT_STATE = virtualCallNoLookup(Scope.class, "getSplitState", int.class);
@@ -52,9 +53,7 @@
      */
     public Scope(final PropertyMap map) {
         super(map);
-        if (Context.DEBUG) {
-            count++;
-        }
+        incrementCount();
     }
 
     /**
@@ -65,9 +64,7 @@
      */
     public Scope(final ScriptObject proto, final PropertyMap map) {
         super(proto, map);
-        if (Context.DEBUG) {
-            count++;
-        }
+        incrementCount();
     }
 
     /**
@@ -79,9 +76,7 @@
      */
     public Scope(final PropertyMap map, final long[] primitiveSpill, final Object[] objectSpill) {
         super(map, primitiveSpill, objectSpill);
-        if (Context.DEBUG) {
-            count++;
-        }
+        incrementCount();
     }
 
     @Override
@@ -123,7 +118,13 @@
      *
      * @return number of scope ScriptObjects created
      */
-    public static int getScopeCount() {
-        return count;
+    public static long getScopeCount() {
+        return count != null ? count.sum() : 0;
+    }
+
+    private static void incrementCount() {
+        if (Context.DEBUG) {
+            count.increment();
+        }
     }
 }