Heap space Exception - jvm

I have 16GB RAM and 64bit windows operating system.I want to run an web application I got heap space exception if i change VM arguments to -Xms3512m -Xmx3512m -XX:MaxPermSize=128m -XX:-UseGCOverheadLimit -XX:ReservedCodeCacheSize=32m I got exception as
Error occurred during initialization of VM
Could not reserve enough space for object heap
but I have another system with same configuration but that system accept this VM Arguments. please give me solution

Increase the heap size with: XX:MaxHeapSize=??m

Heap allocation done at the JVM initialization. It look for contiguous memory space of size -Xmx. If it could not find the continuous space of Xmx size then JVM failed during initialization Please add the argument -verbose:init and check the console output to identify which stage it failed on initialization.

Related

Java process consuming 90% of swap space

I have an application that has an allocated heap memory of 20GB. But even though the Heap memory is barely or less than 50% used, my server swap space gets used up totally. Java is the process that is consuming 90% of the swap.
The swap gets released only after restarting the application with a below warning. Looking for finding out the root cause and any impact due to this. Will my app fail to start if the swap is filled?
Warning i see during App startup in logs:
There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (mmap) failed to map 17895718912 bytes for committing reserved memory.. Out of swap space or heap resource limit exceeded (check with limits or ulimit)?
An error report with more information is generated,
it is saved as a file at this location:
/XX/myapp/apache-tomcat-7.0.90/bin/hs_err_pid86282.log
2020-01-14T05:17:18.742+0100 [INFO] [o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker] Bean '(inner bean)#1814a032' of type [org.springframework.aop.aspectj.AspectJAroundAdvice] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
***Warning: INFO: os::commit_memory(0x00000003fjgh0000, 17895718912, 0) failed; error='Not enough space' (errno=12)
There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (mmap) failed to map 17895718912 bytes for committing reserved memory.. Out of
swap space or heap resource limit exceeded (check with limits or ulimit)?
An error report with more information is generated,
it is saved as a file at this location:
My JVM properties:
/XX/java/bin/java -Djava.util.logging.config.file=/XX/myapp/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -javaagent:/xx/myapp/newrelic/newrelic.jar -Djdk.tls.ephemeralDHKeySize=2048 -Xms20g -Xmx20g -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -Djava.net.preferIPv4Stack=true -Dignore.endorsed.dirs= -classpath /XX/myapp/tomcat/bin/bootstrap.jar:/XX/myapp/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/XX/myapp/tomcat -Dcatalina.home=/XX/myapp/tomcat -Djava.io.tmpdir=/XX/myapp/tomcat/temp org.apache.catalina.startup.Bootstrap start
Swap usage when checked for each process, its Java that uses 90% of Swap
Your Java process is made not only from heap memory, watch this for a good example.
Now, you say that you have 28GB of RAM, out of which you allocate 20GB for heap only. Not only do you reserve virtual memory, but you also commit it, via AlwaysPreTouch (I now doubt you even understand what this does). So your OS, maps 20GB of RAM to your process (simplified explanation).
Even if you see that only 50% is occupied, the garbage collector that you use - does not release memory back to the OS, so the entire 20GC are always occupied and can not be re-used by some other process. As such, it is pointless to measure or monitor the heap.
Your process fails with Native memory allocation (mmap) failed to map..., as said this is unrelated to the heap. It fails in native memory, this is != heap. I also do not know the specifics of your application, but -XX:+DisableExplicitGC might not be a good option; instead you might enable the concurrent invocation (if your GC supports that) via -XX:+ExplicitGCInvokesConcurrent.
You also seem to be using CMS garbage collector - which is deprecated.

Does the jvm code cache area exist in heap or metaspace?

There's nothing I can found this question .
Does the JVM code cache area exist in heap or metaspace in jdk 8?
Neither in Heap nor in Metaspace. In HotSpot JVM Code Cache is a separate off-heap area. Its size is controlled by -XX:ReservedCodeCacheSize option.
On the "Memory" tab of Java Mission Control you'll find the Code Cache among other JVM memory pools:
More about JVM memory areas

Java Memory Out of Heap Space

