With Rational® Purify®, you can determine how much memory your Java program is using, where your program is leaking memory, and how much additional memory your program allocates for a specific set of actions. You can also identify places where forcing a garbage collection would improve your code's performance.
To use Purify to profile Java memory usage:
To Purify your Java program, start Purify and click Run in the Welcome Screen to display the Run Program dialog.
Click to enlargeNote: When you select a Java program (or applet, class, or JAR file) using the Browse button, Purify enters the name of the Purify Java helper program, pstart.exe, in the Program name field. The name of the Java program itself, along with the name of your specified Java virtual machine's Java viewer and any necessary options, is automatically entered in the Command-line arguments field. You must do the same if you enter information into these fields manually.
More information? Look up specifying a JVM and running Java programs in the Purify online Help index.
As your program runs, Purify intercepts and tabulates messages related to memory usage from the Java virtual machine. Based on these messages, Purify keeps track of how much memory each method in your Java program has allocated at any given time.
Taking snapshots of memory useTo zero in on memory leaks in your Java program, wait until your program completes its initialization procedures, then click to take a snapshot of the current memory usage status. This snapshot is your baseline for investigating how your program uses memory as it runs.
Now run the program routines that you suspect of leaking memory. As your program runs, the Purify Data Browser's Memory tab displays a graph that indicates the amount of memory your program is using.
Click to enlargeWatch the graph for fluctuations in memory usage. A large increase in memory usage may indicate a problem, especially when you can't reduce it by clicking to force a garbage collection.
Now take another snapshot so that you have a "before" and "after" record of what's going on, and exit your program.
More information? Look up taking snapshots (Java) and garbage collection in the Purify online Help index.
Comparing snapshots to focus on critical codeSelect your second snapshot in the Navigator and click to compare the second snapshot with the first.
Purify now displays a call graph showing the methods that are responsible for allocating the largest amounts of memory during the interval between the first and second snapshots. Click to enlarge
The call graph also shows you the calling relationship between methods. This can give you clues about which method may be ultimately responsible for unnecessary references to objects in memory that prevent the garbage collector from doing its job.
Move your cursor over the method or path you want to investigate. A tool tip pops up to give you memory-related statistics for that object. Click to enlarge
This allows you to zero in on the method that is wasting memory, as well as its descendants.
To view your code from within Purify, right-click a method for which source is available, and select Source File.
More information? Look up diff'ing snapshots (Java), call graph (Java), and source code in the Purify online Help index.
The Function List View tab in the Data Browser provides a textual, non-hierarchical view of the same data. You can do full-program sorts in the Function List View to find the biggest memory-consuming methods in your entire program. Click to enlarge
More information? Look up function list view (Java) in the Purify online Help index.
By double-clicking any method in the call graph or function list view, you can open a Function Detail window. This window shows how the method, its callers, and its descendants allocated memory. Click to enlarge
If the amount of memory attributed to any method seems unexpectedly high, examine your source code. It may be the case that another method, possibly a descendant, is holding an obsolete reference that is preventing the memory from being garbage-collected. For example, a descendant method may have created a static variable as part of a string array. This would keep the memory for the entire array from going out of scope, which may slow your program down, and even kill it.
More information? Look up function detail (Java) in the Purify online Help index.
You can save Purify data and analyze it later, share it with other members of your team, or include it in reports. Purify can save Java data in the following formats:
More information? Look up saving data (Java) in the Purify online Help index.
You can highlight methods in the call graph to display specific memory-related characteristics or to show calling relationships. Click to enlarge
More information? Look up highlighting (Java) in the Purify online Help index.
Use Purify's filter commands to remove a selected method, or all methods in a class file, from the set of data that Purify has collected. Alternatively, use subtree commands to focus on or remove a specific method and all its descendants from the dataset. Right-click a method in the call graph, function list view, or function detail to perform these operations.
Click to enlargePurify has undo capabilities for all filter and subtree commands so that you can easily return to any previous dataset configuration.
The call graph also provides a series of expand and collapse commands that work with subtrees. Unlike the filter and subtree commands, however, these commands affect only what is displayed in the call graph; they do not change the dataset.
In addition to the menu commands, you can use the Filter Manager to select the data you need.
Click to enlargeMore information? Look up filtering data (Java) and subtrees (Java) in the Purify online Help index.
Now you're ready to put Purify to work on your Java code. Remember that Purify's online Help contains detailed information to assist you.
Back| Next| Index| Table of contents
Copyright © 1996, 2000 by Rational Software Corporation. All rights reserved. |