# HG changeset patch # User farvidsson # Date 1381908023 -7200 # Node ID 7fe6ef09d2424c8f92244fa61393fa64f555ebd7 # Parent f509b8f4699b0f8c2bd2826046a9625c591f5fa4 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 diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java Wed Oct 16 09:20:23 2013 +0200 @@ -51,8 +51,7 @@ public static void main(String[] args) { ClassLoaderStats cls = new ClassLoaderStats(); - cls.start(args); - cls.stop(); + cls.execute(args); } private static class ClassData { diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java Wed Oct 16 09:20:23 2013 +0200 @@ -54,8 +54,7 @@ public static void main(String[] args) { FinalizerInfo finfo = new FinalizerInfo(); - finfo.start(args); - finfo.stop(); + finfo.execute(args); } public void run() { diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java Wed Oct 16 09:20:23 2013 +0200 @@ -54,7 +54,6 @@ public static void main(String[] args) { FlagDumper fd = new FlagDumper(); - fd.start(args); - fd.stop(); + fd.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java Wed Oct 16 09:20:23 2013 +0200 @@ -80,8 +80,7 @@ } HeapDumper dumper = new HeapDumper(file); - dumper.start(args); - dumper.stop(); + dumper.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java Wed Oct 16 09:20:23 2013 +0200 @@ -46,8 +46,7 @@ public static void main(String[] args) { HeapSummary hs = new HeapSummary(); - hs.start(args); - hs.stop(); + hs.execute(args); } public void run() { diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java Wed Oct 16 09:20:23 2013 +0200 @@ -134,8 +134,7 @@ } JInfo jinfo = new JInfo(mode); - jinfo.start(args); - jinfo.stop(); + jinfo.execute(args); } private void printVMFlags() { diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java Wed Oct 16 09:20:23 2013 +0200 @@ -136,7 +136,9 @@ 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 @@ } JMap jmap = new JMap(mode); - jmap.start(args); - jmap.stop(); + jmap.execute(args); } public boolean writeHeapHprofBin(String fileName) { diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java Wed Oct 16 09:20:23 2013 +0200 @@ -64,7 +64,6 @@ public static void main(String[] args) { JSnap js = new JSnap(); - js.start(args); - js.stop(); + js.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java Wed Oct 16 09:20:23 2013 +0200 @@ -89,8 +89,7 @@ } JStack jstack = new JStack(mixedMode, concurrentLocks); - jstack.start(args); - jstack.stop(); + jstack.execute(args); } private boolean mixedMode; diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java Wed Oct 16 09:20:23 2013 +0200 @@ -61,7 +61,6 @@ public static void main(String[] args) { ObjectHistogram oh = new ObjectHistogram(); - oh.start(args); - oh.stop(); + oh.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java Wed Oct 16 09:20:23 2013 +0200 @@ -69,7 +69,6 @@ public static void main(String[] args) throws Exception { PMap t = new PMap(); - t.start(args); - t.stop(); + t.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java Wed Oct 16 09:20:23 2013 +0200 @@ -182,8 +182,7 @@ 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 diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java Wed Oct 16 09:20:23 2013 +0200 @@ -137,8 +137,7 @@ public static void main(String[] args) { StackTrace st = new StackTrace(); - st.start(args); - st.stop(); + st.execute(args); } private boolean verbose; diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java Wed Oct 16 09:20:23 2013 +0200 @@ -58,7 +58,6 @@ public static void main(String[] args) { SysPropsDumper pd = new SysPropsDumper(); - pd.start(args); - pd.stop(); + pd.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java Wed Oct 16 09:20:23 2013 +0200 @@ -26,6 +26,7 @@ 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 static void main(String[] args) { obj = new ; - 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 @@ default: usage(); + return 1; } agent = new HotSpotAgent(); @@ -191,15 +211,16 @@ 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. diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java Wed Oct 16 09:20:23 2013 +0200 @@ -177,7 +177,6 @@ public static void main(String[] args) { ClassDump cd = new ClassDump(); - cd.start(args); - cd.stop(); + cd.execute(args); } } diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java Wed Oct 16 09:20:23 2013 +0200 @@ -42,8 +42,7 @@ public static void main(String[] args) { JSDB jsdb = new JSDB(); - jsdb.start(args); - jsdb.stop(); + jsdb.execute(args); } public void run() { diff -r f509b8f4699b -r 7fe6ef09d242 agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java --- a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java Tue Oct 15 08:25:43 2013 -0700 +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java Wed Oct 16 09:20:23 2013 +0200 @@ -40,8 +40,7 @@ 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() {