I am using a SOLVER to solve an issue in Java using OptaPlanner but after some point of time, i get an exception saying Java.lang.OutOfMemoryError: Java Heap Space. What does this signify
JVM-Java Virtual Machine will limit your execution with some space of memory if you exceed the allocated memory you got to experience this "JAVA HEAP SPACE" ERROR.
You can also increase the Heap space by doing this,
java -Xms<initial heap size> -Xmx<maximum heap size> CLASS_FILE_TO_EXECUTE
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
Ie
java -Xmx2g assign 2 gigabytes of ram as maximum to your app
But you should see if you don't have a memory leak first.
Btw What is meant above: adjust the -Xmx setting in runExamples.bat or .sh file in: optaplanner-distribution-6.0.1.Final\examples\ (by default it is 512m). What I do to circumvent this problem and getting better results: I monitor the progress by checking MEM usage in Windows Task Manager. When it gets close to the max value I hit the "Terminate solving early" button. Than I click Save As and store a file in the "Solved" folder. Than I kill all OptaPlanner windows and restart it afresh. In "Quick Open" window I click on the file I just saved and hit Solve again. It will lower the number of Soft Constraints violated a bit better till I see the MEM is close to the limit again. I do this a couple of times till I see 2-3 times that I don't get better results. TADA, workaround.

Cannot create JVM with -XX:+UseLargePages enabled

I have a Java service that currently runs with a 14GB heap. I am keen to try out the -XX:+UseLargePages option to see how this might affect the performance of the system. I have configured the OS as described by Oracle using appropriate shared memory and page values (these can also be calculated with an online tool).
Once the OS is configured, I can see that it allocates the expected amount of memory as huge-pages. However, starting the VM with the -XX:+UseLargePages option set always results in one of the following errors:
When -Xms / -Xmx is almost equal to the huge page allocation:
Failed to reserve shared memory (errno = 28). // 'No space left on device'
When -Xms / -Xmx is less than the huge page allocation:
Failed to reserve shared memory (errno = 12). // 'Out of memory'
I did try introducing some leeway - so on a 32GB system I allocated 24GB of shared memory and hugepages to use with a JVM configured with a 20GB heap, of which only 14GB is currently utilized. I also verified that the user executing the JVM did have group rights consistent with /proc/sys/vm/hugetlb_shm_group.
Can anyone give me some pointers on where I might be going wrong and what I could try next?
Allocations/utilization:
-Xms / -Xmx - 20GB
Utilized heap - 14GB
/proc/sys/kernel/shmmax - 25769803776 (24GB)
/proc/sys/vm/nr_hugepages - 12288
Environment:
System memory - 32GB
System page size - 2048KB
debian 2.6.26-2-amd64
Sun JVM 1.6.0_20-b02
Solution
Thanks to #jfgagne for providing an answer that lead to a solution. In addition to the /proc/sys/kernel/shmall setting (specified as 4KB pages), I had to add entries to /etc/security/limits.conf as described on Thomas' blog. However, as my application is started using jsvc I also had to duplicate the settings for the root user (note that the limits are specified in KB):
root soft memlock 25165824
root hard memlock 25165824
pellegrino soft memlock 25165824
pellegrino hard memlock 25165824
It's also worth mentioning that settings could be tested quickly by starting the JVM with the -version argument:
java -XX:+UseLargePages -Xmx20g -version
When you use huge pages with Java, there is not only the heap using huge pages, but there is also the PermGen: do not forget to allocate space for it. It seems this is why you have a different errno message when you set Xmx near the amount of huge pages.
There is also the shmall kernel parameter that needs to be set which you did not mention, maybe it is what is blocking you. In your case, you should set it to 6291456.
The last thing to say: when using huge pages, the Xms parameter is not used anymore: Java reserves all Xmx in shared memory using huge pages.

Where are default JVM heap sizes defined on linux (SL4)

I'm currently using sun's java 1.6 on a SL4 cluster.
For some reason, the 1.6 JVM is starting up with an impossibly large heap, and cannot start:
java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
If I start it with e.g. -Xmx1800M, then it works OK. So, I'm wondering where the default heap size is set, and more importantly how to change it?
The machine has 8GB of physical memory, and I believe that sun's server JVM is supposed to start with a default of half the memory up to 512M, but this is clearly not the case, as it's trying to allocate over 1800M.
EDIT: I realise that it's possible to use _JAVA_OPTIONS, but this feels a bit clunky; I was expecting a properties file somewhere, but so far I've been unable to find it.
There is no properties file for this. According to Garbage Collector Ergonomics:
initial heap size:
Larger of 1/64th of the machine's
physical memory on the machine or some
reasonable minimum. Before J2SE 5.0,
the default initial heap size was a
reasonable minimum, which varies by
platform. You can override this
default using the -Xms command-line
option.
maximum heap size:
Smaller of 1/4th of the physical
memory or 1GB. Before J2SE 5.0, the
default maximum heap size was 64MB.
You can override this default using
the -Xmx command-line option.
Note: The boundaries and fractions given for the heap size are correct
for J2SE 5.0. They are likely to be
different in subsequent releases as
computers get more powerful.
Given you have 8GB of RAM, default maximum heap size should be 1GB assuming you're using Java 6.
There's no standard properties file. The (Sun) JVM has the default values hardcoded in it.