mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 03:24:38 +02:00
8025638: jmap returns 0 instead of 1 when it fails
Re-factored some code handling return values and fails/errors during tool execution. Reviewed-by: sla, kevinw
This commit is contained in:
parent
232c4efbdb
commit
ec5d05699e
18 changed files with 48 additions and 42 deletions
|
@ -51,8 +51,7 @@ public class ClassLoaderStats extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
ClassLoaderStats cls = new ClassLoaderStats();
|
||||
cls.start(args);
|
||||
cls.stop();
|
||||
cls.execute(args);
|
||||
}
|
||||
|
||||
private static class ClassData {
|
||||
|
|
|
@ -54,8 +54,7 @@ public class FinalizerInfo extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
FinalizerInfo finfo = new FinalizerInfo();
|
||||
finfo.start(args);
|
||||
finfo.stop();
|
||||
finfo.execute(args);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -54,7 +54,6 @@ public class FlagDumper extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
FlagDumper fd = new FlagDumper();
|
||||
fd.start(args);
|
||||
fd.stop();
|
||||
fd.execute(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,8 +80,7 @@ public class HeapDumper extends Tool {
|
|||
}
|
||||
|
||||
HeapDumper dumper = new HeapDumper(file);
|
||||
dumper.start(args);
|
||||
dumper.stop();
|
||||
dumper.execute(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,8 +46,7 @@ public class HeapSummary extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
HeapSummary hs = new HeapSummary();
|
||||
hs.start(args);
|
||||
hs.stop();
|
||||
hs.execute(args);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -134,8 +134,7 @@ public class JInfo extends Tool {
|
|||
}
|
||||
|
||||
JInfo jinfo = new JInfo(mode);
|
||||
jinfo.start(args);
|
||||
jinfo.stop();
|
||||
jinfo.execute(args);
|
||||
}
|
||||
|
||||
private void printVMFlags() {
|
||||
|
|
|
@ -136,7 +136,9 @@ public class JMap extends Tool {
|
|||
mode = MODE_HEAP_GRAPH_GXL;
|
||||
} else {
|
||||
System.err.println("unknown heap format:" + format);
|
||||
return;
|
||||
|
||||
// Exit with error status
|
||||
System.exit(1);
|
||||
}
|
||||
} else {
|
||||
copyArgs = false;
|
||||
|
@ -153,8 +155,7 @@ public class JMap extends Tool {
|
|||
}
|
||||
|
||||
JMap jmap = new JMap(mode);
|
||||
jmap.start(args);
|
||||
jmap.stop();
|
||||
jmap.execute(args);
|
||||
}
|
||||
|
||||
public boolean writeHeapHprofBin(String fileName) {
|
||||
|
|
|
@ -64,7 +64,6 @@ public class JSnap extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
JSnap js = new JSnap();
|
||||
js.start(args);
|
||||
js.stop();
|
||||
js.execute(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,8 +89,7 @@ public class JStack extends Tool {
|
|||
}
|
||||
|
||||
JStack jstack = new JStack(mixedMode, concurrentLocks);
|
||||
jstack.start(args);
|
||||
jstack.stop();
|
||||
jstack.execute(args);
|
||||
}
|
||||
|
||||
private boolean mixedMode;
|
||||
|
|
|
@ -61,7 +61,6 @@ public class ObjectHistogram extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
ObjectHistogram oh = new ObjectHistogram();
|
||||
oh.start(args);
|
||||
oh.stop();
|
||||
oh.execute(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,6 @@ public class PMap extends Tool {
|
|||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PMap t = new PMap();
|
||||
t.start(args);
|
||||
t.stop();
|
||||
t.execute(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,8 +182,7 @@ public class PStack extends Tool {
|
|||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PStack t = new PStack();
|
||||
t.start(args);
|
||||
t.stop();
|
||||
t.execute(args);
|
||||
}
|
||||
|
||||
// -- Internals only below this point
|
||||
|
|
|
@ -137,8 +137,7 @@ public class StackTrace extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
StackTrace st = new StackTrace();
|
||||
st.start(args);
|
||||
st.stop();
|
||||
st.execute(args);
|
||||
}
|
||||
|
||||
private boolean verbose;
|
||||
|
|
|
@ -58,7 +58,6 @@ public class SysPropsDumper extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
SysPropsDumper pd = new SysPropsDumper();
|
||||
pd.start(args);
|
||||
pd.stop();
|
||||
pd.execute(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ package sun.jvm.hotspot.tools;
|
|||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import sun.jvm.hotspot.*;
|
||||
import sun.jvm.hotspot.runtime.*;
|
||||
import sun.jvm.hotspot.debugger.*;
|
||||
|
@ -105,26 +106,44 @@ public abstract class Tool implements Runnable {
|
|||
|
||||
public static void main(String[] args) {
|
||||
<derived class> obj = new <derived class>;
|
||||
obj.start(args);
|
||||
obj.execute(args);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
protected void stop() {
|
||||
protected void execute(String[] args) {
|
||||
int returnStatus = 1;
|
||||
|
||||
try {
|
||||
returnStatus = start(args);
|
||||
} finally {
|
||||
stop();
|
||||
}
|
||||
|
||||
// Exit with 0 or 1
|
||||
System.exit(returnStatus);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (agent != null) {
|
||||
agent.detach();
|
||||
}
|
||||
}
|
||||
|
||||
protected void start(String[] args) {
|
||||
private int start(String[] args) {
|
||||
|
||||
if ((args.length < 1) || (args.length > 2)) {
|
||||
usage();
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Attempt to handle -h or -help or some invalid flag
|
||||
if (args[0].startsWith("-")) {
|
||||
if (args[0].startsWith("-h")) {
|
||||
usage();
|
||||
return 0;
|
||||
} else if (args[0].startsWith("-")) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
PrintStream err = System.err;
|
||||
|
@ -154,6 +173,7 @@ public abstract class Tool implements Runnable {
|
|||
|
||||
default:
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
|
||||
agent = new HotSpotAgent();
|
||||
|
@ -191,15 +211,16 @@ public abstract class Tool implements Runnable {
|
|||
break;
|
||||
}
|
||||
if (e.getMessage() != null) {
|
||||
err.print(e.getMessage());
|
||||
err.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
err.println();
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
err.println("Debugger attached successfully.");
|
||||
startInternal();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// When using an existing JVMDebugger.
|
||||
|
|
|
@ -177,7 +177,6 @@ public class ClassDump extends Tool {
|
|||
public static void main(String[] args) {
|
||||
|
||||
ClassDump cd = new ClassDump();
|
||||
cd.start(args);
|
||||
cd.stop();
|
||||
cd.execute(args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,7 @@ public class JSDB extends Tool {
|
|||
|
||||
public static void main(String[] args) {
|
||||
JSDB jsdb = new JSDB();
|
||||
jsdb.start(args);
|
||||
jsdb.stop();
|
||||
jsdb.execute(args);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
|
|
@ -40,8 +40,7 @@ import sun.jvm.hotspot.utilities.soql.*;
|
|||
public class SOQL extends Tool {
|
||||
public static void main(String[] args) {
|
||||
SOQL soql = new SOQL();
|
||||
soql.start(args);
|
||||
soql.stop();
|
||||
soql.execute(args);
|
||||
}
|
||||
|
||||
public SOQL() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue