# HG changeset patch # User Andreas Woess # Date 1444306893 -7200 # Node ID c3ea80aa57628eec5686982fbb2110a48edec36e # Parent ca426f243321eb7f7b0e8106d3ee9deb8a092e47 make debug counters optional diff -r ca426f243321 -r c3ea80aa5762 truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DebugCounter.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DebugCounter.java Thu Oct 08 14:21:19 2015 +0200 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DebugCounter.java Thu Oct 08 14:21:33 2015 +0200 @@ -26,42 +26,75 @@ import java.util.ArrayList; import java.util.concurrent.atomic.AtomicLong; -public final class DebugCounter { - private static final ArrayList allCounters = new ArrayList<>(); - - private final String name; - private final AtomicLong value; +public abstract class DebugCounter { + private DebugCounter() { + } - private DebugCounter(String name) { - this.name = name; - this.value = new AtomicLong(); - allCounters.add(this); - } + public abstract long get(); + + public abstract void inc(); public static DebugCounter create(String name) { - return new DebugCounter(name); - } - - public long get() { - return value.get(); - } - - public void inc() { - value.incrementAndGet(); - } - - @Override - public String toString() { - return name + ": " + value; + return ObjectStorageOptions.DebugCounters ? DebugCounterImpl.createImpl(name) : Dummy.INSTANCE; } public static void dumpCounters() { - dumpCounters(System.out); + if (ObjectStorageOptions.DebugCounters) { + DebugCounterImpl.dumpCounters(System.out); + } } - public static void dumpCounters(PrintStream out) { - for (DebugCounter counter : allCounters) { - out.println(counter); + private static final class DebugCounterImpl extends DebugCounter { + private static final ArrayList allCounters = new ArrayList<>(); + + private final String name; + private final AtomicLong value; + + private DebugCounterImpl(String name) { + this.name = name; + this.value = new AtomicLong(); + allCounters.add(this); + } + + private static DebugCounter createImpl(String name) { + return new DebugCounterImpl(name); + } + + @Override + public long get() { + return value.get(); + } + + @Override + public void inc() { + value.incrementAndGet(); + } + + @Override + public String toString() { + return name + ": " + get(); + } + + private static void dumpCounters(PrintStream out) { + for (DebugCounter counter : allCounters) { + out.println(counter); + } + } + } + + private static final class Dummy extends DebugCounter { + static final DebugCounter INSTANCE = new Dummy(); + + private Dummy() { + } + + @Override + public long get() { + return 0; + } + + @Override + public void inc() { } } } diff -r ca426f243321 -r c3ea80aa5762 truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java --- a/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java Thu Oct 08 14:21:19 2015 +0200 +++ b/truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java Thu Oct 08 14:21:33 2015 +0200 @@ -38,6 +38,7 @@ public static boolean InObjectFields = booleanOption(OPTION_PREFIX + "InObjectFields", true); // Debug options (should be final) + public static final boolean DebugCounters = booleanOption(OPTION_PREFIX + "DebugCounters", true); public static final boolean TraceReshape = booleanOption(OPTION_PREFIX + "TraceReshape", false); public static final boolean DumpShapes = booleanOption(OPTION_PREFIX + "DumpShapes", false);