Skip to content

Commit 3cd4224

Browse files
committed
[GR-53442] Split nodes that use inline caching
PullRequest: truffleruby/4274
2 parents ec75e98 + 487a236 commit 3cd4224

File tree

66 files changed

+299
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+299
-332
lines changed

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ Object rbGvGet(VirtualFrame frame, String name,
10741074
}
10751075

10761076

1077-
@ReportPolymorphism
1077+
@ReportPolymorphism // inline cache
10781078
@GenerateInline
10791079
@GenerateCached(false)
10801080
public abstract static class RbGvGetInnerNode extends RubyBaseNode {
@@ -1990,7 +1990,7 @@ RubyArray rbAryNewFromValues(Object cArray,
19901990
}
19911991

19921992
@CoreMethod(names = "rb_tr_sprintf_types", onSingleton = true, required = 1)
1993-
@ReportPolymorphism
1993+
@ReportPolymorphism // inline cache (but not working due to single call site in C)
19941994
public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgumentsNode {
19951995

19961996
@Child protected TruffleString.GetInternalByteArrayNode byteArrayNode = TruffleString.GetInternalByteArrayNode
@@ -2001,7 +2001,6 @@ public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgument
20012001
"libFormat.isRubyString(format)",
20022002
"equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
20032003
limit = "2")
2004-
20052004
static Object typesCached(VirtualFrame frame, Object format,
20062005
@Cached @Shared RubyStringLibrary libFormat,
20072006
@Cached("asTruffleStringUncached(format)") TruffleString cachedFormat,
@@ -2069,7 +2068,7 @@ static RubyString format(Object format, Object stringReader, RubyArray argArray,
20692068

20702069
@GenerateInline
20712070
@GenerateCached(false)
2072-
@ReportPolymorphism
2071+
@ReportPolymorphism // inline cache, CallTarget cache (but not working due to single call site in C)
20732072
public abstract static class RBSprintfInnerNode extends RubyBaseNode {
20742073

20752074
public abstract BytesResult execute(Node node, AbstractTruffleString format, RubyEncoding encoding,

src/main/java/org/truffleruby/cext/IDToSymbolNode.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020

2121
import com.oracle.truffle.api.dsl.Cached;
2222
import com.oracle.truffle.api.dsl.GenerateUncached;
23-
import com.oracle.truffle.api.dsl.ReportPolymorphism;
2423
import com.oracle.truffle.api.dsl.Specialization;
2524

2625
@GenerateUncached
27-
@ReportPolymorphism
2826
public abstract class IDToSymbolNode extends RubyBaseNode {
2927

3028
public abstract RubySymbol execute(Object value);

src/main/java/org/truffleruby/cext/SymbolToIDNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import com.oracle.truffle.api.dsl.Specialization;
2121

2222
@GenerateUncached
23-
@ReportPolymorphism
23+
@ReportPolymorphism // inline cache (but not working due to single call site in C)
2424
public abstract class SymbolToIDNode extends RubyBaseNode {
2525

2626
public abstract Object execute(Object value);

src/main/java/org/truffleruby/core/TruffleSystemNodes.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@
4343
import java.lang.management.ManagementFactory;
4444
import java.nio.file.NoSuchFileException;
4545
import java.util.Set;
46-
import java.util.logging.Level;
4746

4847
import com.oracle.truffle.api.dsl.Bind;
4948
import com.oracle.truffle.api.nodes.Node;
5049
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
5150
import com.oracle.truffle.api.strings.TruffleString;
5251
import com.sun.management.ThreadMXBean;
53-
import org.truffleruby.RubyLanguage;
5452
import org.truffleruby.annotations.CoreMethod;
5553
import org.truffleruby.annotations.SuppressFBWarnings;
5654
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -63,7 +61,6 @@
6361
import org.truffleruby.core.encoding.RubyEncoding;
6462
import org.truffleruby.core.string.RubyString;
6563
import org.truffleruby.core.string.StringUtils;
66-
import org.truffleruby.core.symbol.RubySymbol;
6764
import org.truffleruby.interop.FromJavaStringNode;
6865
import org.truffleruby.interop.ToJavaStringNode;
6966
import org.truffleruby.language.RubyGuards;
@@ -74,7 +71,6 @@
7471
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7572
import com.oracle.truffle.api.TruffleFile;
7673
import com.oracle.truffle.api.dsl.Cached;
77-
import com.oracle.truffle.api.dsl.Cached.Shared;
7874
import com.oracle.truffle.api.dsl.Specialization;
7975

8076
@CoreModule("Truffle::System")
@@ -230,45 +226,6 @@ RubyString hostOS() {
230226

231227
}
232228

233-
@CoreMethod(names = "log", onSingleton = true, required = 2)
234-
public abstract static class LogNode extends CoreMethodArrayArgumentsNode {
235-
236-
@Specialization(guards = { "strings.isRubyString(message)", "level == cachedLevel" }, limit = "3")
237-
Object logCached(RubySymbol level, Object message,
238-
@Cached @Shared RubyStringLibrary strings,
239-
@Cached @Shared ToJavaStringNode toJavaStringNode,
240-
@Cached("level") RubySymbol cachedLevel,
241-
@Cached("getLevel(cachedLevel)") Level javaLevel) {
242-
log(javaLevel, toJavaStringNode.execute(this, message));
243-
return nil;
244-
}
245-
246-
@Specialization(guards = "strings.isRubyString(message)", replaces = "logCached")
247-
Object log(RubySymbol level, Object message,
248-
@Cached @Shared RubyStringLibrary strings,
249-
@Cached @Shared ToJavaStringNode toJavaStringNode) {
250-
log(getLevel(level), toJavaStringNode.execute(this, message));
251-
return nil;
252-
}
253-
254-
@TruffleBoundary
255-
protected Level getLevel(RubySymbol level) {
256-
try {
257-
return Level.parse(level.getString());
258-
} catch (IllegalArgumentException e) {
259-
throw new RaiseException(getContext(), getContext().getCoreExceptions().argumentError(
260-
"Could not find log level for: " + level,
261-
this));
262-
}
263-
}
264-
265-
@TruffleBoundary
266-
public static void log(Level level, String message) {
267-
RubyLanguage.LOGGER.log(level, message);
268-
}
269-
270-
}
271-
272229
@CoreMethod(names = "available_processors", onSingleton = true)
273230
public abstract static class AvailableProcessorsNode extends CoreMethodNode {
274231

src/main/java/org/truffleruby/core/array/ArrayAppendOneNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@NodeChild(value = "arrayNode", type = RubyNode.class)
3131
@NodeChild(value = "valueNode", type = RubyNode.class)
3232
@ImportStatic(ArrayGuards.class)
33-
@ReportPolymorphism
33+
@ReportPolymorphism // for ArrayStoreLibrary
3434
public abstract class ArrayAppendOneNode extends RubyContextSourceNode {
3535

3636
@NeverDefault

src/main/java/org/truffleruby/core/array/ArrayCopyCompatibleRangeNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* <p>
2828
* Typically only called after {@link ArrayPrepareForCopyNode} has been invoked on the destination. */
2929
@ImportStatic(ArrayGuards.class)
30-
@ReportPolymorphism
30+
@ReportPolymorphism // for ArrayStoreLibrary
3131
public abstract class ArrayCopyCompatibleRangeNode extends RubyBaseNode {
3232

3333
public static ArrayCopyCompatibleRangeNode create() {
@@ -49,7 +49,6 @@ void noop(Object dstStore, Object srcStore, int dstStart, int srcStart, int leng
4949
limit = "storageStrategyLimit()")
5050
void copy(Object dstStore, Object srcStore, int dstStart, int srcStart, int length,
5151
@CachedLibrary("srcStore") ArrayStoreLibrary stores) {
52-
5352
stores.copyContents(srcStore, srcStart, dstStore, dstStart, length);
5453
}
5554
}

src/main/java/org/truffleruby/core/array/ArrayEachIteratorNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.truffleruby.language.yield.CallBlockNode;
2929

3030
@ImportStatic(ArrayGuards.class)
31-
@ReportPolymorphism
31+
@ReportPolymorphism // for ArrayStoreLibrary
3232
@GenerateInline(inlineByDefault = true)
3333
public abstract class ArrayEachIteratorNode extends RubyBaseNode {
3434

src/main/java/org/truffleruby/core/array/ArrayIndexNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public abstract class ArrayIndexNodes {
3131

3232
@NodeChild(value = "arrayNode", type = RubyNode.class)
3333
@ImportStatic(ArrayGuards.class)
34-
@ReportPolymorphism
34+
@ReportPolymorphism // for ArrayStoreLibrary
3535
public abstract static class ReadConstantIndexNode extends RubyContextSourceNode {
3636

3737
private final int index;
@@ -71,7 +71,7 @@ public RubyNode cloneUninitialized() {
7171
}
7272

7373
@ImportStatic(ArrayGuards.class)
74-
@ReportPolymorphism
74+
@ReportPolymorphism // for ArrayStoreLibrary
7575
public abstract static class ReadNormalizedNode extends PrimitiveArrayArgumentsNode {
7676

7777
@NeverDefault

src/main/java/org/truffleruby/core/array/ArrayNodes.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ RubyArray allocate(RubyClass rubyClass) {
132132

133133
@CoreMethod(names = "+", required = 1)
134134
@ImportStatic(ArrayGuards.class)
135-
@ReportPolymorphism
135+
@ReportPolymorphism // for ArrayStoreLibrary
136136
public abstract static class AddNode extends CoreMethodArrayArgumentsNode {
137137

138138
@Specialization(
@@ -160,7 +160,7 @@ static RubyArray addGeneralize(RubyArray a, Object bObject,
160160

161161
@Primitive(name = "array_mul", lowerFixnum = 1)
162162
@ImportStatic(ArrayGuards.class)
163-
@ReportPolymorphism
163+
@ReportPolymorphism // for ArrayStoreLibrary
164164
public abstract static class MulNode extends PrimitiveArrayArgumentsNode {
165165

166166
@Specialization(guards = "count < 0")
@@ -347,7 +347,6 @@ public static SetIndexNode create() {
347347
// array[index] = object
348348

349349
@Specialization
350-
@ReportPolymorphism.Exclude
351350
Object set(RubyArray array, int index, Object value, NotProvided unused,
352351
@Cached ArrayWriteNormalizedNode writeNode,
353352
@Cached @Shared ConditionProfile negativeDenormalizedIndex,
@@ -484,9 +483,10 @@ RubyArray clear(RubyArray array,
484483

485484
@CoreMethod(names = "compact")
486485
@ImportStatic(ArrayGuards.class)
487-
@ReportPolymorphism
486+
@ReportPolymorphism // for ArrayStoreLibrary
488487
public abstract static class CompactNode extends ArrayCoreMethodNode {
489488

489+
@ReportPolymorphism.Exclude
490490
@Specialization(guards = "stores.isPrimitive(store)", limit = "storageStrategyLimit()")
491491
RubyArray compactPrimitive(RubyArray array,
492492
@Bind("array.getStore()") Object store,
@@ -527,11 +527,11 @@ Object compactObjects(RubyArray array,
527527
}
528528

529529
@CoreMethod(names = "compact!", raiseIfFrozenSelf = true)
530-
@ReportPolymorphism
530+
@ReportPolymorphism // for ArrayStoreLibrary
531531
public abstract static class CompactBangNode extends ArrayCoreMethodNode {
532532

533-
@Specialization(guards = "stores.isPrimitive(store)", limit = "storageStrategyLimit()")
534533
@ReportPolymorphism.Exclude
534+
@Specialization(guards = "stores.isPrimitive(store)", limit = "storageStrategyLimit()")
535535
Object compactNotObjects(RubyArray array,
536536
@Bind("array.getStore()") Object store,
537537
@CachedLibrary("store") ArrayStoreLibrary stores) {
@@ -582,6 +582,7 @@ Object compactObjects(RubyArray array,
582582
}
583583

584584
@CoreMethod(names = "concat", optional = 1, rest = true, raiseIfFrozenSelf = true)
585+
@ReportPolymorphism // inline cache
585586
@ImportStatic(ArrayGuards.class)
586587
public abstract static class ConcatNode extends CoreMethodArrayArgumentsNode {
587588

@@ -751,7 +752,7 @@ private Object delete(RubyArray array, Object value, Object maybeBlock,
751752

752753
@CoreMethod(names = "delete_at", required = 1, raiseIfFrozenSelf = true, lowerFixnum = 1)
753754
@ImportStatic(ArrayGuards.class)
754-
@ReportPolymorphism
755+
@ReportPolymorphism // for ArrayStoreLibrary
755756
public abstract static class DeleteAtNode extends CoreMethodArrayArgumentsNode {
756757

757758
@Specialization(limit = "storageStrategyLimit()")
@@ -1060,7 +1061,7 @@ static long hash(RubyArray array,
10601061
}
10611062

10621063
@CoreMethod(names = "include?", required = 1)
1063-
@ReportPolymorphism
1064+
@ReportPolymorphism // for ArrayStoreLibrary
10641065
public abstract static class IncludeNode extends ArrayCoreMethodNode {
10651066

10661067
@Specialization(limit = "storageStrategyLimit()")
@@ -1513,7 +1514,7 @@ RubyString pack(RubyArray array, Object format, Object buffer,
15131514

15141515
@GenerateCached(false)
15151516
@GenerateInline
1516-
@ReportPolymorphism
1517+
@ReportPolymorphism // inline cache, CallTarget cache
15171518
public abstract static class PackNode extends RubyBaseNode {
15181519

15191520
public abstract RubyString execute(Node node, RubyArray array, Object format, Object buffer);
@@ -1633,7 +1634,7 @@ protected int getCacheLimit() {
16331634
}
16341635

16351636
@CoreMethod(names = "pop", raiseIfFrozenSelf = true, optional = 1, lowerFixnum = 1)
1636-
@ReportPolymorphism
1637+
@ReportPolymorphism // for ArrayStoreLibrary
16371638
public abstract static class PopNode extends ArrayCoreMethodNode {
16381639

16391640
public abstract Object executePop(RubyArray array, Object n);
@@ -1835,7 +1836,7 @@ RubyArray replace(RubyArray array, Object otherObject,
18351836

18361837
@Primitive(name = "array_rotate", lowerFixnum = 1)
18371838
@ImportStatic(ArrayGuards.class)
1838-
@ReportPolymorphism
1839+
@ReportPolymorphism // for ArrayStoreLibrary
18391840
public abstract static class RotateNode extends PrimitiveArrayArgumentsNode {
18401841

18411842
@Specialization(limit = "storageStrategyLimit()")
@@ -1862,7 +1863,7 @@ protected static void rotateArrayCopy(int rotation, int size, ArrayStoreLibrary
18621863

18631864
@Primitive(name = "array_rotate_inplace", lowerFixnum = 1)
18641865
@ImportStatic(ArrayGuards.class)
1865-
@ReportPolymorphism
1866+
@ReportPolymorphism // for ArrayStoreLibrary
18661867
public abstract static class RotateInplaceNode extends PrimitiveArrayArgumentsNode {
18671868

18681869
@Specialization(
@@ -2012,7 +2013,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s
20122013

20132014
@CoreMethod(names = "shift", raiseIfFrozenSelf = true, optional = 1, lowerFixnum = 1)
20142015
@ImportStatic(ArrayGuards.class)
2015-
@ReportPolymorphism
2016+
@ReportPolymorphism // for ArrayStoreLibrary
20162017
public abstract static class ShiftNode extends CoreMethodArrayArgumentsNode {
20172018

20182019
public abstract Object executeShift(RubyArray array, Object n);
@@ -2238,7 +2239,7 @@ static RubyArray stealStorage(RubyArray array, RubyArray other,
22382239

22392240
@Primitive(name = "array_zip")
22402241
@ImportStatic(ArrayGuards.class)
2241-
@ReportPolymorphism
2242+
@ReportPolymorphism // for ArrayStoreLibrary
22422243
public abstract static class ZipNode extends PrimitiveArrayArgumentsNode {
22432244

22442245
@Specialization(limit = "storageStrategyLimit()")

src/main/java/org/truffleruby/core/array/ArrayPrepareForCopyNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* <p>
3131
* The copy itself can then be performed with {@link ArrayCopyCompatibleRangeNode}. In fact it MUST be performed, as the
3232
* array may otherwise contain uninitialized elements (in particular, {@code null} values in {@code Object} arrays). */
33-
@ReportPolymorphism
33+
@ReportPolymorphism // for ArrayStoreLibrary
3434
@ImportStatic(ArrayGuards.class)
3535
public abstract class ArrayPrepareForCopyNode extends RubyBaseNode {
3636

0 commit comments

Comments
 (0)