Diagnostics Guide

     Previous  Next    Open TOC in new window  Open Index in new window  View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Oracle JRockit Mission Control Use Cases

This chapter demonstrates various ways Oracle JRockit Mission Control can be used to monitor and manage application running on the Oracle JRockit JVM. It includes the following use cases:

 


Analyzing System Behavior with the JRockit Management Console

Marcus wants to monitor his application, DemoLeak which he’s running on an instance of the JRockit JVM, to ensure that he has tuned it to provide the best possible performance. To do this, he will run the JRockit Management Console concurrent with the application run. The Management Console will provide realtime information about memory, CPU usage, and other runtime metrics. The Management Console is a multi-tabbed interface, each tab allowing him to monitor and/or manage an aspect of a running application. Which tabs his version of the Management Console uses depends on which Java plug-ins he has installed with the console. When fully-implemented, the console will include eight tabs and one menu, which map to seven plug-ins.

Getting Started

To get started, Marcus launches the JRockit Mission Control Client from the command prompt, by entering:

jrockit\bin\jrmc

While the JRockit Mission Control Client is starting up, he launches the DemoLeak application. At the command prompt, he enters:

jrockit\bin\java DemoLeak

Next, he starts the Management Console with a local connection.

To launch the Management Console, Marcus does the following:

  1. In the JRockit Browser, he locates the JRockit JVM instance to which he wants to connect. In this case, it will be the one running the DemoLeak class under Discovered/Local.
  2. Figure 23-1 Locating the Appropriate JRockit JVM Instance


    Locating the Appropriate JRockit JVM Instance

  3. He right-clicks the mouse to open a context menu for the connection.
  4. Figure 23-2 Context Menu for Selected JRockit JVM Instance


    Context Menu for Selected JRockit JVM Instance

  5. He selects Start Console.
  6. After a few moments, the Management Console appears in the right panel of the JRockit Mission Control Client. Note that in Marcus’s implementation of the JRockit Mission Control Client, he can see the following tabs:

    • Overview
    • MBean Browser
    • Memory
    • Threads
    • Runtime
    • Triggers
    • Exception Count
    • Method Profiler

Analyzing Memory Usage

One way to spot problems with application performance to is to see how it uses memory during runtime. To analyze how his application is using the memory available to it, Marcus will use the Memory Tab. This tab focuses on heap usage, memory usage, and garbage collection schemes. The information provided on this tab can greatly assist Marcus in determining whether he has configured the JRockit JVM to provide optimal application performance.

To analyze memory usage, Marcus does the following:

  1. First, he examines the Heap graph, which shows the used Java heap growing until it reaches 80% to 90% of the available heap before a garbage collection is triggered. At that, point the graph falls back, indicating that new heap space is available. As the graph in Figure  shows, this cycle repeats itself throughout the run.
  2. Figure 23-3 Heap Graph
  3. Next, he takes a look at the Memory Statistics and Garbage Collector panels, which show additional information about memory usage and the garbage collector, respectively. If necessary, Marcus can change some of the values from this tab; for example he could change the allocated Java heap size or the garbage collection strategy if he felt that those originally selected weren’t allowing the application to run optimally.

Plotting Garbage Collection Times

Next, he decides to see the duration for each garbage collection. Overly long garbage collection times are a common cause of poor application performance. To see the duration of the garbage collections, Marcus can plot this information on the Heap graph.

The graphs shown in the various tabs are all preconfigured with a few useful default attributes, but any numerical attribute from any MBean can be added. In addition to the standard MBeans in J2SE 5.0 and the JRockit JVM specific MBeans, JRockit Mission Control itself provides so called synthetic MBeans that derives attributes from multiple other attributes. One such attribute is the garbage collection times

Note: The attribute for garbage collection durations is called PauseTimes even though the Java application isn’t necessarily paused during the whole garbage collection. When a concurrent garbage collector is in use, the garbage collector runs concurrently with the Java application for the most part of the garbage collection duration. The misleading naming of the attribute is a known issue and will be fixed in upcoming releases. The correct name of the attribute would be Duration.

