Skip to content

Commit 0a0afb4

Browse files
committed
Addressing truffle-inlining warnings in cext package
1 parent 03e33e1 commit 0a0afb4

File tree

9 files changed

+135
-117
lines changed

9 files changed

+135
-117
lines changed

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

Lines changed: 87 additions & 81 deletions
Large diffs are not rendered by default.

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

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

1212
import static org.truffleruby.core.symbol.CoreSymbols.idToIndex;
1313

14+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
1415
import org.truffleruby.core.string.StringUtils;
1516
import org.truffleruby.core.symbol.CoreSymbols;
1617
import org.truffleruby.core.symbol.RubySymbol;
@@ -21,7 +22,6 @@
2122
import com.oracle.truffle.api.dsl.GenerateUncached;
2223
import com.oracle.truffle.api.dsl.ReportPolymorphism;
2324
import com.oracle.truffle.api.dsl.Specialization;
24-
import com.oracle.truffle.api.profiles.BranchProfile;
2525

2626
@GenerateUncached
2727
@ReportPolymorphism
@@ -31,11 +31,11 @@ public abstract class IDToSymbolNode extends RubyBaseNode {
3131

3232
@Specialization(guards = "isStaticSymbol(value)")
3333
protected RubySymbol unwrapStaticSymbol(long value,
34-
@Cached BranchProfile errorProfile) {
34+
@Cached InlinedBranchProfile errorProfile) {
3535
final int index = idToIndex(value);
3636
final RubySymbol symbol = getLanguage().coreSymbols.STATIC_SYMBOLS[index];
3737
if (symbol == null) {
38-
errorProfile.enter();
38+
errorProfile.enter(this);
3939
throw new RaiseException(
4040
getContext(),
4141
coreExceptions().runtimeError(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package org.truffleruby.cext;
1111

12+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
1213
import org.truffleruby.core.symbol.RubySymbol;
1314
import org.truffleruby.language.RubyBaseNode;
1415

@@ -17,7 +18,6 @@
1718
import com.oracle.truffle.api.dsl.GenerateUncached;
1819
import com.oracle.truffle.api.dsl.ReportPolymorphism;
1920
import com.oracle.truffle.api.dsl.Specialization;
20-
import com.oracle.truffle.api.profiles.ConditionProfile;
2121

2222
@GenerateUncached
2323
@ReportPolymorphism
@@ -36,8 +36,8 @@ protected Object getIDCached(RubySymbol symbol,
3636
@Specialization(replaces = "getIDCached")
3737
protected Object getIDUncached(RubySymbol symbol,
3838
@Cached @Shared WrapNode wrapNode,
39-
@Cached ConditionProfile staticSymbolProfile) {
40-
if (staticSymbolProfile.profile(symbol.getId() != RubySymbol.UNASSIGNED_ID)) {
39+
@Cached InlinedConditionProfile staticSymbolProfile) {
40+
if (staticSymbolProfile.profile(this, symbol.getId() != RubySymbol.UNASSIGNED_ID)) {
4141
return symbol.getId();
4242
}
4343
return wrapNode.execute(symbol);

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import com.oracle.truffle.api.dsl.Bind;
1919
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
2020
import com.oracle.truffle.api.nodes.ExplodeLoop;
21+
import com.oracle.truffle.api.nodes.Node;
22+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
2123
import com.oracle.truffle.api.profiles.LoopConditionProfile;
2224
import org.truffleruby.language.NotProvided;
2325
import org.truffleruby.language.RubyBaseNode;
@@ -34,7 +36,6 @@
3436
import com.oracle.truffle.api.interop.InteropLibrary;
3537
import com.oracle.truffle.api.interop.UnsupportedMessageException;
3638
import com.oracle.truffle.api.library.CachedLibrary;
37-
import com.oracle.truffle.api.profiles.BranchProfile;
3839

3940
@GenerateUncached
4041
@ImportStatic(ValueWrapperManager.class)
@@ -73,12 +74,12 @@ protected long unwrapTaggedLong(long handle) {
7374

7475
@Specialization(guards = "isTaggedObject(handle)")
7576
protected Object unwrapTaggedObject(long handle,
76-
@Cached BranchProfile noHandleProfile) {
77+
@Cached InlinedBranchProfile noHandleProfile) {
7778
final ValueWrapper wrapper = getContext()
7879
.getValueWrapperManager()
7980
.getWrapperFromHandleMap(handle, getLanguage());
8081
if (wrapper == null) {
81-
noHandleProfile.enter();
82+
noHandleProfile.enter(this);
8283
raiseError(handle);
8384
}
8485
return wrapper.getObject();
@@ -159,16 +160,17 @@ protected ValueWrapper longToWrapper(long value,
159160
}
160161

161162
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
162-
protected ValueWrapper genericToWrapper(Object value,
163+
protected static ValueWrapper genericToWrapper(Object value,
163164
@CachedLibrary("value") InteropLibrary values,
164165
@Cached @Shared NativeToWrapperNode nativeToWrapperNode,
165-
@Cached BranchProfile unsupportedProfile) {
166+
@Cached InlinedBranchProfile unsupportedProfile,
167+
@Bind("this") Node node) {
166168
long handle;
167169
try {
168170
handle = values.asPointer(value);
169171
} catch (UnsupportedMessageException e) {
170-
unsupportedProfile.enter();
171-
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this, e));
172+
unsupportedProfile.enter(node);
173+
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node, e));
172174
}
173175
return nativeToWrapperNode.execute(handle);
174176
}
@@ -256,16 +258,17 @@ protected Object longToWrapper(long value,
256258
}
257259

258260
@Specialization(guards = { "!isWrapper(value)", "values.isPointer(value)" }, limit = "getCacheLimit()")
259-
protected Object unwrapGeneric(Object value,
261+
protected static Object unwrapGeneric(Object value,
260262
@CachedLibrary("value") InteropLibrary values,
261263
@Cached @Exclusive UnwrapNativeNode unwrapNativeNode,
262-
@Cached BranchProfile unsupportedProfile) {
264+
@Cached InlinedBranchProfile unsupportedProfile,
265+
@Bind("this") Node node) {
263266
long handle;
264267
try {
265268
handle = values.asPointer(value);
266269
} catch (UnsupportedMessageException e) {
267-
unsupportedProfile.enter();
268-
throw new RaiseException(getContext(), coreExceptions().argumentError(e.getMessage(), this, e));
270+
unsupportedProfile.enter(node);
271+
throw new RaiseException(getContext(node), coreExceptions(node).argumentError(e.getMessage(), node, e));
269272
}
270273
return unwrapNativeNode.execute(handle);
271274
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
package org.truffleruby.cext;
1111

12+
import com.oracle.truffle.api.dsl.Bind;
13+
import com.oracle.truffle.api.nodes.Node;
14+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
1215
import org.truffleruby.RubyLanguage;
1316
import org.truffleruby.cext.ValueWrapperManager.AllocateHandleNode;
1417
import org.truffleruby.cext.ValueWrapperManager.HandleBlock;
@@ -25,7 +28,6 @@
2528
import com.oracle.truffle.api.interop.UnsupportedMessageException;
2629
import com.oracle.truffle.api.library.ExportLibrary;
2730
import com.oracle.truffle.api.library.ExportMessage;
28-
import com.oracle.truffle.api.profiles.BranchProfile;
2931

3032
/** This object represents a VALUE in C which wraps the raw Ruby object. This allows foreign access methods to be set up
3133
* which convert these value wrappers to native pointers without affecting the semantics of the wrapped objects. */
@@ -102,22 +104,24 @@ protected boolean isPointer() {
102104
@ExportMessage
103105
protected static void toNative(ValueWrapper wrapper,
104106
@Cached AllocateHandleNode createNativeHandleNode,
105-
@Cached @Exclusive BranchProfile createHandleProfile) {
107+
@Cached @Exclusive InlinedBranchProfile createHandleProfile,
108+
@Bind("$node") Node node) {
106109
if (!wrapper.isPointer()) {
107-
createHandleProfile.enter();
110+
createHandleProfile.enter(node);
108111
createNativeHandleNode.execute(wrapper);
109112
}
110113
}
111114

112115
@ExportMessage
113116
protected static long asPointer(ValueWrapper wrapper,
114117
@Cached KeepAliveNode keepAliveNode,
115-
@Cached @Exclusive BranchProfile taggedObjectProfile) {
118+
@Cached @Exclusive InlinedBranchProfile taggedObjectProfile,
119+
@Bind("$node") Node node) {
116120
long handle = wrapper.getHandle();
117121
assert handle != ValueWrapperManager.UNSET_HANDLE;
118122

119123
if (ValueWrapperManager.isTaggedObject(handle)) {
120-
taggedObjectProfile.enter();
124+
taggedObjectProfile.enter(node);
121125

122126
keepAliveNode.execute(wrapper);
123127
}
@@ -142,11 +146,12 @@ protected boolean isMemberReadable(String member) {
142146

143147
@ExportMessage
144148
protected static Object readMember(ValueWrapper wrapper, String member,
145-
@Cached @Exclusive BranchProfile errorProfile) throws UnknownIdentifierException {
149+
@Cached @Exclusive InlinedBranchProfile errorProfile,
150+
@Bind("$node") Node node) throws UnknownIdentifierException {
146151
if ("value".equals(member)) {
147152
return wrapper.object;
148153
} else {
149-
errorProfile.enter();
154+
errorProfile.enter(node);
150155
throw UnknownIdentifierException.create(member);
151156
}
152157
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import static org.truffleruby.cext.ValueWrapperManager.LONG_TAG;
1313
import static org.truffleruby.cext.ValueWrapperManager.UNSET_HANDLE;
1414

15+
import com.oracle.truffle.api.dsl.Bind;
1516
import com.oracle.truffle.api.dsl.NeverDefault;
17+
import com.oracle.truffle.api.nodes.Node;
18+
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
1619
import com.oracle.truffle.api.strings.TruffleString;
1720
import org.truffleruby.Layouts;
1821
import org.truffleruby.core.encoding.Encodings;
@@ -30,7 +33,6 @@
3033
import com.oracle.truffle.api.dsl.Specialization;
3134
import com.oracle.truffle.api.library.CachedLibrary;
3235
import com.oracle.truffle.api.object.DynamicObjectLibrary;
33-
import com.oracle.truffle.api.profiles.BranchProfile;
3436

3537
import java.lang.invoke.VarHandle;
3638

@@ -46,9 +48,9 @@ public static WrapNode create() {
4648

4749
@Specialization
4850
protected ValueWrapper wrapLong(long value,
49-
@Cached @Exclusive BranchProfile smallFixnumProfile) {
51+
@Cached @Exclusive InlinedBranchProfile smallFixnumProfile) {
5052
if (value >= ValueWrapperManager.MIN_FIXNUM_VALUE && value <= ValueWrapperManager.MAX_FIXNUM_VALUE) {
51-
smallFixnumProfile.enter();
53+
smallFixnumProfile.enter(this);
5254
long val = (value << 1) | LONG_TAG;
5355
return new ValueWrapper(null, val, null);
5456
} else {
@@ -87,10 +89,10 @@ protected ValueWrapper wrapNil(Nil value) {
8789

8890
@Specialization(guards = "!isNil(value)")
8991
protected ValueWrapper wrapImmutable(ImmutableRubyObject value,
90-
@Cached @Shared BranchProfile noHandleProfile) {
92+
@Cached @Shared InlinedBranchProfile noHandleProfile) {
9193
ValueWrapper wrapper = value.getValueWrapper();
9294
if (wrapper == null) {
93-
noHandleProfile.enter();
95+
noHandleProfile.enter(this);
9496
synchronized (value) {
9597
wrapper = value.getValueWrapper();
9698
if (wrapper == null) {
@@ -106,12 +108,13 @@ protected ValueWrapper wrapImmutable(ImmutableRubyObject value,
106108
}
107109

108110
@Specialization(limit = "getDynamicObjectCacheLimit()")
109-
protected ValueWrapper wrapValue(RubyDynamicObject value,
111+
protected static ValueWrapper wrapValue(RubyDynamicObject value,
110112
@CachedLibrary("value") DynamicObjectLibrary objectLibrary,
111-
@Cached @Shared BranchProfile noHandleProfile) {
113+
@Cached @Shared InlinedBranchProfile noHandleProfile,
114+
@Bind("this") Node node) {
112115
ValueWrapper wrapper = (ValueWrapper) objectLibrary.getOrDefault(value, Layouts.VALUE_WRAPPER_IDENTIFIER, null);
113116
if (wrapper == null) {
114-
noHandleProfile.enter();
117+
noHandleProfile.enter(node);
115118
synchronized (value) {
116119
wrapper = (ValueWrapper) objectLibrary.getOrDefault(value, Layouts.VALUE_WRAPPER_IDENTIFIER, null);
117120
if (wrapper == null) {

src/main/java/org/truffleruby/cext/package-info.java

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ protected void marksToRun(ExtensionCallStack stack,
119119
}
120120

121121

122+
@NeverDefault
122123
public static RunMarkOnExitNode create() {
123124
return MarkingServiceNodesFactory.RunMarkOnExitNodeGen.create();
124125
}

src/main/java/org/truffleruby/language/RubyBaseNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ protected final RubyArray createArray(int[] store) {
191191
return ArrayHelpers.createArray(getContext(), getLanguage(), store);
192192
}
193193

194+
protected static RubyArray createArray(Node node, int[] store) {
195+
return ArrayHelpers.createArray(getContext(node), getLanguage(node), store);
196+
}
197+
194198
protected final RubyArray createArray(long[] store) {
195199
return ArrayHelpers.createArray(getContext(), getLanguage(), store);
196200
}

0 commit comments

Comments
 (0)