From 3915eda3d79bec3d58de8102c08e0b6ad4b716d0 Mon Sep 17 00:00:00 2001 From: farvidsson Date: Wed, 16 Oct 2013 09:20:23 +0200 Subject: [PATCH] 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 --- .../jvm/hotspot/tools/ClassLoaderStats.java | 3 +- .../sun/jvm/hotspot/tools/FinalizerInfo.java | 3 +- .../sun/jvm/hotspot/tools/FlagDumper.java | 3 +- .../sun/jvm/hotspot/tools/HeapDumper.java | 3 +- .../sun/jvm/hotspot/tools/HeapSummary.java | 3 +- .../classes/sun/jvm/hotspot/tools/JInfo.java | 3 +- .../classes/sun/jvm/hotspot/tools/JMap.java | 7 ++-- .../classes/sun/jvm/hotspot/tools/JSnap.java | 3 +- .../classes/sun/jvm/hotspot/tools/JStack.java | 3 +- .../jvm/hotspot/tools/ObjectHistogram.java | 3 +- .../classes/sun/jvm/hotspot/tools/PMap.java | 3 +- .../classes/sun/jvm/hotspot/tools/PStack.java | 3 +- .../sun/jvm/hotspot/tools/StackTrace.java | 3 +- .../sun/jvm/hotspot/tools/SysPropsDumper.java | 3 +- .../classes/sun/jvm/hotspot/tools/Tool.java | 35 +++++++++++++++---- .../jvm/hotspot/tools/jcore/ClassDump.java | 3 +- .../sun/jvm/hotspot/tools/soql/JSDB.java | 3 +- .../sun/jvm/hotspot/tools/soql/SOQL.java | 3 +- 18 files changed, 48 insertions(+), 42 deletions(-) diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java b/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java index eeda376b1..d2ea2db85 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/ClassLoaderStats.java @@ -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 { diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java b/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java index ed707b9ee..2a8ca2cfb 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FinalizerInfo.java @@ -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() { diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java b/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java index c8db6d6b0..37fa4c83c 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/FlagDumper.java @@ -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); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java index c5af0ed00..e2da202ac 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapDumper.java @@ -80,8 +80,7 @@ public class HeapDumper extends Tool { } HeapDumper dumper = new HeapDumper(file); - dumper.start(args); - dumper.stop(); + dumper.execute(args); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java index daab682aa..f87457c3c 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/HeapSummary.java @@ -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() { diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java index f24524207..6f9cd0f41 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JInfo.java @@ -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() { diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java index f6f3c0741..847eac194 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JMap.java @@ -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) { diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java index 9301f1059..c2e5ed52f 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JSnap.java @@ -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); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java b/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java index 7cbe8f4d9..52fb6654e 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/JStack.java @@ -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; diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java b/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java index 168202eec..6c6c555ba 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/ObjectHistogram.java @@ -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); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java b/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java index 2a2341309..e18aa76cf 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/PMap.java @@ -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); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java b/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java index 7f10612b3..c4e7b5c7b 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/PStack.java @@ -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 diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java b/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java index eb0cc88d1..bbb0b081b 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/StackTrace.java @@ -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; diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java b/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java index d601fef44..014655740 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/SysPropsDumper.java @@ -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); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java b/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java index 3021801c9..19cfb349d 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java @@ -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) { 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 @@ 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. diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java index afd7f9865..98300c1d6 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ClassDump.java @@ -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); } } diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java index 09874af17..db6dc3393 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/JSDB.java @@ -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() { diff --git a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java index b3054b90b..67f5ed1e9 100644 --- a/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java +++ b/agent/src/share/classes/sun/jvm/hotspot/tools/soql/SOQL.java @@ -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() { -- GitLab