To do this, Marcus does the following:

  1. In the Memory tab, he clicks Add… (to the right of the Heap graph).
  2. The Attribute Selector appears.

  3. He drills down to the PauseTimes attribute, as shown in Figure 23-4, select it and clicks OK.
  4. Figure 23-4 Selecting an Attribute to Add to the Heap Graph


    Selecting an Attribute to Add to the Heap Graph

    The new attribute should now be shown in the Heap graph. This synthetic attribute is a somewhat special in that it only shows values just before and after a garbage collection, causing the triangular-shaped plot, as shown in Figure 23-5. The value is shown in milliseconds.

    Figure 23-5 Heap Graph with Pause Time Plot Added


    Heap Graph with Pause Time Plot Added

Setting an Alert Trigger

In his search for bottlenecks in the system, Marcus looks at the CPU load graph and notices that the CPU load for the JVM sometimes hits the roof. Marcus would like to know how often this happens for a longer period of time. Instead of staying and watching the CPU graph continuously he sets an alert trigger to alert him whenever the CPU load generated by the VM is high for a longer period of time.

To set the alert, Marcus does the following:

  1. Marcus goes to the Triggers tab and clicks Add… (under Trigger Rules).
  2. The Add New Trigger Rule wizard appears.

  3. He drills down and selects the VMGeneratedCPULoad as shown in Figure 23-6. He then clicks Next >.
  4. Figure 23-6 Selecting an Attribute to Trigger On


     Selecting an Attribute to Trigger On

  5. He enters the conditions as shown in Figure 23-7.
  6. Figure 23-7 Setting Conditions for Triggering


    Setting Conditions for Triggering

    Since the CPU load value ranges from 0-1, Marcus sets the Max trigger value to 0.95. Marcus wants to be alerted when the CPU usage is high for at least five minutes and sets Sustained [s] to 300. He sets the Limit period [s] to 10 to prevent triggers less than 10 seconds apart.

  7. He clicks Next >.
  8. The Add New Trigger Rule: Select Action dialog box appears (Figure 23-8). Marcus selects Application alert and clicks Next >.
  9. Figure 23-8 Selecting the Trigger Action


     Selecting the Trigger Action

  10. Marcus skips the optional constraints of when to arm the trigger by clicking Next >.
  11. Marcus names the rule as shown in Figure 23-9 (CPU load for JRockit > 0.95) and clicks Finish.
  12. Figure 23-9 Naming the Rule


    Naming the Rule

  13. Marcus then activates the new rule by checking the box next to the rule name.
  14. Figure 23-10 Trigger Selected


    Trigger Selected

  15. To verify that he is getting useful data, Marcus then returns to the Memory tab and checks the CPU activity. He notices that the Trigger Alerts dialog box doesn't appear, so he edits the rule by going back to the Triggers tab, selecting the rule and lowering the Max trigger value to 0.90 or so under Trigger Condition.
  16. Since Marcus doesn’t want the Triggers Alert dialog box to appear every time an event is triggered, he will uncheck Show dialog on alerts to prevent the this from happening (he can display the dialog from the Window menu whenever he wants).

Profiling Methods Online by Using the Console

Next, Marcus wants to see how many times and for how long some specific methods have run, a process called method profiling. JRockit Mission Control has two tools for profiling methods:

