--- a/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Thu Feb 07 09:55:57 2019 +0100
+++ b/src/jdk.jcmd/share/classes/sun/tools/common/ProcessArgumentMatcher.java Fri Feb 08 09:41:45 2019 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2019, 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
@@ -78,25 +78,40 @@
}
private static boolean check(VirtualMachineDescriptor vmd, String excludeClass, String partialMatch) {
+
String mainClass = null;
- try {
- VmIdentifier vmId = new VmIdentifier(vmd.id());
- MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
- MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
- mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
- monitoredHost.detach(monitoredVm);
- } catch (NullPointerException npe) {
- // There is a potential race, where a running java app is being
- // queried, unfortunately the java app has shutdown after this
- // method is started but before getMonitoredVM is called.
- // If this is the case, then the /tmp/hsperfdata_xxx/pid file
- // will have disappeared and we will get a NullPointerException.
- // Handle this gracefully....
- return false;
- } catch (MonitorException | URISyntaxException e) {
- return false;
+
+ // Get the main class name using platform specific helper
+ ProcessHelper helper = ProcessHelper.platformProcessHelper();
+ if (helper != null) {
+ mainClass = helper.getMainClass(vmd.id());
+ if (mainClass == null) {
+ return false;
+ }
}
+ // If the main class name is still unset then retrieve it with the attach mechanism
+ if (mainClass == null) {
+ try {
+ VmIdentifier vmId = new VmIdentifier(vmd.id());
+ MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(vmId);
+ MonitoredVm monitoredVm = monitoredHost.getMonitoredVm(vmId, -1);
+ mainClass = MonitoredVmUtil.mainClass(monitoredVm, true);
+ monitoredHost.detach(monitoredVm);
+ } catch (NullPointerException npe) {
+ // There is a potential race, where a running java app is being
+ // queried, unfortunately the java app has shutdown after this
+ // method is started but before getMonitoredVM is called.
+ // If this is the case, then the /tmp/hsperfdata_xxx/pid file
+ // will have disappeared and we will get a NullPointerException.
+ // Handle this gracefully....
+ return false;
+ } catch (MonitorException | URISyntaxException e) {
+ return false;
+ }
+ }
+
+
if (excludeClass != null && mainClass.equals(excludeClass)) {
return false;
}