Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a600633c18fa
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a8e1f1482371
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Mar 2, 2015

  1. [Truffle] Take the lock earlier for pauseAllThreadsAndExecuteFromNonR…

    …ubyThread.
    
    * So we ensure to enter and leave within the lock
      so no other thread can see us in the Phaser.
    eregon committed Mar 2, 2015
    Copy the full SHA
    45a37cb View commit details
  2. [Truffle] Remove old import.

    eregon committed Mar 2, 2015
    Copy the full SHA
    a8e1f14 View commit details
Showing with 34 additions and 25 deletions.
  1. +34 −25 truffle/src/main/java/org/jruby/truffle/runtime/subsystems/SafepointManager.java
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@
import org.jruby.RubyThread.Status;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyThread;
import org.jruby.truffle.runtime.util.Consumer;

import java.util.ArrayList;
import java.util.Collections;
@@ -128,50 +127,60 @@ private void step(Node currentNode, RubyThread thread, boolean isDrivingThread)
}

public void pauseAllThreadsAndExecute(Node currentNode, SafepointAction action) {
pauseAllThreadsAndExecute(currentNode, true, action);
}

public void pauseAllThreadsAndExecuteFromNonRubyThread(Node currentNode, SafepointAction action) {
enterThread();
try {
pauseAllThreadsAndExecute(currentNode, false, action);
} finally {
leaveThread();
}
}

public void pauseAllThreadsAndExecute(Node currentNode, boolean holdsGlobalLock, SafepointAction action) {
CompilerDirectives.transferToInterpreter();

if (lock.isHeldByCurrentThread()) {
throw new IllegalStateException("Re-entered SafepointManager");
}

// Need to lock interruptibly since we are in the registered threads.
while (true) {
try {
lock.lockInterruptibly();
break;
} catch (InterruptedException e) {
poll(currentNode, holdsGlobalLock);
poll(currentNode);
}
}

try {
this.action = action;
pauseAllThreadsAndExecute(currentNode, true, action);
} finally {
lock.unlock();
}
}

/* this is a potential cause for race conditions,
* but we need to invalidate first so the interrupted threads
* see the invalidation in poll() in their catch(InterruptedException) clause
* and wait on the barrier instead of retrying their blocking action. */
assumption.invalidate();
interruptOtherThreads();
public void pauseAllThreadsAndExecuteFromNonRubyThread(Node currentNode, SafepointAction action) {
if (lock.isHeldByCurrentThread()) {
throw new IllegalStateException("Re-entered SafepointManager");
}

assumptionInvalidated(currentNode, holdsGlobalLock, true);
assert !runningThreads.contains(Thread.currentThread());
// Just wait to grab the lock, since we are not in the registered threads.
lock.lock();
try {
enterThread();
try {
pauseAllThreadsAndExecute(currentNode, false, action);
} finally {
leaveThread();
}
} finally {
lock.unlock();
}
}

private void pauseAllThreadsAndExecute(Node currentNode, boolean holdsGlobalLock, SafepointAction action) {
this.action = action;

/* this is a potential cause for race conditions,
* but we need to invalidate first so the interrupted threads
* see the invalidation in poll() in their catch(InterruptedException) clause
* and wait on the barrier instead of retrying their blocking action. */
assumption.invalidate();
interruptOtherThreads();

assumptionInvalidated(currentNode, holdsGlobalLock, true);
}

private void interruptOtherThreads() {
Thread current = Thread.currentThread();
for (Thread thread : runningThreads) {