To profile methods by using the Method Profiler tab, Marcus does the following

  1. First, he needs to create a method profiling template by going to the Method Profiler tab and click Add… in the Templates panel.
  2. The Add Template dialog box appears.

  3. He enters a name for the new template in the Add Template dialog box, as shown in Figure 23-11.
  4. Figure 23-11 Template Name Added


    Template Name Added

  5. He then clicks OK.
  6. The dialog box closes and the new template is added to the list (Figure 23-12).

    Figure 23-12 DemoLeak Template Added


    DemoLeak Template Added

  7. He enables the new DemoLeak template by checking the box in front of the name, then selects the template and clicks Add… in the DemoLeak panel (Figure 23-13).
  8. Figure 23-13 DemoLeak Panel


    DemoLeak Panel

    Add class to method profiler dialog box appears.

  9. In the Add class to method profiler dialog box, he enters java.util.Hashtable, as shown in Figure 23-14
  10. Figure 23-14 Adding java.util.Hashtable Class


    Adding java.util.Hashtable Class

  11. He clicks OK.
  12. In the DemoLeak panel, he expands the java.util.Hashtable class, scrolls down and checks the boxes in front of the put(Object, Object) and remove(Object) methods, as shown inn Figure 23-15.
  13. Figure 23-15 java.util.Hashtable Methods Selected


    java.util.Hashtable Methods Selected

  14. He then starts profiling by clicking the green play button in the Control Panel (Figure 23-16).
  15. Figure 23-16 Start Profiling Button


    Start Profiling Button

  16. To interpret the results, he examines the Profiling Information panel. He notes how the number of invocations of Hashtable.put(Object, Object) grows slightly faster than the number of invocations of Hashtable.remove(Object).
  17. Marcus then stops profiling by clicking the red stop button in the Control Panel (Figure 23-17).
  18. Figure 23-17 Stop Profiling Button


    Stop Profiling Button

 


Analyzing System Problems with the JRockit Runtime Analyzer

Fiona is not happy with how the application DemoLeak is performing. She is particularly concerned about the way her application performs the longer it runs. For example, while the application works fine early in its run, after a while, it starts reporting the wrong results and throwing exceptions where it shouldn’t. She also notices that eventually, it hangs at roughly the same time every time she runs it. To assess what the problem is, Fiona decides to create a runtime analysis by use the JRockit Runtime Analyzer (JRA).

The JRA is an on-demand “flight recorder” that produces detailed recordings about the JVM and the application it is running. The recorded profile can later be analyzed off line, using the JRA Tool. Recorded data includes profiling of methods and locks, as well as garbage collection statistics, optimization decisions, and, in JRockit Mission Control 3.0, latency analysis.

Getting Started

To start the diagnostics process, Fiona does the following:

  1. She starts the JRockit Mission Control Client from the command line by typing:
  2. jrockit\bin\jrmc
  3. While the JRockit Mission Control Client starts, Fiona starts the DemoLeak by entering:
  4. jrockit\bin\java DemoLeak

Creating the Recording

Next, Fiona creates a JRA recording from a local connection. To do so, Fiona does the following:

  1. Launches the JRockit Mission Control Client and locates in the JRockit Browser the JRockit JVM instance to which she wants to connect. This should be the one running the DemoLeak class under Discovered/Local.
  2. Right-clicks the mouse to display a context menu for the selected connection.
  3. Selects Start JRA Recording to launch the Start JRA Recording wizard.
  4. Selects the connection to the JRockit JVM instance on which she wants to start the recording.
  5. Selects filename and directory and types a descriptive name for the recording in the Local filename field. Note that the JRA recording file is created in the current directory of the JRockit JVM process, unless Fiona specifies a different path. If an old file already exists, it will be overwritten by the new recording.
  6. Enters the desired length of the recording (in seconds) in Recording time.
  7. Note: If Fiona sets a recording length that is too short, for example, less than 30 seconds, she will probably not get enough sample data for the recording to be meaningful.
  8. Selects the sampling options, as described in Table 23-1:
  9. Table 23-1 Selected Sampling Options
    Sampling Option
    Description
    Record samples of methods
    Records samples of methods
    Use gc sampling
    Records garbage collection events
    Use native sampling
    Records samples of native code
    Compress recording
    Compresses recording to a zip file
    Selected JRockits
    Shows the JRockit JVM instance from which she will create her recording

  10. Clicks Finish.
  11. The JRA recording progress window appears. When the recording is finished, it loads in the JRA. Fiona will now look at the JRA Recording.

Looking at the Recording

