# HG changeset patch # User Doug Simon # Date 1383674570 -3600 # Node ID 5dbfb4d5eaba47252f3b045a853435de894ae939 # Parent 343477cb53ff2d432be1f56421fcc206d04d795e added a histogram to OptionValue (enabled by -Dgraal.showOptionValueReadsHistogram=true) to see which options are most frequently read diff -r 343477cb53ff -r 5dbfb4d5eaba graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java --- a/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Tue Nov 05 19:02:14 2013 +0100 +++ b/graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionValue.java Tue Nov 05 19:02:50 2013 +0100 @@ -22,6 +22,7 @@ */ package com.oracle.graal.options; +import java.io.*; import java.util.*; import java.util.Map.Entry; @@ -136,8 +137,24 @@ private OptionDescriptor descriptor; + private long reads; + private OptionValue next; + private static OptionValue head; + + private static final boolean ShowReadsHistogram = Boolean.getBoolean("graal.showOptionValueReadsHistogram"); + + private static void addToHistogram(OptionValue option) { + if (ShowReadsHistogram) { + synchronized (OptionValue.class) { + option.next = head; + head = option; + } + } + } + public OptionValue(T value) { this.value = value; + addToHistogram(this); } private static final Object UNINITIALIZED = "UNINITIALIZED"; @@ -149,6 +166,7 @@ @SuppressWarnings("unchecked") protected OptionValue() { this.value = (T) UNINITIALIZED; + addToHistogram(this); } /** @@ -167,10 +185,11 @@ /** * Gets the name of this option. The name for an option value with a null - * {@linkplain #setDescriptor(OptionDescriptor) descriptor} is {@code ""}. + * {@linkplain #setDescriptor(OptionDescriptor) descriptor} is the value of + * {@link Object#toString()}. */ public String getName() { - return descriptor == null ? "" : (descriptor.getDeclaringClass().getName() + "." + descriptor.getName()); + return descriptor == null ? super.toString() : (descriptor.getDeclaringClass().getName() + "." + descriptor.getName()); } @Override @@ -182,6 +201,9 @@ * Gets the value of this option. */ public T getValue() { + if (ShowReadsHistogram) { + reads++; + } if (!(this instanceof StableOptionValue)) { OverrideScope overrideScope = overrideScopes.get(); if (overrideScope != null) { @@ -317,4 +339,35 @@ } } } + + static { + if (ShowReadsHistogram) { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + ArrayList> options = new ArrayList<>(); + for (OptionValue option = head; option != null; option = option.next) { + options.add(option); + } + Collections.sort(options, new Comparator>() { + + public int compare(OptionValue o1, OptionValue o2) { + if (o1.reads < o2.reads) { + return -1; + } else if (o1.reads > o2.reads) { + return 1; + } else { + return o1.getName().compareTo(o2.getName()); + } + } + }); + PrintStream out = System.out; + out.println("=== OptionValue reads histogram ==="); + for (OptionValue option : options) { + out.println(option.reads + "\t" + option); + } + } + }); + } + } }