Skip to content

Commit 6064e31

Browse files
committed
[GR-16336] Correctly set the call node for alwaysInlinedUncached()
* If we are in a cached CallInternalMethodNode and go to an uncached AlwaysInlinedMethodNode, we need to set the EncapsulatingNodeReference, so code inside that call can find the caller node properly. See DefaultCallTarget#call for how it uses EncapsulatingNodeReference.
1 parent 0f97297 commit 6064e31

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/main/java/org/truffleruby/language/methods/CallInternalMethodNode.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
1515
import com.oracle.truffle.api.dsl.CachedContext;
1616
import com.oracle.truffle.api.frame.MaterializedFrame;
17+
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
1718
import com.oracle.truffle.api.nodes.Node;
1819
import com.oracle.truffle.api.nodes.NodeUtil;
1920
import com.oracle.truffle.api.profiles.BranchProfile;
@@ -115,27 +116,40 @@ protected Object alwaysInlinedUncached(
115116
self,
116117
block,
117118
args,
118-
contextRef);
119+
contextRef,
120+
isAdoptable());
119121
}
120122

121123
@TruffleBoundary // getUncachedAlwaysInlinedMethodNode(method) and arity are not PE constants
122124
private Object alwaysInlinedBoundary(
123125
MaterializedFrame frame, Object callerData, InternalMethod method, Object self, Object block, Object[] args,
124-
ContextReference<RubyContext> contextRef) {
125-
return alwaysInlined(
126-
frame,
127-
callerData,
128-
method,
129-
self,
130-
block,
131-
args,
132-
method.getCallTarget(),
133-
method,
134-
getUncachedAlwaysInlinedMethodNode(method),
135-
method.getSharedMethodInfo().getArity(),
136-
BranchProfile.getUncached(),
137-
BranchProfile.getUncached(),
138-
contextRef);
126+
ContextReference<RubyContext> contextRef, boolean cachedToUncached) {
127+
EncapsulatingNodeReference encapsulating = null;
128+
Node prev = null;
129+
if (cachedToUncached) {
130+
encapsulating = EncapsulatingNodeReference.getCurrent();
131+
prev = encapsulating.set(this);
132+
}
133+
try {
134+
return alwaysInlined(
135+
frame,
136+
callerData,
137+
method,
138+
self,
139+
block,
140+
args,
141+
method.getCallTarget(),
142+
method,
143+
getUncachedAlwaysInlinedMethodNode(method),
144+
method.getSharedMethodInfo().getArity(),
145+
BranchProfile.getUncached(),
146+
BranchProfile.getUncached(),
147+
contextRef);
148+
} finally {
149+
if (cachedToUncached) {
150+
encapsulating.set(prev);
151+
}
152+
}
139153
}
140154

141155
protected AlwaysInlinedMethodNode createAlwaysInlinedMethodNode(InternalMethod method) {

0 commit comments

Comments
 (0)