Next, Fiona will use the JRockit Mission Control Client to view the JRA recording. First, she opens the General tab by doing the following:

  1. In the JRockit Mission Control Client, clicking File > Open file > Open JRA Recording.
  2. Locating and selecting the recorded file and clicking Open.
  3. Clicking OK.
  4. The JRA General tab for that recorded file now opens, allowing Fiona to view the data in the recording. The General tab contains information on the JVM, your system and your application. It is divided into the panels described in Table 23-2:

    Table 23-2 General Tab Sections
    Data Field
    Description
    General Information
    Contains all general information about the JVM, operating system, recording time, and so on.
    Memory Usage
    Contains information on how the JRockit JVM is using the memory.
    VM Arguments
    Lists all startup options that were used.
    Allocation
    Contains information on how your application allocates memory on the Java heap.
    Threads
    Contains information on thread usage.
    Exceptions
    Contains exceptions related information.

By looking at this tab, Fiona is able to verify which version of the JVM she was running. She can also see that large object were allocated at a rate, or “frequency”, of 22.153 MB per second while small objects were allocated at a significantly faster rate of 261.983 MB per second.

Examining the Methods Tab

Next, Fiona will look at the Methods tab. The Method tab lists the top hot methods with their predecessors and successors during the recording. The Methods tab is divided into the following panels described in Table 23-3:

Table 23-3 Methods Tab Panels
Field
Description
Top Hot Methods
A listing of the top hot methods. A hot method is defined as the methods where the JVM spends most of its time during application execution. Being “hot” might indicate that a specific method is causing system problems.
Predecessors
A listing of all methods called prior to calling the method Fiona selected in the Top Hot Methods list. This information can be helpful in determining if some aspect of a certain method is complicit is poor system performance. If Fiona selects too many methods, no information will appear in this section.
Successors
A listing of all methods called after the calling method that Fiona selected in the Top Hot Methods list. This information can be helpful in determining if some aspect of a certain method is complicit is poor system performance. If Fiona selects too many methods, no information will appear in this section.

Examining the Top Hot Methods

The method sampling in the JRockit JVM is based on CPU sampling. The Top Hot Methods section lists all methods sampled during the recording and sorts them with the most sampled method s first, as shown in Figure 23-18.

Figure 23-18 Top Hot Methods

Top Hot Methods

Note: If Fiona enabled native sampling during the recording, she would see symbols with a pound sign, such as jvm.dll#_qBitSetClear. These denote functions in native libraries such as the JVM itself or various operating system libraries.

By looking at the list of top hot methods, Fiona sees that the three hottest methods are:

Starting with this information, Fiona has a good idea of where to start looking for possible areas of concern. Fiona knows that the hottest methods are those that are sampled most often. In some situations, the number of samplings in the hottest methods will dwarf those of the less-hot methods. Hot methods are a good indicator of performance problems, especially memory leaks, because the high amount of sampling affects how much time the JVM has been executing the specific method.

Examine Garbage Collection Events

Next Fiona examines the GC’s tab (Figure 23-19) to better understand system behavior and garbage collection performance during runtime.

Figure 23-19 GC’s Tab

GC’s Tab

This tab is divided into the six panels described in Table 23-4

Table 23-4 GC Events Tab Panels
Panel
Description
GC Events Overview timeline
This timeline shows the entire recording based on when the recording is initially started. Fiona uses this information to refocus the Heap Usage graph.
Heap Usage graph
This graph shows heap usage compared to pause times and how that varies during the recording. When Fiona selects a specific area in the GC Events Overview, she only sees that section of the recording. She can change the graph content in the Heap Usage drop-down list (marked 6 in Figure 23-19) to get a graphical view of the references and finalizers after each old collection.
Garbage Collections events
This list shows all garbage collection events that occurred during the recording. When she clicks a specific event, Fiona will see a flag in the Heap Usage graph for that particular event.
Details
This panel contains all the details about the specific garbage collection round. When Fiona selects a garbage collection in the Garbage Collection list, the tabs in the Details section change depending on whether or not she selected an old collection or a young collection.
Chart Configuration
This panel lets Fiona change the appearance on the active chart.
Heap Usage
Fiona uses this list to toggle the view on the Heap Usage chart to view References and finalizers. It shows different types of reference counts after each collection.

