...
Metaspace implementation is divided into separate sub systems, each of which is isolated from its peers and has a small number of tasks.
The Virtual Memory Subsystem
...
"Allocate new root chunk"
Metachunk* VirtualSpaceList::allocate_root_chunk();
This carves out a new root chunk from the underlying reserved space and hands it to the caller (nothing is committed yet, this is purely reserved memory).
"commit this range"
bool VirtualSpaceNode::ensure_range_is_committed(MetaWord* p, size_t word_size);
Upper layers request that a given arbitrary address range should be committed. Subsystem figures out which granules would be affected and makes sure those are committed (which may be a noop if they had been committed before).
When committing, subsystem honors VM limits (
MaxMetaspaceSize
resp. the commit gc threshold) via the commit limiter."uncommit this range"
void VirtualSpaceNode::uncommit_range(MetaWord* p, size_t word_size);
Similar to committing. Subsystem figures out which commit granules are affected, and uncommits those.
"purge"
void VirtualSpaceList::purge()
This unmaps all completely empty memory regions, and uncommits all unused commit granules.
...
base end
| |
v v
| root chunk area | root chunk area | root chunk area | root chunk area |
|x| |x|x|x| | | | |x|x|x| | | |x|x| | | |x|x|x|x| | | | | |x| |x| | | | | <-- commit granules (x=committed)
CommitMask
...