Skip to content

Commit 93211d3

Browse files
committed
[GR-28932] Prepare for always-inlined builtins
PullRequest: truffleruby/2377
2 parents e26ae04 + 20dccee commit 93211d3

30 files changed

+200
-195
lines changed

src/main/java/org/truffleruby/core/basicobject/BasicObjectNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public InternalMethod getMethod() {
330330
}
331331

332332
@Override
333-
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
333+
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
334334
return execute();
335335
}
336336
}
@@ -646,7 +646,7 @@ public static AllocateNode create() {
646646
return AllocateNodeFactory.create(null);
647647
}
648648

649-
public abstract Object execute(VirtualFrame frame, Object rubyClass);
649+
public abstract Object execute(Object rubyClass);
650650

651651
@Specialization(guards = "!rubyClass.isSingleton")
652652
protected RubyBasicObject allocate(RubyClass rubyClass) {
@@ -663,8 +663,8 @@ protected Shape allocateSingleton(RubyClass rubyClass) {
663663
}
664664

665665
@Override
666-
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
667-
return execute(frame, self);
666+
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
667+
return execute(self);
668668
}
669669

670670
@Override

src/main/java/org/truffleruby/core/inlined/InlinedDispatchNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.oracle.truffle.api.Assumption;
1313
import com.oracle.truffle.api.CompilerDirectives;
1414
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
15-
import com.oracle.truffle.api.frame.VirtualFrame;
15+
import com.oracle.truffle.api.frame.Frame;
1616

1717
import org.truffleruby.RubyLanguage;
1818
import org.truffleruby.core.array.ArrayUtils;
@@ -56,7 +56,7 @@ public Object callWithBlock(Object receiver, String method, Object block, Object
5656
return dispatch(null, receiver, method, block, arguments);
5757
}
5858

