Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
19103:ccabd82be35c | 19141:67d9e635102f |
---|---|
37 | 37 |
38 @Test | 38 @Test |
39 public void testCorrectReplacement() { | 39 public void testCorrectReplacement() { |
40 TestRootNode root = new TestRootNode(); | 40 TestRootNode root = new TestRootNode(); |
41 final TestNode oldChild = new TestNode(); | 41 final TestNode oldChild = new TestNode(); |
42 final TestNode newChild = new TestNode(); | |
42 root.child = oldChild; | 43 root.child = oldChild; |
43 assertFalse(oldChild.isReplaceable()); // No parent node | 44 assertFalse(oldChild.isSafelyReplaceableBy(newChild)); // No parent node |
44 root.adoptChildren(); | 45 root.adoptChildren(); |
45 assertTrue(oldChild.isReplaceable()); // Now adopted by parent | 46 assertTrue(oldChild.isSafelyReplaceableBy(newChild)); // Now adopted by parent |
46 final TestNode newChild = new TestNode(); | |
47 assertTrue(oldChild.isSafelyReplaceableBy(newChild)); // Parent field type is assignable by | |
48 // new node | 47 // new node |
49 oldChild.replace(newChild); | 48 oldChild.replace(newChild); |
50 root.execute(null); | 49 root.execute(null); |
51 assertEquals(root.executed, 1); | 50 assertEquals(root.executed, 1); |
52 assertEquals(oldChild.executed, 0); | 51 assertEquals(oldChild.executed, 0); |
57 public void testIncorrectReplacement() { | 56 public void testIncorrectReplacement() { |
58 TestRootNode root = new TestRootNode(); | 57 TestRootNode root = new TestRootNode(); |
59 final TestNode oldChild = new TestNode(); | 58 final TestNode oldChild = new TestNode(); |
60 root.child = oldChild; | 59 root.child = oldChild; |
61 root.adoptChildren(); | 60 root.adoptChildren(); |
62 final WrongTestNode newChild = new WrongTestNode(); | 61 final TestNode newChild = new TestNode(); |
63 assertFalse(oldChild.isSafelyReplaceableBy(newChild)); | 62 final TestNode strayChild = new TestNode(); |
64 // Can't test: oldChild.replace(newChild); | 63 assertFalse(strayChild.isSafelyReplaceableBy(newChild)); // Stray not a child of parent |
65 // Fails if assertions checked; else unsafe assignment will eventually crash the VM | 64 final WrongTestNode wrongTypeNewChild = new WrongTestNode(); |
65 assertFalse(oldChild.isSafelyReplaceableBy(wrongTypeNewChild)); | |
66 } | 66 } |
67 | 67 |
68 private static class TestNode extends Node { | 68 private static class TestNode extends Node { |
69 | 69 |
70 private int executed; | 70 private int executed; |