This tutorial provides an overview of Java Mission Control and Flight Recorder. Starting with Java 7 u40 (and later versions), Java Mission Control and Flight Recorder are included with the Java JDK download. This tutorial consists of a series of demos and notes on how to use those tools.
Time to Complete
Approximately 2 hours
This tutorial is a visual guide to the use of Java Mission Control and Flight Recorder 5.2 on Java u40 and later. Although Mission Control and Flight Recorder have been available for the Oracle Fusion Middleware products, this is the first time they have been available for the Hotspot Java Virtual Machine (JVM). Both tools are now included in the standard distribution of the Java JDK.
The tutorial consists of a series of YouTube demos highlighting key features of both Mission Control and Flight Recorder. All demos were recorded at a resolution of 720p. If you want to watch them at a higher resolution, click the settings icon at the bottom of the video player and select the appropriate video resolution.
This tutorial also includes some text notes summarizing the information that is included in the various parts of Java Mission Control and Flight Recorder. Coverage of key command-line options is also provided.
Hardware and Software Requirements
The following is a list of hardware and software requirements:
- A machine running Windows, Mac OS X, or Linux that meets the system requirements for Java u40 or later
Note: The demos were created with Windows 7 and have not been tested on all platforms, but should work fine on the listed platforms. Also a machine with more than one core is preferable.
- Java 7 JDK Update 40 or later
- Java 7 Demos and Samples zip file (The file is listed on the same page as the JDK download.)
Before starting this tutorial, you should download and install:
- Java JDK 7 u40 or later: Java 7 JDK Downloads
- Demos and Samples zip file from the same location. Unzip the file and place the contents in the Java JDK directory. For example, assuming that you are using Java 7 u45, copy the
Introducing Java Mission Control and Flight Recorder
This video provides a brief introduction to the series of demos that follow and to Java Mission Control and Flight Recorder.
Java Mission Control and Flight Recorder
Java Mission Control is a monitoring and analysis tool. Mission Control can be used to monitor running JVMs and provide event-based feedback to key personnel about the health of an application. Mission Control is also tightly integrated with Java Flight Recorder. Mission Control can control live flight recordings and load existing recordings for analysis.
Java Flight Recorder is a tool for recording live data and events from a running JVM. This data, a flight recording, can be loaded in Mission Control for detailed analysis. Flight Recorder has a minimal impact on a running application and provides a great deal of flexibility in determining what data is recorded.
Following Along with the Demos
All the demos use software that is free to download and use. The following information provides the details you need to follow along.
Step 1: Initial Setup
The software required to do this activity is described in the Overview section. If you have not downloaded and installed the required software, do so now.
The software must be installed if you want to try the demos.
Step 2: Start the Demo Application
With the Java JDK and demos installed, run the demo application.
The demo application is a 2D graphics demo. To execute it, enter the following:
java -Xmx32m -Xms16m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:+UseSerialGC -jar "C:/Program Files/Java/jdk1.7.0_45/demo/jfc/Java2D/Java2Demo.jar"
New Switches: Notice the two unfamiliar switches on that command line.
The two switches enable the use of Java Flight Recorder. Therefore, these switches were used for every demo in this tutorial.
The Java 2D demo should launch and look something like this:
You can see a number of different tabs that demonstrate various Java graphics features.
Click on the Transforms tab. You should see a new screen that looks like this:
This part of the application creates some nice garbage collection (GC) behavior that we can observe. Leave the application running and start Java Mission Control in a new Command Prompt window:
You should be all set to follow along with the demos that follow.
Mission Control General Tab
This demo shows you how to start Java Mission Control and how to monitor a Java application.
Mission Control General Tab Notes
The Mission Control General tab group shows information about memory utilization and CPU usage on the JVM. Key facts about the JVM are also included on the Server Information tab.
Mission Control MBeans Tab
This demo explores how the MBeans tab is used in Java Mission Control.
Mission Control MBeans Tab Notes
The Mission Control MBeans tab enables you to explore the various attributes monitored by Mission Control. Key features available on the MBeans tab include:
- Most of the attributes can be added as charts to the General tab.
- The Operations subtab enables you to retrieve data or make changes to a running JVM.
- The Notifications subtab enables you to receive data when a certain even occurs in the JVM.
Mission Control Runtime Tab
In this demo, the Runtime tab group is reviewed.
Mission Control Runtime Tab Notes
The Mission Control Runtime tab group provides a lot of information about a running JVM. Key tabs include:
- The System tab provide a CPU usage chart along with System Properties table and JVM Statistics table. The System Properties table can be searched using wild cards or regular expressions.
- The Memory and Memory Pool tabs provide graphs and tabular data about memory usage on this JVM.
- The Garbage Collection tab provides stats about garbage collection during this monitoring session.
- The Threads tab provides detailed information about running threads on this JVM. Threads can be further investigated by turning on options to:
- CPU profile
- Detect deadlocks
- Examine memory allocation
Mission Control Triggers Tab
The Mission Control Triggers tab is part of the MBeans tab group. This demo shows how to set up and use a trigger.
Mission Control Triggers Tab Notes
The Triggers tab is a powerful tool for monitoring a JVM. It enables you to take action based on an event or trigger. Actions include:
- Display a pop up message
- Write a message to the console
- Start, stop, or dump a flight recording
- Dump the thread information for this application
- Write to a log file
- Send email
Triggers can be set up based on events like CPU usage or deadlocked threads. In addition, if you are using Oracle WebLogic Server, you can set triggers for events, such as too many sessions or a high message queue.
Making a Flight Recording
This demo shows how to make a flight recording with Mission Control.
Making a Flight Recording Notes
The demo shows you how to make different kinds of recordings from the Mission Control interface. However, most of the time, you will probably start and stop Flight Recorder from the command line.
Starting a Recording from the Command Line
To get you started, here are a few examples of starting a recording from the command line. See the Java Flight Recorder Runtime Guide for more details.
Example 1: JFR Continuous Recording
java -Xmx32m -Xms16m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,maxage=5m -XX:+UseSerialGC -jar "C:/Program Files/Java/jdk1.7.0_45/demo/jfc/Java2D/Java2Demo.jar"
This example starts a continuous recording, which stores a maximum of 5 minutes of data. No flight recorder file is created unless an explicit command is given from Mission Control or
Example 2: JFR Continuous Recording with Dump on Exit
java -Xmx32m -Xms16m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=defaultrecording=true,disk=true,maxage=5m,dumponexit=true,dumponexitpath=C:/temp/FlightRecordingDump.jfr -XX:+UseSerialGC -jar "C:/Program Files/Java/jdk1.7.0_45/demo/jfc/Java2D/Java2Demo.jar"
This example is like example 1, but it creates a flight recording when the application exits. In this example, the flight recording is written to
Example 3: JFR Timed Recording written to Disk
java -Xmx32m -Xms16m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:FlightRecorderOptions=disk=true, -XX:StartFlightRecording=duration=2m,filename=C:/temp/2m.jfr -XX:+UseSerialGC -jar "C:/Program Files/Java/jdk1.7.0_45/demo/jfc/Java2D/Java2Demo.jar"
This example performs a 2-minute recording and saves the result in
Checking, Starting, and Stopping a Recording with
Flight Recorder can be controlled from the command line by using
jcmd. This method enables you to start, stop, or check a recording.
Example 1: Check JVM for a Recording
C:\Users\oracle>jcmd 2368 JFR.check 2368: Recording: recording=0 name="HotSpot default" maxage=5m (running)
This example shows that a continuous recording is running on the JVM. The process ID was obtained by running
jcmd with no options.
Example 2: Getting a list of JFR Start Options
This example shows how to find out what options are available for
C:\Users\oracle>jcmd 2368 help JFR.start 2368: JFR.start Starts a new JFR recording Impact: Medimum: Depending on the settings for a recording, the impact can range from low to high. Syntax : JFR.start [options] Options: (options must be specified using the <key> or <key>=<value> syntax) name : [optional] Name that can be used to identify recording, e.g. \"My Recording\" (STRING, no default value) defaultrecording : [optional] Starts the default recording, can only be combined with settings. (BOOLEAN, false) settings : [optional] Settings file(s), e.g. profile or default. See JRE_HOME/lib/jfr (STRING SET, no default value) delay : [optional] Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, e.g. 5h. (NANOTIME, 0) duration : [optional] Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 300s. (NANOTIME, 0) filename : [optional] Resulting recording filename, e.g. \"C:\Users\user\My Recording.jfr\" (STRING, no default value) compress : [optional] GZip-compress the resulting recording file (BOOLEAN, false) maxage : [optional] Maximum time to keep recorded data (on disk) in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 60m, or 0 for no limit (NANOTIME, 0) maxsize : [optional] Maximum amount of bytes to keep (on disk) in (k)B, (M)B or (G)B, e.g. 500M, or 0 for no limit (MEMORY SIZE, 0)
Flight Recorder General Tab
This demo discusses the information included on the Java Flight Recorder General tab group. The tab provides an overview of performance and system settings.
Flight Recorder General Tab Notes
The Flight Recorder General tab group includes the subtabs described in the following sections.
The Overview tab provides an overview of CPU performance and heap usage during the recording.
JVM Information Tab
The JVM Information tab lists key information about the JVM that was used to make the recording.
System Properties Tab
The System Properties tab lists the system properties for the JVM that was used to make the recording.
The Recording tab shows a detailed list of the selected options.
Flight Recorder Memory Tab
The Flight Recorder Memory tab provides detailed information about JVM heap usage and garbage collections.
Flight Recorder Memory Tab Notes
The Flight Recorder Memory tab group includes the subtabs described in the following sections.
The Overview tab provides general information about memory during the recording.
Garbage Collections Tab
The Garbage Collections tab shows a chart of the heap memory during the recording. It also shows a table of the garbage collections that occurred. When you select an individual collection event, the tab shows detailed information about all phases of the collection in a tabbed interface.
GC Times Tab
The GC Times tab is a different take on the information on the Garbage Collections tab. It displays a graph to show GC pause times during the recording. In addition, key GC statistics about young and old generation collections are shown.
GC Configuration Tab
The GC Configuration tab shows configuration data related to the heap size and garbage collectors selected for this JVM.
The Allocations tab shows data about the object allocations in the JVM. Detailed statistics show which objects were allocated inside and outside the Thread Local Allocation Buffer (TLAB). When you select an object type, the tab shows a stack trace that provides information about where the object was allocated.
Object Statistics Tab
The Object Statistics tab shows information about object allocation in relation to the total heap. Statistics show which objects took up the most memory.
Flight Recorder Code Tab
The Flight Recorder Code tab group displays code-related information that was stored during a flight recording.
Flight Recorder Code Tab Notes
The Flight Recorder Code tab group includes information that is relevant to the source code for your application, such as classes, object, packages, and methods. The tab group includes the subtabs described in the following sections.
The Overview tab provides information about hot packages. "Hot" is defined as the place where your code spends most of its execution time. On this tab, the package data is displayed. A searchable table of hot classes is also shown.
Hot Methods Tab
The Hot Methods tab contains a lot of useful data. The main hot methods table shows methods ranked by their percentage of execution time. When you click a method, the tab displays a stack trace showing either preceding methods or succeeding methods to the method selected. This tab can tell you a lot about where your application runs most often.
Call Tree Tab
The Call Tree tab shows the execution call trees, starting from the primary execution methods.
The Exceptions tab shows all errors and exceptions that occurred during the recording. When you select an exception, the tab displays the stack trace and reveals detailed information about where the error occurred.
The Compilations tab displays data about the just-in-time (JIT) compiler.
Class Loading Tab
The Class Loading tab shows two charts, which display information about the number of classes that loaded during the recording.
Flight Recorder Threads Tab
The Flight Recorder Threads tab group displays information about processing usage by thread.
Flight Recorder Threads Tab Notes
The Flight Recorder Threads tab group displays processor usage information by thread, as well as information about thread contention, latencies, and locks. The tab group includes the subtabs described in the following sections.
The Overview tab shows two pieces of information: a chart of CPU usage (top of the page) and a chart listing the number of active threads during the recording.
Hot Threads Tab
The Hot Threads tab is similar to the Hot Methods tab, except that the information is organized by thread. When you select individual threads, the tab displays stack trace information about the thread.
The Contention tab indicates where your threads may be blocking. Information can be presented by lock or by thread. When you select a lock or thread, the tab displays stack traces with detailed information about method calls.
The Latencies tab shows information about what kind of events caused latencies in your application; for example, Java Monitor Wait, Java Monitor Blocked, or Java Thread Park.
Thread Dumps Tab
The Thread Dumps tab creates a list of thread dumps that were recorded during the recording. When you select a single dump instance, the tab displays all text from the thread dump.
Lock Instances Tab
The Lock Instances tab shows information about all locks that occurred in the application. Stack trace information can be used to drill down further into the data provided.
Flight Recorder I/O and System Tabs
The Flight Recorder System tab provides general system information about the recorded JVM. The Flight Recorder I/O tab shows both disk and network I/O that took place during the recording.
I/O Tab Notes
The I/O tab group displays information about file and network I/O. The tab group includes the subtabs described in the following sections.
The Overview tab provides a subtab for all file I/O and network I/O. A color-coded chart displays reads and writes during the recording.
Remaining I/O Tabs
There is a tab for each type of I/O: file reads, file writes, socket reads, and socket writes. Each page has three subtabs. The first tab displays information by file name or host address. The second tab displays I/O activity by thread. The third tab displays data by I/O event. This makes it easy to drill down into the data.
System Tab Notes
The System tab group provides information about the system under which the JVM is running. Information like the number of processors, the kind of CPUs on the system, and the amount of physical memory is provided. There is also a tab for searching environment variables.
Flight Recorder Events Tab
The Flight Recorder Events tab group provides detailed information about JVM events that were recorded during the recording process.
Events Tab Notes
When this tab group is selected, the Event Types tab is populated with all events that are recordable. With this interface, you can filter the data that is included on this and other tabs. The tab group includes the subtabs described in the following sections.
The Overview tab provides a summary of event activity by event type. The event information is displayed in both tables and pie charts.
The Log tab shows a log of all event activity during the recording. When you click a specific event, the tab displays detailed information about that event.
The Graph tab graphs events by thread groups. Expand a thread group to see all events that occurred in the group. All events are color coded. If you mouse over an event, a popup dialog box displays information about the event.
The Threads tab shows a table sorted by number of events per thread.
Stack Traces Tab
The Stack Traces tab lists methods in a table that is sorted by the amount of CPU time spent in each method. When you select a method, you can see the stack trace data for the method.
The Histogram tab enables you to search through events in different ways. For example, you can get a count of the number of TLAB allocations by class name.
Flight Recorder Operative Set
The Flight Recorder Operative Set feature limits the data shown from a flight recording.
Flight Recording Operative Set Notes
The Flight Recorder Operative Set feature enables you to focus on a specific aspect of your application. For example, you can filter data to show only events related to a specific thread, and then you can analyze a smaller data set.
In this tutorial, you learned to:
- Analyze your Java applications by using Java Mission Control and Flight Recorder
- Start Java Mission Control and monitor a running JVM
For further information related to this OBE, see the following links:
- Java Flight Recorder Runtime Guide
- Java Command Line Reference
- To learn more about Java, explore the Oracle Learning Library.
- Java Mission Control and Flight Recorder Demo Series Playlist on YouTube
- Training: Java Performance Tuning with Mission Control and Flight Recorder
- Lead Curriculum Developer: Michael Williams
- Other Contributors: Cindy Church, Susan Moxley
To navigate this Oracle by Example tutorial, note the following:
- Topic List:
- Click a topic to navigate to that section.
- Expand All Topics:
- Click the button to show or hide the details for the sections. By default, all topics are collapsed.
- Hide All Images:
- Click the button to show or hide the screenshots. By default, all images are displayed.
- Click the button to print the content. The content that is currently displayed or hidden is printed.
To navigate to a particular section in this tutorial, select the topic from the list.