Reputation: 1059
Does GC need to “Stop The World” for Minor GC or only for Full GC? As I understand, a minor GC will happen when there is no space available in EDEN to allocate an object, so does that mean that for each minor GC there will be a STW event?
Upvotes: 5
Views: 2190
Reputation: 1059
After reading several books I found that a Minor GC is always a Stop The World event, which will stop all the application threads and will normally have a short duration, as opposed to a GC pause for Full GC, which will take considerably much more time because it will run on Both Young and Old generations. So both Minor GC and Full GC are always Stop the World events.
Upvotes: 2
Reputation: 718876
The answer is "it depends".
With most modern Java collectors, a minor (young / Eden space) collection is indeed a stop-the-world collection. This is not a direct logical consequence of minor GC's being triggered by a young space filling up. (Other strategies are possible for triggering a minor GC, or for dealing with a young space filling up.) Rather it is just ... they way that most Java GCs are implemented.
One exception is ZGC which is not generational. Hence there is no such thing as a minor collection. Instead, when the GC is triggered there is a short (less than 10ms) stop the world event while the GC roots are found. A second exception is the Shenandoah GC, which is likewise not generational.
(And of course, the original Java 1.1 GC was a mark-sweep collector, non-generational and stop-the-world.)
Upvotes: 1