changeset 12:1f3b4692160c

JMC-5893: Commercial features check removed in JDK 11 Reviewed-by: klward, egahlin
author sballal
date Thu, 21 Jun 2018 09:50:10 +0530
parents f0d01d20dcd1
children ee529752f619
files application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/version/JavaVersionSupport.java
diffstat 3 files changed, 36 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java	Tue Jun 12 17:24:11 2018 +0200
+++ b/application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java	Thu Jun 21 09:50:10 2018 +0530
@@ -93,6 +93,7 @@
 	private final ICommercialFeaturesService cfs;
 	private final IMBeanHelperService mbhs;
 	private final String serverId;
+	private final IConnectionHandle connection;
 
 	@Override
 	public String getVersion() {
@@ -104,11 +105,16 @@
 				&& ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.DYNAMIC_JFR_SUPPORTED);
 	}
 
+	private boolean isFlightRecorderCommercial() {
+		return ConnectionToolkit.isHotSpot(connection)
+				&& !ConnectionToolkit.isJavaVersionAboveOrEqual(connection, JavaVersionSupport.JFR_NOT_COMMERCIAL);
+	}
+
 	private boolean isFlightRecorderDisabled(IConnectionHandle handle) {
-		if (cfs != null) {
+		if (cfs != null && isFlightRecorderCommercial()) {
 			return !cfs.isCommercialFeaturesEnabled() || JVMSupportToolkit.isFlightRecorderDisabled(handle, false);
 		} else {
-			return true;
+			return JVMSupportToolkit.isFlightRecorderDisabled(handle, false);
 		}
 	}
 
@@ -124,6 +130,7 @@
 		if (JVMSupportToolkit.isFlightRecorderDisabled(handle, true)) {
 			throw new ServiceNotAvailableException(""); //$NON-NLS-1$
 		}
+		connection = handle;
 		helper = new FlightRecorderCommunicationHelperV2(handle.getServiceOrThrow(MBeanServerConnection.class));
 		mbhs = handle.getServiceOrThrow(IMBeanHelperService.class);
 		serverId = handle.getServerDescriptor().getGUID();
@@ -470,7 +477,9 @@
 
 	@Override
 	public boolean isEnabled() {
-		return cfs.isCommercialFeaturesEnabled();
+		return isFlightRecorderCommercial()
+				? cfs.isCommercialFeaturesEnabled()
+				: isAvailable(connection);
 	}
 
 	@Override
--- a/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java	Tue Jun 12 17:24:11 2018 +0200
+++ b/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java	Thu Jun 21 09:50:10 2018 +0530
@@ -35,16 +35,19 @@
 import javax.management.MBeanServerConnection;
 
 import org.openjdk.jmc.rjmx.ConnectionException;
+import org.openjdk.jmc.rjmx.ConnectionToolkit;
 import org.openjdk.jmc.rjmx.IConnectionHandle;
 import org.openjdk.jmc.rjmx.ServiceNotAvailableException;
 import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService;
 import org.openjdk.jmc.rjmx.services.IDiagnosticCommandService;
+import javax.management.ObjectName;
 
 public class HotSpot23CommercialFeaturesService implements ICommercialFeaturesService {
 	private final static String VM_FLAG = "UnlockCommercialFeatures"; //$NON-NLS-1$
 	private final static String UNLOCK_COMMAND = "VM.unlock_commercial_features"; //$NON-NLS-1$
 	private final MBeanServerConnection server;
 	private final IDiagnosticCommandService dcs;
+	private final static String JDK_MANAGEMENT_JFR_MBEAN_NAME = "jdk.management.jfr:type=FlightRecorder"; //$NON-NLS-1$
 
 	public HotSpot23CommercialFeaturesService(IConnectionHandle handle)
 			throws ConnectionException, ServiceNotAvailableException {
@@ -53,7 +56,10 @@
 		try {
 			HotspotManagementToolkit.getVMOption(server, VM_FLAG); // Will fail if option is not available
 		} catch (Exception e) {
-			throw new ServiceNotAvailableException(""); //$NON-NLS-1$
+			// Commercial Feature option is not available but Flight Recorder is.
+			if (!isJfrMBeanAvailable()) {
+				throw new ServiceNotAvailableException(""); //$NON-NLS-1$
+			}
 		}
 	}
 
@@ -75,4 +81,19 @@
 			HotspotManagementToolkit.setVMOption(server, VM_FLAG, "true"); //$NON-NLS-1$
 		}
 	}
+
+	private boolean isJfrMBeanAvailable() {
+		try {
+			getJfrMBeanObjectName();
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+	private ObjectName getJfrMBeanObjectName() throws Exception {
+		ObjectName candidateObjectName = ConnectionToolkit.createObjectName(JDK_MANAGEMENT_JFR_MBEAN_NAME);
+		server.getMBeanInfo(candidateObjectName);
+		return candidateObjectName;
+	}
 }
--- a/core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/version/JavaVersionSupport.java	Tue Jun 12 17:24:11 2018 +0200
+++ b/core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/version/JavaVersionSupport.java	Thu Jun 21 09:50:10 2018 +0530
@@ -60,5 +60,7 @@
 	public static final JavaVersion DEBUG_NON_SAFEPOINTS_IMPLICITLY_ENABLED = JDK_9;
 	// FIXME: Update this if JDK-8054307 is ever backported to 8uX.
 	public static final JavaVersion STRING_IS_BYTE_ARRAY = JDK_9;
+	public static final JavaVersion JDK_11_EA = new JavaVersion(true, 11);
+	public static final JavaVersion JFR_NOT_COMMERCIAL = JDK_11_EA;
 
 }