Nope, the implementation is probablistic. If there is extra space
available at the end of the allocated block's address space, then it is
added. If not, then a newly allocated block is returned. Since most
large allocations will occur on mmap pages, there will most likely be
available address space (not necessarily mapped RAM) beyond the end of
the allocated section.
so what you are doing is leaving lots of free address space past the
array for it to grow into. There is not much advantage in that over
just allocating the array max size to begin with, so long as your
underlying JVM does not insist on actually zeroing everything out
before it is ever referenced.
IIRC you need two different memory allocation schemes in C++, one for
movable objects and one for immovable ones. For these large arrays,
to handle things your way, they have to be movable, with extra pinning
logic etc. That all comes out in the wash in Java. C++ has no way to
update references to a moved object. All it can do is insist you use
an indirect handle and pin the object in place, and logically
invalidate any cached pointer when the object has to move.
The test would be to write the code both ways, using teams to each do
their best and just see how different the end result is.
A scheme in either C++ or Java that could precalculate exact array
sizes should beat out any other dynamic array solution in either C++
or Java. Then arrays can be allocated once, and stay put and allow the
most direct access.