What I want to do
I have a Java program which I am trying to improve. I suspect synchronized blocks within the code to hurt performance but I would like to make sure this is my problem before touching my code.
How I went on about it
To check if synchronized blocks are indeed the issue, I recorded the execution of my program on a test server with Flight Recorder, downloaded the created jfr
file on my desktop and opened it with Java Mission Control. However the Lock Instances
page in Java Application
does not show anything. The only clue I get is a message in the Results view which reads:
The Java Blocking rule requires event(s) to be available from the following event types: com.oracle.jdk.JavaMonitorEnter
I am therefore assuming there must be some kind of option to activate along with the flight recorder but I wasn't able to find it so far.
My question
How do you enable events from the com.oracle.jdk.JavaMonitorEnter
type to be recorded by the Java Flight Recorder ?
Or I am missing something else and there is a better way to figure out how much blocking on synchronized blocks is done in a Java program ?
My environment
I am using Oracle JDK version 1.8.0_191. The version of Java Mission Control I am using on my desktop is 6.0.0. Finally, the command I use to record my program's execution is the following:
java -XX:+UnlockCommercialFeatures -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+FlightRecorder -XX:StartFlightRecording=settings=profile,dumponexit=true,filename=test.jfr -classpath lib/*:src/ <my program with its arguments>
I should also add that connecting to the server directly with Java Mission Control is not an option (or is it?) as I am using an ssh rebound to actually connect to it ...
A liitle more research on my own provided me with the answer.
The JavaMonitorEnter events (and other events that one would like to monitor) need to be specified in a flight recorder configuration file. In this situation, I was using the
profile
configuration which is provided along with thedefault
configuration with the Oracle JDK.I created my own configuration using Java Mission Control. This blog was very helpful in presenting how to find the tool to create custom recording configurations in Java Mission Control.
I then exported my newly created configuration, uploaded it on my test environment and specified this configuration in my command (below the modified option only):
What my problem actually was
Blocking recordings are activated in the flight recorder configurations provided by the Oracle JDK. However, for the blockings to actually be recorded, they need to last for more than a certain threshold (20ms in the
default
configuration, 10ms in theprofile
configuration).In my application, individual blockings were shorter than this threshold, hence nothing appeared when I opened my recording in Java Mission Control.
My main source of confusion was the message stating that the "Java Blocking rule required events to be available ...". A more accurate description of my situation would be that no blockings exceeding the configuration threshold were recorded.