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: 1a744fad7a66
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 604c12930ff1
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Feb 28, 2015

  1. Copy the full SHA
    fb350f2 View commit details
  2. Copy the full SHA
    c16977e View commit details
  3. [Truffle] Also do necessary cleanup for the main thread.

    * Most importantly, get out of the SafepointManager.
    eregon committed Feb 28, 2015
    Copy the full SHA
    604c129 View commit details
12 changes: 9 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ public class RubyContext extends ExecutionContext {
private final LexicalScope rootLexicalScope;
private final CompilerOptions compilerOptions;
private final RubiniusPrimitiveManager rubiniusPrimitiveManager;
private final InstrumentationServerManager instrumentationServerManager;

private final AtomicLong nextObjectID = new AtomicLong(ObjectIDOperations.FIRST_OBJECT_ID);

@@ -113,7 +114,10 @@ public RubyContext(Ruby runtime) {
rubiniusPrimitiveManager = RubiniusPrimitiveManager.create();

if (Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load() != 0) {
new InstrumentationServerManager(this, Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load()).start();
instrumentationServerManager = new InstrumentationServerManager(this, Options.TRUFFLE_INSTRUMENTATION_SERVER_PORT.load());
instrumentationServerManager.start();
} else {
instrumentationServerManager = null;
}

runningOnWindows = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).indexOf("win") >= 0;
@@ -260,10 +264,12 @@ public long getNextObjectID() {
public void shutdown() {
atExitManager.run();

if (fiberManager != null) {
fiberManager.shutdown();
if (instrumentationServerManager != null) {
instrumentationServerManager.shutdown();
}

fiberManager.shutdown();

threadManager.shutdown();
}

Original file line number Diff line number Diff line change
@@ -100,18 +100,23 @@ public void run(final RubyContext context, Node currentNode, String info, Runnab
} catch (ReturnException e) {
exception = getContext().getCoreLibrary().unexpectedReturn(currentNode);
} finally {
status = Status.ABORTING;
context.getThreadManager().leaveGlobalLock();
context.getSafepointManager().leaveThread();
manager.unregisterThread(this);

status = Status.DEAD;
thread = null;
releaseOwnedLocks();
finished.countDown();
cleanup(context);
}
}

// Only used by the main thread which cannot easily wrap everything inside a try/finally.
public void cleanup(RubyContext context) {
status = Status.ABORTING;
context.getThreadManager().leaveGlobalLock();
context.getSafepointManager().leaveThread();
manager.unregisterThread(this);

status = Status.DEAD;
thread = null;
releaseOwnedLocks();
finished.countDown();
}

public void setRootThread(Thread thread) {
this.thread = thread;
}
Original file line number Diff line number Diff line change
@@ -32,14 +32,15 @@ public class InstrumentationServerManager {
private final RubyContext context;
private final int port;

private HttpServer server;
private volatile boolean shuttingDown = false;

public InstrumentationServerManager(RubyContext context, int port) {
this.context = context;
this.port = port;
}

public void start() {
final HttpServer server;

try {
server = HttpServer.create(new InetSocketAddress(port), 0);
} catch (IOException e) {
@@ -89,6 +90,9 @@ public void run(RubyThread thread, Node currentNode) {
stream.write(bytes);
stream.close();
} catch (IOException e) {
if (shuttingDown) {
return;
}
e.printStackTrace();
}
}
@@ -123,6 +127,9 @@ public void run() {
httpExchange.sendResponseHeaders(200, 0);
httpExchange.getResponseBody().close();
} catch (IOException e) {
if (shuttingDown) {
return;
}
e.printStackTrace();
}
}
@@ -132,4 +139,12 @@ public void run() {
server.start();
}

public void shutdown() {
if (server != null) {
shuttingDown = true;
// Leave it some time to send the remaining bytes.
server.stop(1);
}
}

}
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ public void run(RubyThread thread, Node currentThread) {
}
});

leaveGlobalLock();
rootThread.cleanup(context);
}

}