Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Does a generational garbage collector have to visit all objects during a minor GC?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I would like to know if a generational garbage collector visits all objects during a minor GC or it only visits the objects in the Young Generation?
If the answer is no, how can it do this? Because in my understanding, it has to start from a "root" and visit all reachable objects from this "root". There is no way it can knows in advance which objects are in the Young Generation and which objects are in Old Generation.

If the answer is yes, how it can be better than a traditional garbage collector while it also has to spend time to visit all objects.

Thank you very much.
 
Marshal
Posts: 75642
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is a Young Generation and an Old Generation? Those concepts have ceased to exist in recent versions of Java®.
If it is possible to release enough memory by visiting half the objects on the heap, then a GC can visit only half the objects. It does not matter whether a GC really operates like that, and that is something which you do not need to know. It may also vary from version to version and vendor to vendor.
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swerrgy Smith wrote:
I would like to know if a generational garbage collector visits all objects during a minor GC or it only visits the objects in the Young Generation?
If the answer is no, how can it do this? Because in my understanding, it has to start from a "root" and visit all reachable objects from this "root". There is no way it can knows in advance which objects are in the Young Generation and which objects are in Old Generation.



As Campbell stated, this is merely an implementation detail, and not really important to know how... but... as an FYI...

Depending on the implementation, the JVM maintains a set of roots -- of objects in the young generation, that are referred from the tenure generation. Of course, to keep this set of roots somewhat up to date, there are code which are executed when code in the JVM runs. I don't know the full details of what is tracked when, nor do I know how accurate is this set of roots. Sorry.

Hope this helps,
Henry
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic