10

How can I get aheap dump from a remote JVM which runs on linux with WL application server?

When I run locally on a windows machine I know how to get a dump. But, how do I get a dump from the user acceptance test server? Thanks in advance.

Kara
  • 6,115
  • 16
  • 50
  • 57
Srisfti
  • 157
  • 2
  • 3
  • 10
  • I usually SSH into it and do it – jmj Dec 29 '14 at 22:20
  • This question is off topic for Stack Overflow. Questions on Stack Overflow must be directly related to programming. Questions about remote server administration should be directed to [sf]. – spicy.dll Oct 20 '21 at 13:46

4 Answers4

11

You can use JMX to connect to the remote application server (it should be enabled in advance) and use the HotSpotDiagnostic MBean which allows taking a heap dump.
You can use JConsole or VisualVM for invoking the MBean operation.
This post by Mike Haller describes how to use this method with JVisualVM.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
2

Since its a *-nix system, and if you have the necessary privieleges, then it would be easy to connect to using SSH protocol:

  • Connect to the remote machine:

    ssh user@remote-machine-ip-address
    
  • Enter the user password once prompted for it (it should be the one for the user on the remote machine and not your current system user).

  • Generate your heap dump using the jmap utility (JDK binaries path should be availble into your system PATH variable or use a full path to it):

    jmap -dump:format=b,file=cheap.bin <pid>
    
tmarwen
  • 15,750
  • 5
  • 43
  • 62
1

There are three steps:

  1. ssh to your server

ssh <your_user_name>@<remote_ip>

  1. jmap to trigger memory dump

jmap -dump:format=b,file=<your_file_name> <your_jvm_pid>

  1. visualize the heap by jhat (here 512m is the size limit, you can set it depends on the leak's file size, like -J-Xmx2g)

jhat -J-Xmx512m <your_file_name>

jhat -port 7401 <your_file_name>

I write a blog to help analyze performance issue: Performance Optimization

Haimei
  • 12,577
  • 3
  • 50
  • 36
  • When the server is running with just a JRE (and not a JDK), the `jmap` tool is not available on the server. – Michiel Haisma Oct 13 '21 at 14:59
  • 2
    @MichielHaisma why are you focusing on this answer instead of [that answer](https://stackoverflow.com/a/27707332/2711488)? Shouldn’t you consider all answers before deciding to start a bounty? – Holger Oct 14 '21 at 11:08
1

I've used Visual VM successfully for thread dumps and heap dumps, however, you don't list your JAVA version?

JAVA Visual VM is no longer shipped with JAVA, but can still be downloaded here and it's still being maintained. They just did a new minor release: October 19, 2021: VisualVM 2.1.1 Released.

VisualVM has also been distributed in Oracle JDK 6~8 as Java VisualVM. It has been discontinued in Oracle JDK 9.

Here are steps for connecting to the VM from Dzone, VisualVM: Monitoring Remote JVM Over SSH (JMX Or Not)

For other alternatives, the Baeldung JAVA site, which has great information and tutorials, has A Guide to Java Profilers.

James Drinkard
  • 15,342
  • 16
  • 114
  • 137