|
59 | 59 | import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
|
60 | 60 | import com.oracle.truffle.api.dsl.test.RewriteUnexpectedResultTestFactory.DoubleReplaceNodeGen;
|
61 | 61 | import com.oracle.truffle.api.dsl.test.RewriteUnexpectedResultTestFactory.InlineCacheBoxingOverloadNodeGen;
|
| 62 | +import com.oracle.truffle.api.dsl.test.RewriteUnexpectedResultTestFactory.InlineCacheWithGenericBoxingOverloadNodeGen; |
62 | 63 | import com.oracle.truffle.api.dsl.test.RewriteUnexpectedResultTestFactory.InlinedBoxingOverloadNodeGen;
|
63 | 64 | import com.oracle.truffle.api.dsl.test.RewriteUnexpectedResultTestFactory.PrimitiveOverloadNodeGen;
|
64 | 65 | import com.oracle.truffle.api.dsl.test.RewriteUnexpectedResultTestFactory.RewriteUnexpected3NodeGen;
|
@@ -370,6 +371,60 @@ public void testInlinedBoxingOverloadNode() throws UnexpectedResultException {
|
370 | 371 | assertThrows(UnsupportedSpecializationException.class, () -> node.executeGeneric(44));
|
371 | 372 | }
|
372 | 373 |
|
| 374 | + @GenerateInline(false) |
| 375 | + @SuppressWarnings("unused") |
| 376 | + abstract static class InlineCacheWithGenericBoxingOverloadNode extends BaseNode { |
| 377 | + |
| 378 | + @Specialization(guards = "arg == cachedArg", limit = "3", rewriteOn = UnexpectedResultException.class) |
| 379 | + static int doIntCached(Object arg, @Cached("arg") Object cachedArg) throws UnexpectedResultException { |
| 380 | + if (cachedArg instanceof Integer i) { |
| 381 | + return 42; |
| 382 | + } |
| 383 | + throw new UnexpectedResultException(cachedArg); |
| 384 | + } |
| 385 | + |
| 386 | + @Specialization(guards = "arg == cachedArg", limit = "3", replaces = {"doIntCached"}) |
| 387 | + static Object doObjectCached(Object arg, @Cached("arg") Object cachedArg) { |
| 388 | + return cachedArg; |
| 389 | + } |
| 390 | + |
| 391 | + @Specialization(replaces = {"doIntCached", "doObjectCached"}, rewriteOn = UnexpectedResultException.class) |
| 392 | + static int doIntGeneric(Object arg) throws UnexpectedResultException { |
| 393 | + if (arg instanceof Integer i) { |
| 394 | + return 43; |
| 395 | + } |
| 396 | + throw new UnexpectedResultException(arg); |
| 397 | + } |
| 398 | + |
| 399 | + @Specialization(replaces = {"doIntGeneric", "doIntCached", "doObjectCached"}) |
| 400 | + static Object doGeneric(Object arg) { |
| 401 | + return 44; |
| 402 | + } |
| 403 | + } |
| 404 | + |
| 405 | + @Test |
| 406 | + public void testInlineCacheWithGenericBoxingOverloadNode() throws UnexpectedResultException { |
| 407 | + InlineCacheWithGenericBoxingOverloadNode node = InlineCacheWithGenericBoxingOverloadNodeGen.create(); |
| 408 | + |
| 409 | + Object o1 = 42; |
| 410 | + Object o2 = "43"; |
| 411 | + Object o3 = 43; |
| 412 | + |
| 413 | + assertEquals(o1, node.executeGeneric(o1)); |
| 414 | + assertEquals(o2, node.executeGeneric(o2)); |
| 415 | + assertEquals(o1, node.executeInt(o1)); |
| 416 | + UnexpectedResultException e = assertThrows(UnexpectedResultException.class, () -> node.executeInt(o2)); |
| 417 | + assertEquals(o2, e.getResult()); |
| 418 | + assertEquals(o2, node.executeGeneric(o2)); |
| 419 | + assertEquals(o3, node.executeInt(o3)); |
| 420 | + |
| 421 | + // inline cache full -> generic executeAndSpecialize |
| 422 | + assertEquals(44, node.executeGeneric(44)); |
| 423 | + |
| 424 | + assertEquals(43, node.executeInt(44)); |
| 425 | + assertEquals(44, node.executeGeneric(44)); |
| 426 | + } |
| 427 | + |
373 | 428 | @GenerateInline(false)
|
374 | 429 | @SuppressWarnings("unused")
|
375 | 430 | abstract static class InlinedBoxingOverloadNode extends BaseNode {
|
|
0 commit comments