38
38
import org .truffleruby .language .arguments .RubyArguments ;
39
39
import org .truffleruby .language .control .RaiseException ;
40
40
41
- import com .oracle .truffle .api .CompilerDirectives ;
42
41
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
43
42
import com .oracle .truffle .api .dsl .Cached ;
44
43
import com .oracle .truffle .api .dsl .Specialization ;
@@ -183,52 +182,52 @@ protected Object transfer(VirtualFrame frame, RubyFiber toFiber, Object[] rawArg
183
182
}
184
183
185
184
186
- public abstract static class FiberResumeNode extends CoreMethodArrayArgumentsNode {
185
+ @ GenerateInline
186
+ @ GenerateCached (false )
187
+ public abstract static class FiberResumeNode extends RubyBaseNode {
187
188
188
- public static FiberResumeNode create () {
189
- return FiberNodesFactory .FiberResumeNodeFactory .create (null );
190
- }
191
189
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 ,
193
192
Object [] args );
194
193
195
194
@ 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 ,
198
197
@ Cached FiberTransferNode fiberTransferNode ,
199
198
@ Cached InlinedBranchProfile errorProfile ) {
200
199
201
- final RubyFiber currentFiber = getLanguage ().getCurrentFiber ();
200
+ final RubyFiber currentFiber = getLanguage (node ).getCurrentFiber ();
202
201
203
202
if (toFiber .isTerminated ()) {
204
- errorProfile .enter (this );
203
+ errorProfile .enter (node );
205
204
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 ));
208
207
} else if (toFiber == currentFiber ) {
209
- errorProfile .enter (this );
208
+ errorProfile .enter (node );
210
209
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 ));
213
212
} else if (toFiber .lastResumedByFiber != null ) {
214
- errorProfile .enter (this );
213
+ errorProfile .enter (node );
215
214
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 ));
218
217
} else if (toFiber .resumingFiber != null ) {
219
- errorProfile .enter (this );
218
+ errorProfile .enter (node );
220
219
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 ));
223
222
} else if (toFiber .lastResumedByFiber == null &&
224
223
(!toFiber .yielding && toFiber .status != FiberStatus .CREATED )) {
225
- errorProfile .enter (this );
224
+ errorProfile .enter (node );
226
225
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 ));
229
228
}
230
229
231
- return fiberTransferNode .execute (this , currentFiber , toFiber , operation , descriptor , args );
230
+ return fiberTransferNode .execute (node , currentFiber , toFiber , operation , descriptor , args );
232
231
}
233
232
234
233
}
@@ -237,10 +236,9 @@ protected Object resume(
237
236
@ Primitive (name = "fiber_raise" )
238
237
public abstract static class FiberRaiseNode extends PrimitiveArrayArgumentsNode {
239
238
240
- @ Child private FiberResumeNode fiberResumeNode ;
241
-
242
239
@ Specialization
243
240
protected Object raise (RubyFiber fiber , RubyException exception ,
241
+ @ Cached FiberResumeNode fiberResumeNode ,
244
242
@ Cached FiberTransferNode fiberTransferNode ,
245
243
@ Cached InlinedBranchProfile errorProfile ) {
246
244
if (fiber .resumingFiber != null ) {
@@ -265,29 +263,19 @@ protected Object raise(RubyFiber fiber, RubyException exception,
265
263
EmptyArgumentsDescriptor .INSTANCE ,
266
264
new Object []{ exception });
267
265
} else {
268
- return getResumeNode (). executeResume ( FiberOperation .RAISE , fiber ,
266
+ return fiberResumeNode . execute ( this , FiberOperation .RAISE , fiber ,
269
267
EmptyArgumentsDescriptor .INSTANCE , new Object []{ exception });
270
268
}
271
269
}
272
-
273
- private FiberResumeNode getResumeNode () {
274
- if (fiberResumeNode == null ) {
275
- CompilerDirectives .transferToInterpreterAndInvalidate ();
276
- fiberResumeNode = insert (FiberResumeNode .create ());
277
- }
278
- return fiberResumeNode ;
279
- }
280
-
281
270
}
282
271
283
272
@ CoreMethod (names = "resume" , rest = true )
284
273
public abstract static class ResumeNode extends CoreMethodArrayArgumentsNode {
285
274
286
- @ Child private FiberResumeNode fiberResumeNode = FiberResumeNode .create ();
287
-
288
275
@ 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 ,
291
279
RubyArguments .getDescriptor (frame ), rawArgs );
292
280
}
293
281
@@ -296,7 +284,6 @@ protected Object resume(VirtualFrame frame, RubyFiber fiber, Object[] rawArgs) {
296
284
@ CoreMethod (names = "yield" , onSingleton = true , rest = true )
297
285
public abstract static class YieldNode extends CoreMethodArrayArgumentsNode {
298
286
299
-
300
287
@ Specialization
301
288
protected Object fiberYield (VirtualFrame frame , Object [] rawArgs ,
302
289
@ Cached FiberTransferNode fiberTransferNode ,
0 commit comments