From 719bfa8b74b7bc62f94978cd1d3e9cef53639ad9 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 18 Apr 2023 12:40:33 +0200 Subject: [PATCH] Address Truffle deprecations --- .../core/thread/ThreadManager.java | 23 +++++++------------ .../truffleruby/debug/TruffleDebugNodes.java | 2 +- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/truffleruby/core/thread/ThreadManager.java b/src/main/java/org/truffleruby/core/thread/ThreadManager.java index 7eebce51f5a3..2277de982d22 100644 --- a/src/main/java/org/truffleruby/core/thread/ThreadManager.java +++ b/src/main/java/org/truffleruby/core/thread/ThreadManager.java @@ -25,14 +25,12 @@ import com.oracle.truffle.api.TruffleContext; import com.oracle.truffle.api.TruffleOptions; import com.oracle.truffle.api.TruffleSafepoint; -import com.oracle.truffle.api.TruffleSafepoint.CompiledInterruptible; import com.oracle.truffle.api.TruffleSafepoint.Interrupter; import com.oracle.truffle.api.interop.InteropLibrary; import com.oracle.truffle.api.object.DynamicObjectLibrary; import com.oracle.truffle.api.source.SourceSection; import org.truffleruby.RubyContext; import org.truffleruby.RubyLanguage; -import org.truffleruby.collections.Memo; import org.truffleruby.collections.ConcurrentWeakSet; import org.truffleruby.core.DummyNode; import org.truffleruby.core.InterruptMode; @@ -199,7 +197,7 @@ private Thread createJavaThread(Runnable runnable, RubyThread rubyThread, String throw new UnsupportedOperationException("threads should not be created while pre-initializing the context"); } - final Thread thread = context.getEnv().createThread(runnable); + final Thread thread = context.getEnv().newTruffleThreadBuilder(runnable).build(); language.rubyThreadInitMap.put(thread, rubyThread); language.rubyFiberInitMap.put(thread, rubyThread.getRootFiber()); @@ -533,11 +531,11 @@ public static Object executeBlockingCall(RubyThread thread, Interrupter interrup final TruffleSafepoint safepoint = TruffleSafepoint.getCurrent(); final BlockingCallInterruptible.State state = new BlockingCallInterruptible.State(thread, executable, args); - safepoint.setBlockedWithException(currentNode, interrupter, blockingCallInterruptible, state, null, null); - return state.result; + return safepoint.setBlockedFunction(currentNode, interrupter, blockingCallInterruptible, state, null, null); } - public static class BlockingCallInterruptible implements CompiledInterruptible { + public static class BlockingCallInterruptible + implements TruffleSafepoint.CompiledInterruptibleFunction { final InteropLibrary receivers; final TranslateInteropExceptionNode translateInteropExceptionNode; @@ -554,7 +552,6 @@ private static class State { final RubyThread thread; final Object executable; final Object[] args; - Object result; private State(RubyThread thread, Object executable, Object[] args) { this.thread = thread; @@ -564,7 +561,7 @@ private State(RubyThread thread, Object executable, Object[] args) { } @Override - public void apply(State state) { + public Object apply(State state) { CompilerAsserts.partialEvaluationConstant(this); final RubyThread thread = state.thread; @@ -574,8 +571,7 @@ public void apply(State state) { // NOTE: NFI uses CallTargets, so the TruffleSafepoint.poll() will happen before coming back from this call CompilerAsserts.partialEvaluationConstant(receivers); CompilerAsserts.partialEvaluationConstant(translateInteropExceptionNode); - state.result = InteropNodes - .execute(state.executable, state.args, receivers, translateInteropExceptionNode); + return InteropNodes.execute(state.executable, state.args, receivers, translateInteropExceptionNode); } finally { thread.status = status; } @@ -605,7 +601,6 @@ public T runUntilResult(Node currentNode, BlockingAction action, Runnable // we want to allow side-effecting actions to interrupt this blocking action and run here. final boolean onBlocking = runningThread.interruptMode == InterruptMode.ON_BLOCKING; - final Memo result = new Memo<>(null); final ThreadStatus status = runningThread.status; boolean sideEffects = false; @@ -613,10 +608,10 @@ public T runUntilResult(Node currentNode, BlockingAction action, Runnable sideEffects = safepoint.setAllowSideEffects(true); } try { - safepoint.setBlockedWithException(currentNode, Interrupter.THREAD_INTERRUPT, arg -> { + return safepoint.setBlockedFunction(currentNode, Interrupter.THREAD_INTERRUPT, arg -> { runningThread.status = ThreadStatus.SLEEP; try { - result.set(action.block()); + return action.block(); } finally { runningThread.status = status; // restore status for running the safepoint } @@ -626,8 +621,6 @@ public T runUntilResult(Node currentNode, BlockingAction action, Runnable safepoint.setAllowSideEffects(sideEffects); } } - - return result.get(); } @TruffleBoundary diff --git a/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java b/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java index c6354ca699d8..8215e24b6104 100644 --- a/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java +++ b/src/main/java/org/truffleruby/debug/TruffleDebugNodes.java @@ -1385,7 +1385,7 @@ public abstract static class CreatePolyglotThread extends CoreMethodArrayArgumen @Specialization protected Object parseName(Object hostRunnable) { Runnable runnable = (Runnable) getContext().getEnv().asHostObject(hostRunnable); - final Thread thread = getContext().getEnv().createThread(runnable); + final Thread thread = getContext().getEnv().newTruffleThreadBuilder(runnable).build(); return getContext().getEnv().asGuestValue(thread); } }