Looking at the data in the Garbage Collections panel (Figure 23-20), Fiona sees that the three longest garbage collection pause times are indexed 95 (856 ms), 41 (707 ms), and 73 (691 ms).

Figure 23-20 Garbage Collection Panel

Garbage Collection Panel

This data implied that, as processing continued on her application, garbage collections were taking longer. Fiona now has additional evidence to help diagnose what might be causing her application’s performance to deteriorate. She sees that garbage collection times are increasing, particularly later during runtime, and that the garbage collections are freeing less space on the heap. She can, with some confidence, predict that she is experiencing a memory leak.

Note: In this example, a memory leak is revealed to Fiona fairly quickly and she finds it because the evidence is obviously pointing in that direction. In most cases, a memory leak will reveal itself much more slowly and probably wouldn’t be obvious on the GC’s tab. Instead, a user would get better results by using the JRockit Memory Leak Detector, as described in Detecting a Memory Leak.

Examine the GC General Tab

Fiona can gain more insight into how garbage collection activity might be indicating a memory leak by looking at the GC General tab (Figure 23-21).

Figure 23-21 GC General Tab

GC General Tab

This tab is divided into three panels that provide information about the garbage collection at a glance. This tab is divided into the panels described in Table 23-5:

Table 23-5 GC General Tab
Panel
Description
General
This section shows overall statistics about the garbage collections during the entire JRA recording.
Garbage Collection Call Tree
This section is a collection of all call traces that were sampled for all garbage collections for the JRA recording.
GC Strategy Changes
This section lists when a garbage collection strategy change took place and how it changed.

Fiona expands the stack tree down to user code and sees that many allocations are from the hashtable type, which indicates that this type is allocation intense. Reducing the allocation of this type would probably reduce the pressure on the memory management system.

Compare Object Statistics

Next, Fiona decides that it would be helpful to compare object statistics collected at the beginning of the recording to those collected after the recording. At the beginning and at the end of a recording session, snapshots are taken of the most common types and classes of object types that occupy the Java heap; that is, the types of which the total number of instances occupy the most memory. The results are shown on the Objects tab (Figure 23-22).

Figure 23-22 Objects Tab

Objects Tab

The Object Statistics tab is divided into the panels described in Table 23-6.

Fiona can again see that hashtable shows the most dramatic growth and is consuming the greatest amount of memory on the heap. This again is a strong indication of not only a memory leak but that said leak involves the hashtable object.

Examine Lock Profiling Information

Fiona then checks the lock statistics for clues to performance bottlenecks involving locks. She opens the Locks tab (Figure 23-23) to investigate this information for both her application and the specific JRockit JVM instance.

Figure 23-23 Locks Tab

Locks Tab

The Lock Profiling tab is divided into the panels defined in Table 23-7.

Table 23-7 Lock Profiling Tab Panels
Panel
Description
Java Locks
This section lists all locks in the application.
Native Locks
This section lists all JVM internal locks.

By looking at the Java Locks panel, Fiona can see immediately that the hashtable type has taken over 300 million uncontended locks, compared to a relative few for other objects. While this information does not point directly to a memory leak, it is indicative of poor performance.

Since the lock is mostly uncontended, Fiona could optimize her application by switching to an unsynchronized data structure such as hashmap and provide synchronization only for the few cases where contention may occur.

 


Detecting a Memory Leak

Since Fiona determined that a memory leak is causing her application to run poorly, she can take advantage of the JRockit Memory Leak Detector to confirm her suspicions and begin corrective action. A memory leak occurs when a program fails to release memory that is no longer needed. The term is actually a misnomer, since memory is not physically lost from the computer. Rather, memory is allocated to a program, and that program subsequently loses the ability to access it due to program logic flaws.

Getting Started

To start the memory leak detection process, Fiona does the following:

