--- old/application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java 2018-06-04 11:28:50.805029300 +0530 +++ new/application/org.openjdk.jmc.rjmx.services.jfr/src/main/java/org/openjdk/jmc/rjmx/services/jfr/internal/FlightRecorderServiceV2.java 2018-06-04 11:28:49.816331600 +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 --- old/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java 2018-06-04 11:28:58.456059200 +0530 +++ new/application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java 2018-06-04 11:28:57.472362500 +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 Flighter 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; + } } --- old/core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/version/JavaVersionSupport.java 2018-06-04 11:29:05.698507400 +0530 +++ new/core/org.openjdk.jmc.common/src/main/java/org/openjdk/jmc/common/version/JavaVersionSupport.java 2018-06-04 11:29:04.724312600 +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 = new JavaVersion(11); + public static final JavaVersion JFR_NOT_COMMERCIAL = JDK_11; }