|
24 | 24 | */
|
25 | 25 | package jdk.graal.compiler.truffle.test;
|
26 | 26 |
|
27 |
| -import jdk.graal.compiler.nodes.ConstantNode; |
28 |
| -import jdk.graal.compiler.nodes.ReturnNode; |
29 |
| -import jdk.graal.compiler.nodes.StructuredGraph; |
| 27 | +import static org.junit.Assert.assertNull; |
| 28 | + |
30 | 29 | import org.junit.Assert;
|
31 | 30 | import org.junit.Test;
|
32 | 31 |
|
33 | 32 | import com.oracle.truffle.api.CompilerAsserts;
|
34 | 33 | import com.oracle.truffle.api.Truffle;
|
35 | 34 | import com.oracle.truffle.api.frame.Frame;
|
36 | 35 | import com.oracle.truffle.api.frame.FrameDescriptor;
|
| 36 | +import com.oracle.truffle.api.frame.FrameSlotTypeException; |
37 | 37 | import com.oracle.truffle.api.frame.MaterializedFrame;
|
38 | 38 | import com.oracle.truffle.api.frame.VirtualFrame;
|
39 | 39 | import com.oracle.truffle.api.nodes.RootNode;
|
40 | 40 | import com.oracle.truffle.runtime.OptimizedCallTarget;
|
41 | 41 |
|
| 42 | +import jdk.graal.compiler.nodes.ConstantNode; |
| 43 | +import jdk.graal.compiler.nodes.ReturnNode; |
| 44 | +import jdk.graal.compiler.nodes.StructuredGraph; |
| 45 | + |
42 | 46 | public class FrameDescriptorTest extends PartialEvaluationTest {
|
43 | 47 |
|
44 | 48 | @Test
|
@@ -129,4 +133,90 @@ public void testInfo() {
|
129 | 133 | FrameDescriptor fd = builder.info("foo").info(obj).build();
|
130 | 134 | assertEmptyFrameDescriptor(fd, obj);
|
131 | 135 | }
|
| 136 | + |
| 137 | + @Test |
| 138 | + public void testIllegalDefaultFails() { |
| 139 | + FrameDescriptor.Builder builder = FrameDescriptor.newBuilder().defaultValueIllegal(); |
| 140 | + int index0 = builder.addSlots(1); |
| 141 | + |
| 142 | + FrameDescriptor fd = builder.build(); |
| 143 | + FrameSlotTypeException e; |
| 144 | + |
| 145 | + RootNode root1 = new RootNode(null, fd) { |
| 146 | + @Override |
| 147 | + public Object execute(VirtualFrame frame) { |
| 148 | + return frame.getObject(index0); |
| 149 | + } |
| 150 | + }; |
| 151 | + |
| 152 | + // fails in interpreted |
| 153 | + e = Assert.assertThrows(FrameSlotTypeException.class, () -> { |
| 154 | + root1.getCallTarget().call(); |
| 155 | + }); |
| 156 | + Assert.assertEquals("Frame slot kind Object expected, but got Illegal at frame slot index 0.", e.getMessage()); |
| 157 | + |
| 158 | + compile(root1); |
| 159 | + |
| 160 | + // fails in compiled |
| 161 | + e = Assert.assertThrows(FrameSlotTypeException.class, () -> { |
| 162 | + root1.getCallTarget().call(); |
| 163 | + }); |
| 164 | + Assert.assertEquals("Frame slot kind Object expected, but got Illegal at frame slot index 0.", e.getMessage()); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + public void testIllegalDefaultNull() { |
| 169 | + FrameDescriptor.Builder builder = FrameDescriptor.newBuilder().defaultValueIllegal(); |
| 170 | + int index0 = builder.addSlots(1); |
| 171 | + FrameDescriptor fd = builder.build(); |
| 172 | + |
| 173 | + RootNode root1 = new RootNode(null, fd) { |
| 174 | + @Override |
| 175 | + public Object execute(VirtualFrame frame) { |
| 176 | + frame.setObject(index0, null); |
| 177 | + return frame.getObject(index0); |
| 178 | + } |
| 179 | + }; |
| 180 | + |
| 181 | + assertNull(root1.getCallTarget().call()); |
| 182 | + compile(root1); |
| 183 | + assertNull(root1.getCallTarget().call()); |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + public void testIllegalDefaultCleared() { |
| 188 | + FrameDescriptor.Builder builder = FrameDescriptor.newBuilder().defaultValueIllegal(); |
| 189 | + int index0 = builder.addSlots(1); |
| 190 | + FrameDescriptor fd = builder.build(); |
| 191 | + FrameSlotTypeException e; |
| 192 | + |
| 193 | + RootNode root1 = new RootNode(null, fd) { |
| 194 | + @Override |
| 195 | + public Object execute(VirtualFrame frame) { |
| 196 | + frame.setObject(index0, null); |
| 197 | + frame.clear(index0); |
| 198 | + return frame.getObject(index0); |
| 199 | + } |
| 200 | + }; |
| 201 | + |
| 202 | + // fails in interpreted |
| 203 | + e = Assert.assertThrows(FrameSlotTypeException.class, () -> { |
| 204 | + root1.getCallTarget().call(); |
| 205 | + }); |
| 206 | + Assert.assertEquals("Frame slot kind Object expected, but got Illegal at frame slot index 0.", e.getMessage()); |
| 207 | + |
| 208 | + compile(root1); |
| 209 | + |
| 210 | + // fails in compiled |
| 211 | + e = Assert.assertThrows(FrameSlotTypeException.class, () -> { |
| 212 | + root1.getCallTarget().call(); |
| 213 | + }); |
| 214 | + Assert.assertEquals("Frame slot kind Object expected, but got Illegal at frame slot index 0.", e.getMessage()); |
| 215 | + } |
| 216 | + |
| 217 | + private static void compile(RootNode root) { |
| 218 | + OptimizedCallTarget target = (OptimizedCallTarget) root.getCallTarget(); |
| 219 | + target.compile(true); |
| 220 | + target.waitForCompilation(); |
| 221 | + } |
132 | 222 | }
|
0 commit comments