I've ssh'ed into a machine and am running a java program. After quit a while, I get a heap dump and have sent that into a file java_pid28356.hprof How can I read from that file with just command line tools to find what is causing the dump?
less %DUMP_FILE_DIR%/java_pid28356.hprof
Also you can try ParseHeapDump.sh - part of eclipse memory analyzer (you can google it, but I post the script below for your convenience)
#!/bin/sh
#
# This script parses a heap dump.
# Adjust the path to java, version 5 or later, and the heap size as required.
# Suitable for 64-bit and 32-bit Java, but a 64-bit Java is required
# for larger heap sizes.
#
# Usage: ParseHeapDump.sh <path/to/dump.dmp.zip> [report]*
#
# The leak report has the id org.eclipse.mat.api:suspects
# The top component report has the id org.eclipse.mat.api:top_components
#
java -Xmx3072M -jar "`dirname "$0"`"/plugins/org.eclipse.equinox.launcher_1*.jar -consoleLog -application org.eclipse.mat.api.parse "$#"
Related
I have a program running under a java wrapper, as the application has to be run as a Windows service. However, I am encountering Exception in thread "Thread-5" java.lang.OutOfMemoryError: Java heap space after running the application every couple of weeks.
The memory values are commented out. Does this mean there is no limit of memory this application is allowed to use?
I'm also checking the codes of possible memory leaks, but are there any ways to modify the config in order to find the cause/prevent out of memory errors?
#********************************************************************
# Wrapper Java Properties
#********************************************************************
# Java Application
# Locate the java binary on the system PATH:
#wrapper.java.command=%JAVA_HOME%\bin\java
# Specify a specific java binary:
set.JAVA_HOME=%JAVA_HOME%
wrapper.java.command=%JAVA_HOME%\bin\java
# Tell the Wrapper to log the full generated Java command line.
#wrapper.java.command.loglevel=INFO
# Java Main class. This class must implement the WrapperListener interface
# or guarantee that the WrapperManager class is initialized. Helper
# classes are provided to do this for you. See the Integration section
# of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=%JAVA_HOME%\lib\tools.jar
wrapper.java.classpath.3=C:\daifuku\wms\tomcat\webapps\wms\WEB-INF\classes
wrapper.java.classpath.4=C:\daifuku\wms\tomcat\webapps\wms\WEB-INF\lib\*.jar
wrapper.java.classpath.5=C:\daifuku\wms\tomcat\lib\comm.jar
wrapper.java.classpath.6=C:\daifuku\wms\tomcat\lib\servlet-api.jar
wrapper.java.classpath.7=C:\daifuku\wms\tomcat\lib\jsp-api.jar
# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=%JAVA_HOME%\jre\lib
# Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE
# Java Additional Parameters
wrapper.java.additional.1=
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=64
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=512
# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=XXX
Many Thanks!
Does this mean there is no limit of memory this application is allowed to use?
I believe that it will use the default value configured for your system: How is the default Java heap size determined?
Since you mentioned that the problem appears after running your application for a few weeks, most likely you have a memory leak. I advise you to make a dump using JvisualVm for your java wrapper process, and afterwards just analyze the dump using the Mat analyzer https://www.eclipse.org/mat/.
So you're basically asking which parameters for Heap does java actually allocate when you don't specify the init and max memory (which I believe translate to well known -Xmx and -Xms
In general its system dependent and the algorithm also has changed many times, so to be sure, you actually should check on your system:
java -XX:+PrintFlagsFinal -version | grep HeapSize // or run you application with that flag if you wish
// or on windows
java -XX:+PrintFlagsFinal -version | findstr HeapSize
Then check for:
InitialHeapSize
MaxHeapSize
My command line java program works when run on a Windows 10 workstation with a dual core CPU with 1GB RAM allocated.
However, it encounters an out of memory error when I run it on a Ubuntu virtual machine with four vCPUs with 12GB RAM.
Both are run using -Xms and -Xmx set accordingly to the same value.
This is a strange error.
UPDATE:
1) I can't share the code and not to sound arrogant or anything but I think there is nothing wrong with the code.
2) The error is as follows:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 12288 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2627), pid=22403, tid=0x00007f52f9f2c700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Btw, my vm's max memory is 12GB and I used -Xms12160m -Xmx12160m.
As for my workstation, my max memory is 2GB but I used -Xms1024m -Xmx1024m
So it seems to me on the Linux system you are asking it to reserve the full 12 MBs as the initial heap size; this is not really practical as it obviously needs memory for other stuff (code, operating system etc).
From other questions on SO it seems clear that the defaults for minimum is something like 1/64th of the physical RAM.
Problem
When call the java in php (web server), Out of Memory Error occurs.
State
web server - centos 6 , nginx, php-fpm , java
call the java in centos - success
call the java in php - Out of Memory Error occurs
Call API
Case : php
$string = exec('java -Xms2g -Xmx2g -jar /usr/share/nginx/html/my_test.jar /mytmp/testfile’, $output, $code);
Case : centos 6 (linux)
java -Xms2g -Xmx2g -jar /usr/share/nginx/html/my_test.jar /mytmp/testfile
Error Message
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2555904 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2673), pid=2549, tid=140226036020992
#
# JRE version: (8.0_45-b14) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Question
why different work ?
how to solved that ?
I try that (not solve)
set memory
java -Xms2g -Xmx2g
i solve thaht.
"setsebool -P httpd_execmem on"
My Tomcat server has been running for several days, but I can't shut it down normally because when executing shutdown.sh, I got this error:
# root#iZ94hjppdqzZ:~/projects/taolijie# cat hs_err_pid5519.log
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2673), pid=5519, tid=3061726064
#
# JRE version: (8.0_45-b14) (build )
# Java VM: Java HotSpot(TM) Server VM (25.45-b02 mixed mode linux-x86 )
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Therefore I have to kill Tomcat in order to shut it down. But the weird thing is that Tomcat worked normally when this error is generated(It can process web request normally).
Here are the VM options:
-server -Xms1G -Xmx1G -XX:+UseG1GC
My server has 2GB memory. Could anyone figure out what's happening?
Thanks!!
This looks like you are setting your memory configuration by:
JAVA_OPTS="-server -Xms1G -Xmx1G -XX:+UseG1GC"
The JAVA_OPTS environment variable is used for all of Tomcat's java processes such as the one that is used to send the shutdown message.
You need to be certain that you are configuring your Tomcat memory by setting:
CATALINA_OPTS="-server -Xms1G -Xmx1G -XX:+UseG1GC"
This setting will then only be applied to the Tomcat process. The other control processes will execute fine using default memory settings.
I have a java file which is being triggered from a shell script. If I execute the shell script at command line it is executing the java file without any issues but if i execute this shell script from browser( i have a index.php which executes this shell script in linux server ) it is not executing the java file in shell script. The shell script is executed properly If I remove the java execution line from the shell script.
below is the error i received when executed from browser.
Error From browser:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00007fcf589ac000, 2555904, 1) failed; error='Permission denied' (errno=13) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (malloc) failed to allocate 2555904 bytes for committing reserved memory. # An error report file with more information is saved as: # /tmp/hs_err_pid306.log
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 2555904 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2726), pid=306, tid=140528680765184
#
# JRE version: (7.0_51-b13) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode linux-amd64 compressed oops)
Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Please help me on how I can fix this problem.. Stuck with this issue from last one week. :|
Permission problem.
Probably you run this java file as a different user from a browser.
An error report file with more information is saved as: # /tmp/hs_err_pid306.log
What does this error say?
Issue you have is with the HEAP memory.You don't have set enough memory to run the application.
Default size of Heap space in Java is 128MB on most of 32 bit Sun's JVM but its highly varies from JVM to JVM e.g. default maximum and start heap size for the 32-bit Solaris Operating System (SPARC Platform Edition) is -Xms=3670K and -Xmx=64M and Default values of heap size parameters on 64-bit systems have been increased up by approximately 30%. Also if you are using throughput garbage collector in Java 1.5 default maximum heap size of JVM would be Physical Memory/4 and default initial heap size would be Physical Memory/16. Another way to find default heap size of JVM is to start an application with default heap parameters and monitor in using JConsole which is available on JDK 1.5 onwards, on VMSummary tab you will be able to see maximum heap size.
By the way you can increase size of java heap space based on your application need and I always recommend this to avoid using default JVM heap values. if your application is large and lots of object created you can change size of heap space by using JVM options -Xms and -Xmx. Xms denotes starting size of Heap while -Xmx denotes maximum size of Heap in Java. There is another parameter called -Xmn which denotes Size of new generation of Java Heap Space. Only thing is you can not change the size of Heap in Java dynamically, you can only provide Java Heap Size parameter while starting JVM. I have shared some more useful JVM options related to Java Heap space and Garbage collection on my post 10 JVM options Java programmer must know, you may find useful.
Read more: http://javarevisited.blogspot.com/2011/05/java-heap-space-memory-size-jvm.html#ixzz30FsKCqeT
If it's tomcat you have to set this Memory Variables in "catalina.sh".
Eg : If you a starting the application through command Line :
/bin/java -Xms2048M -Xmx2048M Djava.util.logging.config.file= -Xms2048M -Xmx2048M