The question is basically contained in the title.
Say you have an application that has reached its JVM -Xmx limit. When that application requires more memory is garbage collection forced ? (in the HotSpot JVM)
A second odd thing I can't explain is that I currently have an application server which is ran with -Xmx=2048m, the "top" command (on linux) reports 2.7g for its process.
So how/when is an application allowed to exceed its -Xmx ?
Thanks,
Yes, the JVM will certainly call the GC if it reaches the heap limit (and probably much sooner). If this doesn't help, it will throw OutOfMemoryError
s.
The reason why you are seeing a bigger process memory consumption is that the -Xmx
option only limits the Java heap space (where the Java objects are allocated on). There are several other memory regions used by the JVM additionally: space for Thread stacks, the "PermGen" (where the classes and their code is stored), "direct" memory allocated via ByteBuffers
, memory allocated by native libraries, etc. For some of these additional memory regions there exist other configuration options which allow to limit them, for example -Xss
, but some are even out of control of the JVM.
Actually the normal GC is triggered when young generation is full (not the whole heap) and major GC is triggered when there is no space left in survivor space so some objects need to be migrated to old generation.
The Xmx parameter does only specify the size of the heap. The Java process takes more memory since the heap is only one part of the Java process, I guess you also have other stuff that the java process contains like native libraries, the perm gen and also native memory allocations made by the application.
Here's an nice article describing memory allocation: http://www.ibm.com/developerworks/java/library/j-nativememory-linux/
This is usually the case, althought GC is normally triggered much sooner, depending on the Garbage Collector you use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With