Skip to content

Commit

Permalink
[GR-44867] Backports for 23.0 batch 4
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/3775
  • Loading branch information
eregon committed Apr 17, 2023
2 parents be33607 + 62f599c commit b2b73e2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 60 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ Bug fixes:
* Fix processing of proc rest arguments located at the beginning if there are no actual arguments (#2921, @andrykonchin).
* Fix `Monitor#exit` to raise `ThreadError` when monitor not owned by the current thread (#2922, @andrykonchin).
* Fix `MatchData#[]` to support negative `length` argument (#2929, @andrykonchin).
* Fix `IO` line reading calls when using a multi-byte delimiter (`IO#{each,gets,readline,readlines,etc.}) (#2961, @vinistock, @nirvdrum).
* Fix `IO` line reading calls when using a multi-byte delimiter (`IO#{each,gets,readline,readlines,etc.}`) (#2961, @vinistock, @nirvdrum).
* Fix the exception type raised when type coercion raises a `NoMethodError` (#2903, @paracycle, @nirvdrum).
* Fix `Method` and `Proc` `#parameters` method to return `_` parameter name without synthetic suffix when there are multiple `_` parameters (@paracycle).
* Fixed errors in IRB when attempting to navigate beyond bounds in singleline mode (@rwstauner).

Compatibility:

Expand Down Expand Up @@ -116,7 +117,6 @@ Performance:
* `Process.pid` is now cached per process like `$$` (#2882, @horakivo)
* Use the system `libyaml` for `psych` to improve warmup when parsing YAML (#2089, @eregon).
* Fixed repeated deoptimizations for methods building an `Array` which is growing over multiple calls at a given call site (@eregon).
* Fixed errors in IRB when attempting to navigate beyond bounds in singleline mode (@rwstauner).

Changes:

Expand Down
4 changes: 2 additions & 2 deletions spec/truffle/identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
RUBY_VERSION.should =~ /\A\d+\.\d+\.\d+\z/
end

it 'RUBY_ENGINE_VERSION matches /\A\d+(\.\d+)*(-(rc|beta\.)\d+)?(\-dev)?(-\h+)?\z/' do
RUBY_ENGINE_VERSION.should =~ /\A\d+(\.\d+)*(-(rc|beta\.)\d+)?(\-dev)?(-\h+)?\z/
it 'RUBY_ENGINE_VERSION matches /\A\d+(\.\d+)*(-(preview|rc)\d+|-dev-\h+)?\z/' do
RUBY_ENGINE_VERSION.should =~ /\A\d+(\.\d+)*(-(preview|rc)\d+|-dev-\h+)?\z/
end

it "RUBY_ENGINE_VERSION can be parsed as a Gem::Version" do
Expand Down
33 changes: 2 additions & 31 deletions src/main/java/org/truffleruby/core/ReferenceProcessingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.truffleruby.annotations.SuppressFBWarnings;
import org.truffleruby.core.thread.RubyThread;
import org.truffleruby.core.thread.ThreadManager;
import org.truffleruby.language.control.KillException;
import org.truffleruby.language.control.RaiseException;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
Expand Down Expand Up @@ -73,7 +72,6 @@ public ReferenceProcessingService<R, T> service() {
public static class ReferenceProcessor {
protected final ReferenceQueue<Object> processingQueue = new ReferenceQueue<>();

private volatile boolean shutdown = false;
protected RubyThread processingThread;
protected final RubyContext context;

Expand Down Expand Up @@ -121,40 +119,13 @@ protected void createProcessingThread(ReferenceProcessingService<?, ?> service)

threadManager.initialize(newThread, DummyNode.INSTANCE, THREAD_NAME, sharingReason, () -> {
while (true) {
final PhantomProcessingReference<?, ?> reference = threadManager
.runUntilResult(DummyNode.INSTANCE, () -> {
try {
return (PhantomProcessingReference<?, ?>) processingQueue.remove();
} catch (InterruptedException interrupted) {
if (shutdown) {
throw new KillException(DummyNode.INSTANCE);
} else {
throw interrupted;
}
}
});
final PhantomProcessingReference<?, ?> reference = threadManager.runUntilResult(DummyNode.INSTANCE,
() -> (PhantomProcessingReference<?, ?>) processingQueue.remove());
reference.service().processReference(context, language, reference);
}
});
}

public boolean shutdownProcessingThread() {
final Thread javaThread = processingThread == null ? null : processingThread.thread;
if (javaThread == null) {
return false;
}

shutdown = true;
javaThread.interrupt();

context.getThreadManager().runUntilResultKeepStatus(DummyNode.INSTANCE, t -> t.join(1000), javaThread);
return true;
}

public RubyThread getProcessingThread() {
return processingThread;
}

@TruffleBoundary
protected final void drainReferenceQueues() {
final RubyLanguage language = context.getLanguageSlow();
Expand Down
27 changes: 2 additions & 25 deletions src/main/java/org/truffleruby/core/thread/ThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,33 +662,10 @@ public void checkNoRunningThreads() {
@TruffleBoundary
public void killAndWaitOtherThreads() {
// Kill all Ruby Threads and Fibers

// The logic below avoids using the SafepointManager if there is
// only the current thread and the reference processing thread.
final RubyThread currentThread = language.getCurrentThread();
boolean otherThreads = false;
RubyThread referenceProcessingThread = null;
for (RubyThread thread : runningRubyThreads) {
if (thread == currentThread) {
// no need to kill the current thread
} else if (thread == context.getReferenceProcessor().getProcessingThread()) {
referenceProcessingThread = thread;
} else {
otherThreads = true;
break;
}
}

if (!otherThreads && referenceProcessingThread != null) {
if (!context.getReferenceProcessor().shutdownProcessingThread()) {
otherThreads = true;
}
}

if (otherThreads) {
if (runningRubyThreads.size() > 1) {
doKillOtherThreads();
}
context.fiberManager.killOtherFibers(currentThread);
context.fiberManager.killOtherFibers(language.getCurrentThread());

// Wait and join all Java threads we created
for (Thread thread : rubyManagedThreads) {
Expand Down

0 comments on commit b2b73e2

Please sign in to comment.