I have to parse enormous hprof file(54GB) and I'm out of RAM(given 30GB). Is there a walkaround?
Or maybe there is a way to proces hprof file via terminal? I could run it on my production server if there is a way.
Edit: I forgot to mention I want to analyse it using Eclipse MAT.
Related
On Linux, I want to run java .jar file from command line and produce some output about memory usage over time that can be later visualize in some program. I found this question, but HPjmeter is unable to load produced log.out file. How can I achieve that?
I am creating heap dump using below command:
jmap -dump:file=DumpFile.txt <process-id>
I have opened the generated file - DumpFile.txt but it is not in readable format.
So please let me know how to analyze the data in the generated file.
You should use jmap -heap:format=b <process-id> without any paths. So it creates a *.bin file which you can open with jvisualvm.exe (same path as jmap). It's a great tool to open such dump files.
You can use jhat (Java Heap Analysis Tool) to read the generated file:
jhat [ options ] <heap-dump-file>
The jhat command parses a java heap dump file and launches a webserver. jhat enables you to browse heap dumps using your favorite webbrowser.
Note that you should have a hprof binary format output to be able to parse it with jhat. You can use format=b option to generate the dump in this format.
-dump:format=b,file=<filename>
Very late to answer this, but worth to take a quick look at. Just 2 minutes needed to understand in detail.
First create this java program
import java.util.ArrayList;
import java.util.List;
public class GarbageCollectionAnalysisExample{
public static void main(String[] args) {
List<String> l = new ArrayList<String>();
for (int i = 0; i < 100000000; i++) {
l = new ArrayList<String>(); //Memory leak
System.out.println(l);
}
System.out.println("Done");
}
}
Use jps to find the vmid (virtual machine id i.e. JVM id)
Go to CMD and type below commands >
C:\>jps
18588 Jps
17252 GarbageCollectionAnalysisExample
16048
2084 Main
17252 is the vmid which we need.
Now we will learn how to use jmap and jhat
Use jmap - to generate heap dump
From java docs about jmap
“jmap prints shared object memory maps or heap memory details of a given process or core file or a remote debug server”
Use following command to generate heap dump >
C:\>jmap -dump:file=E:\heapDump.jmap 17252
Dumping heap to E:\heapDump.jmap ...
Heap dump file created
Where 17252 is the vmid (picked from above).
Heap dump will be generated in E:\heapDump.jmap
Now use Jhat
Jhat is used for analyzing the garbage collection dump in java -
C:\>jhat E:\heapDump.jmap
Reading from E:\heapDump.jmap...
Dump file created Mon Nov 07 23:59:19 IST 2016
Snapshot read, resolving...
Resolving 241865 objects...
Chasing references, expect 48 dots................................................
Eliminating duplicate references................................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.
By default, it will start http server on port 7000.
Then we will go to http://localhost:7000/
Courtesy : JMAP, How to monitor and analyze the garbage collection in 10 ways
If you use Eclipse as your IDE I would recommend the excellent eclipse plugin memory analyzer
Another option is to use JVisualVM, it can read (and create) heap dumps as well, and is shipped with every JDK. You can find it in the bin directory of your JDK.
VisualVm does not come with Apple JDK. You can use VisualVM Mac Application bundle(dmg) as a separate application, to compensate for that.
MAT, jprofiler,jhat are possible options. since jhat comes with jdk, you can easily launch it to do some basic analysis. check this out
If you just run jmap -histo:live or jmap -histo, it outputs the contents on the console!
I have a Memory Dump file and JHAT gives the following message and I cannot analyze anything (as no data is displayed.
Resolving 0 objects...
WARNING: hprof file does not include java.lang.Class!
WARNING: hprof file does not include java.lang.String!
WARNING: hprof file does not include java.lang.ClassLoader!
Does this mean the hprof file is incomplete or corrupt?
I am using
-XX:+HeapDumpOnOutOfMemoryError"
option in my tomcat.
I just came across this same issue with my own heap dump.
jhat shows the warnings you describe, and there's no useful data displayed
Eclipse MAT complains about a NullPointerException
VisualVM can't open the heap dump file at all
It looks like this happens when there is not enough disk space at the time that the heap is dumped, so the file is indeed incomplete/corrupt.
http://forums.oracle.com/forums/thread.jspa?threadID=1175621&tstart=135
I have the same problem today. To clarify, I am using the option heap=sites which is different than a memory dump. I also get the same messages from jhat and jvisualvm. It is possible that jhat does not support reading HPROF files created by heap=sites mode.
I'm using ASANT to run a xml file which points to a NARS.jar file.
I'm getting "java.lang.OutOfMemoryError: Java heap space" and i'm researching around this.
So i have found that i need to set "-XX:+HeapDumpOnOutOfMemoryError", to create a dump file to analyze.
I edited ASANT.bat and added the "-XX:+HeapDumpOnOutOfMemoryError" to ANT_OPTS:
set ANT_OPTS= "-XX:+HeapDumpOnOutOfMemoryError" "-Dos.name=Windows_NT" "-Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"
But i can't seem to find any dump file.
I will use the Eclipse Memory Analyzer to analyze when i find the dump.
I also tried to set the option "-XX:HeapDumpPath=c:\memdump\bds.hprof", but no dump was created there.
Anyone got an idea of what i'm doing wrong?
Thanks in advance
It looks like your application is running on Windows. A Windows file path needs to be escaped with \. As per your example, -XX:HeapDumpPath should look like:
-XX:HeapDumpPath=c:\\memdump\\bds.hprof
Besides ‘-XX:+HeapDumpOnOutOfMemoryError’ there are several other options to capture heap dumps as well.
I found that i could use VisualVM from SUN to get a heapdump, and see it live.
Easy solution
It's in the working directory of the application (i.e. where you've started it). I'm not sure what happens if the process does not have the necessary privileges to do so. Probably, writing the dump would fail silently.
are you sure that ANT is the process with the OOME ? It may be a process started by ANT.
Add "-debug" to the ANT_OPTS for debugging information.
Are you seeing the targets being printed out during the execution?
You can also fork the various processes started by ant ( will slow things down but may help isolate the culprit )
Lastly, maybe you just need more memory than the default. Add:
-Xms256m -Xmx512m -XX:PermSize=64m -XX:MaxPermSize=256m
to the ANT_OPTS
Umm... how about wherever java.io.tmpdir is pointing?
I was told I can add the -XX:+HeapDumpOnOutOfMemoryError parameter to my JVM start up options to my JBoss start up script to get a heap dump when we get an out of memory error in our application. I was wondering where this data gets dumped? Is it just to the console, or to some log file? If it's just to the console, what if I'm not logged into the Unix server through the console?
Here's what Oracle's documentation has to say:
By default the heap dump is created in
a file called java_pid.hprof in the
working directory of the VM, as in the
example above. You can specify an
alternative file name or directory
with the -XX:HeapDumpPath= option. For
example -XX:HeapDumpPath=/disk2/dumps
will cause the heap dump to be
generated in the /disk2/dumps
directory.
You can view this dump from the UNIX console.
The path for the heap dump will be provided as a variable right after where you have placed the mentioned variable.
E.g.:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${DOMAIN_HOME}/logs/mps"
You can view the dump from the console on the mentioned path.
I found it hard to decipher what is meant by "working directory of the VM". In my example, I was using the Java Service Wrapper program to execute a jar - the dump files were created in the directory where I had placed the wrapper program, e.g. c:\myapp\bin. The reason I discovered this is because the files can be quite large and they filled up the hard drive before I discovered their location.
If you are not using "-XX:HeapDumpPath" option then in case of JBoss EAP/As by default the heap dump file will be generated in "JBOSS_HOME/bin" directory.
If you only configure -XX:+HeapDumpOnOutOfMemoryError parameter then heapdump will be generated in JBOSS_HOME/bin directory for OpenJDK/Oracle JDK. If you are using IBM JDK then heapdump will be created under /tmp directory as phd file. -XX:HeapDumpPath option gives us more feasibility for configuring our custom headpump path location (-XX:HeapDumpPath=/my-custom-jboss-server-path/). It's recommended to have this parameters configured in your environment as it will collect heapdump on OutOfMemory error for analyzing the issue with memory leak of the application or checking any large object retention in the application.