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 eeda376b1d65d3cc57418b9e62f1db07480064d2..d2ea2db855d758b0e520b3c842cb78909dec0913 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 ed707b9ee8a424e996cabc3095259dd1f2215b2d..2a8ca2cfb7a926a2aae6b4b16403651a0a4e04ce 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 c8db6d6b044b7e04ac633e412621aa70acd94ee6..37fa4c83c262ba7ebb0324821cdf0203c6b5e770 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 c5af0ed005dae2885b5c087386489d6ee5d704ae..e2da202acb94cb31e6c09554d3058b78415e35e3 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 daab682aaef402cadb4dc251815b14e6a7ccb2d8..f87457c3c3ec442169e0cff6a504b8490a6a3c25 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 f2452420744d78f530bc5b3d3a06c84681591f85..6f9cd0f41d24b5b569b626f4ad93afba0ccb6ee3 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 f6f3c0741c04d0a45a940606da3d3468aad8376e..847eac19468290980147369c771d8d79289e211e 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 9301f1059fd3a3819003b2466d5a6f6a6b7e0c8c..c2e5ed52f846498fc2f080fc9c496538ca503f84 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 7cbe8f4d94540386dbd0cb76327c4e1c56e1779d..52fb6654e70ff6051919cce1c23c7157f7b0bb5d 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 168202eec2cef7a92e309443dd5a753e1dd61ea8..6c6c555badf4467e977bd184bf88327252c68cff 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 2a234130991cf204564c744559056617f17929b7..e18aa76cfa60d8e7fd27e1a6d9c8793028fec4e2 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 7f10612b3170fa29e814657e7841d608be04b9db..c4e7b5c7b74935934a5c56abff0579f2791281fa 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 eb0cc88d116a071177ea5e514d967f82e0db6e5e..bbb0b081b2d389ee352d6eb3c59da809283bba77 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 d601fef44010a510261395c799616d318dd9cf17..01465574006906b6de2db5f417effa5bae7ae3d0 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 3021801c9ddff28a2e36d5868b61b6d97b948a72..19cfb349da8d4c5cc90b2d3d10841ba61e3f56c9 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 afd7f9865b5fea2e8555a70689ec19d02830b498..98300c1d6c43fa0fe856ef0fb0d09c1a94e24e07 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 09874af178ef9c46a6a677fe5e24aa2c92bbdbdc..db6dc339394b092949d0b5e899b70cdb28eed918 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 b3054b90bd05ab58f90f0fb89a92ab71d47edf2a..67f5ed1e9209dc0d3ebde96ca5f292ba14deec87 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() {