25
25
import com .oracle .truffle .api .TruffleContext ;
26
26
import com .oracle .truffle .api .TruffleOptions ;
27
27
import com .oracle .truffle .api .TruffleSafepoint ;
28
- import com .oracle .truffle .api .TruffleSafepoint .CompiledInterruptible ;
29
28
import com .oracle .truffle .api .TruffleSafepoint .Interrupter ;
30
29
import com .oracle .truffle .api .interop .InteropLibrary ;
31
30
import com .oracle .truffle .api .object .DynamicObjectLibrary ;
32
31
import com .oracle .truffle .api .source .SourceSection ;
33
32
import org .truffleruby .RubyContext ;
34
33
import org .truffleruby .RubyLanguage ;
35
- import org .truffleruby .collections .Memo ;
36
34
import org .truffleruby .collections .ConcurrentWeakSet ;
37
35
import org .truffleruby .core .DummyNode ;
38
36
import org .truffleruby .core .InterruptMode ;
@@ -199,7 +197,7 @@ private Thread createJavaThread(Runnable runnable, RubyThread rubyThread, String
199
197
throw new UnsupportedOperationException ("threads should not be created while pre-initializing the context" );
200
198
}
201
199
202
- final Thread thread = context .getEnv ().createThread (runnable );
200
+ final Thread thread = context .getEnv ().newTruffleThreadBuilder (runnable ). build ( );
203
201
204
202
language .rubyThreadInitMap .put (thread , rubyThread );
205
203
language .rubyFiberInitMap .put (thread , rubyThread .getRootFiber ());
@@ -533,11 +531,11 @@ public static Object executeBlockingCall(RubyThread thread, Interrupter interrup
533
531
final TruffleSafepoint safepoint = TruffleSafepoint .getCurrent ();
534
532
535
533
final BlockingCallInterruptible .State state = new BlockingCallInterruptible .State (thread , executable , args );
536
- safepoint .setBlockedWithException (currentNode , interrupter , blockingCallInterruptible , state , null , null );
537
- return state .result ;
534
+ return safepoint .setBlockedFunction (currentNode , interrupter , blockingCallInterruptible , state , null , null );
538
535
}
539
536
540
- public static class BlockingCallInterruptible implements CompiledInterruptible <BlockingCallInterruptible .State > {
537
+ public static class BlockingCallInterruptible
538
+ implements TruffleSafepoint .CompiledInterruptibleFunction <BlockingCallInterruptible .State , Object > {
541
539
542
540
final InteropLibrary receivers ;
543
541
final TranslateInteropExceptionNode translateInteropExceptionNode ;
@@ -554,7 +552,6 @@ private static class State {
554
552
final RubyThread thread ;
555
553
final Object executable ;
556
554
final Object [] args ;
557
- Object result ;
558
555
559
556
private State (RubyThread thread , Object executable , Object [] args ) {
560
557
this .thread = thread ;
@@ -564,7 +561,7 @@ private State(RubyThread thread, Object executable, Object[] args) {
564
561
}
565
562
566
563
@ Override
567
- public void apply (State state ) {
564
+ public Object apply (State state ) {
568
565
CompilerAsserts .partialEvaluationConstant (this );
569
566
final RubyThread thread = state .thread ;
570
567
@@ -574,8 +571,7 @@ public void apply(State state) {
574
571
// NOTE: NFI uses CallTargets, so the TruffleSafepoint.poll() will happen before coming back from this call
575
572
CompilerAsserts .partialEvaluationConstant (receivers );
576
573
CompilerAsserts .partialEvaluationConstant (translateInteropExceptionNode );
577
- state .result = InteropNodes
578
- .execute (state .executable , state .args , receivers , translateInteropExceptionNode );
574
+ return InteropNodes .execute (state .executable , state .args , receivers , translateInteropExceptionNode );
579
575
} finally {
580
576
thread .status = status ;
581
577
}
@@ -605,18 +601,17 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> action, Runnable
605
601
// we want to allow side-effecting actions to interrupt this blocking action and run here.
606
602
final boolean onBlocking = runningThread .interruptMode == InterruptMode .ON_BLOCKING ;
607
603
608
- final Memo <T > result = new Memo <>(null );
609
604
final ThreadStatus status = runningThread .status ;
610
605
boolean sideEffects = false ;
611
606
612
607
if (onBlocking ) {
613
608
sideEffects = safepoint .setAllowSideEffects (true );
614
609
}
615
610
try {
616
- safepoint .setBlockedWithException (currentNode , Interrupter .THREAD_INTERRUPT , arg -> {
611
+ return safepoint .setBlockedFunction (currentNode , Interrupter .THREAD_INTERRUPT , arg -> {
617
612
runningThread .status = ThreadStatus .SLEEP ;
618
613
try {
619
- result . set ( action .block () );
614
+ return action .block ();
620
615
} finally {
621
616
runningThread .status = status ; // restore status for running the safepoint
622
617
}
@@ -626,8 +621,6 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> action, Runnable
626
621
safepoint .setAllowSideEffects (sideEffects );
627
622
}
628
623
}
629
-
630
- return result .get ();
631
624
}
632
625
633
626
@ TruffleBoundary
0 commit comments