Say I have three Java applications; A
and B
are 32 bit, C
is 64 bit. All of them are configured with
maxHeapPercent = 50
maxHeapSize = 1024
which reads "50 percent of available memory no less than 1024 MB", according to the documentation. Now my question is, what will happen if I run these applications on the same machine?
A
and B
(being 32 bit applications!) only allow 4GB each, using 2GB of it? Ending up at 2x2GB+1x8GB=12GB? Or 2x4GB+1x8GB=16GB, leaving nothing for the OS?OutOfMemoryError
? Or will it just force swapping?The memory usage of the heap of (Java) applications is only a part of the memory that the applications requires. Other typical uses of memory are:
So besides crashing there is also a great risk of slowing down the system, even before the applications are swapped/paged out to disk, but just for lack of cache. And for Java with a small heap, very frequent Full GC cycles (scanning all object on the heap) will slow down your application long before OutOfMemoryError is thrown.
If you want to see for yourself what the MaxHeapSize becomes, try running it with PrintFlagsFinal like:
java -XX:+PrintFlagsFinal |find "MaxHeapSize"
on Windows or on Unices:
java -XX:+PrintFlagsFinal |grep "MaxHeapSize"
.
Maybe you can lower the memory usage by using a smaller stack size or even a different VM (Eclipse OpenJ9 donated by IBM, or GraalVM Native Image) while making the application start faster too, or look into CDS and other optimizations (although that won't work across 32/64 bit architectures)
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