8135337: NativeDebug.dumpCounters with incorrect scope count

Reviewed-by: hannesw, sundar
This commit is contained in:
Attila Szegedi 2015-09-10 15:28:05 +02:00
parent 0ec14b759a
commit 4206843153
2 changed files with 15 additions and 13 deletions

View File

@ -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 @@ public final class NativeDebug extends ScriptObject {
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());

View File

@ -27,6 +27,7 @@ package jdk.nashorn.internal.runtime;
import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup;
import java.util.concurrent.atomic.LongAdder;
import jdk.nashorn.internal.codegen.CompilerConstants;
/**
@ -38,7 +39,7 @@ public class Scope extends ScriptObject {
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 class Scope extends ScriptObject {
*/
public Scope(final PropertyMap map) {
super(map);
if (Context.DEBUG) {
count++;
}
incrementCount();
}
/**
@ -65,9 +64,7 @@ public class Scope extends ScriptObject {
*/
public Scope(final ScriptObject proto, final PropertyMap map) {
super(proto, map);
if (Context.DEBUG) {
count++;
}
incrementCount();
}
/**
@ -79,9 +76,7 @@ public class Scope extends ScriptObject {
*/
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 @@ public class Scope extends ScriptObject {
*
* @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();
}
}
}