Hunting Java Memory Leaks

Introduction

A memory leak can generally be assumed when freespace in the JVM heap reduces over time. This indicates that the Garbage Collector is unable to release unused objects and classes.

There are many tools available for detecting memory leaks in Java applications some are free and others are commerical. In this document I will cover the set of tools that I used whilst working on a Severity 1 CritSit involving WebSphere 4.0.5 using JRE 1.3.1 SR 6 on AIX.

The first thing you should do is enable verbose garbage collection. This is done by setting the -verbosegc command-line option on the JVM. For WebSphere Application Servers this can be found under the JVM settings section.

After the Application Server crashes, due to a java.lang.OutOfMemoryError, the JVM will generate a heap dump and a Javadump file. These files can be analysed to trace the source the memory leak.

Tracing and Analyzing Garbage Collection Logs

As a first step to determining if you have a memory leak you can manually review the stderr.log file for verbose GC output. You will need to make sure that you have enabled

There is a TechNote  on the IBM Technical Sales Library that covers the steps for manually analyzing the Java Garbage Collection output.

IBM Tools

IBM provides a variety of tools for analyzing garbage collection and heap dumps. Here I present an outline of the tools that I used on the CritSit.

VerboseGC Analyzer

The Java Service Group, part of the JTC in Hursley, has developed an experimental web based tool, called VerboseGC Analyzer, for analysing VerboseGC output. The tool is easy to use. It accepts a compressed stderr.log file as input and produces graphs showing garbage collection activity as output. The graphs are useful in determining wether a memory leak exists.

Presently there is an unofficial project to create a VerboseGC Analyzer plugin for WSAD. If this is succesful this will become a standard IBM offering.

VerboseGC Analyzer can be accessed only through the IBM intranet .


HeapRoots

HeapRoots is a tool for debugging memory leaks in JavaTM applications through analysis of heap dump files. HeapRoots loads these heap dump files and provides commands for analyzing the data through a text-based console window.

HeapRoots is freely available from IBM’s alphaWorks  emerging technologies website.

HeapWizard

HeapWizard reads and analyzes a heapdump.txt file produced by IBM JDKs (1.1.8 and up), and it can be used to anaylse heap dumps generated by WebSphere Application Server 3.0.2.4 and higher. It can be run from the command line (to provide an XML format file) or work as a GUI to provide an expandable tree view.

HeapWizard is freely available from IBM’s support  website.

Rational PurifyPlus

IBM Rational® PurifyPlus is a runtime analysis solution designed to help developers write faster, more reliable code.

Runtime analysis includes four basic functions:
-        Memory corruption detection
-        Memory leak detection
-        Application performance profiling
-        Code coverage analysis

Rational PurifyPlus packages support for all four of these functions in a single product with a common install and licensing system.

At the time of this document Rational PurifyPlus  did not support AIX.


3rd Party Tools

If you require more detail than the IBM tools listed above, you may also be interested in Wily Introscope or Borland Optimizeit.

Wily Introscope

Introscope is a system management application for managing Java Application performance. It is designed to scale with minimal performance impact, this it can be used to monitor and manage your application performance in live production environments.

Introscope  provides real-time Java Application performance management without requiring access to or modification of the application’s source code. Rich and customizable data views are integral to the product. Alerts can be user-defined and set up to be triggered by application activity. Introscope also includes historical performance analysis and trend analysis. All of these features can be used on every Java component in the system – even purchased software for which there is no source code, including the Java Web application server.

Installation: Follow the instructions in the product documentation.

LeakHunter

Introscope LeakHunter is an add-on component designed for locating the source of potential memory leaks, by watching for Java collection instances that appear to be increasing in size over time (the number of objects stored in the collection is increasing over time).

Installation: Follow the instructions in the product documentation. This simply involves copying a JAR file to the classpath and then editing a configuration file.

Borland Optimizeit

Borland Optimizeit  is great for isolating and resolving performance bottlenecks during the development of J2EE applications. This is a resource intensive tool and should not be used for monitoring production environments.

The memory and CPU profiling, thread and code coverage analysis features proved a detailed view of performance data that starts from high-level J2EE diagnostic metrics right down to deep code-level granularity (providing that the source code is available).

Developers can now track performance bottlenecks at the JDBC, JMS, JNDI, JSP and EJB level, drilling down to the exact line of source code for root-cause precision.

This is a fairly complex too to get to grips with and will require at least 3 days to learn the basics of it.

Installation: Follow the instructions in the product documentation. If you follow the documentation from the CD you should be okay. However when you come to specifying the advanced JVM settings you should ensure that the following parament is set:
-Xrunpri:startAudit=t,filter=/opt/OptimizeitStudio/filters/WebSphere.oif

References

IBM JVM Diagnostics Guide
        http://www-106.ibm.com/developerworks/java/jdk/diagnosis/
 

你可能感兴趣的:(java,IBM,application,performance,websphere,Borland)