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

Support HotSpotDiagnosticMXBean in OpenJ9 JDK21+ #17709

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,6 @@ static void registerAll() {
.addInterface(com.ibm.lang.management.JvmCpuMonitorMXBean.class)
.validateAndRegister();

create(OPENJ9_DIAGNOSTICS_MXBEAN_NAME, openj9.lang.management.internal.OpenJ9DiagnosticsMXBeanImpl.getInstance())
.addInterface(openj9.lang.management.OpenJ9DiagnosticsMXBean.class)
.validateAndRegister();
Comment on lines -773 to -775
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help me understand why this was removed. This code is specific to Java 8 where there's no possibility that OpenJ9DiagnosticsMXBeanImpl.getInstance() might return null (even though the code would properly handle that situation). Why do we no longer want this bean to be registered?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, I missed it was specific to 8 (and we didn't test 8). So we need to add it back and add the HotspotBean there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #17726 to readd the registration calls.


// register standard optional beans
create(ManagementFactory.COMPILATION_MXBEAN_NAME, CompilationMXBeanImpl.getInstance())
.addInterface(java.lang.management.CompilationMXBean.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import openj9.lang.management.OpenJ9DiagnosticsMXBean;
import openj9.lang.management.internal.OpenJ9DiagnosticsMXBeanImpl;

/*[IF JAVA_SPEC_VERSION >= 21]*/
import com.sun.management.internal.ExtendedHotSpotDiagnostic;
import com.sun.management.HotSpotDiagnosticMXBean;
/*[ENDIF] JAVA_SPEC_VERSION >= 21 */

/**
* This class implements the service-provider interface to make OpenJ9-specific
* MXBeans available. These beans are either in addition to the basic set or
Expand Down Expand Up @@ -101,6 +106,12 @@ public final class PlatformMBeanProvider extends sun.management.spi.PlatformMBea
.register(allComponents);
}

/*[IF JAVA_SPEC_VERSION >= 21]*/
ComponentBuilder.create("com.sun.management:type=HotSpotDiagnostic", ExtendedHotSpotDiagnostic.getInstance()) //$NON-NLS-1$
.addInterface(HotSpotDiagnosticMXBean.class)
.register(allComponents);
/*[ENDIF] JAVA_SPEC_VERSION >= 21 */

// register beans with zero or more instances

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*[INCLUDE-IF JAVA_SPEC_VERSION >= 21]*/
/*******************************************************************************
* Copyright IBM Corp. and others 2023
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] https://openjdk.org/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/

package com.sun.management.internal;

import java.io.IOException;
import java.util.List;
import java.util.Collections;
import com.sun.management.VMOption;
import com.sun.management.HotSpotDiagnosticMXBean;
import com.sun.management.internal.HotSpotDiagnostic;

/**
* Runtime type for {@link com.sun.management.HotSpotDiagnosticMXBean}.
*/
public class ExtendedHotSpotDiagnostic extends HotSpotDiagnostic implements HotSpotDiagnosticMXBean {

private static final HotSpotDiagnosticMXBean instance = new ExtendedHotSpotDiagnostic();

/**
* Singleton accessor method.
*
* @return the <code>HotSpotDiagnostic</code> singleton.
*/
public static HotSpotDiagnosticMXBean getInstance() {
return instance;
}

/**
* Constructor intentionally private to prevent instantiation by others.
*/
private ExtendedHotSpotDiagnostic() {
super();
}

/**
* {@inheritDoc}
*/
@Override
public void dumpHeap(String outputFile, boolean live) throws IOException {
throw new UnsupportedOperationException();
}

/**
* {@inheritDoc}
*/
@Override
public List<VMOption> getDiagnosticOptions() {
return Collections.emptyList();
}

/**
* {@inheritDoc}
*/
@Override
public VMOption getVMOption(String name) {
if (name == null) {
throw new NullPointerException("A non-null name is required");
}
throw new IllegalArgumentException("OpenJ9 doesn't support the API i.e. the VM option might exist, but OpenJ9 can't retrieve it");
}

/**
* {@inheritDoc}
*/
@Override
public void setVMOption(String name, String value) {
if (name == null) {
throw new NullPointerException("A non-null name is required");
}
if (value == null) {
throw new NullPointerException("A non-null value is required");
}
throw new IllegalArgumentException("OpenJ9 doesn't support the API i.e. the VM option might exist, but OpenJ9 can't set it");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*[INCLUDE-IF Sidecar19-SE]*/
/*[INCLUDE-IF Sidecar19-SE & (JAVA_SPEC_VERSION <= 20)]*/

/*******************************************************************************
* Copyright IBM Corp. and others 2017
Expand Down