Mercurial > hg > graal-compiler
diff agent/src/share/classes/sun/jvm/hotspot/tools/Tool.java @ 12932:7fe6ef09d242
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
author | farvidsson |
---|---|
date | Wed, 16 Oct 2013 09:20:23 +0200 |
parents | 38ea2efa32a7 |
children | 5280822ddfcd |
line wrap: on
line diff
--- 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) { <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 @@ 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.