Since the implementation of JDK-8171181 JEP 316: Heap Allocation on Alternative Memory Devices there are two notions of maximum number of regions in the heap in HeapRegionManager:
max_length(): maximum number of regions in the entire reserved area of the heap (to be used for sizing for arrays etc.)
max_expandable_length(): maximum number of regions g1 is allowed to commit.
There are some wrong uses of both. This is not an issue for regular G1 as both are the same, but a problem when having a larger reserved space than committable (e.g. with that feature enabled).
There are also some missing bounds checks in the code assuming max_length == max_expandable_length.
Fix this (and users of HeapRegionManager::max_length/max_expandable_length)