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: 1440adc98efa
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 220534d56673
Choose a head ref
  • 6 commits
  • 5 files changed
  • 1 contributor

Commits on Feb 27, 2015

  1. Copy the full SHA
    c19f57b View commit details
  2. Copy the full SHA
    dff7478 View commit details
  3. 3
    Copy the full SHA
    e084f9d View commit details
  4. Copy the full SHA
    aafa84f View commit details
  5. Copy the full SHA
    e2cb255 View commit details
  6. Copy the full SHA
    220534d View commit details
Original file line number Diff line number Diff line change
@@ -51,7 +51,9 @@ public class RubyThread extends RubyBasicObject {

private final RubyBasicObject threadLocals;

private final List<Lock> ownedLocks = new ArrayList<Lock>(); // Always accessed by the same underlying Java thread.
private final List<Lock> ownedLocks = new ArrayList<>(); // Always accessed by the same underlying Java thread.

private final List<Runnable> deferredSafepointActions = new ArrayList<>();

public RubyThread(RubyClass rubyClass, ThreadManager manager) {
super(rubyClass);
@@ -179,6 +181,14 @@ public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Runnable> getDeferredSafepointActions() {
return deferredSafepointActions;
}

public static class ThreadAllocator implements Allocator {

@Override
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
*/
package org.jruby.truffle.runtime.subsystems;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.FrameInstance;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
@@ -62,7 +64,7 @@ public void accept(RubyThread thread) {
// Not thread-safe so keep the formatting synchronized for now.
String[] lines = Backtrace.DISPLAY_FORMATTER.format(context, null, backtrace);

builder.append(Thread.currentThread().getName());
builder.append(String.format("#%d %s", Thread.currentThread().getId(), Thread.currentThread().getName()));
builder.append("\n");
for (String line : lines) {
builder.append(line);
@@ -85,7 +87,41 @@ public void accept(RubyThread thread) {
final OutputStream stream = httpExchange.getResponseBody();
stream.write(bytes);
stream.close();
} catch (Exception e) {
} catch (IOException e) {
e.printStackTrace();
}
}

});

server.createContext("/break", new HttpHandler() {

@Override
public void handle(HttpExchange httpExchange) {
try {
context.getSafepointManager().pauseAllThreadsAndExecuteFromNonRubyThread(new Consumer<RubyThread>() {

@Override
public void accept(RubyThread thread) {
if (thread.getName().equals("main")) {
thread.getDeferredSafepointActions().add(new Runnable() {

@Override
public void run() {
new SimpleShell(context).run(Truffle.getRuntime().getCurrentFrame()
.getFrame(FrameInstance.FrameAccess.MATERIALIZE, false).materialize(), null);
}

});
}
}

});

httpExchange.getResponseHeaders().set("Content-Type", "text/plain");
httpExchange.sendResponseHeaders(200, 0);
httpExchange.getResponseBody().close();
} catch (IOException e) {
e.printStackTrace();
}
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@
import org.jruby.truffle.runtime.core.RubyThread;
import org.jruby.truffle.runtime.util.Consumer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Phaser;
@@ -85,13 +87,26 @@ private void assumptionInvalidated(boolean holdsGlobalLock, boolean isDrivingThr
thread = context.getThreadManager().leaveGlobalLock();
}

// TODO CS 27-Feb-15 how do we get thread if it wasn't holding the global lock?

try {
step(thread, isDrivingThread);
} finally {
if (holdsGlobalLock) {
context.getThreadManager().enterGlobalLock(thread);
}
}

// We're now running again normally, with the global lock, and can run deferred actions

if (thread != null) {
final List<Runnable> deferredActions = new ArrayList<>(thread.getDeferredSafepointActions());
thread.getDeferredSafepointActions().clear();

for (Runnable action : deferredActions) {
action.run();
}
}
}

private void step(RubyThread thread, boolean isDrivingThread) {
@@ -168,7 +183,7 @@ private void interruptAllThreads() {
}
}

private class RunningThread {
private static class RunningThread {

private final Thread thread;
private final boolean interruptible;
Original file line number Diff line number Diff line change
@@ -42,9 +42,13 @@ public void run(MaterializedFrame frame, RubyNode currentNode) {
}

switch (tokenizer.nextToken()) {
case "exit":
case "continue":
return;

case "exit":
System.exit(0);
break;

default:
try {
final Object result = context.execute(
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ public class ThreadManager {
public ThreadManager(RubyContext context) {
this.context = context;
rootThread = new RubyThread(context.getCoreLibrary().getThreadClass(), this);
rootThread.setName("main");
rootThread.setRootThread(Thread.currentThread());
runningRubyThreads.add(rootThread);
enterGlobalLock(rootThread);