Note: This procedure assumes that the application was stopped after the JRA recording was completed. Had Fiona not stopped the application, she would be able to skip step 1 and step 2
  1. She starts the application by entering, at the command line:
  2. java DemoLeak
  3. While the application starts, she creates a connection to the server on which the application is running.
  4. Next, she starts the Memory Leak Detector by doing the following:
    1. Right-clicking a Oracle JRockit JVM instance in the JRockit Browser to open a context menu.
    2. Selecting Start Memleak (Figure 23-24).
    3. Figure 23-24 Starting The Memory Leak Detector from a Context Menu


      Starting The Memory Leak Detector from a Context Menu

Analyze the Java Application

Fiona starts the analysis from the Trend tab (Figure 23-25), which should open when she launches the Memory Leak Detector.

Figure 23-25 Trend Tab

Trend Tab

Tip: The trend analysis should be running by default. If it is not running, you can start it by clicking the start symbol among the trend analysis buttons (Figure 23-27).

The trend analysis page shows Fiona the statistics on memory usage trends for the object types within the application. The JVM collects this data during garbage collections, which means that at least two garbage collections must be done before any trends are shown.

Figure 23-26 Garbage Collection Button
Trend Tab
  1. In order to speed up the process, Fiona clicks on the Garbage Collection button (Figure 23-26) a couple of times to start some garbage collections.
  2. Figure 23-27 Trends Analysis Buttons


    Trends Analysis Buttons

  3. Fiona then pauses the trend analysis by clicking the pause symbol among the trend analysis buttons (Figure 23-27).
  4. Figure 23-28 Show Referring Types


    Show Referring Types

Fiona finds that a class named DemoObject shows the largest growth.

  1. Fiona right-clicks the DemoObject class and selects “Show Referring Types” in the drop-down menu, as seen in Figure 23-28.
  2. Figure 23-29 Types Tab


    Types Tab

This opens the Types tab (Figure 23-29). Here Fiona can see that the DemoObjects are stored in hashtable entries.

  1. Fiona clicks on the plus sign on the java.util.Hashtabe$Entry node to expand the graph to show types referring to the hashtable entries.
  2. Fiona continues expanding the graph to the left until she finds nodes in gray that do not show any growth trend.

Now Fiona can see that the DemoObjects are indeed stored in hashtable entries. The next step for Fiona is to find out more about the instances holding on to the hashtable entries containing these DemoObjects.

Figure 23-30 List Instances

List Instances

  1. Fiona right-clicks the node that refers to the DemoObjects and selects List Instances in the drop-down menu, as seen in Figure 23-30.
  2. Figure 23-31 Show Instances Pointing To


    Show Instances Pointing To

Not all hashtable entries in the application point to the same type of objects, so Fiona gets a popup that asks her to select the type of references she is interested in.

  1. Fiona selects DemoObject in the popup (Figure 23-31), since this is the type that she is interested in, and clicks Ok.
  2. Figure 23-32 Show Referring Instances


    Show Referring Instances

At the bottom of the Types tab Fiona gets a list of instances of java.util.Hashtable$Entry that refer to DemoObjects.

  1. Fiona right-clicks the topmost instance and selects “Show Referring Instances” (Figure 23-32) to start analyzing the instances that hold on to this particular hashtable entry.
  2. Figure 23-33 Instances Tab


    Instances Tab

This opens the Instances tab, as seen in Figure 23-33.

  1. Just as in the Types tab, Fiona clicks on the plus signs to expand the graph to the left.

Fiona finds that the DemoObject is stored in a hashtable, which is held by a DemoThread. This is the culprit causing the memory leak.

The Leak is Discovered

Judging from the evidence she collected using the Oracle JRockit Mission Control tools, Fiona was able to not only identify her system problem as a memory leak, but was able to locate exactly which object type was leaking the memory. The key to making the identification began with noting in her JRA recording the increasing length of garbage collections and the types upon which those lengthening garbage collections were occurring. She then ran the Memory Leak Detector to pinpoint which of the questionable types were actually the source of the leak. She was able to spot types that continued to increase in their number of instances and allocations, obviously holding on to memory so that it couldn’t be freed for allocating other objects. This, then identified the memory leak and where it was occurring.


  Back to Top       Previous  Next