Skip to content

Commit

Permalink
[GR-18411] Address Truffle deprecations
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3777
  • Loading branch information
eregon committed Apr 18, 2023
2 parents 773ddc6 + 719bfa8 commit d42c333
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 8 additions & 15 deletions src/main/java/org/truffleruby/core/thread/ThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<BlockingCallInterruptible.State> {
public static class BlockingCallInterruptible
implements TruffleSafepoint.CompiledInterruptibleFunction<BlockingCallInterruptible.State, Object> {

final InteropLibrary receivers;
final TranslateInteropExceptionNode translateInteropExceptionNode;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -605,18 +601,17 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> 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<T> result = new Memo<>(null);
final ThreadStatus status = runningThread.status;
boolean sideEffects = false;

if (onBlocking) {
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
}
Expand All @@ -626,8 +621,6 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> action, Runnable
safepoint.setAllowSideEffects(sideEffects);
}
}

return result.get();
}

@TruffleBoundary
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/truffleruby/debug/TruffleDebugNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit d42c333

Please sign in to comment.