Mercurial > hg > truffle
diff graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/SafeReplaceTest.java @ 19141:67d9e635102f
Truffle/Instrumentation: refine checks for safe node replacement
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 03 Feb 2015 11:48:25 -0800 |
parents | 867058575979 |
children |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/SafeReplaceTest.java Tue Feb 03 18:30:07 2015 +0100 +++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/SafeReplaceTest.java Tue Feb 03 11:48:25 2015 -0800 @@ -39,12 +39,11 @@ public void testCorrectReplacement() { TestRootNode root = new TestRootNode(); final TestNode oldChild = new TestNode(); + final TestNode newChild = new TestNode(); root.child = oldChild; - assertFalse(oldChild.isReplaceable()); // No parent node + assertFalse(oldChild.isSafelyReplaceableBy(newChild)); // No parent node root.adoptChildren(); - assertTrue(oldChild.isReplaceable()); // Now adopted by parent - final TestNode newChild = new TestNode(); - assertTrue(oldChild.isSafelyReplaceableBy(newChild)); // Parent field type is assignable by + assertTrue(oldChild.isSafelyReplaceableBy(newChild)); // Now adopted by parent // new node oldChild.replace(newChild); root.execute(null); @@ -59,10 +58,11 @@ final TestNode oldChild = new TestNode(); root.child = oldChild; root.adoptChildren(); - final WrongTestNode newChild = new WrongTestNode(); - assertFalse(oldChild.isSafelyReplaceableBy(newChild)); - // Can't test: oldChild.replace(newChild); - // Fails if assertions checked; else unsafe assignment will eventually crash the VM + final TestNode newChild = new TestNode(); + final TestNode strayChild = new TestNode(); + assertFalse(strayChild.isSafelyReplaceableBy(newChild)); // Stray not a child of parent + final WrongTestNode wrongTypeNewChild = new WrongTestNode(); + assertFalse(oldChild.isSafelyReplaceableBy(wrongTypeNewChild)); } private static class TestNode extends Node {