• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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: 76822
366
  • 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: 23928
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
 
It's feeding time! Give me the food you were going to give to this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic