Monitoring Locks with Java Flight Recorder and Java Mission Control
Asked Answered
D

1

11

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 ...

Dc answered 26/11, 2018 at 5:26 Comment(0)
D
10

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 the default 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):

-XX:StartFlightRecording=settings=/home/<username>/Custom,<other options>...

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 the profile 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.

Dc answered 26/11, 2018 at 7:50 Comment(2)
In Java 8, the event is called "java/monitor_enter", and should be enabled by default for both default and profile configurations.... So you should have seen it from the beginning.. (JMC 6 translates from the old Java 8 event ids (java/monitor_enter) into the new Java 9+ ids (JavaMonitorEnter) )Happiness
@Happiness You are right, the java/monitor_enter event is activated in both default and profile configurations. Except that the threshold in these settings is too long for my application (10ms in the profile configuration, 20ms in the default configuration). In my application, the individual blockings I was trying to monitor were about 20 microseconds long so they would not show with these previous configurations.Dc

© 2022 - 2024 — McMap. All rights reserved.