"java -Xshare:dump" would intermittently fail with
Unable to write archive heap ... due to fragmentation.
This usually happens when you try to dump lots of classes (e.g. 10000) with a relatively small heap (e.g., 1g) with a lot of GC threads (e.g., 24).
(Example use case -- Eclipse IDE loads 15,000 classes with 512MB heap.)
At CDS static archiving dump time, we allocate free GC regions at high address (near or at the top of java heap) for archiving java objects (with G1 currently). If GC happens during the dump time, the java heap might be fragmented with free and used regions interlaced.
During the object archiving process, we search for a highest free region in the java heap, then allocating downwards starting from the one that's found. If GC activities causes the heap to be fragmented, the consecutive free regions that we find might not be large enough for archiving all selected java objects. In that case, we currently report fragmentation issue and bail out.