garbage collection algorithms
In generational garbage collector, when objects are promoted from eden to young generation or later from young generation to old one, is it that their references are copied? If that is the case that would further slow down the garbage collector as compared to a single space garbage collection algorithm, causing huge pauses when the references are being promoted/copied?
If they are not copied, what other mechanism does the JVM utilize to determine which heap an object is in at a particular point in time
[521 byte] By [
kilyasa] at [2007-11-26 15:52:16]

Promotion copies the actual object. Whether that takes a huge time depends on how many objects survive in a program, and what you consider "huge" anyway. You can run with -verbose:gc to see collection times; usually minor collections are fractions of a second. The parallel collector (-Xincgc) makes the pauses shorter if you have a program that suffers from visible pauses.
> In generational garbage collector, when objects are promoted from
> eden to young generation or later from young generation to old one, is
> it that their references are copied?
My naive understanding is that once objects end up in eden space they
never leave that space anymore unless they are eligable for garbage
collection. Correct me please if I'm wrong.
kind regards,
Jos
> > In generational garbage collector, when objects
> are promoted from
> > eden to young generation or later from young
> generation to old one, is
> > it that their references are copied?
>
> My naive understanding is that once objects end up in
> eden space they
> never leave that space anymore unless they are
> eligable for garbage
> collection. Correct me please if I'm wrong.
>
> kind regards,
>
> Jos
That I guess would be the single space garbage collection. In a generational garbage collector, It is a little different.
> Promotion copies the actual object. Whether that
> takes a huge time depends on how many objects survive
> in a program, and what you consider "huge" anyway.
> You can run with -verbose:gc to see collection times;
> usually minor collections are fractions of a second.
> The parallel collector (-Xincgc) makes the pauses
> shorter if you have a program that suffers from
> visible pauses.
Now my understanding was that the advantage of generational GC over a Copy Collector algorithm was that it didnot have to copy objects to a new space. Now if the generational is doing the same how would it be better than copy collector any way.
As a matter of fact it would be worse, since the young generation space would be fragmented since it would be using regular Mark and Sweep
> That I guess would be the single space garbage collection. In a
> generational garbage collector, It is a little different.
Is that so? Anything that survives a reaping session gets copied to a
'more persistent' store where other gc strategies may be applicable.
At the end the eden space awaits where a simple mark-and-sweep
could get rid of those old-timers; again: if I'm wrong, please correct me.
kind regards,
Jos
> Now my understanding was that the advantage of
> generational GC over a Copy Collector algorithm was
> that it didnot have to copy objects to a new space.
> Now if the generational is doing the same how would
> it be better than copy collector any way.
The advantage is that most objects die young (or that's the assumption; a program whose behaviour goes radically against that assumption will suffer). A quick sweep of Eden space finds few live objects; what are there are copied to Survivor Space. There are few pointers that point to inside Eden and SS, so those are quickly processed.
> As a matter of fact it would be worse, since the
> young generation space would be fragmented since it
> would be using regular Mark and Sweep
New objects are allocated simply by incrementing a pointer that points to inside Eden, until the pointer hits the top of the Eden space. At that point a minor GC moves the few live objects to SS, resets the pointer, and we have a clean Eden again. Fragmentation doesn't matter, because GC touches only the few live objects; tons and tons of garbage between them is automatically ignored.
Check out the section on generational gc: http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29
