Skip to content

Commit

Permalink
Fixes btraceio#136 and a introduced Bug of btraceio#93 - make sure th…
Browse files Browse the repository at this point in the history
…e BTrace Runtime is stopped before exitting the jvm

- no client is connected, only the agent with a script
- make sure the PrintWriter is always flushed after printing with GridDataCommand
  • Loading branch information
mfilser committed Aug 28, 2015
1 parent 681572f commit 22311e7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/share/classes/com/sun/btrace/agent/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ protected Class loadClass(InstrumentCommand instr) throws IOException {
Main.dumpClass(className, className, btraceCode);
if (debug) Main.debugPrint("creating BTraceRuntime instance for " + className);
this.runtime = new BTraceRuntime(className, args, this, inst);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
runtime.handleExit(0);
}
}));
if (debug) Main.debugPrint("created BTraceRuntime instance for " + className);
if (debug) Main.debugPrint("removing @OnMethod, @OnProbe methods");
byte[] codeBuf = removeMethods(btraceCode);
Expand Down
12 changes: 0 additions & 12 deletions src/share/classes/com/sun/btrace/agent/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ public Thread newThread(Runnable r) {

private static final ExecutorService serializedExecutor = Executors.newSingleThreadExecutor(daemonizedThreadFactory);

private static void registerExitHook(final Client c) {
Runtime.getRuntime().addShutdownHook(new Thread(
new Runnable() {
@Override
public void run() {
BTraceRuntime rt = c.getRuntime();
if (rt != null) rt.handleExit(0);
}
}));
}

public static void premain(String args, Instrumentation inst) {
main(args, inst);
}
Expand Down Expand Up @@ -413,7 +402,6 @@ private static void startServer() {
Socket sock = ss.accept();
if (isDebug()) debugPrint("client accepted " + sock);
Client client = new RemoteClient(inst, sock);
registerExitHook(client);
handleNewClient(client).get();
} catch (RuntimeException | IOException | ExecutionException re) {
if (isDebug()) debugPrint(re);
Expand Down
1 change: 1 addition & 0 deletions src/share/classes/com/sun/btrace/comm/GridDataCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public void print(PrintWriter out) {
out.println(line);
}
}
out.flush();
}

private static final HashMap<Class< ? >, String> typeFormats = new HashMap<Class< ? >, String>();
Expand Down

0 comments on commit 22311e7

Please sign in to comment.