Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/SpecializationGroupingTest.java @ 16756:5148aab962af
Truffle-DSL: updated tests for the new generation layout.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:53:05 +0200 |
parents | 85dcc7f59c34 |
children | a665483c3881 |
comparison
equal
deleted
inserted
replaced
16755:bd28da642eea | 16756:5148aab962af |
---|---|
46 public void testGrouping() { | 46 public void testGrouping() { |
47 MockAssumption a1 = new MockAssumption(true); | 47 MockAssumption a1 = new MockAssumption(true); |
48 MockAssumption a2 = new MockAssumption(false); | 48 MockAssumption a2 = new MockAssumption(false); |
49 MockAssumption a3 = new MockAssumption(true); | 49 MockAssumption a3 = new MockAssumption(true); |
50 | 50 |
51 TestRootNode<TestGrouping> root = TestHelper.createGenericRoot(TestGroupingFactory.getInstance(), a1, a2, a3); | 51 TestRootNode<TestGrouping> root = TestHelper.createRoot(TestGroupingFactory.getInstance(), a1, a2, a3); |
52 | 52 |
53 SimpleTypes.intCast = 0; | 53 SimpleTypes.intCast = 0; |
54 SimpleTypes.intCheck = 0; | 54 SimpleTypes.intCheck = 0; |
55 TestGrouping.true1 = 0; | 55 TestGrouping.true1 = 0; |
56 TestGrouping.false1 = 0; | 56 TestGrouping.false1 = 0; |
57 TestGrouping.true2 = 0; | 57 TestGrouping.true2 = 0; |
58 TestGrouping.false2 = 0; | 58 TestGrouping.false2 = 0; |
59 TestGrouping.true3 = 0; | 59 TestGrouping.true3 = 0; |
60 | 60 |
61 Assert.assertEquals(42, TestHelper.executeWith(root, 21, 21)); | 61 Assert.assertEquals(42, TestHelper.executeWith(root, 21, 21)); |
62 Assert.assertEquals(1, TestGrouping.true1); | 62 Assert.assertEquals(4, TestGrouping.true1); |
63 Assert.assertEquals(1, TestGrouping.false1); | 63 Assert.assertEquals(0, TestGrouping.false1); |
64 Assert.assertEquals(1, TestGrouping.true2); | 64 Assert.assertEquals(4, TestGrouping.true2); |
65 Assert.assertEquals(1, TestGrouping.false2); | 65 Assert.assertEquals(5, TestGrouping.false2); |
66 Assert.assertEquals(1, TestGrouping.true3); | 66 Assert.assertEquals(5, TestGrouping.true3); |
67 Assert.assertEquals(2, SimpleTypes.intCheck); | 67 Assert.assertEquals(8, SimpleTypes.intCheck); |
68 Assert.assertEquals(2, SimpleTypes.intCast); | 68 Assert.assertEquals(8, SimpleTypes.intCast); |
69 Assert.assertEquals(1, a1.checked); | 69 Assert.assertEquals(4, a1.checked); |
70 Assert.assertEquals(1, a2.checked); | 70 Assert.assertEquals(0, a2.checked); |
71 Assert.assertEquals(1, a3.checked); | 71 Assert.assertEquals(4, a3.checked); |
72 | 72 |
73 Assert.assertEquals(42, TestHelper.executeWith(root, 21, 21)); | 73 Assert.assertEquals(42, TestHelper.executeWith(root, 21, 21)); |
74 Assert.assertEquals(2, TestGrouping.true1); | 74 Assert.assertEquals(5, TestGrouping.true1); |
75 Assert.assertEquals(2, TestGrouping.false1); | 75 Assert.assertEquals(0, TestGrouping.false1); |
76 Assert.assertEquals(2, TestGrouping.true2); | 76 Assert.assertEquals(5, TestGrouping.true2); |
77 Assert.assertEquals(2, TestGrouping.false2); | 77 Assert.assertEquals(6, TestGrouping.false2); |
78 Assert.assertEquals(2, TestGrouping.true3); | 78 Assert.assertEquals(6, TestGrouping.true3); |
79 | 79 |
80 Assert.assertEquals(2, a1.checked); | 80 Assert.assertEquals(5, a1.checked); |
81 Assert.assertEquals(2, a2.checked); | 81 Assert.assertEquals(0, a2.checked); |
82 Assert.assertEquals(2, a3.checked); | 82 Assert.assertEquals(5, a3.checked); |
83 Assert.assertEquals(4, SimpleTypes.intCheck); | 83 Assert.assertEquals(8, SimpleTypes.intCheck); |
84 Assert.assertEquals(4, SimpleTypes.intCast); | 84 Assert.assertEquals(8, SimpleTypes.intCast); |
85 | 85 |
86 } | 86 } |
87 | 87 |
88 @SuppressWarnings("unused") | 88 @SuppressWarnings("unused") |
89 @NodeChildren({@NodeChild, @NodeChild}) | 89 @NodeChildren({@NodeChild, @NodeChild}) |
119 protected boolean true3(int value) { | 119 protected boolean true3(int value) { |
120 true3++; | 120 true3++; |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 @Specialization(order = 1) | 124 @Specialization |
125 public int fail(int value1, String value2) { | 125 public int fail(int value1, String value2) { |
126 throw new AssertionError(); | 126 throw new AssertionError(); |
127 } | 127 } |
128 | 128 |
129 @Specialization(order = 2, guards = {"true1", "false1"}) | 129 @Specialization(guards = {"true1", "true2", "!false2", "true3"}, assumptions = {"a1", "a3"}, rewriteOn = RuntimeException.class) |
130 public int fail1(int value1, int value2) { | |
131 throw new AssertionError(); | |
132 } | |
133 | |
134 @Specialization(order = 3, guards = {"true1", "true2"}, assumptions = {"a1", "a2"}) | |
135 public int fail2(int value1, int value2) { | |
136 throw new AssertionError(); | |
137 } | |
138 | |
139 @Specialization(order = 4, guards = {"true1", "true2"}, assumptions = {"a1", "a3"}, rewriteOn = RuntimeException.class) | |
140 public int throwRewrite(int value1, int value2) { | 130 public int throwRewrite(int value1, int value2) { |
141 throw new RuntimeException(); | 131 throw new RuntimeException(); |
142 } | 132 } |
143 | 133 |
144 @Specialization(order = 5, guards = {"true1", "true2", "false2"}, assumptions = {"a1", "a3"}) | 134 @Specialization(guards = {"true1", "true2", "!false2", "true3"}, contains = "throwRewrite", assumptions = {"a1", "a3"}) |
145 public int fail4(int value1, int value2) { | |
146 throw new AssertionError(); | |
147 } | |
148 | |
149 @Specialization(order = 6, guards = {"true1", "true2", "!false2", "!true3"}, assumptions = {"a1", "a3"}) | |
150 public int fail5(int value1, int value2) { | |
151 throw new AssertionError(); | |
152 } | |
153 | |
154 @Specialization(order = 7, guards = {"true1", "true2", "!false2", "true3"}, assumptions = {"a1", "a3"}) | |
155 public int success(int value1, int value2) { | 135 public int success(int value1, int value2) { |
156 return value1 + value2; | 136 return value1 + value2; |
137 } | |
138 | |
139 @Specialization(guards = {"true1", "true2", "!false2", "!true3"}, assumptions = {"a1", "a3"}) | |
140 public int fail5(int value1, int value2) { | |
141 throw new AssertionError(); | |
142 } | |
143 | |
144 @Specialization(guards = {"true1", "true2", "false2"}, assumptions = {"a1", "a3"}) | |
145 public int fail4(int value1, int value2) { | |
146 throw new AssertionError(); | |
147 } | |
148 | |
149 @Specialization(guards = {"true1", "true2"}, assumptions = {"a1", "a3"}) | |
150 public int fail2break(int value1, int value2) { | |
151 throw new AssertionError(); | |
152 } | |
153 | |
154 @Specialization(guards = {"true1", "false1"}) | |
155 public int fail1(int value1, int value2) { | |
156 throw new AssertionError(); | |
157 } | 157 } |
158 | 158 |
159 } | 159 } |
160 | 160 |
161 @Test | 161 @Test |
166 | 166 |
167 @SuppressWarnings("unused") | 167 @SuppressWarnings("unused") |
168 @NodeChild(value = "genericChild", type = GenericInt.class) | 168 @NodeChild(value = "genericChild", type = GenericInt.class) |
169 public abstract static class TestElseConnectionBug1 extends ValueNode { | 169 public abstract static class TestElseConnectionBug1 extends ValueNode { |
170 | 170 |
171 @Specialization(order = 1, rewriteOn = {SlowPathException.class}, guards = "isInitialized") | 171 @Specialization(rewriteOn = {SlowPathException.class}, guards = "isInitialized") |
172 public int doInteger(int value) throws SlowPathException { | 172 public int do1(int value) throws SlowPathException { |
173 throw new SlowPathException(); | 173 throw new SlowPathException(); |
174 } | 174 } |
175 | 175 |
176 @Specialization(order = 3, guards = "isInitialized") | 176 @Specialization(contains = "do1", guards = "isInitialized") |
177 public int doObject(int value) { | 177 public int do2(int value) { |
178 return value == 42 ? value : 0; | 178 return value == 42 ? value : 0; |
179 } | 179 } |
180 | 180 |
181 @Specialization(order = 4, guards = "!isInitialized") | 181 @Specialization(guards = "!isInitialized") |
182 public Object doUninitialized(int value) { | 182 public Object do3(int value) { |
183 throw new AssertionError(); | 183 throw new AssertionError(); |
184 } | 184 } |
185 | 185 |
186 boolean isInitialized(int value) { | 186 boolean isInitialized(int value) { |
187 return true; | 187 return true; |
202 | 202 |
203 } | 203 } |
204 | 204 |
205 @Test | 205 @Test |
206 public void testElseConnectionBug2() { | 206 public void testElseConnectionBug2() { |
207 TestHelper.assertRuns(TestElseConnectionBug2Factory.getInstance(), 42, 42); | 207 TestHelper.assertRuns(TestElseConnectionBug2Factory.getInstance(), new Object[]{42}, new Object[]{42}); |
208 } | 208 } |
209 | 209 |
210 @SuppressWarnings("unused") | 210 @SuppressWarnings("unused") |
211 @NodeChild | 211 @NodeChild |
212 public abstract static class TestElseConnectionBug2 extends ValueNode { | 212 public abstract static class TestElseConnectionBug2 extends ValueNode { |
213 | 213 |
214 @Specialization(order = 2, guards = "guard0") | 214 @Specialization(guards = "guard0") |
215 public int doGuard0(int value) { | 215 public int do1(int value) { |
216 throw new AssertionError(); | 216 throw new AssertionError(); |
217 } | 217 } |
218 | 218 |
219 @Specialization(order = 3, guards = "guard1") | 219 @Specialization(guards = "guard1") |
220 public int doGuard1(int value) { | 220 public int do2(int value) { |
221 throw new AssertionError(); | 221 throw new AssertionError(); |
222 } | 222 } |
223 | 223 |
224 @Specialization(order = 4, guards = "!guard0") | 224 @Specialization(guards = "!guard0") |
225 public int doUninitialized(int value) { | 225 public int do3(int value) { |
226 return value; | 226 return value; |
227 } | 227 } |
228 | 228 |
229 boolean guard0(int value) { | 229 boolean guard0(int value) { |
230 return false; | 230 return false; |