My question is why? Is this due to the fact that the main GC occurs as a whole for a larger number of objects than the secondary one, since insignificant gc is more common than the main one?
You pretty much hit a nail on your head. From an Oracle article, the focus is on:
Often the main collection is much slower because it includes all living objects .
Thus, not only the large GC analyzes these 15 objects in the old generation, it also passes through the young generation (again), and the permg and GC are those areas of the heap. Small GC analyzes only the younger generation, so in general there are not many objects to see.
According to the understanding, the main GC should be faster, since it has to do less work (i.e., restore memory from inaccessible objects) than the younger GC, since there is a high mortality rate in the younger generation.
I think I understand why you think so. I could imagine that a large GC can be launched very soon after a small GC, when objects are moving up to an almost complete old generation. Thus, the younger generation (presumably) does not contain too many objects for collection.
However, if I remember things correctly, the old generation is usually larger than the younger generation, so the GC not only needs to analyze more space, but also has to move again, and the rest of the objects in the younger generation (again). So this is probably why the main GC is slower - simply because there is still something to do. You may be able to make the main GC faster than the younger GC by resizing the generation spaces so that the younger generation is larger than the old generation and spoofing, but I don't think it would be a general setting to use ...
source share