Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(jmc-core): update RJMX sources #228

Merged
merged 4 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -71,7 +71,7 @@ public class DefaultConnectionHandle implements IConnectionHandle {
public DefaultConnectionHandle(RJMXConnection connection, String description, IConnectionListener[] listeners) {
this.connection = connection;
this.description = description;
this.listeners = listeners;
this.listeners = listeners == null ? new IConnectionListener[0] : listeners;
registerDefaultServices();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public interface ICommercialFeaturesService {
*/
void enableCommercialFeatures() throws Exception;

/**
* @return true if there are commercial features available, or false if this JVM doesn't have
* commercial features.
*/
boolean hasCommercialFeatures();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ICommercialFeaturesService getServiceInstance(IConnectionHandle handle)
if (descriptor != null) {
JavaVersion version = new JavaVersion(descriptor.getJavaVersion());
if (version.getMajorVersion() >= 11) {
return new Jdk11CommercialFeaturesService();
return new NoCommercialFeaturesService();
}
}
return new HotSpot23CommercialFeaturesService(handle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -43,7 +43,7 @@
import javax.management.ObjectName;

public class HotSpot23CommercialFeaturesService implements ICommercialFeaturesService {
private final static String VM_FLAG = "UnlockCommercialFeatures"; //$NON-NLS-1$
private final static String UNLOCK_COMMERCIAL_FEATURES_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;
Expand All @@ -54,7 +54,7 @@ public HotSpot23CommercialFeaturesService(IConnectionHandle handle)
server = handle.getServiceOrThrow(MBeanServerConnection.class);
dcs = handle.getServiceOrNull(IDiagnosticCommandService.class);
try {
HotspotManagementToolkit.getVMOption(server, VM_FLAG); // Will fail if option is not available
HotspotManagementToolkit.getVMOption(server, UNLOCK_COMMERCIAL_FEATURES_FLAG); // Will fail if option is not available
} catch (Exception e) {
// Commercial Feature option is not available but Flight Recorder is.
if (!isJfrMBeanAvailable()) {
Expand All @@ -66,7 +66,8 @@ public HotSpot23CommercialFeaturesService(IConnectionHandle handle)
@Override
public boolean isCommercialFeaturesEnabled() {
try {
return ((String) HotspotManagementToolkit.getVMOption(server, VM_FLAG)).contains("true"); //$NON-NLS-1$
return ((String) HotspotManagementToolkit.getVMOption(server, UNLOCK_COMMERCIAL_FEATURES_FLAG))
.contains("true"); //$NON-NLS-1$
} catch (Exception e) {
return false;
}
Expand All @@ -78,7 +79,7 @@ public void enableCommercialFeatures() throws Exception {
dcs.runCtrlBreakHandlerWithResult(UNLOCK_COMMAND);
}
if (!isCommercialFeaturesEnabled()) {
HotspotManagementToolkit.setVMOption(server, VM_FLAG, "true"); //$NON-NLS-1$
HotspotManagementToolkit.setVMOption(server, UNLOCK_COMMERCIAL_FEATURES_FLAG, "true"); //$NON-NLS-1$
}
}

Expand All @@ -96,4 +97,9 @@ private ObjectName getJfrMBeanObjectName() throws Exception {
server.getMBeanInfo(candidateObjectName);
return candidateObjectName;
}
}

@Override
public boolean hasCommercialFeatures() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -34,8 +34,11 @@

import org.openjdk.jmc.rjmx.services.ICommercialFeaturesService;

public class Jdk11CommercialFeaturesService implements ICommercialFeaturesService {

/**
* Used by JVMs with no commercial features, e.g. OpenJDK 8 and JDK 11+ JVMs.
*/
public class NoCommercialFeaturesService implements ICommercialFeaturesService {

@Override
public boolean isCommercialFeaturesEnabled() {
return true;
Expand All @@ -45,4 +48,9 @@ public boolean isCommercialFeaturesEnabled() {
public void enableCommercialFeatures() throws Exception {
// Noop
}
}

@Override
public boolean hasCommercialFeatures() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -103,17 +103,22 @@ public String getVersion() {
}

private boolean isDynamicFlightRecorderSupported(IConnectionHandle handle) {
return ConnectionToolkit.isHotSpot(handle)
&& ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.DYNAMIC_JFR_SUPPORTED);
}
// All OpenJDK versions of JFR support dynamic enablement of JFR, so if there are no commercial features in play
andrewazores marked this conversation as resolved.
Show resolved Hide resolved
// 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);
}

private boolean isFlightRecorderCommercial() {
return ConnectionToolkit.isHotSpot(connection)
&& !ConnectionToolkit.isJavaVersionAboveOrEqual(connection, JavaVersionSupport.JFR_NOT_COMMERCIAL);
return !cfs.hasCommercialFeatures() || (ConnectionToolkit.isHotSpot(handle)
&& ConnectionToolkit.isJavaVersionAboveOrEqual(handle, JavaVersionSupport.DYNAMIC_JFR_SUPPORTED));
}

private boolean isFlightRecorderDisabled(IConnectionHandle handle) {
if (cfs != null && isFlightRecorderCommercial()) {
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 @@ -126,10 +131,11 @@ public static boolean isAvailable(IConnectionHandle handle) {

public FlightRecorderServiceV2(IConnectionHandle handle) throws ConnectionException, ServiceNotAvailableException {
cfs = handle.getServiceOrThrow(ICommercialFeaturesService.class);

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 Expand Up @@ -480,7 +486,7 @@ public InputStream openStream(IRecordingDescriptor descriptor, IQuantity lastPar
@Override
public boolean isEnabled() {
if (!wasEnabled) {
boolean isEnabled = isFlightRecorderCommercial() ? cfs.isCommercialFeaturesEnabled()
boolean isEnabled = cfs.hasCommercialFeatures() ? cfs.isCommercialFeaturesEnabled()
: isAvailable(connection);
if (isEnabled) {
wasEnabled = true;
Expand Down