提交 3915eda3 编写于 作者: F farvidsson

8025638: jmap returns 0 instead of 1 when it fails.

Summary: Re-factored some code handling return values and fails/errors during tool execution.
Reviewed-by: sla, kevinw
Contributed-by: fredrik.arvidsson@oracle.com
上级 097601ec
...@@ -51,8 +51,7 @@ public class ClassLoaderStats extends Tool { ...@@ -51,8 +51,7 @@ public class ClassLoaderStats extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
ClassLoaderStats cls = new ClassLoaderStats(); ClassLoaderStats cls = new ClassLoaderStats();
cls.start(args); cls.execute(args);
cls.stop();
} }
private static class ClassData { private static class ClassData {
......
...@@ -54,8 +54,7 @@ public class FinalizerInfo extends Tool { ...@@ -54,8 +54,7 @@ public class FinalizerInfo extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
FinalizerInfo finfo = new FinalizerInfo(); FinalizerInfo finfo = new FinalizerInfo();
finfo.start(args); finfo.execute(args);
finfo.stop();
} }
public void run() { public void run() {
......
...@@ -54,7 +54,6 @@ public class FlagDumper extends Tool { ...@@ -54,7 +54,6 @@ public class FlagDumper extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
FlagDumper fd = new FlagDumper(); FlagDumper fd = new FlagDumper();
fd.start(args); fd.execute(args);
fd.stop();
} }
} }
...@@ -80,8 +80,7 @@ public class HeapDumper extends Tool { ...@@ -80,8 +80,7 @@ public class HeapDumper extends Tool {
} }
HeapDumper dumper = new HeapDumper(file); HeapDumper dumper = new HeapDumper(file);
dumper.start(args); dumper.execute(args);
dumper.stop();
} }
} }
...@@ -46,8 +46,7 @@ public class HeapSummary extends Tool { ...@@ -46,8 +46,7 @@ public class HeapSummary extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
HeapSummary hs = new HeapSummary(); HeapSummary hs = new HeapSummary();
hs.start(args); hs.execute(args);
hs.stop();
} }
public void run() { public void run() {
......
...@@ -134,8 +134,7 @@ public class JInfo extends Tool { ...@@ -134,8 +134,7 @@ public class JInfo extends Tool {
} }
JInfo jinfo = new JInfo(mode); JInfo jinfo = new JInfo(mode);
jinfo.start(args); jinfo.execute(args);
jinfo.stop();
} }
private void printVMFlags() { private void printVMFlags() {
......
...@@ -136,7 +136,9 @@ public class JMap extends Tool { ...@@ -136,7 +136,9 @@ public class JMap extends Tool {
mode = MODE_HEAP_GRAPH_GXL; mode = MODE_HEAP_GRAPH_GXL;
} else { } else {
System.err.println("unknown heap format:" + format); System.err.println("unknown heap format:" + format);
return;
// Exit with error status
System.exit(1);
} }
} else { } else {
copyArgs = false; copyArgs = false;
...@@ -153,8 +155,7 @@ public class JMap extends Tool { ...@@ -153,8 +155,7 @@ public class JMap extends Tool {
} }
JMap jmap = new JMap(mode); JMap jmap = new JMap(mode);
jmap.start(args); jmap.execute(args);
jmap.stop();
} }
public boolean writeHeapHprofBin(String fileName) { public boolean writeHeapHprofBin(String fileName) {
......
...@@ -64,7 +64,6 @@ public class JSnap extends Tool { ...@@ -64,7 +64,6 @@ public class JSnap extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
JSnap js = new JSnap(); JSnap js = new JSnap();
js.start(args); js.execute(args);
js.stop();
} }
} }
...@@ -89,8 +89,7 @@ public class JStack extends Tool { ...@@ -89,8 +89,7 @@ public class JStack extends Tool {
} }
JStack jstack = new JStack(mixedMode, concurrentLocks); JStack jstack = new JStack(mixedMode, concurrentLocks);
jstack.start(args); jstack.execute(args);
jstack.stop();
} }
private boolean mixedMode; private boolean mixedMode;
......
...@@ -61,7 +61,6 @@ public class ObjectHistogram extends Tool { ...@@ -61,7 +61,6 @@ public class ObjectHistogram extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
ObjectHistogram oh = new ObjectHistogram(); ObjectHistogram oh = new ObjectHistogram();
oh.start(args); oh.execute(args);
oh.stop();
} }
} }
...@@ -69,7 +69,6 @@ public class PMap extends Tool { ...@@ -69,7 +69,6 @@ public class PMap extends Tool {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
PMap t = new PMap(); PMap t = new PMap();
t.start(args); t.execute(args);
t.stop();
} }
} }
...@@ -182,8 +182,7 @@ public class PStack extends Tool { ...@@ -182,8 +182,7 @@ public class PStack extends Tool {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
PStack t = new PStack(); PStack t = new PStack();
t.start(args); t.execute(args);
t.stop();
} }
// -- Internals only below this point // -- Internals only below this point
......
...@@ -137,8 +137,7 @@ public class StackTrace extends Tool { ...@@ -137,8 +137,7 @@ public class StackTrace extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
StackTrace st = new StackTrace(); StackTrace st = new StackTrace();
st.start(args); st.execute(args);
st.stop();
} }
private boolean verbose; private boolean verbose;
......
...@@ -58,7 +58,6 @@ public class SysPropsDumper extends Tool { ...@@ -58,7 +58,6 @@ public class SysPropsDumper extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
SysPropsDumper pd = new SysPropsDumper(); SysPropsDumper pd = new SysPropsDumper();
pd.start(args); pd.execute(args);
pd.stop();
} }
} }
...@@ -26,6 +26,7 @@ package sun.jvm.hotspot.tools; ...@@ -26,6 +26,7 @@ package sun.jvm.hotspot.tools;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Hashtable; import java.util.Hashtable;
import sun.jvm.hotspot.*; import sun.jvm.hotspot.*;
import sun.jvm.hotspot.runtime.*; import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.debugger.*; import sun.jvm.hotspot.debugger.*;
...@@ -105,26 +106,44 @@ public abstract class Tool implements Runnable { ...@@ -105,26 +106,44 @@ public abstract class Tool implements Runnable {
public static void main(String[] args) { public static void main(String[] args) {
<derived class> obj = new <derived class>; <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) { if (agent != null) {
agent.detach(); agent.detach();
} }
} }
protected void start(String[] args) { private int start(String[] args) {
if ((args.length < 1) || (args.length > 2)) { if ((args.length < 1) || (args.length > 2)) {
usage(); usage();
return; return 1;
} }
// Attempt to handle -h or -help or some invalid flag // 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(); usage();
return 1;
} }
PrintStream err = System.err; PrintStream err = System.err;
...@@ -154,6 +173,7 @@ public abstract class Tool implements Runnable { ...@@ -154,6 +173,7 @@ public abstract class Tool implements Runnable {
default: default:
usage(); usage();
return 1;
} }
agent = new HotSpotAgent(); agent = new HotSpotAgent();
...@@ -191,15 +211,16 @@ public abstract class Tool implements Runnable { ...@@ -191,15 +211,16 @@ public abstract class Tool implements Runnable {
break; break;
} }
if (e.getMessage() != null) { if (e.getMessage() != null) {
err.print(e.getMessage()); err.println(e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
err.println(); err.println();
return; return 1;
} }
err.println("Debugger attached successfully."); err.println("Debugger attached successfully.");
startInternal(); startInternal();
return 0;
} }
// When using an existing JVMDebugger. // When using an existing JVMDebugger.
......
...@@ -177,7 +177,6 @@ public class ClassDump extends Tool { ...@@ -177,7 +177,6 @@ public class ClassDump extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
ClassDump cd = new ClassDump(); ClassDump cd = new ClassDump();
cd.start(args); cd.execute(args);
cd.stop();
} }
} }
...@@ -42,8 +42,7 @@ public class JSDB extends Tool { ...@@ -42,8 +42,7 @@ public class JSDB extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
JSDB jsdb = new JSDB(); JSDB jsdb = new JSDB();
jsdb.start(args); jsdb.execute(args);
jsdb.stop();
} }
public void run() { public void run() {
......
...@@ -40,8 +40,7 @@ import sun.jvm.hotspot.utilities.soql.*; ...@@ -40,8 +40,7 @@ import sun.jvm.hotspot.utilities.soql.*;
public class SOQL extends Tool { public class SOQL extends Tool {
public static void main(String[] args) { public static void main(String[] args) {
SOQL soql = new SOQL(); SOQL soql = new SOQL();
soql.start(args); soql.execute(args);
soql.stop();
} }
public SOQL() { public SOQL() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册