Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

java - Why is heap divided into Eden, Survivor spaces and Old Generation?

Could you please answer me a question about JVM Garbage Collection process?

Why is heap divided into Eden, Survivor spaces and Old Generation?

When a young evacuation is processed objects are visited through references starting from the roots to find out unreachable ones. Reachable objects are marked as ‘alive’ and unreachable are not marked and will be eliminated.

As a result, ALL objects are considered, including objects allocated in Old Generation are also visited and marked if they are reachable.

As I understand reclaiming Young Generation and Old Generation at once is demanding because these generations are located in different contiguous parts of memory.

But why do we need this division if even after the simplest marking on the Young evacuation level we have the entire bitmap with all alive and dead objects if all reachable and unreachable objects are known and can be deleted?

I also know weak generational hypothesis about but why do we need the division?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The basic premise is that when new objects are created, no reference from an old object to the new one exists and for a lot of objects, or even most of them, this never changes. This implies that you can do a “minor” garbage collection scanning the young generation only, if you can prove that there are still no references from old objects to new objects or when you know precisely which references have been created.

This implies that reference changes to old objects must be tracked and remembered (but recall the premise that such changes don’t happen so often).

One implementation strategy is Card Marking:

If a garbage collector does not collect the entire heap (an incremental collection), the garbage collector needs to know where there are pointers from the uncollected part of the heap into the part of the heap that is being collected. This is typically for a generational garbage collector in which the uncollected part of the heap is usually the old generation, and the collected part of the heap is the young generation. The data structure for keeping this information (old generation pointers to young generation objects), is a remembered set. A card table is a particular type of remembered set. Java HotSpot VM uses an array of bytes as a card table. Each byte is referred to as a card. A card corresponds to a range of addresses in the heap. Dirtying a card means changing the value of the byte to a dirty value; a dirty value might contain a new pointer from the old generation to the young generation in the address range covered by the card.

Processing a card means looking at the card to see if there is an old generation to young generation pointer and perhaps doing something with that information such as transferring it to another data structure.

Of course, using generations only provides a benefit, if it enables us to skip certain memory regions during the scan and if maintaining these remembered sets does not outweigh the savings.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...