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

Included a new MXBean to dynamically configure dump options #718

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

chandrams
Copy link
Contributor

Included a new MXBean to dynamically configure dump options. Internally it reuses the methods in com.ibm.jvm.Dump APIs to trigger dumps.

Issue #153
Signed-off-by: Chandrakala chandra-ms@in.ibm.com

* </table>
*/

public interface DiagnosticsMXBean extends PlatformManagedObject {
Copy link
Member

Choose a reason for hiding this comment

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

This would be better named OpenJ9DiagnosticsMXBean

*/
@Override
public void triggerDump(String dumpAgent) throws IllegalArgumentException {
switch (dumpAgent) {
Copy link
Member

Choose a reason for hiding this comment

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

I think there should be a security check here. Although these Dump APIs contain security checks, they are only enabled when the com.ibm.jvm.enableLegacyDumpSecurity system property is set to true, which it is not by default. Considering you can attach to a running JVM and invoke this, the proper security checks need to be in place.

* {@inheritDoc}
*/
@Override
public void configureDumpOptions(String dumpOptions) throws InvalidDumpOptionException, DumpConfigurationUnavailableException {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be called setDumpOptions instead of configureDumpOptions? According to the MXBean naming conventions, a setter should be called set...
As a practical example, jconsole handles the APIs differently when they are getters, setters and boolean APIs,

*/
@Override
public void configureDumpOptions(String dumpOptions) throws InvalidDumpOptionException, DumpConfigurationUnavailableException {
System.out.println("Dump Options = " + dumpOptions);
Copy link
Member

Choose a reason for hiding this comment

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

This PR is marked WIP, but its been sitting for a while with no updates, not sure if you are ready for a review? The println() needs to be removed before merging.

@chandrams chandrams force-pushed the diagnosticsMXBean branch 4 times, most recently from ed9635c to bd2d966 Compare January 15, 2018 10:50
@chandrams
Copy link
Contributor Author

@pshipton Sorry for the delay I was on vacation. I have a query,

Dump.setDumpOptions() did not work when I passed the below option:
"java:events=throw,filter=java/lang/NullPointerException#DumpTest.main*,range=1..1"

After investigation, I found -Xdump:dynamic has to be specified if throw/catch events are configured through Dump.setDumpOptions() when JIT is ON, whereas this option is not required when we set the above option on command line using -Xdump.

Shouldn't this be documented in Dump API or somewhere else? I could not find any documentation on this.

@pshipton
Copy link
Member

Shouldn't this be documented in Dump API ?

Yes it should. I've seen this mentioned elsewhere recently as well, but can't remember where. Can you please request an update to the User Guide.

@chandrams
Copy link
Contributor Author

Thanks Peter. I had asked the same query here too - #153

@chandrams chandrams force-pushed the diagnosticsMXBean branch 3 times, most recently from e81da25 to 1937ab8 Compare January 22, 2018 10:12
@chandrams chandrams changed the title WIP Included a new MXBean to dynamically configure dump options Included a new MXBean to dynamically configure dump options Jan 23, 2018
@chandrams
Copy link
Contributor Author

@pshipton - I have implemented the review comments and also fixed some synchronization issues in the test case. Please review. Thanks.

import com.ibm.jvm.DumpConfigurationUnavailableException;
import com.ibm.jvm.InvalidDumpOptionException;

import com.ibm.jvm.Trace;
import com.ibm.lang.management.OpenJ9DiagnosticsMXBean;

public class OpenJ9DiagnosticsMXBeanImpl implements OpenJ9DiagnosticsMXBean {
private static final DumpPermission DUMP_PERMISSION = new DumpPermission();
Copy link
Member

Choose a reason for hiding this comment

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

Checking security here is no longer required. Since my original comment, OpenJ9 has turned on the legacy security checks by default, in #979.

*
* @throws DumpConfigurationUnavailableException - if the configuration cannot be changed because a dump is already in progress.
*/
public void resetDumpOption() throws DumpConfigurationUnavailableException;
Copy link
Member

Choose a reason for hiding this comment

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

This should be resetDumpOptions with a 's', to match the jvm.Dump API being called.

* This function sets options for the dump subsystem.
* The dump option is passed in as a String. Use the same syntax as the -Xdump command-line option, with the
* initial -Xdump: omitted. See Using the -Xdump option as described in the section on dump agents in the
* documentation for the IBM JVM. This method may throw a DumpConfigurationUnavailableException if the dump
Copy link
Member

Choose a reason for hiding this comment

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

This should not refer to IBM

* This function triggers the specified dump agent.
* The JVM will attempt to write the file to the specified file name. This may
* include replacement tokens as documented in the section on dump agents
* in the documentation for the IBM JVM.
Copy link
Member

Choose a reason for hiding this comment

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

Should not refer to IBM

@@ -32,6 +32,7 @@
import com.ibm.lang.management.JvmCpuMonitorMXBean;
import com.ibm.virtualization.management.internal.GuestOS;
import com.ibm.virtualization.management.internal.HypervisorMXBeanImpl;
import com.ibm.lang.management.OpenJ9DiagnosticsMXBean;

/**
* This class implements the service-provider interface to make IBM-specific
Copy link
Member

Choose a reason for hiding this comment

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

Please change IBM to OpenJ9 here.

* @param dumpAgent - the dump agent to be triggered
* @throws IllegalArgumentException - if the specified dump agent is invalid or unsupported by this method.
* @throws java.lang.RuntimeException - if the vm does not contain RAS dump support
* @throws java.lang.SecurityException - if there is a security manager and it doesn't allow the checks required to take this dump
Copy link
Member

Choose a reason for hiding this comment

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

please use different wording, perform instead of take would work.

Copy link
Member

Choose a reason for hiding this comment

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

or trigger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pshipton I have taken this description from Dump.java, Should I change take to trigger in that file too?

Copy link
Member

Choose a reason for hiding this comment

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

yes, please change it there too

Dump.SnapDump();
break;
default:
throw new IllegalArgumentException("Invalid or Unsupported Dump Agent Option, cannot be triggered");
Copy link
Member

Choose a reason for hiding this comment

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

Please externalize this message. For an example, search for /*[MSG and also see openj9/jcl/src/java.base/share/classes/com/ibm/oti/util/ExternalMessages-MasterIndex.properties

fileName = Dump.snapDumpToFile(fileNamePattern);
break;
default:
throw new IllegalArgumentException("Invalid or Unsupported Dump Agent Option, cannot be triggered");
Copy link
Member

Choose a reason for hiding this comment

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

Please externalize the message

*
*/

@Test(groups = { "level.sanity" })
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this needs to be a sanity test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed it to level.extended, is this alright or is there any other group that I need to include it in?

Copy link
Member

Choose a reason for hiding this comment

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

I think its fine. The test team can comment on this.

@pshipton
Copy link
Member

@llxia please have someone review the tests

@pshipton pshipton requested a review from llxia January 26, 2018 17:54
@chandrams
Copy link
Contributor Author

pull request for openjdk8 - ibmruntimes/openj9-openjdk-jdk8#60

Submitted a personal build, openjdk8 build was created and all sanity tests passed. So, I think it is fine to merge the changes required in the make. Have asked the same in the above pull request too.

* @throws IllegalArgumentException if the specified dump agent is invalid or unsupported by this method
* @throws RuntimeException if the vm does not contain RAS dump support
* @throws SecurityException if there is a security manager and it doesn't allow the checks required to trigger this dump
*/
Copy link
Contributor

@keithc-ca keithc-ca Mar 12, 2018

Choose a reason for hiding this comment

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

Please document NPE (if dumpAgent is null).

* @throws IllegalArgumentException if the specified dump agent is invalid or unsupported by this method
* @throws SecurityException if there is a security manager and it doesn't allow the checks required to trigger this dump
*/
public String triggerDumpToFile(String dumpAgent, String fileNamePattern) throws IllegalArgumentException, InvalidOptionException;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please document NPE (if dumpAgent is null).

}
/*[ELSE]
try {
Dump.resetDumpOptions();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please move the conditional boundaries as only the body of the try statement is different (and to similar situations in other methods).

@@ -56,6 +56,7 @@
<class name="org.openj9.test.java.lang.management.TestMisc" />
<class name="org.openj9.test.java.lang.management.TestManagementUtils" />
<class name="org.openj9.test.java.lang.management.TestLoggingMXBean" />
<class name="org.openj9.test.java.lang.management.TestOpenJ9DiagnosticsMXBean" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for late review. I had issue with my email filtering.

TestOpenJ9DiagnosticsMXBean has annotation level.extended and it is added into JLM_Tests_IBMinternal in testng.xml.
In playlist.xml, we only run sanity for JLM_Tests_IBMinternal, which means we will not run tests in TestOpenJ9DiagnosticsMXBean.

@chandrams
Copy link
Contributor Author

@llxia @keithc-ca

Implemented the review comments, please review again. Thanks

<variation>Mode100</variation>
<variation>Mode101</variation>
</variations>
<command>$(ADD_JVM_LIB_DIR_TO_LIBPATH) \
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run test in REPORTDIR as the test may generate core file.

$(MKTREE) $(REPORTDIR); \
cd $(REPORTDIR); \

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@llxia I have made these changes, please review. Thanks

@chandrams chandrams force-pushed the diagnosticsMXBean branch 4 times, most recently from 7783f1f to 4922923 Compare March 19, 2018 06:32
*/
@Override
public void resetDumpOptions() throws ConfigurationUnavailableException {
try {
Copy link
Member

Choose a reason for hiding this comment

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

Although the dump APIs already check security permissions, it may be useful to have an extra layer of permission checking for the MXBean, since the MXBean can be used remotely. Please add a security check for java.lang.ManagementPermission("control") (i.e. ManagementPermissionHelper.MPCONTROL) to each of the APIs. This allows the local application to have DumpPermssion, but if ManagementPermission("control") is not granted then the MXBean APIs cannot be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ManagementPermissionHelper is an internal class in java.management module, not sure if there would be any restrictions in accessing internal classes using reflection from another module in future. Instead can I just use ManagementPermission("control") directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you can use ManagementPermission("control") directly, but you should capture that object somewhere (like ManagementPermissionHelper does) so that you can reuse it.

Copy link
Member

Choose a reason for hiding this comment

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

java.management already exports com.ibm.java.lang.management.internal to jdk.management; so I think ManagementPermissionHelper can be used directly.

@pshipton
Copy link
Member

fyi #1551, similar changes are required here

@chandrams chandrams force-pushed the diagnosticsMXBean branch 2 times, most recently from 8ddfd06 to d1d7b6a Compare March 29, 2018 15:17
@chandrams
Copy link
Contributor Author

@pshipton @keithc-ca

I have made the changes as suggested, please review. Thanks.


/**
* <p>
* This interface provides APIs to dynamically trigger Dump agents. APIs are also available to
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't captialize 'Dump'.

public interface OpenJ9DiagnosticsMXBean extends PlatformManagedObject {
/**
* Reset the JVM dump options to the settings specified when the JVM was started removing any additional
* configuration done since then. This method may throw a DumpConfigurationUnavailableException if the dump
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be 'ConfigurationUnavailableException' instead of 'DumpConfigurationUnavailableException'.

* This function sets options for the dump subsystem.
* The dump option is passed in as a String. Use the same syntax as the -Xdump command-line option, with the
* initial -Xdump: omitted. See Using the -Xdump option as described in the section on dump agents in the
* documentation for the OpenJ9 JVM. This method may throw a DumpConfigurationUnavailableException if the dump
Copy link
Contributor

Choose a reason for hiding this comment

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

DumpConfigurationUnavailableException -> ConfigurationUnavailableException

ObjectName name = new ObjectName("openj9.lang.management:type=OpenJ9Diagnostics"); //$NON-NLS-1$
return name;
} catch (MalformedObjectNameException e) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably throw an Error rather than return null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other MXBeans such as JVMCpuMonitor, ProcessorMXBeanImpl all have similar logic and return null on MalformedObjectNameException. Hence used the same logic here. Should I change it to throw an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they all should throw an Error, but I'm fine leaving that cleanup for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Keith. I have made the other changes as per your review comments. Please review again.

/*[IF Sidecar19-SE]*/
try {
Object controlPermission = managementPermission.get(null);
manager.checkPermission((java.security.Permission)controlPermission);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please pull the call to checkPermission() out of the try statement so it doesn't flow through handleError and is common for all Java versions.

</groups>
<subsets>
<subset>SE80</subset>
<subset>SE90</subset>
Copy link
Contributor

Choose a reason for hiding this comment

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

This test should apply to all Java versions: can we just remove the <subsets> element?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, in able to support special subsets like Panama and Valhalla, we are caught in the position of explicitly stating the subset. If you do remove < subsets >, it will generate make targets for 5-6 supported subsets (SE80, SE90, SE100, SE110, Panama, Valhalla) and test compilation will fail, as Panama and Valhalla have special requirements for build. (At some point we should address this in a more satisfying way, in order not to play this game of continuously updating these... perhaps Panama & Valhalla off in a separate branch of openj9? but currently explicit statement is the way)

So, in this case, you may want to add SE100 to run this test also against Java10.

@chandrams chandrams force-pushed the diagnosticsMXBean branch from d1d7b6a to 7efef6b Compare April 5, 2018 12:15
Signed-off-by: Chandrakala <chandra-ms@in.ibm.com>
@chandrams chandrams force-pushed the diagnosticsMXBean branch from 7efef6b to 54c8280 Compare April 5, 2018 19:28
dumpConfigurationUnavailableExClass = classes[2];
Class<?> managementPermissionHelperClass = classes[3];

managementPermission= managementPermissionHelperClass.getField("MPCONTROL"); //$NON-NLS-1$
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think access to ManagementPermissionHelper.MPCONTROL needs to be via reflection. That package is exported to this module so it should be able to use the class and field directly in all Java versions. That change can wait for a separate PR though.

@keithc-ca
Copy link
Contributor

jenkins test sanity plinux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants