Skip to content

Commit

Permalink
feat(jmx): check for SubstrateVM and whether JFR is available
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Toyonaga <rtoyonag@redhat.com>
  • Loading branch information
andrewazores and roberttoyonaga committed Jun 7, 2023
1 parent 9ee6c7d commit 35e963c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/openjdk/jmc/rjmx/ConnectionToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ public static boolean isHotSpot(IConnectionHandle connectionHandle) {
return vmName != null && JavaVMVersionToolkit.isHotspotJVMName(vmName);
}

public static boolean isSubstrateVm(IConnectionHandle connectionHandle) {
return getVMName(connectionHandle).equals("Substrate VM");
}
/**
* Returns {@code true} if the connection handle is associated with an Oracle built JVM,
* {@code false} otherwise. If the information is already present in the {@link JVMDescriptor},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ public String getVersion() {
private boolean isDynamicFlightRecorderSupported(IConnectionHandle handle) {
// All OpenJDK versions of JFR support dynamic enablement of JFR, so if there are no commercial features in play
// all is A-OK.
if (ConnectionToolkit.isSubstrateVm(handle)){
// JFR may not have been built into the native image. Check that FlightRecorderMXBean is accessible from the MBean server.
return isAvailable(handle);
}

return !cfs.hasCommercialFeatures() || (ConnectionToolkit.isHotSpot(handle)
&& ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.DYNAMIC_JFR_SUPPORTED));
}

private boolean isFlightRecorderDisabled(IConnectionHandle handle) {
if (cfs != null && cfs.hasCommercialFeatures()) {
if (ConnectionToolkit.isSubstrateVm(handle)){
// For SVM commercial features may be available but disabled and JFR is still enabled
return !isAvailable(handle);
} else if (cfs != null && cfs.hasCommercialFeatures()) {
return !cfs.isCommercialFeaturesEnabled() || JVMSupportToolkit.isFlightRecorderDisabled(handle, false);
} else {
return JVMSupportToolkit.isFlightRecorderDisabled(handle, false);
Expand All @@ -127,7 +135,7 @@ public FlightRecorderServiceV2(IConnectionHandle handle) throws ConnectionExcept
if (!isDynamicFlightRecorderSupported(handle) && isFlightRecorderDisabled(handle)) {
throw new ServiceNotAvailableException(""); //$NON-NLS-1$
}
if (JVMSupportToolkit.isFlightRecorderDisabled(handle, true)) {
if (!ConnectionToolkit.isSubstrateVm(handle) && JVMSupportToolkit.isFlightRecorderDisabled(handle, true)) {
throw new ServiceNotAvailableException(""); //$NON-NLS-1$
}
connection = handle;
Expand Down

0 comments on commit 35e963c

Please sign in to comment.