59-
public Object dispatch(VirtualFrame frame, Object receiver, String methodName, Object block, Object[] arguments) {
59+
public Object dispatch(Frame frame, Object receiver, String methodName, Object block, Object[] arguments) {
6060
if ((lookupNode.lookupProtected(frame, receiver, methodName) != coreMethod()) ||
6161
!Assumption.isValidAssumption(assumptions)) {
6262
return rewriteAndCallWithBlock(frame, receiver, methodName, block, arguments);
@@ -78,7 +78,7 @@ private DispatchNode rewriteToDispatchNode() {
7878
}
7979
}
8080

81-
protected Object rewriteAndCallWithBlock(VirtualFrame frame, Object receiver, String methodName, Object block,
81+
protected Object rewriteAndCallWithBlock(Frame frame, Object receiver, String methodName, Object block,
8282
Object... arguments) {
8383
return rewriteToDispatchNode().dispatch(frame, receiver, methodName, block, arguments);
8484
}

src/main/java/org/truffleruby/core/inlined/InlinedMethodNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
*/
1010
package org.truffleruby.core.inlined;
1111

12-
import com.oracle.truffle.api.frame.VirtualFrame;
12+
import com.oracle.truffle.api.frame.Frame;
1313

1414
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1515
import org.truffleruby.language.methods.InternalMethod;
1616

1717
public abstract class InlinedMethodNode extends CoreMethodArrayArgumentsNode {
1818

19-
public abstract Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc);
19+
public abstract Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block);
2020

2121
public abstract InternalMethod getMethod();
2222
}

src/main/java/org/truffleruby/core/kernel/KernelNodes.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.concurrent.TimeUnit;
2222

2323
import com.oracle.truffle.api.dsl.CachedContext;
24+
import com.oracle.truffle.api.frame.Frame;
2425
import com.oracle.truffle.api.utilities.AssumedValue;
2526
import org.jcodings.specific.UTF8Encoding;
2627
import org.truffleruby.RubyContext;
@@ -688,7 +689,7 @@ public static InlinedMethodNode create() {
688689

689690
@Child private DispatchingNode initializeDupNode;
690691

691-
public abstract Object execute(VirtualFrame frame, Object self);
692+
public abstract Object execute(Object self);
692693

693694
@Specialization
694695
protected Object dup(Object self,
@@ -708,8 +709,8 @@ protected Object dup(Object self,
708709
}
709710

710711
@Override
711-
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
712-
return execute(frame, self);
712+
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
713+
return execute(self);
713714
}
714715

715716
@Override
@@ -1021,15 +1022,15 @@ public static InitializeCopyNode create() {
10211022

10221023
@Child protected ReferenceEqualNode equalNode = ReferenceEqualNode.create();
10231024

1024-
public abstract Object execute(VirtualFrame frame, Object self, Object from);
1025+
public abstract Object execute(Object self, Object from);
10251026

10261027
@Specialization(guards = "equalNode.executeReferenceEqual(self, from)")
10271028
protected Object initializeCopySame(Object self, Object from) {
10281029
return self;
10291030
}
10301031

10311032
@Specialization(guards = "!equalNode.executeReferenceEqual(self, from)")
1032-
protected Object initializeCopy(VirtualFrame frame, Object self, Object from,
1033+
protected Object initializeCopy(Object self, Object from,
10331034
@Cached CheckFrozenNode checkFrozenNode,
10341035
@Cached LogicalClassNode lhsClassNode,
10351036
@Cached LogicalClassNode rhsClassNode,
@@ -1046,9 +1047,9 @@ protected Object initializeCopy(VirtualFrame frame, Object self, Object from,
10461047
}
10471048

10481049
@Override
1049-
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
1050+
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
10501051
assert args.length == 1;
1051-
return execute(frame, self, args[0]);
1052+
return execute(self, args[0]);
10521053
}
10531054

10541055
@Override
@@ -1072,7 +1073,7 @@ protected Object initializeDup(RubyDynamicObject self, Object from) {
10721073
}
10731074

10741075
@Override
1075-
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
1076+
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
10761077
return initializeDup((RubyDynamicObject) self, args[0]);
10771078
}
10781079

@@ -1345,15 +1346,14 @@ protected RubyMethod method(VirtualFrame frame, Object self, Object name,
13451346
@Cached ConditionProfile respondToMissingProfile,
13461347
@Cached LogicalClassNode logicalClassNode) {
13471348
final String normalizedName = nameToJavaStringNode.execute(name);
1348-
InternalMethod method = lookupMethodNode
1349-
.lookup(frame, self, normalizedName, dispatchConfig);
1349+
InternalMethod method = lookupMethodNode.execute(frame, self, normalizedName, dispatchConfig);
13501350

13511351
if (notFoundProfile.profile(method == null)) {
13521352
final Object respondToMissing = respondToMissingNode
13531353
.call(self, "respond_to_missing?", name, dispatchConfig.ignoreVisibility);
13541354
if (respondToMissingProfile.profile(booleanCastNode.executeToBoolean(respondToMissing))) {
13551355
final InternalMethod methodMissing = lookupMethodNode
1356-
.lookup(frame, self, "method_missing", dispatchConfig);
1356+
.execute(frame, self, "method_missing", dispatchConfig);
13571357
method = createMissingMethod(self, name, normalizedName, methodMissing);
13581358
} else {
13591359
throw new RaiseException(

src/main/java/org/truffleruby/core/kernel/TruffleKernelNodes.java

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

1212
import java.io.IOException;
1313

14+
import com.oracle.truffle.api.frame.Frame;
1415
import com.oracle.truffle.api.library.CachedLibrary;
1516
import org.truffleruby.Layouts;
1617
import org.truffleruby.builtins.CoreMethod;
@@ -188,7 +189,7 @@ protected Object defineHookedVariableInnerNode(
188189

189190
}
190191

191-
public static int declarationDepth(VirtualFrame topFrame) {
192+
public static int declarationDepth(Frame topFrame) {
192193
MaterializedFrame frame = topFrame.materialize();
193194
int count = 0;
194195

@@ -208,7 +209,7 @@ public static int declarationDepth(VirtualFrame topFrame) {
208209
}
209210
}
210211

211-
public static FrameDescriptor declarationDescriptor(VirtualFrame topFrame, int depth) {
212+
public static FrameDescriptor declarationDescriptor(Frame topFrame, int depth) {
212213
if (depth == 0) {
213214
return topFrame.getFrameDescriptor();
214215
} else {
@@ -228,13 +229,13 @@ private static FrameSlot getVariableSlot(MaterializedFrame frame) {
228229
@ImportStatic({ Layouts.class, TruffleKernelNodes.class })
229230
public abstract static class GetSpecialVariableStorage extends RubyContextNode {
230231

231-
public abstract SpecialVariableStorage execute(VirtualFrame frame);
232+
public abstract SpecialVariableStorage execute(Frame frame);
232233

233234
@Specialization(
234235
guards = "frame.getFrameDescriptor() == descriptor",
235236
assumptions = "frameAssumption",
236237
limit = "1")
237-
protected SpecialVariableStorage getFromKnownFrameDescriptor(VirtualFrame frame,
238+
protected SpecialVariableStorage getFromKnownFrameDescriptor(Frame frame,
238239
@Cached("frame.getFrameDescriptor()") FrameDescriptor descriptor,
239240
@Cached("declarationDepth(frame)") int declarationFrameDepth,
240241
@Cached("declarationDescriptor(frame, declarationFrameDepth)") FrameDescriptor declarationFrameDescriptor,
@@ -278,7 +279,7 @@ protected SpecialVariableStorage getFromKnownFrameDescriptor(VirtualFrame frame,
278279
}
279280

280281
@Specialization(replaces = "getFromKnownFrameDescriptor")
281-
protected SpecialVariableStorage slowPath(VirtualFrame frame) {
282+
protected SpecialVariableStorage slowPath(Frame frame) {
282283
return getSlow(frame.materialize());
283284
}
284285

@@ -363,7 +364,7 @@ protected Object storage() {
363364
public abstract static class GetProcSpecialVariableStorage extends PrimitiveArrayArgumentsNode {
364365

365366
@Specialization
366-
protected Object variables(VirtualFrame frame, RubyProc proc) {
367+
protected Object variables(RubyProc proc) {
367368
return proc.declarationVariables;
368369
}
369370
}

src/main/java/org/truffleruby/core/klass/ClassNodes.java

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

12+
import com.oracle.truffle.api.frame.Frame;
1213
import org.truffleruby.RubyContext;
1314
import org.truffleruby.builtins.CoreMethod;
1415
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
@@ -35,7 +36,6 @@
3536
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3637
import com.oracle.truffle.api.dsl.Cached;
3738
import com.oracle.truffle.api.dsl.Specialization;
38-
import com.oracle.truffle.api.frame.VirtualFrame;
3939
import com.oracle.truffle.api.profiles.BranchProfile;
4040
import com.oracle.truffle.api.source.SourceSection;
4141

@@ -281,16 +281,16 @@ public static NewNode create() {
281281
@Child private DispatchingNode allocateNode;
282282
@Child private DispatchingNode initialize;
283283

284-
public abstract Object execute(VirtualFrame frame, Object rubyClass, Object[] args, Object block);
284+
public abstract Object execute(Object rubyClass, Object[] args, Object block);
285285

286286
@Specialization(guards = "!rubyClass.isSingleton")
287-
protected Object newInstance(VirtualFrame frame, RubyClass rubyClass, Object[] args, NotProvided block) {
288-
return doNewInstance(frame, rubyClass, args, nil);
287+
protected Object newInstance(RubyClass rubyClass, Object[] args, NotProvided block) {
288+
return doNewInstance(rubyClass, args, nil);
289289
}
290290

291291
@Specialization(guards = "!rubyClass.isSingleton")
292-
protected Object newInstance(VirtualFrame frame, RubyClass rubyClass, Object[] args, RubyProc block) {
293-
return doNewInstance(frame, rubyClass, args, block);
292+
protected Object newInstance(RubyClass rubyClass, Object[] args, RubyProc block) {
293+
return doNewInstance(rubyClass, args, block);
294294
}
295295

296296
@Specialization(guards = "rubyClass.isSingleton")
@@ -301,11 +301,11 @@ protected RubyClass newSingletonInstance(RubyClass rubyClass, Object[] args, Obj
301301
}
302302

303303
@Override
304-
public Object inlineExecute(VirtualFrame frame, Object self, Object[] args, Object proc) {
305-
return execute(frame, self, args, proc);
304+
public Object inlineExecute(Frame callerFrame, Object self, Object[] args, Object block) {
305+
return execute(self, args, block);
306306
}
307307

308-
private Object doNewInstance(VirtualFrame frame, RubyClass rubyClass, Object[] args, Object block) {
308+
private Object doNewInstance(RubyClass rubyClass, Object[] args, Object block) {
309309
final Object instance = allocateNode().call(rubyClass, "__allocate__");
310310
initialize().callWithBlock(instance, "initialize", block, args);
311311
return instance;

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ public abstract static class CallNode extends CoreMethodArrayArgumentsNode {
132132
@Child private CallBoundMethodNode callBoundMethodNode = CallBoundMethodNode.create();
133133

134134
@Specialization
135-
protected Object call(RubyMethod method, Object[] arguments, Object maybeBlock) {
135+
protected Object call(VirtualFrame frame, RubyMethod method, Object[] arguments, Object maybeBlock) {
136136
return callBoundMethodNode
137-
.executeCallBoundMethod(method, arguments, maybeBlock == NotProvided.INSTANCE ? nil : maybeBlock);
137+
.execute(frame, method, arguments, maybeBlock == NotProvided.INSTANCE ? nil : maybeBlock);
138138
}
139139

140140
}

src/main/java/org/truffleruby/core/method/RubyMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Object execute(Object[] arguments,
6868
@Cached CallBoundMethodNode callBoundMethodNode,
6969
@Cached ForeignToRubyArgumentsNode foreignToRubyArgumentsNode) {
7070
return callBoundMethodNode
71-
.executeCallBoundMethod(this, foreignToRubyArgumentsNode.executeConvert(arguments), Nil.INSTANCE);
71+
.execute(null, this, foreignToRubyArgumentsNode.executeConvert(arguments), Nil.INSTANCE);
7272
}
7373
// endregion
7474

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.oracle.truffle.api.Assumption;
2424
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
25-
import com.oracle.truffle.api.frame.VirtualFrame;
2625
import com.oracle.truffle.api.nodes.Node;
2726
import com.oracle.truffle.api.utilities.AlwaysValidAssumption;
2827
import org.truffleruby.language.methods.DeclarationContext;
@@ -58,9 +57,9 @@
5857
*
5958
* <p>
6059
* This class is the sole consumer of {@link RubyRootNode#getNeedsCallerAssumption()}, which is used to optimize
61-
* {@link #getFrameOrStorageIfRequired(VirtualFrame)} (called by subclasses in order to pass down the frame or not).
62-
* Starting to send the frame invalidates the assumption. In other words, the assumption guards the fact that
63-
* {@link #sendsFrame} is a compilation constant, and is invalidated whenever it needs to change. */
60+
* {@link #getFrameOrStorageIfRequired(Frame)} (called by subclasses in order to pass down the frame or not). Starting
61+
* to send the frame invalidates the assumption. In other words, the assumption guards the fact that {@link #sendsFrame}
62+
* is a compilation constant, and is invalidated whenever it needs to change. */
6463
@SuppressFBWarnings("IS")
6564
public abstract class FrameAndVariablesSendingNode extends RubyContextNode {
6665

@@ -213,7 +212,7 @@ private synchronized void resetNeedsCallerAssumption() {
213212
}
214213
}
215214

216-
public Object getFrameOrStorageIfRequired(VirtualFrame frame) {
215+
public Object getFrameOrStorageIfRequired(Frame frame) {
217216
if (frame == null) { // the frame should be proved null or non-null at PE time
218217
return null;
219218
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ public abstract class RubyContextNode extends RubyBaseNode implements RubyNode.W
2929
@CompilationFinal private RubyLanguage language;
3030

3131
@Override
32-
public RubyContext getContext() {
32+
public ContextReference<RubyContext> getContextReference() {
3333
if (contextReference == null) {
3434
CompilerDirectives.transferToInterpreterAndInvalidate();
3535
contextReference = lookupContextReference(RubyLanguage.class);
3636
}
3737

38-
return contextReference.get();
38+
return contextReference;
39+
}
40+
41+
@Override
42+
public RubyContext getContext() {
43+
return getContextReference().get();
3944
}
4045

4146
public RubyLanguage getLanguage() {

0 commit comments

Comments
 (0)