I read yesterday about garbage collection and I don't understand some concepts about it. I've read that for minor collection usually is using copying technique to move reachable objects to survivor space and for major collection it's using often mark and sweep.
The first thing I didn't understand is that garbage collector starts from gc roots and moves along the graph to detect live instances, but how does it know which object is young and which object is old? How does it know which memory area object resides in?
The second thing is that if we're doing only minor collection, how the gc knows if object in young generation is not referenced by objects in old generation or by static reference from method area?
The last thing is that after mark and sweep sometimes compaction is done. How does gc know which references to the moved objects have to be updated? If we have a program with thousands of threads with huge frame stacks and gigabytes of heap used? Does it have some internal structures that have that info in form of map or something?
Thanks!