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.

[@more@]

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[i] 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[ii].

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[iii] 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[iv] 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 [v]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 [vi]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 [vii]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/



[i] Analyzing Java GC logs: http://www-1.ibm.com/support/techdocs/atsmastr.nsf/WebIndex/TD100748

[ii] VerboseGC: http://sylvester.hursley.ibm.com/

[iii] HeapRoots: http://www.alphaworks.ibm.com/tech/heaproots

[iv] HeapWizard: http://www-1.ibm.com/support/docview.wss?uid=swg24004782

[v] Rational PurifyPlus: http://www-306.ibm.com/software/awdtools/purifyplus/

[vi] Wily Technology: http://www.wilytech.com/

[vii] Borland Optimizeit: http://www.borland.com/optimizeit/

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8819325/viewspace-905550/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/8819325/viewspace-905550/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值