changeset 238:63ec7d0ee8d9 tip

JMC-6822: JMC is asking to unlock Commercial Features on JFR enabled OpenJDK8 Reviewed-by: hirt
author aptmac <almacdon@redhat.com>
date Mon, 08 Jun 2020 12:37:07 -0400
parents 399deb5ae377
children
files application/org.openjdk.jmc.browser.attach/src/main/java/org/openjdk/jmc/browser/attach/LocalJVMToolkit.java application/org.openjdk.jmc.browser.jdp/src/main/java/org/openjdk/jmc/browser/jdp/JDPDescriptorProvider.java application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java application/org.openjdk.jmc.rjmx/src/main/resources/org/openjdk/jmc/rjmx/messages/internal/messages.properties application/org.openjdk.jmc.ui.common/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java application/tests/org.openjdk.jmc.rjmx.test/src/test/java/org/openjdk/jmc/rjmx/test/JVMSupportToolkitTest.java
diffstat 8 files changed, 72 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/application/org.openjdk.jmc.browser.attach/src/main/java/org/openjdk/jmc/browser/attach/LocalJVMToolkit.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.browser.attach/src/main/java/org/openjdk/jmc/browser/attach/LocalJVMToolkit.java	Mon Jun 08 12:37:07 2020 -0400
@@ -199,6 +199,7 @@
 					String address = null;
 					String version = null;
 					String jvmArgs = null;
+					String jvmName = null;
 					String jvmVendor = null;
 
 					try {
@@ -210,6 +211,7 @@
 							jvmArgs = MonitoredVmUtil.jvmArgs(mvm);
 							StringMonitor sm = (StringMonitor) mvm.findByName("java.property.java.vm.name"); //$NON-NLS-1$
 							if (sm != null) {
+								jvmName = sm.stringValue();
 								type = getJVMType(sm.stringValue());
 							}
 
@@ -268,7 +270,7 @@
 					} catch (Exception x) {
 						// ignore
 					}
-					connDesc = createDescriptor(name, jvmArgs, jvmVendor, vmid, connectable, type, jvmArch, address, version, isDebug);
+					connDesc = createDescriptor(name, jvmArgs, jvmName, jvmVendor, vmid, connectable, type, jvmArch, address, version, isDebug);
 					return connDesc;
 				}
 			});
@@ -367,6 +369,7 @@
 					String javaArgs = null;
 					String jvmArgs = null;
 					String jvmVersion = null;
