-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[GR-40463] Add initial support for JMX to Native Image #4786
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
Conversation
...vm.core/src/com/oracle/svm/core/jdk/management/Target_jdk_internal_agent_FileSystemImpl.java
Outdated
Show resolved
Hide resolved
...ratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JMXInitializationFeature.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing. I added a few comments.
...tratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/JmxServerFeature.java
Outdated
Show resolved
Hide resolved
...ratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/ManagementSupport.java
Show resolved
Hide resolved
...ratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/ManagementSupport.java
Outdated
Show resolved
Hide resolved
* This feature provides the start up hook required to initialize the JMX server. | ||
* This feature is required by com.oracle.svm.hosted.jdk.JmxServerFeature. | ||
*/ | ||
public class JmxServerFeature implements Feature{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal is that this works in the same way as the existing management features, such as JFR or jvmstat. For that reason, please annotate all your features with @AutomaticFeature
and implement isInConfiguration(...)
.
The existing management features can be enabled selectively via the API option --enable-monitoring
(see VMInspectionOptions
). For your new functionality, you can add new values to that option. There were changes in that area recently, so please look at the latest version that is available in master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok both the jmx client and server features are now @AutomaticFeature
and can be included using --enable-monitoring=jmxclient,jmxserver
|
||
@Substitute | ||
private static <T extends PlatformManagedObject> T getPlatformMXBean(MBeanServerConnection connection, Class<T> mxbeanInterface) throws java.io.IOException { | ||
return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that those substitutions are still needed if the JMX support is not included into Native Image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added them back and also created a new BooleanSupplier
: JmxClientNotIncluded
. If the JmxClientFeature
is not included, then those methods will remain substituted. Is this a good approach? I also did a similar thing for JMXConnectorFactory.connect
method.
@TargetClass(className = "sun.rmi.transport.GC") | ||
final class Target_sun_rmi_transport_GC { | ||
// Work around that essentially prevents supplemental GCs on RMI client. | ||
// Required because JVM_MaxObjectInspectionAge is not implemented in SVM. Maybe there is a better way? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JVM_MaxObjectInspectionAge
should be easy to implement for the serial GC:
- add a field that holds the timestamp of the last full garbage collection to
GCImpl
. - set this field when a full collection finishes (see
GCImpl.doCollectOnce
) - add a new method to the classes
Heap
andHeapImpl
so that it is possible to query the newGCImpl
field. - add a substitution for
JVM_MaxObjectInspectionAge
that calls the newHeap
method.
I will take care of the G1-specific implementation once this PR is ready for integration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented your suggestion. However, I am not sure how to substitute JVM_MaxObjectInspectionAge
because it is a C function that JNI native method Java_sun_rmi_transport_GC_maxObjectInspectionAge
calls. So I have just changed the existing sun.rmi.transport.GC.maxObjectInspectionAge
java method substitution. Is this what you meant?
|
||
private static void configureSerialization(BeforeAnalysisAccess access) { | ||
String[] classes = new String[] { | ||
"[B", "com.oracle.svm.core.jdk.UnsupportedFeatureError", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this configuration is JDK-specific?
@vjovanov, @christianwimmer : is there any better way to do that? There is quite a lot of configuration in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is JDK specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a feature requires that much configuration, it is better to use config-*.json files. Combined with https://www.graalvm.org/22.0/reference-manual/native-image/Reflection/#conditional-configuration it should be possible to make sure that the config data is only applied if JMX support is requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a feature requires that much configuration, it is better to use config-*.json files.
I just realized that unfortunately that does not work in this case because this is not an external Feature thus the META-INF/native-image
based approach cannot be used. Sorry for the noise!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment I don't see a better way to do this. For the build-time init future programming model changes will help in the future. For reachability metadata, we would need both programming model changes and the JDK modifications.
substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxServerFeature.java
Outdated
Show resolved
Hide resolved
substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java
Outdated
Show resolved
Hide resolved
substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java
Outdated
Show resolved
Hide resolved
|
||
@Substitute | ||
private static Properties initAgentProperties(Properties properties) { | ||
JavaMainSupport support = ImageSingletons.lookup(JavaMainSupport.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is causing a build to fail: https://github.com/oracle/graal/actions/runs/3441384844/jobs/5776652403#step:13:1356
Maybe this should use ManagementFactory.getRuntimeMXBean().getInputArguments()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see! Thanks! I think SubstrateRuntimeMXBean.getInputArguments
also uses com.oracle.svm.core.JavaMainWrapper$JavaMainSupport
, but it does a check first to see if it's actually available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, and you get exactly a SubstrateRuntimeMXBean
when you use ManagementFactory.getRuntimeMXBean()
. 😉
Running the internal gates against e00d0ec now. Would be great to add some tests for this in a follow up PR. |
When building the
If you could work on a fix for that, that'd be great. I'm going to look into implementing |
|
Yes, that's correct. |
|
Try building with:
This gives me a few more classes:
|
Strangely, building with this and jdk 17, I was still unable to reproduce the error complaining about the unspecified init policies. But I have specified policies for them anyway and pushed the changes. |
When I build GraalPy, I see the following problem popping up:
#5400 may actually fix this already but I still have to verify that. Nonetheless, I also found more classes with an unspecified initialization policy:
@roberttoyonaga could you please take care of the missing initialization policies while I try and fix the GraalPy and a couple of other issues? |
substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JmxClientFeature.java
Outdated
Show resolved
Hide resolved
@fniephaus It seems like the problem is that, in the JDK code, the path
All of the classes listed there should have already had their initialization policies specified in I've now updated things such that those classes have their policies specified regardless of jdk version used to build with. |
I added some tests for JMX locally. Should I include them as part of the PR or is it better to still separate them into a following pull request? |
Yes, we still run some gates against JDK11, although we are winding them down as we speak.
Tests are always welcome! 🙂 |
Ok the initialization policies should now be specified for jdk 11 too.
Ok I included some tests! :) |
Thanks! Now, I only see this again:
I'm going to fix this. Our internal CE gate seem to pass, I'm looking into fixes for our EE tests. |
...c/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/ManagementAgentStartupHook.java
Outdated
Show resolved
Hide resolved
...ratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/HeapImpl.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Fabio Niephaus <fabio.niephaus@oracle.com>
This was merged via #5596. 🎉 |
Related issue: #4732
Currently, a native image JMX server can be started and a java client can connect. Methods can be invoked on managed beans remotely. The server will start automatically if JMX is specified at executable runtime (ie.
-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9999
). JMX should work with password authentication and SSL for both client and server.To build a native image as a JMX server, use the option
--enable-monitoring=jmxserver
(or--enable-monitoring=jmxserver,jvmstat
to also export JMX connector address to instrumentation buffer so that it can be discovered and read by other JVMs on the same system).To build as a JMX client, use
--enable-monitoring=jmxclient