|
45 | 45 |
|
46 | 46 | import org.junit.Test;
|
47 | 47 |
|
| 48 | +import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
48 | 49 | import com.oracle.truffle.api.dsl.Cached;
|
49 | 50 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
50 | 51 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
|
54 | 55 | import com.oracle.truffle.api.dsl.Specialization;
|
55 | 56 | import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
|
56 | 57 | import com.oracle.truffle.api.dsl.test.GenerateInlineTest.SimpleNode;
|
| 58 | +import com.oracle.truffle.api.dsl.test.SharedCachedTestFactory.SharedCachedInMultiInstanceNodeGen; |
57 | 59 | import com.oracle.truffle.api.dsl.test.SharedCachedTestFactory.SharedStringInGuardNodeGen;
|
58 | 60 | import com.oracle.truffle.api.dsl.test.SharedCachedTestFactory.UnboundExclusiveObjectNodeGen;
|
59 | 61 | import com.oracle.truffle.api.dsl.test.SharedCachedTestFactory.UnboundSharedObjectNodeGen;
|
60 | 62 | import com.oracle.truffle.api.dsl.test.SharedCachedTestFactory.UseGenerateInlineSharedNodeGen;
|
61 | 63 | import com.oracle.truffle.api.nodes.Node;
|
| 64 | +import com.oracle.truffle.api.strings.TruffleString; |
| 65 | +import com.oracle.truffle.api.strings.TruffleString.Encoding; |
62 | 66 | import com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest;
|
63 | 67 |
|
64 | 68 | @SuppressWarnings({"truffle-inlining", "truffle-neverdefault", "unused"})
|
@@ -448,4 +452,39 @@ public void testObjectReference() {
|
448 | 452 | });
|
449 | 453 | }
|
450 | 454 |
|
| 455 | + @Test |
| 456 | + public void testSharedCachedInMultiInstanceNode() { |
| 457 | + SharedCachedInMultiInstanceNode node = SharedCachedInMultiInstanceNodeGen.create(); |
| 458 | + TruffleString a = TruffleString.fromJavaStringUncached("a", Encoding.UTF_16); |
| 459 | + TruffleString b = TruffleString.fromJavaStringUncached("b", Encoding.UTF_16); |
| 460 | + TruffleString c = TruffleString.fromJavaStringUncached("c", Encoding.UTF_16); |
| 461 | + |
| 462 | + assertEquals(a, node.execute(a)); |
| 463 | + assertEquals(b, node.execute(b)); |
| 464 | + assertEquals(c, node.execute(c)); |
| 465 | + } |
| 466 | + |
| 467 | + public abstract static class SharedCachedInMultiInstanceNode extends Node { |
| 468 | + |
| 469 | + abstract Object execute(TruffleString name); |
| 470 | + |
| 471 | + @Specialization(guards = {"stringEquals(equalsNode, cachedName, name)"}, limit = "2") |
| 472 | + protected TruffleString doCached(TruffleString name, |
| 473 | + @Cached("name") TruffleString cachedName, |
| 474 | + @Cached @Shared TruffleString.EqualNode equalsNode, |
| 475 | + @Cached("doGeneric(name)") TruffleString cachedResult) { |
| 476 | + return cachedResult; |
| 477 | + } |
| 478 | + |
| 479 | + static boolean stringEquals(TruffleString.EqualNode equalNode, TruffleString s1, TruffleString s2) { |
| 480 | + return equalNode.execute(s1, s2, Encoding.UTF_16); |
| 481 | + } |
| 482 | + |
| 483 | + @TruffleBoundary |
| 484 | + @Specialization(replaces = "doCached") |
| 485 | + protected TruffleString doGeneric(TruffleString name) { |
| 486 | + return name; |
| 487 | + } |
| 488 | + } |
| 489 | + |
451 | 490 | }
|
0 commit comments