8135337: NativeDebug.dumpCounters with incorrect scope count
authorattila
Thu, 10 Sep 2015 15:28:05 +0200
changeset 32532 39810f7cc2e8
parent 32531 de72522f2bc4
child 32533 47d3ca23ac91
8135337: NativeDebug.dumpCounters with incorrect scope count Reviewed-by: hannesw, sundar
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Scope.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeDebug.java	Thu Sep 10 15:24:39 2015 +0200
+++ b/nashorn/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/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Scope.java	Thu Sep 10 15:24:39 2015 +0200
+++ b/nashorn/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();
+        }
     }
 }