@@ -192,6 +192,7 @@ Object callWithCExtLockAndFrame(
192
192
@ CachedLibrary (limit = "getCacheLimit()" ) InteropLibrary receivers ,
193
193
@ Cached ArrayToObjectArrayNode arrayToObjectArrayNode ,
194
194
@ Cached TranslateInteropExceptionNode translateInteropExceptionNode ,
195
+ @ Cached InlinedConditionProfile lockCExtProfile ,
195
196
@ Cached InlinedConditionProfile ownedProfile ,
196
197
@ Cached RunMarkOnExitNode runMarksNode ) {
197
198
final ExtensionCallStack extensionStack = getLanguage ()
@@ -201,8 +202,10 @@ Object callWithCExtLockAndFrame(
201
202
extensionStack .push (keywordsGiven , specialVariables , block );
202
203
try {
203
204
final Object [] args = arrayToObjectArrayNode .executeToObjectArray (argsArray );
205
+ final boolean lockCExt = lockCExtProfile .profile (this ,
206
+ getContext ().getOptions ().CEXT_LOCK && useCExtLock );
204
207
205
- if (getContext (). getOptions (). CEXT_LOCK && useCExtLock ) {
208
+ if (lockCExt ) {
206
209
final ReentrantLock lock = getContext ().getCExtensionsLock ();
207
210
boolean owned = ownedProfile .profile (this , lock .isHeldByCurrentThread ());
208
211
@@ -235,47 +238,21 @@ protected int getCacheLimit() {
235
238
}
236
239
}
237
240
238
- @ Primitive (name = "call_with_frame_and_unwrap" )
239
- public abstract static class CallWithFrameAndUnwrapNode extends PrimitiveArrayArgumentsNode {
240
-
241
- @ Specialization
242
- Object callWithFrame (
243
- VirtualFrame frame , Object receiver , RubyArray argsArray , Object specialVariables , Object block ,
244
- @ CachedLibrary (limit = "getCacheLimit()" ) InteropLibrary receivers ,
245
- @ Cached ArrayToObjectArrayNode arrayToObjectArrayNode ,
246
- @ Cached TranslateInteropExceptionNode translateInteropExceptionNode ,
247
- @ Cached RunMarkOnExitNode runMarksNode ,
248
- @ Cached UnwrapNode unwrapNode ) {
249
- final ExtensionCallStack extensionStack = getLanguage ().getCurrentFiber ().extensionCallStack ;
250
- final boolean keywordsGiven = RubyArguments .getDescriptor (frame ) instanceof KeywordArgumentsDescriptor ;
251
- extensionStack .push (keywordsGiven , specialVariables , block );
252
- try {
253
- final Object [] args = arrayToObjectArrayNode .executeToObjectArray (argsArray );
254
- try {
255
- return unwrapNode .execute (this ,
256
- InteropNodes .execute (this , receiver , args , receivers , translateInteropExceptionNode ));
257
- } finally {
258
- runMarksNode .execute (this , extensionStack );
259
- }
260
- } finally {
261
- extensionStack .pop ();
262
- }
263
- }
264
-
265
- protected int getCacheLimit () {
266
- return getLanguage ().options .DISPATCH_CACHE ;
267
- }
268
- }
269
-
270
241
@ Primitive (name = "call_with_cext_lock_and_frame_and_unwrap" )
271
242
public abstract static class CallWithCExtLockAndFrameAndUnwrapNode extends PrimitiveArrayArgumentsNode {
272
243
273
244
@ Specialization
274
245
Object callWithCExtLockAndFrame (
275
- VirtualFrame frame , Object receiver , RubyArray argsArray , Object specialVariables , Object block ,
246
+ VirtualFrame frame ,
247
+ Object receiver ,
248
+ RubyArray argsArray ,
249
+ Object specialVariables ,
250
+ Object block ,
251
+ boolean useCExtLock ,
276
252
@ CachedLibrary (limit = "getCacheLimit()" ) InteropLibrary receivers ,
277
253
@ Cached ArrayToObjectArrayNode arrayToObjectArrayNode ,
278
254
@ Cached TranslateInteropExceptionNode translateInteropExceptionNode ,
255
+ @ Cached InlinedConditionProfile lockCExtProfile ,
279
256
@ Cached InlinedConditionProfile ownedProfile ,
280
257
@ Cached RunMarkOnExitNode runMarksNode ,
281
258
@ Cached UnwrapNode unwrapNode ) {
@@ -284,8 +261,10 @@ Object callWithCExtLockAndFrame(
284
261
extensionStack .push (keywordsGiven , specialVariables , block );
285
262
try {
286
263
final Object [] args = arrayToObjectArrayNode .executeToObjectArray (argsArray );
264
+ final boolean lockCExt = lockCExtProfile .profile (this ,
265
+ getContext ().getOptions ().CEXT_LOCK && useCExtLock );
287
266
288
- if (getContext (). getOptions (). CEXT_LOCK ) {
267
+ if (lockCExt ) {
289
268
final ReentrantLock lock = getContext ().getCExtensionsLock ();
290
269
boolean owned = ownedProfile .profile (this , lock .isHeldByCurrentThread ());
291
270
@@ -323,17 +302,19 @@ protected int getCacheLimit() {
323
302
@ Primitive (name = "call_with_cext_lock" )
324
303
public abstract static class CallWithCExtLockNode extends PrimitiveArrayArgumentsNode {
325
304
326
- public abstract Object execute (Object receiver , RubyArray argsArray );
305
+ public abstract Object execute (Object receiver , RubyArray argsArray , boolean useCExtLock );
327
306
328
307
@ Specialization
329
- Object callWithCExtLock (Object receiver , RubyArray argsArray ,
308
+ Object callWithCExtLock (Object receiver , RubyArray argsArray , boolean useCExtLock ,
330
309
@ CachedLibrary (limit = "getCacheLimit()" ) InteropLibrary receivers ,
331
310
@ Cached ArrayToObjectArrayNode arrayToObjectArrayNode ,
332
311
@ Cached TranslateInteropExceptionNode translateInteropExceptionNode ,
312
+ @ Cached InlinedConditionProfile lockCExtProfile ,
333
313
@ Cached InlinedConditionProfile ownedProfile ) {
334
314
Object [] args = arrayToObjectArrayNode .executeToObjectArray (argsArray );
315
+ final boolean lockCExt = lockCExtProfile .profile (this , getContext ().getOptions ().CEXT_LOCK && useCExtLock );
335
316
336
- if (getContext (). getOptions (). CEXT_LOCK ) {
317
+ if (lockCExt ) {
337
318
final ReentrantLock lock = getContext ().getCExtensionsLock ();
338
319
boolean owned = ownedProfile .profile (this , lock .isHeldByCurrentThread ());
339
320
@@ -496,15 +477,15 @@ boolean startNewHandleBlock() {
496
477
}
497
478
}
498
479
499
- @ CoreMethod ( names = "cext_lock_owned?" , onSingleton = true )
480
+ @ Primitive ( name = "cext_lock_owned?" )
500
481
public abstract static class IsCExtLockOwnedPrimitiveNode extends PrimitiveArrayArgumentsNode {
501
482
@ Specialization
502
483
boolean isCExtLockOwned () {
503
484
return getContext ().getCExtensionsLock ().isHeldByCurrentThread ();
504
485
}
505
486
}
506
487
507
- @ CoreMethod ( names = "use_cext_lock?" , onSingleton = true )
488
+ @ Primitive ( name = "use_cext_lock?" )
508
489
public abstract static class UseCExtLockNode extends PrimitiveArrayArgumentsNode {
509
490
@ Specialization
510
491
boolean useCExtLock () {
0 commit comments