Skip to content

Commit 03e33e1

Browse files
committed
Addressing truffle-inlining warnings in support and bidning packages
1 parent 2c2d59c commit 03e33e1

File tree

10 files changed

+184
-141
lines changed

10 files changed

+184
-141
lines changed

src/main/java/org/truffleruby/core/binding/package-info.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/java/org/truffleruby/core/encoding/TStringUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
import com.oracle.truffle.api.CompilerAsserts;
1616
import com.oracle.truffle.api.CompilerDirectives;
17-
import com.oracle.truffle.api.profiles.ConditionProfile;
17+
import com.oracle.truffle.api.nodes.Node;
18+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1819
import com.oracle.truffle.api.strings.AbstractTruffleString;
1920
import org.jcodings.Encoding;
2021

@@ -83,11 +84,11 @@ public static byte[] getBytesOrCopy(AbstractTruffleString tstring, RubyEncoding
8384
}
8485

8586
// Should be avoided as much as feasible
86-
public static byte[] getBytesOrCopy(AbstractTruffleString tstring, TruffleString.Encoding encoding,
87+
public static byte[] getBytesOrCopy(Node node, AbstractTruffleString tstring, TruffleString.Encoding encoding,
8788
TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
88-
ConditionProfile noCopyProfile) {
89+
InlinedConditionProfile noCopyProfile) {
8990
var bytes = getInternalByteArrayNode.execute(tstring, encoding);
90-
if (noCopyProfile.profile(tstring instanceof TruffleString && bytes.getOffset() == 0 &&
91+
if (noCopyProfile.profile(node, tstring instanceof TruffleString && bytes.getOffset() == 0 &&
9192
bytes.getLength() == bytes.getArray().length)) {
9293
return bytes.getArray();
9394
} else {

src/main/java/org/truffleruby/core/support/ByteArrayNodes.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import com.oracle.truffle.api.dsl.Bind;
1313
import com.oracle.truffle.api.object.Shape;
14+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
15+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1416
import com.oracle.truffle.api.strings.AbstractTruffleString;
1517
import com.oracle.truffle.api.strings.TruffleString;
1618
import org.truffleruby.annotations.CoreMethod;
@@ -31,8 +33,6 @@
3133
import com.oracle.truffle.api.dsl.Cached;
3234
import com.oracle.truffle.api.dsl.Cached.Shared;
3335
import com.oracle.truffle.api.dsl.Specialization;
34-
import com.oracle.truffle.api.profiles.BranchProfile;
35-
import com.oracle.truffle.api.profiles.ConditionProfile;
3636
import org.truffleruby.language.library.RubyStringLibrary;
3737
import org.truffleruby.language.objects.AllocationTracing;
3838

@@ -110,10 +110,10 @@ public abstract static class SetByteNode extends CoreMethodArrayArgumentsNode {
110110

111111
@Specialization
112112
protected int setByte(RubyByteArray byteArray, int index, int value,
113-
@Cached BranchProfile errorProfile) {
113+
@Cached InlinedBranchProfile errorProfile) {
114114
final byte[] bytes = byteArray.bytes;
115115
if (index < 0 || index >= bytes.length) {
116-
errorProfile.enter();
116+
errorProfile.enter(this);
117117
throw new RaiseException(getContext(), coreExceptions().indexError("index out of bounds", this));
118118
}
119119

@@ -140,7 +140,7 @@ protected Object fillFromString(
140140
@Specialization
141141
protected Object fillFromPointer(
142142
RubyByteArray byteArray, int dstStart, RubyPointer source, int srcStart, int length,
143-
@Cached BranchProfile nullPointerProfile) {
143+
@Cached InlinedBranchProfile nullPointerProfile) {
144144
assert length > 0;
145145

146146
final Pointer ptr = source.pointer;
@@ -161,8 +161,8 @@ public abstract static class LocateNode extends PrimitiveArrayArgumentsNode {
161161
guards = "isSingleBytePattern(patternTString, patternEncoding)", limit = "1")
162162
protected Object getByteSingleByte(RubyByteArray byteArray, Object pattern, int start, int length,
163163
@Cached TruffleString.ReadByteNode readByteNode,
164-
@Cached BranchProfile tooSmallStartProfile,
165-
@Cached BranchProfile tooLargeStartProfile,
164+
@Cached InlinedBranchProfile tooSmallStartProfile,
165+
@Cached InlinedBranchProfile tooLargeStartProfile,
166166
@Cached @Shared RubyStringLibrary libPattern,
167167
@Bind("libPattern.getTString(pattern)") AbstractTruffleString patternTString,
168168
@Bind("libPattern.getTEncoding(pattern)") TruffleString.Encoding patternEncoding) {
@@ -171,12 +171,12 @@ protected Object getByteSingleByte(RubyByteArray byteArray, Object pattern, int
171171
int searchByte = readByteNode.execute(patternTString, 0, patternEncoding);
172172

173173
if (start >= length) {
174-
tooLargeStartProfile.enter();
174+
tooLargeStartProfile.enter(this);
175175
return nil;
176176
}
177177

178178
if (start < 0) {
179-
tooSmallStartProfile.enter();
179+
tooSmallStartProfile.enter(this);
180180
start = 0;
181181
}
182182

@@ -190,19 +190,19 @@ protected Object getByteSingleByte(RubyByteArray byteArray, Object pattern, int
190190
protected Object getByte(RubyByteArray byteArray, Object pattern, int start, int length,
191191
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
192192
@Cached TruffleString.GetInternalByteArrayNode getInternalByteArrayNode,
193-
@Cached ConditionProfile noCopyProfile,
194-
@Cached ConditionProfile notFoundProfile,
193+
@Cached InlinedConditionProfile noCopyProfile,
194+
@Cached InlinedConditionProfile notFoundProfile,
195195
@Cached @Shared RubyStringLibrary libPattern,
196196
@Bind("libPattern.getTString(pattern)") AbstractTruffleString patternTString,
197197
@Bind("libPattern.getTEncoding(pattern)") TruffleString.Encoding patternEncoding) {
198198
// TODO (nirvdrum 09-June-2022): Copying the byte array here is wasteful, but ArrayUtils.indexOfWithOrMask does not accept an offset or length for the needle.
199199
// Another possibility would be to create a MutableTruffleString for the RubyByteArray and use ByteIndexOfStringNode, but that would force computation of the coderange of the byte[]
200-
final byte[] patternBytes = TStringUtils.getBytesOrCopy(patternTString, patternEncoding,
200+
final byte[] patternBytes = TStringUtils.getBytesOrCopy(this, patternTString, patternEncoding,
201201
getInternalByteArrayNode, noCopyProfile);
202202

203203
final int index = ArrayUtils.indexOfWithOrMask(byteArray.bytes, start, length, patternBytes, null);
204204

205-
if (notFoundProfile.profile(index == -1)) {
205+
if (notFoundProfile.profile(this, index == -1)) {
206206
return nil;
207207
} else {
208208
return index + codePointLengthNode.execute(patternTString, patternEncoding);

src/main/java/org/truffleruby/core/support/IONodes.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
import java.io.OutputStream;
6767
import java.util.Arrays;
6868

69+
import com.oracle.truffle.api.nodes.Node;
70+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
71+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6972
import com.oracle.truffle.api.strings.TruffleString;
7073
import org.truffleruby.RubyContext;
7174
import org.truffleruby.annotations.CoreMethod;
@@ -90,8 +93,6 @@
9093
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
9194
import com.oracle.truffle.api.dsl.Cached;
9295
import com.oracle.truffle.api.dsl.Specialization;
93-
import com.oracle.truffle.api.profiles.BranchProfile;
94-
import com.oracle.truffle.api.profiles.ConditionProfile;
9596

9697
@CoreModule(value = "IO", isClass = true)
9798
public abstract class IONodes {
@@ -422,10 +423,10 @@ public abstract static class IOEnsureOpenPrimitiveNode extends CoreMethodArrayAr
422423

423424
@Specialization
424425
protected Object ensureOpen(RubyIO io,
425-
@Cached BranchProfile errorProfile) {
426+
@Cached InlinedBranchProfile errorProfile) {
426427
final int fd = io.getDescriptor();
427428
if (fd == RubyIO.CLOSED_FD) {
428-
errorProfile.enter();
429+
errorProfile.enter(this);
429430
throw new RaiseException(getContext(), coreExceptions().ioError("closed stream", this));
430431
} else {
431432
assert fd >= 0;
@@ -510,19 +511,19 @@ public abstract static class IOThreadBufferAllocateNode extends PrimitiveArrayAr
510511

511512
@Specialization
512513
protected RubyPointer getThreadBuffer(long size,
513-
@Cached ConditionProfile sizeProfile) {
514+
@Cached InlinedConditionProfile sizeProfile) {
514515
RubyThread thread = getLanguage().getCurrentThread();
515516
final RubyPointer instance = new RubyPointer(
516517
coreLibrary().truffleFFIPointerClass,
517518
getLanguage().truffleFFIPointerShape,
518-
getBuffer(getContext(), thread, size, sizeProfile));
519+
getBuffer(this, getContext(), thread, size, sizeProfile));
519520
AllocationTracing.trace(instance, this);
520521
return instance;
521522
}
522523

523-
public static Pointer getBuffer(RubyContext context, RubyThread rubyThread, long size,
524-
ConditionProfile sizeProfile) {
525-
return rubyThread.getIoBuffer(context).allocate(context, rubyThread, size, sizeProfile);
524+
public static Pointer getBuffer(Node node, RubyContext context, RubyThread rubyThread, long size,
525+
InlinedConditionProfile sizeProfile) {
526+
return rubyThread.getIoBuffer(context).allocate(node, context, rubyThread, size, sizeProfile);
526527
}
527528
}
528529

@@ -531,9 +532,9 @@ public abstract static class IOThreadBufferFreeNode extends PrimitiveArrayArgume
531532

532533
@Specialization
533534
protected Object getThreadBuffer(RubyPointer pointer,
534-
@Cached ConditionProfile freeProfile) {
535+
@Cached InlinedConditionProfile freeProfile) {
535536
RubyThread thread = getLanguage().getCurrentThread();
536-
thread.getIoBuffer(getContext()).free(thread, pointer.pointer, freeProfile);
537+
thread.getIoBuffer(getContext()).free(this, thread, pointer.pointer, freeProfile);
537538
return nil;
538539
}
539540
}

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
1717
import com.oracle.truffle.api.dsl.GenerateUncached;
1818
import com.oracle.truffle.api.dsl.NeverDefault;
19-
import com.oracle.truffle.api.profiles.ConditionProfile;
19+
import com.oracle.truffle.api.nodes.Node;
20+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
21+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
2022
import org.truffleruby.annotations.CoreModule;
2123
import org.truffleruby.annotations.Primitive;
2224
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
@@ -59,7 +61,6 @@
5961
import com.oracle.truffle.api.library.CachedLibrary;
6062
import com.oracle.truffle.api.object.DynamicObjectLibrary;
6163
import com.oracle.truffle.api.object.HiddenKey;
62-
import com.oracle.truffle.api.profiles.BranchProfile;
6364

6465
/** All nodes in this class should be Primitive for efficiency (avoiding an extra call and constant lookup) */
6566
@CoreModule("Truffle::Type")
@@ -137,10 +138,10 @@ protected Object freezeSingletonObject(RubyDynamicObject self,
137138
@Cached @Shared FreezeNode freezeNode,
138139
@Cached @Exclusive FreezeNode freezeMetaClasNode,
139140
@Cached IsFrozenNode isFrozenMetaClassNode,
140-
@Cached ConditionProfile singletonClassUnfrozenProfile,
141+
@Cached InlinedConditionProfile singletonClassUnfrozenProfile,
141142
@Cached @Shared MetaClassNode metaClassNode,
142143
@Bind("metaClassNode.execute(self)") RubyClass metaClass) {
143-
if (singletonClassUnfrozenProfile.profile(
144+
if (singletonClassUnfrozenProfile.profile(this,
144145
!RubyGuards.isSingletonClass(self) && !isFrozenMetaClassNode.execute(metaClass))) {
145146
freezeMetaClasNode.execute(metaClass);
146147
}
@@ -256,16 +257,17 @@ public abstract static class ObjectInstanceVariablesNode extends PrimitiveArrayA
256257
public abstract RubyArray executeGetIVars(Object self);
257258

258259
@Specialization(limit = "getDynamicObjectCacheLimit()")
259-
protected RubyArray instanceVariables(RubyDynamicObject object,
260+
protected static RubyArray instanceVariables(RubyDynamicObject object,
260261
@CachedLibrary("object") DynamicObjectLibrary objectLibrary,
261-
@Cached ConditionProfile noPropertiesProfile) {
262+
@Cached InlinedConditionProfile noPropertiesProfile,
263+
@Bind("this") Node node) {
262264
var shape = objectLibrary.getShape(object);
263265

264-
if (noPropertiesProfile.profile(shape.getPropertyCount() == 0)) {
265-
return createEmptyArray();
266+
if (noPropertiesProfile.profile(node, shape.getPropertyCount() == 0)) {
267+
return createEmptyArray(node);
266268
}
267269

268-
return createIVarNameArray(objectLibrary.getKeyArray(object));
270+
return createIVarNameArray(node, objectLibrary.getKeyArray(object));
269271
}
270272

271273
@Specialization(guards = "!isRubyDynamicObject(object)")
@@ -274,7 +276,7 @@ protected RubyArray instanceVariablesNotDynamic(Object object) {
274276
}
275277

276278
@TruffleBoundary
277-
private RubyArray createIVarNameArray(Object[] keys) {
279+
private static RubyArray createIVarNameArray(Node node, Object[] keys) {
278280
final List<String> names = new ArrayList<>(keys.length);
279281

280282
for (Object name : keys) {
@@ -286,10 +288,10 @@ private RubyArray createIVarNameArray(Object[] keys) {
286288
final int size = names.size();
287289
final Object[] nameSymbols = new Object[size];
288290
for (int i = 0; i < size; i++) {
289-
nameSymbols[i] = getSymbol(names.get(i));
291+
nameSymbols[i] = getSymbol(node, names.get(i));
290292
}
291293

292-
return createArray(nameSymbols);
294+
return createArray(node, nameSymbols);
293295
}
294296

295297
}
@@ -454,10 +456,10 @@ public static CheckFrozenNode create(RubyNode node) {
454456
@Specialization
455457
protected Object check(Object value,
456458
@Cached IsFrozenNode isFrozenNode,
457-
@Cached BranchProfile errorProfile) {
459+
@Cached InlinedBranchProfile errorProfile) {
458460

459461
if (isFrozenNode.execute(value)) {
460-
errorProfile.enter();
462+
errorProfile.enter(this);
461463
throw new RaiseException(getContext(), coreExceptions().frozenError(value, this));
462464
}
463465

@@ -487,13 +489,13 @@ public static CheckMutableStringNode create(RubyNode node) {
487489

488490
@Specialization
489491
protected Object check(RubyString value,
490-
@Cached BranchProfile errorProfile) {
492+
@Cached InlinedBranchProfile errorProfile) {
491493
if (value.locked) {
492-
errorProfile.enter();
494+
errorProfile.enter(this);
493495
throw new RaiseException(getContext(),
494496
coreExceptions().runtimeError("can't modify string; temporarily locked", this));
495497
} else if (value.frozen) {
496-
errorProfile.enter();
498+
errorProfile.enter(this);
497499
throw new RaiseException(getContext(), coreExceptions().frozenError(value, this));
498500
}
499501
return value;
@@ -524,12 +526,13 @@ protected boolean check(double value) {
524526
}
525527

526528
@Fallback
527-
protected boolean other(Object value,
529+
protected static boolean other(Object value,
528530
@Cached IsANode isANode,
529-
@Cached ConditionProfile numericProfile,
531+
@Cached InlinedConditionProfile numericProfile,
530532
@Cached DispatchNode isRealNode,
531-
@Cached BooleanCastNode booleanCastNode) {
532-
return numericProfile.profile(isANode.executeIsA(value, coreLibrary().numericClass)) &&
533+
@Cached BooleanCastNode booleanCastNode,
534+
@Bind("this") Node node) {
535+
return numericProfile.profile(node, isANode.executeIsA(value, coreLibrary(node).numericClass)) &&
533536
booleanCastNode.execute(isRealNode.call(value, "real?"));
534537
}
535538
}

src/main/java/org/truffleruby/core/support/package-info.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/java/org/truffleruby/core/thread/ThreadLocalBuffer.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
package org.truffleruby.core.thread;
1111

1212
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
13-
import com.oracle.truffle.api.profiles.ConditionProfile;
13+
import com.oracle.truffle.api.nodes.Node;
1414

15+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1516
import org.truffleruby.RubyContext;
1617
import org.truffleruby.extra.ffi.Pointer;
1718

@@ -48,12 +49,12 @@ private void freeMemory() {
4849
start.freeNoAutorelease();
4950
}
5051

51-
public void free(RubyThread thread, Pointer ptr, ConditionProfile freeProfile) {
52+
public void free(Node node, RubyThread thread, Pointer ptr, InlinedConditionProfile freeProfile) {
5253
assert ptr.getEndAddress() == cursor() : "free(" + Long.toHexString(ptr.getEndAddress()) +
5354
") but expected " + Long.toHexString(cursor()) + " to be free'd first";
5455
remaining += ptr.getSize();
5556
assert invariants();
56-
if (freeProfile.profile(parent != null && isEmpty())) {
57+
if (freeProfile.profile(node, parent != null && isEmpty())) {
5758
thread.ioBuffer = parent;
5859
freeMemory();
5960
}
@@ -68,15 +69,16 @@ public void freeAll(RubyThread thread) {
6869
}
6970
}
7071

71-
public Pointer allocate(RubyContext context, RubyThread thread, long size, ConditionProfile allocationProfile) {
72+
public Pointer allocate(Node node, RubyContext context, RubyThread thread, long size,
73+
InlinedConditionProfile allocationProfile) {
7274
/* If there is space in the thread's existing buffer then we will return a pointer to that and reduce the
7375
* remaining space count. Otherwise we will either allocate a new buffer, or (if no space is currently being
7476
* used in the existing buffer) replace it with a larger one. */
7577

7678
/* We ensure we allocate a non-zero number of bytes so we can track the allocation. This avoids returning null
7779
* or reallocating a buffer that we technically have a pointer to. */
7880
final long allocationSize = alignUp(size);
79-
if (allocationProfile.profile(remaining >= allocationSize)) {
81+
if (allocationProfile.profile(node, remaining >= allocationSize)) {
8082
final Pointer pointer = new Pointer(context, cursor(), allocationSize);
8183
remaining -= allocationSize;
8284
assert invariants();

0 commit comments

Comments
 (0)