+					String jvmName = null;
 					String jvmVendor = null;
 					VirtualMachine vm = null;
 					try {
@@ -384,8 +387,8 @@
 											+ vmd + ": " + e.getMessage()); //$NON-NLS-1$
 						}
 						if (props != null) {
-							String vmName = props.getProperty("java.vm.name"); //$NON-NLS-1$
-							jvmType = getJVMType(vmName);
+							jvmName = props.getProperty("java.vm.name"); //$NON-NLS-1$
+							jvmType = getJVMType(jvmName);
 							version = props.getProperty("java.version"); //$NON-NLS-1$
 							jvmVersion = props.getProperty("java.vm.version"); //$NON-NLS-1$
 							jvmVendor = props.getProperty("java.vm.vendor");
@@ -406,7 +409,7 @@
 						}
 					}
 					if (connectable.isAttachable()) {
-						connDesc = createDescriptor(javaArgs, jvmArgs, jvmVendor, Integer.parseInt(vmd.id()), connectable, jvmType, jvmArch,
+						connDesc = createDescriptor(javaArgs, jvmArgs, jvmName, jvmVendor, Integer.parseInt(vmd.id()), connectable, jvmType, jvmArch,
 								address, version, isDebug);
 					}
 					BrowserAttachPlugin.getPluginLogger().info("Done resolving PID " + vmd); //$NON-NLS-1$
@@ -471,10 +474,10 @@
 	}
 
 	private static DiscoveryEntry createDescriptor(
-		String javaCommand, String jvmArgs, String jvmVendor, int pid, Connectable connectable, JVMType type,
-		JVMArch arch, String address, String version, boolean isDebug) {
-		JVMDescriptor jvmInfo = new JVMDescriptor(version, type, arch, javaCommand, jvmArgs, jvmVendor, pid, isDebug,
-				connectable);
+		String javaCommand, String jvmArgs, String jvmName, String jvmVendor, int pid, Connectable connectable,
+		JVMType type, JVMArch arch, String address, String version, boolean isDebug) {
+		JVMDescriptor jvmInfo = new JVMDescriptor(version, type, arch, javaCommand, jvmArgs, jvmName, jvmVendor, pid,
+				isDebug, connectable);
 		LocalConnectionDescriptor lcd = new LocalConnectionDescriptor(pid, address, connectable == ATTACHABLE);
 		String guid = "Local-[PID:" + pid + ", seq:" + (SEQ_NUMBER++) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		IServerDescriptor sd = IServerDescriptor.create(guid, null, jvmInfo);
--- a/application/org.openjdk.jmc.browser.jdp/src/main/java/org/openjdk/jmc/browser/jdp/JDPDescriptorProvider.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.browser.jdp/src/main/java/org/openjdk/jmc/browser/jdp/JDPDescriptorProvider.java	Mon Jun 08 12:37:07 2020 -0400
@@ -91,7 +91,7 @@
 				String pid = map.get(JMXDataKeys.KEY_PID);
 				// NOTE: We would like to have the JVM type, architecture and vendor included in the JDP payload. We should probably file an enhancement request on JDK for this.
 				JVMDescriptor jvmInfo = new JVMDescriptor(null, JVMType.UNKNOWN, JVMArch.UNKNOWN, commandLine, null,
-						null, pid == null ? null : Integer.parseInt(pid), false, Connectable.MGMNT_AGENT_STARTED);
+						null, null, pid == null ? null : Integer.parseInt(pid), false, Connectable.MGMNT_AGENT_STARTED);
 				String path = null;
 				if (name == null) {
 				} else if (name.endsWith(PATH_SEPARATOR)) {
--- a/application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV1.java	Mon Jun 08 12:37:07 2020 -0400
@@ -131,6 +131,9 @@
 
 	public FlightRecorderServiceV1(IConnectionHandle handle) throws ConnectionException, ServiceNotAvailableException {
 		cfs = handle.getServiceOrThrow(ICommercialFeaturesService.class);
+		if (!JVMSupportToolkit.hasFlightRecorder(handle)) {
+			throw new ServiceNotAvailableException(""); //$NON-NLS-1$
+		}
 		if (!isDynamicFlightRecorderSupported(handle) && isFlightRecorderDisabled(handle)) {
 			throw new ServiceNotAvailableException(""); //$NON-NLS-1$
 		}
--- a/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java	Mon Jun 08 12:37:07 2020 -0400
@@ -377,24 +377,24 @@
 	public static boolean isOracle(IConnectionHandle handle) {
 		JVMDescriptor descriptor = handle.getServerDescriptor().getJvmInfo();
 		// This should normally not happen for discovered JVMs, but users can create custom connections
-		String vendor = null;
+		String name = null;
 		if (descriptor != null) {
-			vendor = descriptor.getJvmVendor();
+			name = descriptor.getJvmName();
 		} else {
 			// We try checking if connected
 			if (handle.isConnected()) {
 				MBeanServerConnection connection = handle.getServiceOrNull(MBeanServerConnection.class);
 				if (connection != null) {
 					try {
-						vendor = getRuntimeBean(connection).getVmVendor();
+						name = getRuntimeBean(connection).getVmName();
 					} catch (IOException e) {
-						// Worst case we classify JVM vendor wrong
+						// Worst case we classify JVM name wrong
 						RJMXPlugin.getDefault().getLogger().log(Level.WARNING, "Could not check if Oracle JVM", e);
 					}
 				}
 			}
 		}
-		return vendor != null && vendor.contains("Oracle");
+		return name != null && (name.contains("Java HotSpot"));
 	}
 
 	/**
--- a/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/JVMSupportToolkit.java	Mon Jun 08 12:37:07 2020 -0400
@@ -85,6 +85,27 @@
 	}
 
 	/**
+	 * Checks if Flight Recorder is available for use
+	 * 
+	 * @param connection
+	 * @return If it is an Oracle JVM or there is a FlightRecorder VM option, then return true.
+	 *         Otherwise, return false. This is used for verifying JDK 8 JVMs that are not built
+	 *         with JFR enabled, e.g., OpenJDK 8
+	 */
+	public static boolean hasFlightRecorder(IConnectionHandle connection) {
+		if (ConnectionToolkit.isOracle(connection)) {
+			return true;
+		}
+		MBeanServerConnection server = connection.getServiceOrNull(MBeanServerConnection.class);
+		try {
+			HotspotManagementToolkit.getVMOption(server, "FlightRecorder");
+			return true;
+		} catch (Exception e) { // RuntimeMBeanException thrown if FlightRecorder is not present
+			return false;
+		}
+	}
+
+	/**
 	 * Checks if Flight Recorder is disabled.
 	 *
 	 * @param connection
--- a/application/org.openjdk.jmc.rjmx/src/main/resources/org/openjdk/jmc/rjmx/messages/internal/messages.properties	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.rjmx/src/main/resources/org/openjdk/jmc/rjmx/messages/internal/messages.properties	Mon Jun 08 12:37:07 2020 -0400
@@ -54,7 +54,7 @@
 JVMSupport_FLIGHT_RECORDER_NOT_FULLY_SUPPORTED_OLD_HOTSPOT_SHORT=Flight Recorder is not fully supported for JVMs with Java versions below 7u40
 JVMSupport_FLIGHT_RECORDER_NOT_SUPPORTED_NOT_HOTSPOT=Flight Recorder is not supported for non HotSpot JVMs
 JVMSupport_FLIGHT_RECORDER_NOT_SUPPORTED_NOT_HOTSPOT_SHORT=Flight Recorder is not supported for non HotSpot JVMs
-JVMSupport_FLIGHT_RECORDER_NOT_ENABLED=Flight Recorder features are not enabled. To enable this you need to use an Oracle JDK 7u4 or later JVM started with -XX:+UnlockCommercialFeatures -XX:+FlightRecorder or an OpenJDK 11+ JVM.
+JVMSupport_FLIGHT_RECORDER_NOT_ENABLED=Flight Recorder features are not enabled. To enable this you need to use an Oracle JDK 7u4 or later JVM started with -XX:+UnlockCommercialFeatures -XX:+FlightRecorder, an OpenJDK 8 JFR-enabled JVM, or an OpenJDK 11+ JVM.
 JVMSupport_FLIGHT_RECORDER_NOT_ENABLED_SHORT=Flight Recorder features are not enabled
 JVMSupport_FLIGHT_RECORDER_DISABLED=Flight Recorder is explicitly disabled. To enable the Flight Recorder, remove -XX:-FlightRecorder from the command line.
 JVMSupport_FLIGHT_RECORDER_DISABLED_SHORT=Flight Recorder is explicitly disabled
--- a/application/org.openjdk.jmc.ui.common/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/org.openjdk.jmc.ui.common/src/main/java/org/openjdk/jmc/ui/common/jvm/JVMDescriptor.java	Mon Jun 08 12:37:07 2020 -0400
@@ -38,6 +38,7 @@
 public class JVMDescriptor {
 	private final String javaVersion;
 	private final JVMType jvmType;
+	private final String jvmName;
 	private final String jvmVendor;
 	private final JVMArch jvmArch;
 	private final String javaCommand;
@@ -47,13 +48,14 @@
 	private final Connectable connectable;
 
 	public JVMDescriptor(String javaVersion, JVMType jvmType, JVMArch jvmArch, String javaCommand, String jvmArguments,
-			String jvmVendor, Integer pid, boolean debug, Connectable attachable) {
+			String jvmName, String jvmVendor, Integer pid, boolean debug, Connectable attachable) {
 		super();
 		this.javaVersion = javaVersion;
 		this.jvmType = jvmType;
 		this.jvmArch = jvmArch;
 		this.javaCommand = javaCommand;
 		this.jvmArguments = jvmArguments;
+		this.jvmName = jvmName;
 		this.jvmVendor = jvmVendor;
 		this.pid = pid;
 		this.debug = debug;
@@ -80,6 +82,10 @@
 		return jvmArguments;
 	}
 
+	public String getJvmName() {
+		return jvmName;
+	}
+
 	public String getJvmVendor() {
 		return jvmVendor;
 	}
--- a/application/tests/org.openjdk.jmc.rjmx.test/src/test/java/org/openjdk/jmc/rjmx/test/JVMSupportToolkitTest.java	Mon Jun 08 12:23:35 2020 -0400
+++ b/application/tests/org.openjdk.jmc.rjmx.test/src/test/java/org/openjdk/jmc/rjmx/test/JVMSupportToolkitTest.java	Mon Jun 08 12:37:07 2020 -0400
@@ -47,8 +47,10 @@
 
 @SuppressWarnings("nls")
 public class JVMSupportToolkitTest {
-	private static final String VENDOR_OPEN_JDK = "OpenJDK";
-	private static final String VENDOR_ORACLE = "Oracle";
+	private static final String NAME_OPEN_JDK = "OpenJDK 64-Bit Server VM";
+	private static final String NAME_ORACLE = "Java HotSpot(TM) 64-Bit Server VM";
+	private static final String VENDOR_OPEN_JDK = "Oracle Corporation";
+	private static final String VENDOR_ORACLE = "Oracle Corporation";
 	// FIXME: Add tests for the methods that take IConnectionHandle as a parameter.
 
 	private static final String SUPPORTED_MESSAGE = null;
@@ -65,8 +67,8 @@
 	public void testJfr17U40HotSpotSupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.7.0_40", JVMType.HOTSPOT, JVMArch.UNKNOWN, VENDOR_ORACLE, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.7.0_40", JVMType.HOTSPOT, JVMArch.UNKNOWN, null, null, NAME_ORACLE,
+								VENDOR_ORACLE, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(SUPPORTED_MESSAGE, errorMessage);
@@ -76,8 +78,8 @@
 	public void testJfr17U4HotSpotNotFullySupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.7.0_04", JVMType.HOTSPOT, JVMArch.UNKNOWN, VENDOR_ORACLE, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.7.0_04", JVMType.HOTSPOT, JVMArch.UNKNOWN, null, null, NAME_ORACLE,
+								VENDOR_ORACLE, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(Messages.JVMSupport_FLIGHT_RECORDER_NOT_FULLY_SUPPORTED_OLD_HOTSPOT, errorMessage);
@@ -87,8 +89,8 @@
 	public void testJfr17HotSpotNotSupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.7.0", JVMType.HOTSPOT, JVMArch.UNKNOWN, VENDOR_ORACLE, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.7.0", JVMType.HOTSPOT, JVMArch.UNKNOWN, null, null, NAME_ORACLE,
+								VENDOR_ORACLE, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(Messages.JVMSupport_FLIGHT_RECORDER_NOT_SUPPORTED_OLD_HOTSPOT, errorMessage);
@@ -98,8 +100,8 @@
 	public void testJfrJRockitNotSupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.6", JVMType.JROCKIT, JVMArch.UNKNOWN, VENDOR_ORACLE, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.6", JVMType.JROCKIT, JVMArch.UNKNOWN, null, null, NAME_ORACLE,
+								VENDOR_ORACLE, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(Messages.JVMSupport_JROCKIT_NO_LONGER_SUPPORTED, errorMessage);
@@ -109,8 +111,8 @@
 	public void testJfrOldHotSpotNotSupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.6", JVMType.HOTSPOT, JVMArch.UNKNOWN, VENDOR_ORACLE, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.6", JVMType.HOTSPOT, JVMArch.UNKNOWN, null, null, NAME_ORACLE,
+								VENDOR_ORACLE, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(Messages.JVMSupport_FLIGHT_RECORDER_NOT_SUPPORTED_OLD_HOTSPOT, errorMessage);
@@ -119,8 +121,9 @@
 	@Test
 	public void testJfrNonHotSpotNotSupported() {
 		ServerHandle server = new ServerHandle(
-				new ServerDescriptor(null, null, new JVMDescriptor("1.7", JVMType.OTHER, JVMArch.UNKNOWN, VENDOR_ORACLE,
-						null, null, null, false, null)),
+				new ServerDescriptor(null, null,
+						new JVMDescriptor("1.7", JVMType.OTHER, JVMArch.UNKNOWN, null, null, NAME_ORACLE, VENDOR_ORACLE,
+								null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(Messages.JVMSupport_FLIGHT_RECORDER_NOT_SUPPORTED_NOT_HOTSPOT, errorMessage);
@@ -130,8 +133,8 @@
 	public void testJfrUnknownNoWarning() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.7", JVMType.UNKNOWN, JVMArch.UNKNOWN, VENDOR_ORACLE, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.7", JVMType.UNKNOWN, JVMArch.UNKNOWN, null, null, NAME_ORACLE,
+								VENDOR_ORACLE, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(SUPPORTED_MESSAGE, errorMessage);
@@ -141,8 +144,8 @@
 	public void testJfr8HotSpotOpenJDKSupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.8.0", JVMType.HOTSPOT, JVMArch.UNKNOWN, VENDOR_OPEN_JDK, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.8.0", JVMType.HOTSPOT, JVMArch.UNKNOWN, null, null, NAME_OPEN_JDK,
+								VENDOR_OPEN_JDK, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertEquals(SUPPORTED_MESSAGE, errorMessage);
@@ -152,8 +155,8 @@
 	public void testJdk7HotSpotOpenJDKNotSupported() {
 		ServerHandle server = new ServerHandle(
 				new ServerDescriptor(null, null,
-						new JVMDescriptor("1.7.0", JVMType.HOTSPOT, JVMArch.UNKNOWN, VENDOR_OPEN_JDK, null, null, null,
-								false, null)),
+						new JVMDescriptor("1.7.0", JVMType.HOTSPOT, JVMArch.UNKNOWN, null, null, NAME_OPEN_JDK,
+								VENDOR_OPEN_JDK, null, false, null)),
 				new ConnectionDescriptorBuilder().hostName("localhost").port(0).build(), null);
 		String errorMessage = JVMSupportToolkit.checkFlightRecorderSupport(server, false);
 		assertNotNull(errorMessage);