Runtime.getRuntime().getFreeMemory() returns wrong value after humongous allocations.
Humongous objects (objects which size is larger than a half of g1 region) take a whole number of regions.
No other allocations are allowed in humongous regions.
So if we allocate a smallest humongous object of size = (RegionSize/2 +1) it takes a whole region.
Therefore free memory should decrease on one G1 Region size.
Currently it decreases on exact object size which contradicts with javadoc on getFreeMemory():
"an approximation to the total amount of memory currently available for future allocated objects, measured in bytes".
MemoryMXBean returns right value on first humongous allocation but wrong values for next ones.
Testcase attached.
Humongous objects (objects which size is larger than a half of g1 region) take a whole number of regions.
No other allocations are allowed in humongous regions.
So if we allocate a smallest humongous object of size = (RegionSize/2 +1) it takes a whole region.
Therefore free memory should decrease on one G1 Region size.
Currently it decreases on exact object size which contradicts with javadoc on getFreeMemory():
"an approximation to the total amount of memory currently available for future allocated objects, measured in bytes".
MemoryMXBean returns right value on first humongous allocation but wrong values for next ones.
Testcase attached.