Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(Practically) Any garbage collected system has to move objects around in memory to pack them more densely and avoid fragmentation problems.</p> <p>What you are looking at is a very large and complex subject. I'd suggest you read up on existing remote object style API's: .NET remoting and going further back technologies like <a href="http://www.omg.org/gettingstarted/corbafaq.htm" rel="nofollow noreferrer">CORBA</a></p> <p>Any solution for tracking the references will be complicated by having to deal with all the failure modes that exist in distributed systems. The JVM doesn't have to worry about suddenly finding it can't see half of its heap because a network switch glitched. </p> <p>When you drill into the design I think a lot of it will come down to how you want to handle different failure cases.</p> <p><strong>Response to comments:</strong></p> <p>Your question talks about storing objects in a distributed fashion, which is exactly what .NET remoting and CORBA address. Admittedly neither technology supports migration of these objects (AFAIK). But they both deal extensively with the concepts of object identity which is a critical part of any distributed object system: how do different parts of the system know which objects they are talking about.</p> <p>I am not overly familiar with the details of the Java garbage collector, and I'm sure the Java and .NET garbage collectors have a lot of complexity in them to achieve maximum performance with minimum impact on the application.</p> <p>However, the basic idea for garbage collection is:</p> <ul> <li>The VM stops all threads from running managed code</li> <li>It performs a reachability analysis from the set of known 'roots': static variables, local variables on all the threads. For each object it finds it follows all references within the object.</li> <li>Any object not identified by the reachability analysis is garbage.</li> <li>Objects that are still alive can then be moved down in memory to pack them densely. This means that any references to these objects also have to be updated with the new address. By controlling when a garbage collect can occur the VM is able to guarantee that there are no object references 'in-the-air' (ie. being held in a machine register) that would cause a problem.</li> <li>Once the process is complete the VM starts the threads executing again.</li> </ul> <p>As a refinement of this process the VM can perform generational garbage collection, where separate heaps are maintained based on the 'age' of an object. Objects start in heap 0 and if they survive several GCs then the migrate to heap 1 and eventually to heap 2 (and so on - .NET supports 3 generations only though). The advantage of this is that the GC can run heap 0 collections very frequently, and not have to worry about doing the work to prove the long lived objects (which have ended up in heap 2) are still alive (which they almost certainly are).</p> <p>There are other refinements to support concurrent garbage collection, and details around threads that are actually executing unmanaged code when the GC is scheduled that add a lot more complexity to this area.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload