Java Virtual Machine heap management | Heap shrinkage
17.5.1 Heap expansion
Heap expansion occurs after garbage collection while exclusive access of the virtual machine is still held. The active part of the heap is expanded up to the maximum if one of the following is true:
- The garbage collector did not free enough storage to satisfy the allocation request.
- Free space is less than the minimum free space, which you can set by using the -Xminf parameter. The default is 30%.
- More than 13% of the time is being spent in garbage collection.
The amount to expand the heap is calculated as follows:
- If the heap is being expanded because less than -Xminf (default 30%) free space is available, the garbage collector calculates how much the heap needs to expand to get -Xminf free space.
If this is greater than the maximum expansion amount, which you can set with the -Xmaxe parameter (default of 0, which means no maximum expansion), the calculation is reduced to -Xmaxe.
If this is less than the minimum expansion amount, which you can set with the -Xmine parameter (default of 1 MB), it is increased to -Xmine.
- If the heap is expanding and the JVM is spending more than 13% for any other reason, the garbage collector calculates how much expansion is needed to expand the heap by 17% free space. This is adjusted as above, depending on -Xmaxe and -Xmine.
- Finally, the garbage collector ensures that the heap is expanded by at least the allocation request if garbage collection did not free enough storage.
All calculated expansion amounts are rounded up to a 256-byte boundary (512 bytes if concurrent mark is used) on 32-bit architecture, or a 1024 byte boundary on 64-bit architecture.