Why max heap size is incorrect when I enable G1 garbage collector?
Asked Answered
C

1

6

When I enable G1 in java application with -Xmx=1024m -XX:+UseG1GC. And using jvisualvm command to check max heap size. The max heap size is 2GB instead of 1GB.

Does anybody know why ?

Chromous answered 12/8, 2015 at 3:46 Comment(0)
Q
3

The JVM allocates more heap memory from the OS than the usage.
Allocating memory is a heavy operation considering the performance.
So JVM always allocate extra memory then it needs.

Java also allocate memory for other things, including a stack for each thread. It is not unusual for the total memory consumption of the VM to exceed the value of -Xmx.

The JVM maintains two memory areas, the Java™ heap, and the native (or system) heap. These two heaps have different purposes and are maintained by different mechanisms.

The Java heap contains the instances of Java objects and is often referred to as 'the heap'. It is the Java heap that is maintained by Garbage Collection, and it is the Java heap that is changed by the command-line heap settings. The Java heap is allocated using mmap, or shmat if large page support is requested. The maximum size of the Java heap is preallocated during JVM startup as one contiguous area, even if the minimum heap size setting is lower.

The native, or system heap, is allocated by using the underlying malloc and free mechanisms of the operating system, and is used for the underlying implementation of particular Java objects; for example:

1) Compiled code generated by the Just In Time (JIT) Compiler
2) Threads to map to Java threads

jvisualvm is showing you java heap+system heap. whereas the -Xmx parameter is just affecting the java heap.
Link: http://www-01.ibm.com/support/knowledgecenter/SSYKE2_5.0.0/com.ibm.java.doc.diagnostics.50/diag/problem_determination/aix_mem_heaps.html

Quizmaster answered 12/8, 2015 at 3:52 Comment(2)
I don't think so. Because when I change -Xmx=4096m then max heap size is 8GB and heap size is 0.7GB and used heap size is 0.5GBChromous
Thanks. When I use jconsole to check, max heap size is correct.Chromous

© 2022 - 2024 — McMap. All rights reserved.