8176533: REGRESSION: a java process is not recognized by jcmd/jinfo/jstack/jmap tool
Reviewed-by: sspitsyn, dsamersoff
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Tue Mar 14 12:00:03 2017 +0100
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Thu Mar 16 07:27:14 2017 +0100
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.stream.Collectors;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
@@ -145,4 +146,17 @@
return this.getVirtualMachineDescriptors(null);
}
+ public Collection<String> getVirtualMachinePids(Class<?> excludeClass) {
+ if (singlePid != null) {
+ // There is a bug in AttachProvider, when VM is debuggee-suspended it's not listed by the AttachProvider.
+ // If we are talking about a specific pid, just return it.
+ return List.of(singlePid);
+ } else {
+ return getVMDs(excludeClass, matchClass).stream().map(x -> {return x.id();}).collect(Collectors.toList());
+ }
+ }
+
+ public Collection<String> getVirtualMachinePids() {
+ return this.getVirtualMachinePids(null);
+ }
}
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jcmd/JCmd.java Tue Mar 14 12:00:03 2017 +0100
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jcmd/JCmd.java Thu Mar 16 07:27:14 2017 +0100
@@ -80,22 +80,22 @@
System.exit(0);
}
- Collection<VirtualMachineDescriptor> vids = ap.getVirtualMachineDescriptors(JCmd.class);
+ Collection<String> pids = ap.getVirtualMachinePids(JCmd.class);
- if (vids.isEmpty()) {
+ if (pids.isEmpty()) {
System.err.println("Could not find any processes matching : '"
+ arg.getProcessString() + "'");
System.exit(1);
}
boolean success = true;
- for (VirtualMachineDescriptor vid : vids) {
- System.out.println(vid.id() + ":");
+ for (String pid : pids) {
+ System.out.println(pid + ":");
if (arg.isListCounters()) {
- listCounters(vid.id());
+ listCounters(pid);
} else {
try {
- executeCommandForPid(vid.id(), arg.getCommand());
+ executeCommandForPid(pid, arg.getCommand());
} catch(AttachOperationFailedException ex) {
System.err.println(ex.getMessage());
success = false;
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java Tue Mar 14 12:00:03 2017 +0100
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jinfo/JInfo.java Thu Mar 16 07:27:14 2017 +0100
@@ -96,37 +96,37 @@
String parg = args[optionCount];
ProcessArgumentMatcher ap = new ProcessArgumentMatcher(parg);
- Collection<VirtualMachineDescriptor> vids = ap.getVirtualMachineDescriptors(JInfo.class);
+ Collection<String> pids = ap.getVirtualMachinePids(JInfo.class);
- if (vids.isEmpty()) {
+ if (pids.isEmpty()) {
System.err.println("Could not find any processes matching : '" + parg + "'");
System.exit(1);
}
- for (VirtualMachineDescriptor vid : vids) {
- if (vids.size() > 1) {
- System.out.println("Pid:" + vid.id());
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
}
if (!doFlag && !doFlags && !doSysprops) {
// Print flags and sysporps if no options given
- sysprops(vid.id());
+ sysprops(pid);
System.out.println();
- flags(vid.id());
+ flags(pid);
System.out.println();
- commandLine(vid.id());
+ commandLine(pid);
}
if (doFlag) {
if (flag < 0) {
System.err.println("Missing flag");
usage(1);
}
- flag(vid.id(), args[flag]);
+ flag(pid, args[flag]);
}
if (doFlags) {
- flags(vid.id());
+ flags(pid);
}
if (doSysprops) {
- sysprops(vid.id());
+ sysprops(pid);
}
}
}
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java Tue Mar 14 12:00:03 2017 +0100
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jmap/JMap.java Thu Mar 16 07:27:14 2017 +0100
@@ -91,16 +91,15 @@
// As more options are added we should create an abstract tool class and
// have a table to map the options
ProcessArgumentMatcher ap = new ProcessArgumentMatcher(pidArg);
- Collection<VirtualMachineDescriptor> vids = ap.getVirtualMachineDescriptors(JMap.class);
+ Collection<String> pids = ap.getVirtualMachinePids(JMap.class);
- if (vids.isEmpty()) {
+ if (pids.isEmpty()) {
System.err.println("Could not find any processes matching : '" + pidArg + "'");
System.exit(1);
}
- for (VirtualMachineDescriptor vid : vids) {
- String pid = vid.id();
- if (vids.size() > 1) {
+ for (String pid : pids) {
+ if (pids.size() > 1) {
System.out.println("Pid:" + pid);
}
if (option.equals("-histo")) {
--- a/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java Tue Mar 14 12:00:03 2017 +0100
+++ b/jdk/src/jdk.jcmd/share/classes/sun/tools/jstack/JStack.java Thu Mar 16 07:27:14 2017 +0100
@@ -84,18 +84,18 @@
params = new String[0];
}
ProcessArgumentMatcher ap = new ProcessArgumentMatcher(pidArg);
- Collection<VirtualMachineDescriptor> vids = ap.getVirtualMachineDescriptors(JStack.class);
+ Collection<String> pids = ap.getVirtualMachinePids(JStack.class);
- if (vids.isEmpty()) {
+ if (pids.isEmpty()) {
System.err.println("Could not find any processes matching : '" + pidArg + "'");
System.exit(1);
}
- for (VirtualMachineDescriptor vid : vids) {
- if (vids.size() > 1) {
- System.out.println("Pid:" + vid.id());
+ for (String pid : pids) {
+ if (pids.size() > 1) {
+ System.out.println("Pid:" + pid);
}
- runThreadDump(vid.id(), params);
+ runThreadDump(pid, params);
}
}