< prev index next >
application/org.openjdk.jmc.rjmx/src/main/java/org/openjdk/jmc/rjmx/services/internal/HotSpot23CommercialFeaturesService.java
Print this page
*** 33,69 ****
--- 33,80 ----
package org.openjdk.jmc.rjmx.services.internal;
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 JFR2_MBEAN_OBJECT_NAME_OLD = "jdk.jfr.management:type=FlightRecorder"; //$NON-NLS-1$
+ private final static String JFR2_MBEAN_OBJECT_NAME = "jdk.management.jfr:type=FlightRecorder"; //$NON-NLS-1$
public HotSpot23CommercialFeaturesService(IConnectionHandle handle)
throws ConnectionException, ServiceNotAvailableException {
server = handle.getServiceOrThrow(MBeanServerConnection.class);
dcs = handle.getServiceOrNull(IDiagnosticCommandService.class);
try {
HotspotManagementToolkit.getVMOption(server, VM_FLAG); // Will fail if option is not available
} catch (Exception e) {
+ // JDK11 and above Commercial Feature option is not available but Flighter Recorder is.
+ if (!isJfrMBeanAvailable()) {
throw new ServiceNotAvailableException(""); //$NON-NLS-1$
}
}
+ }
@Override
public boolean isCommercialFeaturesEnabled() {
try {
return ((String) HotspotManagementToolkit.getVMOption(server, VM_FLAG)).contains("true"); //$NON-NLS-1$
} catch (Exception e) {
+ // JDK11 and above Commercial Feature option is not available but Flighter Recorder is.
+ if (isJfrMBeanAvailable()) {
+ return true;
+ }
return false;
}
}
@Override
*** 73,78 ****
--- 84,112 ----
}
if (!isCommercialFeaturesEnabled()) {
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 {
+ //FlightRecorder MXBean name JDK10 and later.
+ try {
+ ObjectName candidate2ObjectName = ConnectionToolkit.createObjectName(JFR2_MBEAN_OBJECT_NAME);
+ server.getMBeanInfo(candidate2ObjectName);
+ return candidate2ObjectName;
+ } catch (Exception e) {
+ }
+ //FlightRecorder MXBean name JDK9.
+ ObjectName candidate1ObjectName = ConnectionToolkit.createObjectName(JFR2_MBEAN_OBJECT_NAME_OLD);
+ server.getMBeanInfo(candidate1ObjectName);
+ return candidate1ObjectName;
+ }
}
< prev index next >