Using HeapDumpOnOutOfMemoryError parameter for heap dump for JBoss - java

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.

Related

-XX:HeapDumpPath file output to a remote location

Good day.
I have a JAVA application that writes a heapdump when an OutOfMemoryError ocurrs, the location of the heapdump is inconvenient and I'm trying to figure out if there's a way I can configure the automatic heapdump to place the dump file in a remote location other than the original server.
I know that for jmap there is an option that looks like this:
jmap [ option ] [server-id#]remote-hostname-or-IP
(see https://docs.oracle.com/javase/7/docs/technotes/tools/share/jmap.html)
But what I'm trying to do is directly on the VM options:
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=server-ip/server-directory

JVM crash.. How to get err log or core dump

I have a java application that calls a native dll using jna. The program crashes JVM in the middle after my callback in java is execute and throw "java platform se binary has stopped" dialogue box. the java console logs are not useful, there is nothing there. How to get a core dump or some other useful logs in the windows for figuring out the issue and where it is causing it. looked for hs_err log in the temp folder but could not find it.
We have been seeing this error since past few days with JVM (openjdk 8) running on our RHEL platforms. we notice it generate some error message in /var/log/message file which writes about the location of core_dump file as below.
2020-01-29T03:08:14.980998+00:00 lon6pvlpdgrd103 abrt[2274]: Saved core dump of pid 40132 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-0.el6_10.x86_64/jre/bin/java) to /var/spool/abrt/ccpp-2020-01-29-03:08:10-40132 (1048576000 bytes)
I think its OS level feature to generate core-dump when process crashes abnormally.
This page help further in knowing the reason for crash: https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/crashes001.html
For windows please refer to section 17.4.4 Collect Crash Dumps on Windows form above article.
Please check if this helps.
The hs_err file is usually written in the "current directory" for the JVM process. If the directory is not writable by the user then the file is written to a temporary directory. You can also tell the JVM to write the fatal error report to a specified file.
A core dump will only be written if the "core file size" ulimit (or equivalent) is large enough and their is enough file space. The default ulimit is zero.
For more information:
Location of Fatal Error Log
Collect Core Dumps
Use -XX:ErrorFile to specify the error file.
From Location of Fatal Error Log:
To specify where the log file will be created, use the product flag -XX:ErrorFile=file, where file represents the full path for the log file location.
Also, this:
If the -XX:ErrorFile=file flag is not specified, the default log file name is hs_err_pid.log, where pid is the PID of the process.

How to profile a class inside a jar?

If I have a class inside a JAR (compiled with mvn assembly:assembly) which I'm trying to profile, what's the command to get a valid core dump which I can use with jhat or the Eclipse Memory Analyzer?
I tried running this:
java -agentlib:hprof=heap=sites,cpu=samples,file=profile.hprof,format=b -jar the-jar.jar
and the core dump is created when I stop the process.
But neither jhat or the Eclipse Memory Analyzer recognize this as a valid dump.
jhat gives me this warning:
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!
Also reading through the hprof documentation, I see that I must pass the class name. How do I do that when it's inside the JAR?
The fact the the class was loaded from a JAR file is not relevant for the heap dump.
You can use jmap to get usable HPROF heap dumps without modifying the start command.
jmap -heap:format=b <pid>
where is the process id that you can get the with the jps command line utility. Both executables are part of the JDK.

Heap dump on Out of Memory error

I am using Tomcat server and I want to get a heap dump on Out of Memory error.
How can I do this by specifying parameters in the Catalina.bat file?
Also is there a way to specify the path where the dump file is stored?
According to this http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
you can use option -XX:HeapDumpPath=./java_pid<pid>.hprof.
You do not have to modify calatalina.bat or other scripts to add options to Tomcat. Just set system variable CATALINA_OPTS before running Tomcat.

Hibernate - OutOfMemoryError - java heap size

I'm currently having this problem where I am executing a query that will load large of records. At first execution, it is successful, but when I
execute again, I am having java heap size out of memory.
I Know I can increase java heap size using command line, but that requires a compiled jar file.
But I am currently on the development process, so how can I increase java heap size in that case?
Im using Elipse as my IDE.
Thanks for any response.
It doesn't require a compiled jar file. Choose Run - Run configurations... - Select your run configuration - Arguments tab. Then enter the appropriate command line argument in the VM arguments text box: -Xmx1024m for example.
You can modify the eclipse.ini file located inside of our eclipse directory .There you will find Xms40m Xmx256m parameter with some value , you can increase it to Xms256m Xmx1024m . Then check whether outofmemory error is still there . If its there then try tuning these parameter slightly increasing and check.
Apperently that was not enough for an answer... well, let me just copy the text from those answers instead :S
You can use the environment variable _JAVA_OPTIONS to set the default heap size. This will change the heap size for all Java programs. Like this:
export _JAVA_OPTIONS="-Xmx1g"

Categories