Since version 7u40, Oracle supplies Mission Control with the JDK. It uses the same technology stack as VisualVM so you can use it to profile your applications remotely using the same parameters as described in some previous blog posts (here or here).
If you want to use Mission Control, simply run jmc
from your ${JAVA_HOME}/bin
directory. If you’re lucky, it’s already on your path.
However, to make use of the flight recorder option, you’ll need to add some more parameters to the mix. If you have protectected your JMX connection with a password, as described here, you probably get a message like:
Could not register the Mission Control MBean in the MBeanServer.
This is probably caused by not having enough permissions assigned to your role. In the previous blog post, I used the controlRole
default from the JDK. Unfortunately, this one does not have enough permissions by default. So we’ll need to redefine it. Create a jmxremote.access
next to your existing jmxremote.password
, and add the following content:
monitorRole readonly
controlRole readwrite
create javax.management.monitor.*,javax.management.timer.*,com.sun.management.*,com.oracle.jrockit.*
unregister
Note that we assign write access to com.sun.management
and to com.oracle.jrockit
for the controlRole
. The JRockit stuff is interesting: Mission Control used to be a JRockit feature. Oracle is now merging HotSpot and JRockit so there will be some mixture of parameters here. We’ll need to tell the JVM to use this access file using -Dcom.sun.management.jmxremote.access.file=jmxremote.access
.
Next, we’ll need to enable Mission Control on the JVM which is to be monitored. This is done by adding:
-XX:+UnlockCommercialFeatures
-XX:+FlightRecorder
Yes, it is a commercial feature. License stuff etc. For occasional development I guess it would be ok.
So, to enable remote profiling using Mission Control and protect it minimally with a password, we’ll need to run something like:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=/path/to/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/path/to/jmxremote.access -Dcom.sun.management.jmxremote.port=1098 -Djava.rmi.server.hostname=10.200.1.149 -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -jar BattleBugs.jar
Phew.
Read more: