Mercurial > hg > truffle
changeset 22291:c3ea80aa5762
make debug counters optional
author | Andreas Woess <andreas.woess@oracle.com> |
---|---|
date | Thu, 08 Oct 2015 14:21:33 +0200 |
parents | ca426f243321 |
children | 0e13cbebc04c |
files | truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/DebugCounter.java truffle/com.oracle.truffle.object/src/com/oracle/truffle/object/ObjectStorageOptions.java |
diffstat | 2 files changed, 62 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- 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<DebugCounter> 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<DebugCounter> 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() { } } }
--- 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);