# HG changeset patch # User Doug Simon # Date 1412611549 -7200 # Node ID 825b349a55f9511babe54ccfc1869c42b59813f1 # Parent 3457f147a24f717cf5eff26e697b1dde849865ac# Parent 90dc742e8cc7eab6a31dd5bedeb1dafc64df2700 Merge. diff -r 90dc742e8cc7 -r 825b349a55f9 graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugTimerTest.java --- a/graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugTimerTest.java Mon Oct 06 16:33:58 2014 +0200 +++ b/graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugTimerTest.java Mon Oct 06 18:05:49 2014 +0200 @@ -24,6 +24,8 @@ import static org.junit.Assert.*; +import java.lang.management.*; + import org.junit.*; import com.oracle.graal.debug.*; @@ -31,39 +33,46 @@ public class DebugTimerTest { - private static void sleep(long millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - } - } + private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); - private static boolean runningOnWindows() { - return System.getProperty("os.name").toLowerCase().contains("windows"); + /** + * Actively spins the current thread for at least a given number of milliseconds in such a way + * that timers for the current thread keep ticking over. + * + * @return the number of milliseconds actually spent spinning which is guaranteed to be >= + * {@code ms} + */ + private static long spin(long ms) { + long start = threadMXBean.getCurrentThreadCpuTime(); + do { + long durationMS = (threadMXBean.getCurrentThreadCpuTime() - start) / 1000; + if (durationMS >= ms) { + return durationMS; + } + } while (true); } @Test public void test1() { - if (runningOnWindows()) { - // mx beans regression - return; - } DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { DebugTimer timerA = Debug.timer("TimerA"); DebugTimer timerB = Debug.timer("TimerB"); + long spinA; + long spinB; + try (TimerCloseable a1 = timerA.start()) { - sleep(50); + spinA = spin(50); try (TimerCloseable b1 = timerB.start()) { - sleep(50); + spinB = spin(50); } } Assert.assertTrue(timerB.getCurrentValue() < timerA.getCurrentValue()); if (timerA.getFlat() != null && timerB.getFlat() != null) { - assertTrue(timerB.getFlat().getCurrentValue() < timerA.getFlat().getCurrentValue()); + assertTrue(spinB >= spinA || timerB.getFlat().getCurrentValue() < timerA.getFlat().getCurrentValue()); assertEquals(timerA.getFlat().getCurrentValue(), timerA.getCurrentValue() - timerB.getFlat().getCurrentValue(), 10D); } } @@ -75,15 +84,15 @@ try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { DebugTimer timerC = Debug.timer("TimerC"); try (TimerCloseable c1 = timerC.start()) { - sleep(50); + spin(50); try (TimerCloseable c2 = timerC.start()) { - sleep(50); + spin(50); try (TimerCloseable c3 = timerC.start()) { - sleep(50); + spin(50); try (TimerCloseable c4 = timerC.start()) { - sleep(50); + spin(50); try (TimerCloseable c5 = timerC.start()) { - sleep(50); + spin(50); } } } @@ -97,10 +106,6 @@ @Test public void test3() { - if (runningOnWindows()) { - // mx beans regression - return; - } DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { @@ -108,13 +113,13 @@ DebugTimer timerE = Debug.timer("TimerE"); try (TimerCloseable d1 = timerD.start()) { - sleep(50); + spin(50); try (TimerCloseable e1 = timerE.start()) { - sleep(50); + spin(50); try (TimerCloseable d2 = timerD.start()) { - sleep(50); + spin(50); try (TimerCloseable d3 = timerD.start()) { - sleep(50); + spin(50); } } } diff -r 90dc742e8cc7 -r 825b349a55f9 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Mon Oct 06 16:33:58 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Mon Oct 06 18:05:49 2014 +0200 @@ -107,7 +107,7 @@ @Override public int hashCode() { - return Node.USE_GENERATED_NODES ? node.valueNumberLeaf() : node.getNodeClass().valueNumber(node); + return Node.USE_GENERATED_VALUE_NUMBER ? node.valueNumberLeaf() : node.getNodeClass().valueNumber(node); } @Override diff -r 90dc742e8cc7 -r 825b349a55f9 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Mon Oct 06 16:33:58 2014 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Mon Oct 06 18:05:49 2014 +0200 @@ -59,8 +59,13 @@ @NodeInfo public abstract class Node implements Cloneable, Formattable { - public final static boolean USE_GENERATED_NODES = Boolean.parseBoolean(System.getProperty("graal.useGeneratedNodes", "true")); - public final static boolean USE_UNSAFE_TO_CLONE = Boolean.parseBoolean(System.getProperty("graal.useUnsafeToClone", "true")); + public final static boolean USE_GENERATED_VALUE_NUMBER = Boolean.parseBoolean(System.getProperty("graal.node.useGeneratedValueNumber", "true")); + + public final static boolean USE_GENERATED_VALUE_EQUALS = Boolean.parseBoolean(System.getProperty("graal.node.useGeneratedValueEquals", "false")); + + public final static boolean USE_UNSAFE_TO_CLONE = Boolean.parseBoolean(System.getProperty("graal.node.useUnsafeToClone", "true")); + + public final static boolean USE_GENERATED_NODES = USE_GENERATED_VALUE_NUMBER || USE_GENERATED_VALUE_EQUALS; static final int DELETED_ID_START = -1000000000; static final int INITIAL_ID = -1; @@ -1038,14 +1043,17 @@ } /** - * If this node is a {@linkplain NodeClass#isLeafNode() leaf} node, returns a hash for this node - * based on its {@linkplain NodeClass#getData() data} fields otherwise return 0. + * Gets a hash for this {@linkplain NodeClass#valueNumberable() value numberable} + * {@linkplain NodeClass#isLeafNode() leaf} node based on its {@linkplain NodeClass#getData() + * data} fields. + * + * This method must only be called if {@link #USE_GENERATED_VALUE_NUMBER} is true and this is a + * value numberable leaf node. * * Overridden by a method generated for leaf nodes. */ public int valueNumberLeaf() { - assert !getNodeClass().isLeafNode(); - return 0; + throw new GraalInternalError("Node is not a value numberable leaf", this); } /** @@ -1068,6 +1076,6 @@ * @return true if the data fields of this object and {@code other} are equal */ public boolean valueEquals(Node other) { - return USE_GENERATED_NODES ? dataEquals(other) : getNodeClass().dataEquals(this, other); + return USE_GENERATED_VALUE_EQUALS ? dataEquals(other) : getNodeClass().dataEquals(this, other); } }