--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SAGetopt.java Thu Apr 07 22:03:04 2016 -0700
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SAGetopt.java Wed Apr 06 20:43:03 2016 +0900
@@ -55,11 +55,11 @@
private void extractOptarg(String opt) {
// Argument expected
if (_optind > _argv.length) {
- throw new RuntimeException("Not enough arguments for '" + opt + "'");
+ throw new SAGetoptException("Not enough arguments for '" + opt + "'");
}
if (! _argv[_optind].isEmpty() && _argv[_optind].charAt(0) == '-') {
- throw new RuntimeException("Argument is expected for '" + opt + "'");
+ throw new SAGetoptException("Argument is expected for '" + opt + "'");
}
_optarg = _argv[_optind];
@@ -72,7 +72,7 @@
if (los.contains(ca[0])) {
if (ca.length > 1) {
- throw new RuntimeException("Argument is not expected for '" + ca[0] + "'");
+ throw new SAGetoptException("Argument is not expected for '" + ca[0] + "'");
}
return carg;
}
@@ -87,14 +87,14 @@
try {
extractOptarg(ca[0]);
} catch (ArrayIndexOutOfBoundsException e) {
- throw new RuntimeException("Argument is expected for '" + ca[0] + "'");
+ throw new SAGetoptException("Argument is expected for '" + ca[0] + "'");
}
}
return ca[0];
}
- throw new RuntimeException("Invalid option '" + ca[0] + "'");
+ throw new SAGetoptException("Invalid option '" + ca[0] + "'");
}
public String next(String optStr, String[] longOptStr) {
@@ -148,7 +148,7 @@
int chIndex = optStr.indexOf(ch);
if (chIndex == -1) {
- throw new RuntimeException("Invalid option '" + ch + "'");
+ throw new SAGetoptException("Invalid option '" + ch + "'");
}
if (_optopt >= carg.length()) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SAGetoptException.java Wed Apr 06 20:43:03 2016 +0900
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+package sun.jvm.hotspot;
+
+public class SAGetoptException extends IllegalArgumentException {
+
+ public SAGetoptException(String message) {
+ super(message);
+ }
+
+}
--- a/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncher.java Thu Apr 07 22:03:04 2016 -0700
+++ b/hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/SALauncher.java Wed Apr 06 20:43:03 2016 +0900
@@ -111,34 +111,31 @@
return launcherHelp();
}
- private static void buildAttachArgs(ArrayList<String> newArgs,
- String pid, String exe, String core) {
- if ((pid == null) && (exe == null)) {
- throw new IllegalArgumentException(
- "You have to set --pid or --exe.");
+ private static void buildAttachArgs(ArrayList<String> newArgs, String pid,
+ String exe, String core, boolean allowEmpty) {
+ if (!allowEmpty && (pid == null) && (exe == null)) {
+ throw new SAGetoptException("You have to set --pid or --exe.");
}
if (pid != null) { // Attach to live process
if (exe != null) {
- throw new IllegalArgumentException(
- "Unnecessary argument: --exe");
+ throw new SAGetoptException("Unnecessary argument: --exe");
} else if (core != null) {
- throw new IllegalArgumentException(
- "Unnecessary argument: --core");
+ throw new SAGetoptException("Unnecessary argument: --core");
} else if (!pid.matches("^\\d+$")) {
- throw new IllegalArgumentException("Invalid pid: " + pid);
+ throw new SAGetoptException("Invalid pid: " + pid);
}
newArgs.add(pid);
- } else {
+ } else if (exe != null) {
if (exe.length() == 0) {
- throw new IllegalArgumentException("You have to set --exe.");
+ throw new SAGetoptException("You have to set --exe.");
}
newArgs.add(exe);
if ((core == null) || (core.length() == 0)) {
- throw new IllegalArgumentException("You have to set --core.");
+ throw new SAGetoptException("You have to set --core.");
}
newArgs.add(core);
@@ -170,7 +167,7 @@
}
}
- buildAttachArgs(newArgs, pid, exe, core);
+ buildAttachArgs(newArgs, pid, exe, core, true);
CLHSDB.main(newArgs.toArray(new String[newArgs.size()]));
}
@@ -199,7 +196,7 @@
}
}
- buildAttachArgs(newArgs, pid, exe, core);
+ buildAttachArgs(newArgs, pid, exe, core, true);
HSDB.main(newArgs.toArray(new String[newArgs.size()]));
}
@@ -237,7 +234,7 @@
}
}
- buildAttachArgs(newArgs, pid, exe, core);
+ buildAttachArgs(newArgs, pid, exe, core, false);
JStack.main(newArgs.toArray(new String[newArgs.size()]));
}
@@ -287,7 +284,7 @@
}
}
- buildAttachArgs(newArgs, pid, exe, core);
+ buildAttachArgs(newArgs, pid, exe, core, false);
JMap.main(newArgs.toArray(new String[newArgs.size()]));
}
@@ -325,7 +322,7 @@
}
}
- buildAttachArgs(newArgs, pid, exe, core);
+ buildAttachArgs(newArgs, pid, exe, core, false);
JInfo.main(newArgs.toArray(new String[newArgs.size()]));
}
@@ -358,7 +355,7 @@
}
}
- buildAttachArgs(newArgs, pid, exe, core);
+ buildAttachArgs(newArgs, pid, exe, core, false);
JSnap.main(newArgs.toArray(new String[newArgs.size()]));
}
@@ -416,8 +413,8 @@
return;
}
- throw new IllegalArgumentException("Unknown tool: " + args[0]);
- } catch (Exception e) {
+ throw new SAGetoptException("Unknown tool: " + args[0]);
+ } catch (SAGetoptException e) {
System.err.println(e.getMessage());
toolHelp(args[0]);
}