Adding Lock Instance Visualization

As promised in the blog entry before this one, I’m going to show how to easily add a new tab for visualizing lock instances. This can be done more elegantly in 4.1, so I will post an update to this once 4.1 is out the door.

This is roughly what we need to do:

  1. Start JRMC in design mode.
  2. Add a new tab.
  3. Edit the new tab to add a histogram of all the locking events grouped by lock instance, and a trace tree slaved to that histogram, showing the traces for all the events of a selected lock instance.
  4. Optionally export the tab to a plug-in that can be shared with colleagues.

Starting with #1, we need to start JRMC in design mode. This can be done by providing the parameter –designer to the jrmc launcher.

On windows you can simply provide a shortcut to JRMC and add –designer to the target:


The designer parameter will make available an additional view in JRMC which controls switching between design and run mode in Mission Control.

Next start up Mission Control, and open up a recording you know contains some Java Blocking events. Next open up the designer view, by clicking Window | Show View | Designer View, as shown below. This view will only be available if you started Mission Control with –designer.


I like to have the Designer View to the left, but feel free to drag-and-drop it to dock the view wherever you find is most convenient.


Now, to change the structure of the tabs, such as adding a new tab, you actually need to close the recording. This will show the structure of the tabs in the Designer View. Click on the CPU/Threads tab group, and select New | New Tab.


Fill out the information about the new tab:


Feel free to add a nice icon. 😉 Once the information is filled out, press OK and load the recording again. You should now have an empty Lock Instances tab available.


Press the stop button in the Designer View to enter design mode. First thing we need to do is to choose how to layout the component. Right click the surface and select Vertical Split:


Add a histogram to the top half, by right clicking the top half and selecting Assign Component | Histogram | Event Histogram. In the dialog that appears, do the following changes:

  • Change the Name to “Lock Instances”
  • Change General | Role to Master
  • Change General | Pie chart position to East
  • In Columns, click the Browse button, then Browse again. Select the Java Blocked event type.
  • Next click Add to add the columns to show.
    • Add the Monitor Address attribute.
    • Add the Duration field, and change the name to Count, the description to “The event count”. Change the Aggregate Function to Count. Also change the Content Type to Count. Click Pie Chart, and Sorted.
  • In Group By, click Browse and select the Monitor Address attribute.

Click the play button to see your new histogram in action:


To add the trace tree, press stop to enter design view. Right click the bottom space and select Assign Component | Tree | Trace Tree. In the dialog that opens, modify:

  • Change General | Role to Slave
  • Set Expanded Tree Depth to 0
  • In Columns click Browse and then Browse again in the next dialog. Select the Java Blocked event type.
  • Click add to add the Duration attribute. Select Count as Aggregate Function and Count as Content Type. Click the sorted checkbox.
  • In  Group By, click Browse and select the Stacktrace attribute.

Press play to show the ready made tab ( don’t forget to select a Lock instance in the master histogram):


Last but not least, export the tab to a plug-in that you can share. First close the recording to see the tab structure again. Next right click on the Flight Recording root node. Select Export UI to Plug-in. In the dialog that follows, select only the Lock Instances tab. Press OK. You will now be presented with a dialog where the plug-in name and version can be changed. Once you are happy with the settings, click OK. Next select a place to save the plug-in. Once you’ve chosen a memorable spot, press OK.


The resulting .jar file can be used by anyone simply by placing it in the missioncontrol/plugins folder.

Tip: To add a Range Selector at the top, look at how the other tabs are configured in design mode.

Visualize Those Locks!

There you are, submitting your poor application to the worst load imaginable. However, after looking at the profiling data in Mission Control, the evil grin on your face is quickly replaced by a look of surprise. The [CPU] load on the machine is only a fraction of what should be available to your application. You’ve got a throughput problem.


Picture of heavily loaded multi-threaded app running on a multi-core machine

Mission Control contains a lot of information about why your application isn’t spending time executing Java code. Events are produced for almost everything that can make your threads halt. For example, in the Contention tab there is aggregated information, per class, about what classes of locks are blocking your threads (on monitor enter) the most.


Sometimes, however, you really want to look at the information on a per lock instance basis. Take the following example:


You may, for example, want to know if all the sun.misc.Launcher$AppClassLoader locks are one and the same [instance], or if there are several in play. The easiest way to check this is to set the operative set to the events for that lock class, and then view those events in a histogram grouped by the monitor address (don’t let the name confuse you – it’s actually the lock address).

First add to the operative set:


Then build the histogram (don’t forget to check Show Only Operative Set):


Indeed, in this case they are blocking on the same instance. Admittedly a silly example, but you get the idea. Note that one drawback is that the monitor address information is only guaranteed to be coherent in between garbage collections, as the lock object may have been moved due to propagation and/or compaction during a garbage collection. If it is very important to not have a certain lock instance being reported more than once, make sure you study a range between two garbage collections.

Now, if you find yourself looking at this kind of information a lot, you may want to redesign the GUI to contain this information in a separate tab. This is easier to accomplish than you may think; I’ll post another blog with step-by-step instructions on how to accomplish that in a bit.

Awesome New Release (Hirt 3.0)

Okay, so the reason I’ve been quiet the last few weeks is due to the release of Hirt 3.0, also known as Simon Daniel Hirt. I’m including a screen shot for reference:


Simon was borne the 19th of June, 2011. He was 11 days early, 50 cm tall and 3680g heavy.

Since having a baby and a toddler at the same time has proven more difficult than anticipated, as anticipated, I’ll be on parental leave until mid September.  Winking smile

Note: A not-so-closely guarded secret is that I am working Mondays. If you need to reach me for work related stuff, just e-mail me at Oracle.