Technical Blog Post
Methods for Extracting Java Heap Values and Monitoring Java Heap Usage in WebSphere
There are a few methods or ways to verify Configured Heap Values and monitor Current Heap Usage in WebSphere Application Server as well as a few different dump and file types useful for this task.
Useful Dumps and Files containing information about your Java Heap.
Javacores txt files are useful to determine Initial, Maximum and Current Heap values along with Threading and Locking information and even include a Native Memory usage section. They are generally used to track Abends, Hangs, Out of Memory, GPF Crash, and Trace Assert type conditions.
Heapdumps (Portable Heap Dump) files are useful to determine Heap Occupancy and help identify Primary Leak Suspects and Classes or Types of objects responsible for the highest consumption of heap. They are generally used to investigate Java OutofMemory conditions and unexpected Java Memory growth.
VerboseGC nativestderr.log output is useful to determine Mean or Average Heap usage, verify Garbage Collection Pause Times, track Large Object Allocation Requests and confirm if Excessive GC may be occurring, as well as help identify any noteworthy GC patterns or anomalies and spikes in activity.
Snap.Java Traces trc files are essentially in-flight recorders for Event sequences and also contain GC Allocation information, so a good substitute if you do not have VerboseGC currently enabled.
System Coredumps dmp files contain both Java and Native Memory references and Heapdumps can also be extracted from them. They can be used to help track Abends, Hangs, Java + Native OutofMemory, GPF Crash, Trace Asserts conditions. They are very large dumps and generally not our first recommendation to monitor heap usage, also needing to be Jextracted to include Local Native libraries for our Tooling to format their binary contents.
Useful Methods to generate the above referenced Dumps and Files for Monitoring the Java Heap.
1.) Generate a Javacore manually from the Command line or a DOS box.
a. Execute a kill -3 or kill -quit command on Unix generates Javacore or Threaddump, which contains the following Java Heap information including Initial Heap, Maximum Heap, Total Heap, Heap in use, and Heap Free:
Total memory in use:
Total memory free:
You can also use our Dump Agent as a Generic JVM Arg to specify which dumps to generate on the kill -3 command:
-Xdump:java:events=user (javacore only)
-Xdump:heap+java:events=user (heapdump and javacore)
-->> system+snap parameters can also be used if needed to specify additional System Coredump an Java Snap Traces, system dumps are generally speaking very large requiring proper ulimit setup (ulimit -c -f unlimited for hard and soft values) on Unix or enough file system space on windows and also need to be Jextracted to include required local libraries necessary for out Tooling to process these binary files.
b. CTRL+BREAK can be used on Windows to generate Javacore dumps, but the user needs to create a special startup script first for the JVM.
1. Open the command prompt.
2. Navigate to "bin" subdirectory under the server's profile root (<WAS_HOME>\profiles\<PROFILE_NAME>\bin)
3. From the "bin" subdirectory, execute the one of the following commands. Choose the command from the list below based on the type of server that the javacore will be generated from.
startServer.bat SERVER_NAME -script
Deployment Managers (DMGR)
This will generate a script named start_<SERVER_NAME>.bat in the current directory that can be used to start the JVM activating the CTRL+BREAK key combination to generate Javacores.
c. Invoke WSAdmin user interface from a Command prompt or DOS box against the SOAP port for AppServer or DMgr to generate a Javacore or Threaddump.
set jvm [$AdminControl completeObjectName type=JVM,process=SERVER_NAME,*]
$AdminControl invoke $jvm dumpThreads
jvm = AdminControl.completeObjectName('type=JVM,process=SERVER_NAME,*')
2.) Generate Javacore and Heapdump manually from WebSphere Administrative or Integrated Solutions Console in Full Profile or using javadump command in Liberty Profile.
a. Example in Full Profile using GUI or WUI Console:
- Within the Administrative Console, expand the Troubleshooting section and click Java dumps and cores.
- Find the list of available JVM processes and select the JVM(s) of interest.
- Once selected you can then click the button corresponding to the 'File Type' you would like to generate: Heap dump, Java core, or System dump.
b. Example in Liberty Profile using javadump command:
Assume <server_name> = server1
- To get just a javacore/thread memory dump:
- Server javadump server1
- To get a javacore/thread dump and a heapdump:
- server javadump server1 --include=heap
- To get a javacore/thread dump and a system core dump:
- server javadump server1 --include=system
*** Analyzing Viewing resulting Javacore or Heapdump output ***
Javacores are Plain Text or Ascii files so can be read with any Editor of your choice and do not require additional tooling or formatting. You can also use Thread and Monitor Dump Analyzer if you prefer a GUI front end and this does have the advantage of processing multiple Javacores at one time, performing Threads and Monitor Locks comparisons and so forth, so it can be a very practical and useful tool.
Heapdumps are Binary Files and require one of the following tools to format them for analysis:
Memory Analyzer (MAT) or Heap Analyzer (HA)
Most of these tools can be downloaded as separate eclipse EXEs or java JARs or can also be used in conjunction with IBM Support Assistant tooling as Plugins, see 5.) below for more information regarding ISA download.
3.) Enable VerboseGC, which would be very little or no overhead associated, since the calculations were previously performed during the actual GC runtime.
- a. Select Servers > Application servers > server1 > Java and Process Management > Process Definition > Java Virtual Machine.
- b. Select Verbose garbage collection.
- c. Click Apply and click Save at the top of this page.
* You can use GCMV or PMAT standalone or eclipse plugins to analyze view the resulting output.
IBM Monitoring and Diagnostic Tools - Garbage Collection and Memory Visualizer (GCMV
IBM Pattern Modeling and Analysis Tool for Java Garbage Collector
4.) Setup and use built-in PMI Request Metrics or more specifically Counters for monitoring java heap usage, just need to configure and setup.
Java Virtual MachineCounter Definitions:
You can use the Java virtual machine (JVM) counters that the Performance Monitoring Infrastructure (PMI) and Tivoli® Performance Viewer (TPV) collect to monitor JVM performance.
The total, used, and free heap size counters are available without any additional configuration settings. The remaining counters are available only when a Java virtual machine profiler is enabled.
Enabling the Java virtual machine profiler data
e. g. Heap and Garbage Collection related counters...
5.) Download and use IBM Support Assistant or Team Server, and use the Java HealthCenter and appropriate Plugins (Tools):
ISA IBM Support Assistant:
IBM Support - IBM Support Assistant Team Server
Problem Determination Tools for IBM Support Assistant Team Server 5
Tools or Plugins Available for ISA:
FileNet Optical Storage and Retrieval (OSAR) Cable Tool
Garbage Collection and Memory Visualizer (GCMV)
Java Health Center
Heap Analyzer (HA)
Interactive Diagnostic Data Explorer (IDDE)
Memory Analyzer Tool (MAT)
Pattern Modeling and Analysis Tool for Java Garbage Collector (PMAT)
Portal Log Analyzer
Profile Port Checker
Processor Time Analysis Tool for Linux
Serviceability Tool for Sametime
Thread and Monitor Dump Analyzer for Java (TMDA)
Trace and Request Analyzer for WebSphere Application Server
WAIT Javacore Analyzer
Web Server Plug-in Analyzer for WebSphere Application Server
WebSphere Application Server Configuration Visualizer
WebSphere Cross Component Trace Logviewer
6.) Using WSAdmin Command-Line Interface:
a. Check pre-configured Initial and Maximum Heap size values if explicitly set.
wsadmin Script to check the JVM heap size of a WebSphere Server:
# Usage: wsadmin -f getJvmHeap.py server
server = AdminConfig.getid('/Server:'+sys.argv+'/')
jvm = AdminConfig.list('JavaVirtualMachine', server)
print 'initialHeapSize: ' + AdminConfig.showAttribute(jvm, 'initialHeapSize')
print 'maximumHeapSize: ' + AdminConfig.showAttribute(jvm, 'maximumHeapSize')
b. Check current runtime Total, Free and Maximum Java Heap Memory values.
Get current system data by running wasadmin.sh as follows.
- Declare Object Name
- Run operation, and confirm total memory size, and available memory size.
public long freeMemory()Returns the amount of free memory in the Java Virtual Machine. Calling the
gcmethod may result in increasing the value returned by
- an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.
public long totalMemory()Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.
- the total amount of memory currently available for current and future objects, measured in bytes.
public long maxMemory()Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value
Long.MAX_VALUEwill be returned.
- the maximum amount of memory that the virtual machine will attempt to use, measured in bytes