Mercurial > hg > graal-jvmci-8
changeset 17042:9fe9d32e00b5
fixed unit tests so that they pass when assertions are disabled
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 04 Sep 2014 12:51:43 +0200 |
parents | 0bf917d4d061 |
children | 46cefd15ba3f |
files | graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierVerificationTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/WriteBarrierVerificationPhase.java |
diffstat | 3 files changed, 33 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java Wed Sep 03 18:04:28 2014 +0200 +++ b/graal/com.oracle.graal.graph.test/src/com/oracle/graal/graph/test/NodeMapTest.java Thu Sep 04 12:51:43 2014 +0200 @@ -26,6 +26,7 @@ import org.junit.*; +import com.oracle.graal.api.runtime.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodeinfo.*; @@ -47,6 +48,9 @@ @Before public void before() { + // Need to initialize HotSpotGraalRuntime before any Node class is initialized. + Graal.getRuntime(); + graph = new Graph(); for (int i = 0; i < nodes.length; i++) { nodes[i] = graph.add(TestNode.create()); @@ -97,24 +101,45 @@ } } - @Test(expected = AssertionError.class) + @SuppressWarnings("all") + private static boolean assertionsEnabled() { + boolean assertionsEnabled = false; + assert assertionsEnabled = true; + return assertionsEnabled; + } + + @Test public void testNewGet() { /* * Failing here is not required, but if this behavior changes, usages of get need to be * checked for compatibility. */ TestNode newNode = graph.add(TestNode.create()); - map.get(newNode); + try { + map.get(newNode); + fail("expected " + (assertionsEnabled() ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName())); + } catch (AssertionError ae) { + // thrown when assertions are enabled + } catch (ArrayIndexOutOfBoundsException e) { + // thrown when assertions are disabled + } } - @Test(expected = AssertionError.class) + @Test public void testNewSet() { /* * Failing here is not required, but if this behavior changes, usages of set need to be * checked for compatibility. */ TestNode newNode = graph.add(TestNode.create()); - map.set(newNode, 1); + try { + map.set(newNode, 1); + fail("expected " + (assertionsEnabled() ? AssertionError.class.getSimpleName() : ArrayIndexOutOfBoundsException.class.getSimpleName())); + } catch (AssertionError ae) { + // thrown when assertions are enabled + } catch (ArrayIndexOutOfBoundsException e) { + // thrown when assertions are disabled + } } @Test
--- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierVerificationTest.java Wed Sep 03 18:04:28 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierVerificationTest.java Thu Sep 04 12:51:43 2014 +0200 @@ -692,7 +692,7 @@ }; DebugConfig debugConfig = DebugScope.getConfig(); - DebugConfig fixedConfig = Debug.fixedConfig(0, 0, false, false, false, false, debugConfig.dumpHandlers(), debugConfig.verifyHandlers(), debugConfig.output()); + DebugConfig fixedConfig = debugConfig == null ? null : Debug.fixedConfig(0, 0, false, false, false, false, debugConfig.dumpHandlers(), debugConfig.verifyHandlers(), debugConfig.output()); try (DebugConfigScope s = Debug.setConfig(fixedConfig)) { ReentrantNodeIterator.apply(closure, graph.start(), false); new WriteBarrierVerificationPhase().apply(graph);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/WriteBarrierVerificationPhase.java Wed Sep 03 18:04:28 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/WriteBarrierVerificationPhase.java Thu Sep 04 12:51:43 2014 +0200 @@ -71,7 +71,9 @@ Iterator<Node> iterator = frontier.iterator(); while (iterator.hasNext()) { Node currentNode = iterator.next(); - assert !isSafepoint(currentNode) : "Write barrier must be present " + write; + if (isSafepoint(currentNode)) { + throw new AssertionError("Write barrier must be present " + write); + } if (useG1GC()) { if (!(currentNode instanceof G1PostWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (WriteBarrier) currentNode))) { expandFrontier(frontier, currentNode);