Skip to content

Commit 0b486a6

Browse files
committed
FiberResumeNode is DSL inlinable
1 parent 9d1b2e9 commit 0b486a6

File tree

1 file changed

+29
-42
lines changed

1 file changed

+29
-42
lines changed

src/main/java/org/truffleruby/core/fiber/FiberNodes.java

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.truffleruby.language.arguments.RubyArguments;
3939
import org.truffleruby.language.control.RaiseException;
4040

41-
import com.oracle.truffle.api.CompilerDirectives;
4241
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4342
import com.oracle.truffle.api.dsl.Cached;
4443
import com.oracle.truffle.api.dsl.Specialization;
@@ -183,52 +182,52 @@ protected Object transfer(VirtualFrame frame, RubyFiber toFiber, Object[] rawArg
183182
}
184183

185184

186-
public abstract static class FiberResumeNode extends CoreMethodArrayArgumentsNode {
185+
@GenerateInline
186+
@GenerateCached(false)
187+
public abstract static class FiberResumeNode extends RubyBaseNode {
187188

188-
public static FiberResumeNode create() {
189-
return FiberNodesFactory.FiberResumeNodeFactory.create(null);
190-
}
191189

192-
public abstract Object executeResume(FiberOperation operation, RubyFiber fiber, ArgumentsDescriptor descriptor,
190+
public abstract Object execute(Node node, FiberOperation operation, RubyFiber fiber,
191+
ArgumentsDescriptor descriptor,
193192
Object[] args);
194193

195194
@Specialization
196-
protected Object resume(
197-
FiberOperation operation, RubyFiber toFiber, ArgumentsDescriptor descriptor, Object[] args,
195+
protected static Object resume(
196+
Node node, FiberOperation operation, RubyFiber toFiber, ArgumentsDescriptor descriptor, Object[] args,
198197
@Cached FiberTransferNode fiberTransferNode,
199198
@Cached InlinedBranchProfile errorProfile) {
200199

201-
final RubyFiber currentFiber = getLanguage().getCurrentFiber();
200+
final RubyFiber currentFiber = getLanguage(node).getCurrentFiber();
202201

203202
if (toFiber.isTerminated()) {
204-
errorProfile.enter(this);
203+
errorProfile.enter(node);
205204
throw new RaiseException(
206-
getContext(),
207-
coreExceptions().fiberError("attempt to resume a terminated fiber", this));
205+
getContext(node),
206+
coreExceptions(node).fiberError("attempt to resume a terminated fiber", node));
208207
} else if (toFiber == currentFiber) {
209-
errorProfile.enter(this);
208+
errorProfile.enter(node);
210209
throw new RaiseException(
211-
getContext(),
212-
coreExceptions().fiberError("attempt to resume the current fiber", this));
210+
getContext(node),
211+
coreExceptions(node).fiberError("attempt to resume the current fiber", node));
213212
} else if (toFiber.lastResumedByFiber != null) {
214-
errorProfile.enter(this);
213+
errorProfile.enter(node);
215214
throw new RaiseException(
216-
getContext(),
217-
coreExceptions().fiberError("attempt to resume a resumed fiber (double resume)", this));
215+
getContext(node),
216+
coreExceptions(node).fiberError("attempt to resume a resumed fiber (double resume)", node));
218217
} else if (toFiber.resumingFiber != null) {
219-
errorProfile.enter(this);
218+
errorProfile.enter(node);
220219
throw new RaiseException(
221-
getContext(),
222-
coreExceptions().fiberError("attempt to resume a resuming fiber", this));
220+
getContext(node),
221+
coreExceptions(node).fiberError("attempt to resume a resuming fiber", node));
223222
} else if (toFiber.lastResumedByFiber == null &&
224223
(!toFiber.yielding && toFiber.status != FiberStatus.CREATED)) {
225-
errorProfile.enter(this);
224+
errorProfile.enter(node);
226225
throw new RaiseException(
227-
getContext(),
228-
coreExceptions().fiberError("attempt to resume a transferring fiber", this));
226+
getContext(node),
227+
coreExceptions(node).fiberError("attempt to resume a transferring fiber", node));
229228
}
230229

231-
return fiberTransferNode.execute(this, currentFiber, toFiber, operation, descriptor, args);
230+
return fiberTransferNode.execute(node, currentFiber, toFiber, operation, descriptor, args);
232231
}
233232

234233
}
@@ -237,10 +236,9 @@ protected Object resume(
237236
@Primitive(name = "fiber_raise")
238237
public abstract static class FiberRaiseNode extends PrimitiveArrayArgumentsNode {
239238

240-
@Child private FiberResumeNode fiberResumeNode;
241-
242239
@Specialization
243240
protected Object raise(RubyFiber fiber, RubyException exception,
241+
@Cached FiberResumeNode fiberResumeNode,
244242
@Cached FiberTransferNode fiberTransferNode,
245243
@Cached InlinedBranchProfile errorProfile) {
246244
if (fiber.resumingFiber != null) {
@@ -265,29 +263,19 @@ protected Object raise(RubyFiber fiber, RubyException exception,
265263
EmptyArgumentsDescriptor.INSTANCE,
266264
new Object[]{ exception });
267265
} else {
268-
return getResumeNode().executeResume(FiberOperation.RAISE, fiber,
266+
return fiberResumeNode.execute(this, FiberOperation.RAISE, fiber,
269267
EmptyArgumentsDescriptor.INSTANCE, new Object[]{ exception });
270268
}
271269
}
272-
273-
private FiberResumeNode getResumeNode() {
274-
if (fiberResumeNode == null) {
275-
CompilerDirectives.transferToInterpreterAndInvalidate();
276-
fiberResumeNode = insert(FiberResumeNode.create());
277-
}
278-
return fiberResumeNode;
279-
}
280-
281270
}
282271

283272
@CoreMethod(names = "resume", rest = true)
284273
public abstract static class ResumeNode extends CoreMethodArrayArgumentsNode {
285274

286-
@Child private FiberResumeNode fiberResumeNode = FiberResumeNode.create();
287-
288275
@Specialization
289-
protected Object resume(VirtualFrame frame, RubyFiber fiber, Object[] rawArgs) {
290-
return fiberResumeNode.executeResume(FiberOperation.RESUME, fiber,
276+
protected Object resume(VirtualFrame frame, RubyFiber fiber, Object[] rawArgs,
277+
@Cached FiberResumeNode fiberResumeNode) {
278+
return fiberResumeNode.execute(this, FiberOperation.RESUME, fiber,
291279
RubyArguments.getDescriptor(frame), rawArgs);
292280
}
293281

@@ -296,7 +284,6 @@ protected Object resume(VirtualFrame frame, RubyFiber fiber, Object[] rawArgs) {
296284
@CoreMethod(names = "yield", onSingleton = true, rest = true)
297285
public abstract static class YieldNode extends CoreMethodArrayArgumentsNode {
298286

299-
300287
@Specialization
301288
protected Object fiberYield(VirtualFrame frame, Object[] rawArgs,
302289
@Cached FiberTransferNode fiberTransferNode,

0 commit comments

Comments
 (0)