For both on-heap and off-heap allocations. On-heap - in the context of three major garbage collectors: CMS, Parallel Old and and G1.
What I know (or think that I know) to the moment:
- all object (on-heap) allocations are rounded up to 8 bytes boundary (or larger power of 2, configured by
-XX:ObjectAlignmentInBytes
. - G1
- For on-heap allocations smaller than the region size (1 to 32 MB, likely around heap size / 2048) there is no internal fragmentation, because there is no need, because the allocator never "fills holes".
- For allocations larger the region size, it rounds up allocation to the region size. I. e. allocation of the region size + 1 byte is very unlucky, it wastes almost 50% of memory.
For CMS, the only relevant information I found is
Naturally old space PLABs mimic structure of indexed free list space. Each thread preallocates certain number of chunk of each size below 257 heap words (large chunk allocated from global space).
From http://blog.ragozin.info/2011/11/java-gc-hotspots-cms-promotion-buffers.html. As far as I understand, referred "global space" is the main old space.
Questions:
- Are the above statements correct?
- What are the fragmentation properties of the main old space in CMS? What about allocations of more than "257 heap words"?
- How the old space is managed with Parallel Old GC?
- Does Hotspot JVM use the system memory allocator for off-heap allocations, or it re-manages it with a specific allocator?
UPD. A discussion thread: https://groups.google.com/forum/#!topic/mechanical-sympathy/A-RImwuiFZE
Unsafe.allocateMemory
is not where most of the allocation is done. Most of it occurs before that can even be called (during start-up), and growth of the heaps happens with single, large allocations. Ordinary object allocation does not go through that path, and neither does any other region of managed memory such as where the JIT compiled bytecode goes. – Bromate