Skip to content

Commit d42c333

Browse files
committed
[GR-18411] Address Truffle deprecations
PullRequest: truffleruby/3777
2 parents 773ddc6 + 719bfa8 commit d42c333

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525
import com.oracle.truffle.api.TruffleContext;
2626
import com.oracle.truffle.api.TruffleOptions;
2727
import com.oracle.truffle.api.TruffleSafepoint;
28-
import com.oracle.truffle.api.TruffleSafepoint.CompiledInterruptible;
2928
import com.oracle.truffle.api.TruffleSafepoint.Interrupter;
3029
import com.oracle.truffle.api.interop.InteropLibrary;
3130
import com.oracle.truffle.api.object.DynamicObjectLibrary;
3231
import com.oracle.truffle.api.source.SourceSection;
3332
import org.truffleruby.RubyContext;
3433
import org.truffleruby.RubyLanguage;
35-
import org.truffleruby.collections.Memo;
3634
import org.truffleruby.collections.ConcurrentWeakSet;
3735
import org.truffleruby.core.DummyNode;
3836
import org.truffleruby.core.InterruptMode;
@@ -199,7 +197,7 @@ private Thread createJavaThread(Runnable runnable, RubyThread rubyThread, String
199197
throw new UnsupportedOperationException("threads should not be created while pre-initializing the context");
200198
}
201199

202-
final Thread thread = context.getEnv().createThread(runnable);
200+
final Thread thread = context.getEnv().newTruffleThreadBuilder(runnable).build();
203201

204202
language.rubyThreadInitMap.put(thread, rubyThread);
205203
language.rubyFiberInitMap.put(thread, rubyThread.getRootFiber());
@@ -533,11 +531,11 @@ public static Object executeBlockingCall(RubyThread thread, Interrupter interrup
533531
final TruffleSafepoint safepoint = TruffleSafepoint.getCurrent();
534532

535533
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);
538535
}
539536

540-
public static class BlockingCallInterruptible implements CompiledInterruptible<BlockingCallInterruptible.State> {
537+
public static class BlockingCallInterruptible
538+
implements TruffleSafepoint.CompiledInterruptibleFunction<BlockingCallInterruptible.State, Object> {
541539

542540
final InteropLibrary receivers;
543541
final TranslateInteropExceptionNode translateInteropExceptionNode;
@@ -554,7 +552,6 @@ private static class State {
554552
final RubyThread thread;
555553
final Object executable;
556554
final Object[] args;
557-
Object result;
558555

559556
private State(RubyThread thread, Object executable, Object[] args) {
560557
this.thread = thread;
@@ -564,7 +561,7 @@ private State(RubyThread thread, Object executable, Object[] args) {
564561
}
565562

566563
@Override
567-
public void apply(State state) {
564+
public Object apply(State state) {
568565
CompilerAsserts.partialEvaluationConstant(this);
569566
final RubyThread thread = state.thread;
570567

@@ -574,8 +571,7 @@ public void apply(State state) {
574571
// NOTE: NFI uses CallTargets, so the TruffleSafepoint.poll() will happen before coming back from this call
575572
CompilerAsserts.partialEvaluationConstant(receivers);
576573
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);
579575
} finally {
580576
thread.status = status;
581577
}
@@ -605,18 +601,17 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> action, Runnable
605601
// we want to allow side-effecting actions to interrupt this blocking action and run here.
606602
final boolean onBlocking = runningThread.interruptMode == InterruptMode.ON_BLOCKING;
607603

608-
final Memo<T> result = new Memo<>(null);
609604
final ThreadStatus status = runningThread.status;
610605
boolean sideEffects = false;
611606

612607
if (onBlocking) {
613608
sideEffects = safepoint.setAllowSideEffects(true);
614609
}
615610
try {
616-
safepoint.setBlockedWithException(currentNode, Interrupter.THREAD_INTERRUPT, arg -> {
611+
return safepoint.setBlockedFunction(currentNode, Interrupter.THREAD_INTERRUPT, arg -> {
617612
runningThread.status = ThreadStatus.SLEEP;
618613
try {
619-
result.set(action.block());
614+
return action.block();
620615
} finally {
621616
runningThread.status = status; // restore status for running the safepoint
622617
}
@@ -626,8 +621,6 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> action, Runnable
626621
safepoint.setAllowSideEffects(sideEffects);
627622
}
628623
}
629-
630-
return result.get();
631624
}
632625

633626
@TruffleBoundary

src/main/java/org/truffleruby/debug/TruffleDebugNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ public abstract static class CreatePolyglotThread extends CoreMethodArrayArgumen
13851385
@Specialization
13861386
protected Object parseName(Object hostRunnable) {
13871387
Runnable runnable = (Runnable) getContext().getEnv().asHostObject(hostRunnable);
1388-
final Thread thread = getContext().getEnv().createThread(runnable);
1388+
final Thread thread = getContext().getEnv().newTruffleThreadBuilder(runnable).build();
13891389
return getContext().getEnv().asGuestValue(thread);
13901390
}
13911391
}

0 commit comments

Comments
 (0)