I'll hold my hand up to being B :-) To answer one of my own questions:
<quote> Now, consider a gen2 object A that refers to a gen0 object B, because the GC needs to consider the possibility of a gen2 object now referring to a gen0 object, does the *entire* object graph have to be examined? Or can it stop when it hits an object not in gen0 and just allow object B to migrate naturally to gen2 over time – I would have thought the latter. </quote> Of course the entire object graph needs to be walked as the GC has absolutely no way of knowing whether B is collectable or not without performing a full walk. Without doing this the GC would never be able to collect anything in gen0 just in case it was referenced from an object in another generation Amazing what occurs to you in the shower ;-) Richard Blewett DevelopMentor -----Original Message----- From: Moderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Richard Blewett Sent: 07 November 2003 18:19 To: [EMAIL PROTECTED] Subject: [ADVANCED-DOTNET] GC internals - discussion and Questions In response to the very interesting article on performance and cost on MSDN [1] we've been having a discussion internally, within DevelopMentor, about GC internals. Seeing as none of us actually have the real CLR source code we thought we'd air the discussion publicly and see if anyone from Microsoft (or anyone else) would like to weigh in ... The thread goes something like this: A) Hey interesting article about perf here B) Yes, but it seems to suggest that promotion from one generation to another involves copying - I thought it was one contiguous block of memory with markers delineating the generations. C) I've done some tests and there appears to be no copying - unfortunately to check the object location involves having to pin memory while it was read which could have impacted the GC results. D) ROTOR uses a different heap for gen0 I think but I can't remember the details B) I've just had an email conversation with a couple of the Microsoft CLR guys and apparently gen0 and gen1 are always allocated in the same memory block. Gen2 and the large object heap (LOH) may span multiple blocks and in fact may share memory segments. A collection of a generation may not involve compaction if the amount of free space that would be regained was minimal. C) ROTOR has a different implementation of the GC doesn't it? And the generational stuff is even more long-winded than I thought: I didn’t previously realize that even if your object is now unreachable, AND has there have been many full GCs it might still not bother to collect the memory! I used to think that a gen1 collect meant compacting the gen1 heap, and a gen2 collect meant compacting the gen2 heap. The CLR can most certainly detect that an object in gen2 has become unreachable without performing a full gen2 collect, so the reason I assumed that ‘gen2 collect’ meant ‘reclaim unused memory in gen2’, was that it can’t mean ‘detect which objects in gen2 are unused’ – it already knows that long before it does a gen2 collect. D) I'm pretty sure that ROTOR and the CLR use the same data structures but that the algorithms that drive them are different. B) So here’s an interesting question. Say we have small amounts of garbage from a series of collections, none of these individually enough to trigger a compaction … Will the GC take note of previously non-compacting collections and decide that even though the garbage identified for this one GC cycle isn’t enough to bother compacting, the *cumulative* garbage *is* enough. Now, consider a gen2 object A that refers to a gen0 object B, because the GC needs to consider the possibility of a gen2 object now referring to a gen0 object, does the *entire* object graph have to be examined? Or can it stop when it hits an object not in gen0 and just allow object B to migrate naturally to gen2 over time – I would have thought the latter. Finally, I’m probably missing something obvious, but why do threads need to be stopped during the object graph walk? I can see why during compacting this needs to be done, but not during the object graph walk. All that would happen is we may miss objects that become garbage during the walk. Obviously the names have been removed to protect the innocent ;-) but as you can see we're sort of at an impasse - unless someone has knowledge of the GC internals or some cool way of checking this stuff out that isn't invasive and therefore likely to change the GC behaviour. As an aside we also have this discussion going on: E) BTW, just FYI, Java also uses a generational GC where the gen 0 heap is actually an arena-based collector--extremely fast allocation/deallocation, at the expense of subdividing the gen 0 heap area into 2. F) IBM's JVM uses Mark&Sweep, while occasionally compacting the heap. It was once considered obvious that compaction was better, but IBM's GC was a strong counter-example. Now most modern GCs have complicated adaptive heuristics to decide when, whether and where to compact. Things will get more interesting in the future: Richard Blewett DevelopMentor [1] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht ml/fastmanagedcode.asp --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.537 / Virus Database: 332 - Release Date: 06/11/2003 =================================== This list is hosted by DevelopMentor® http://www.develop.com Some .NET courses you may be interested in: Guerrilla ASP.NET, 10 Nov 2003 in London and 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnet Guerrilla .NET, 8 Dec 2003, in Los Angeles http://www.develop.com/courses/gdotnet View archives and manage your subscription(s) at http://discuss.develop.com --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.537 / Virus Database: 332 - Release Date: 06/11/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.537 / Virus Database: 332 - Release Date: 06/11/2003 =================================== This list is hosted by DevelopMentor® http://www.develop.com Some .NET courses you may be interested in: Guerrilla ASP.NET, 10 Nov 2003 in London and 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnet Guerrilla .NET, 8 Dec 2003, in Los Angeles http://www.develop.com/courses/gdotnet View archives and manage your subscription(s) at http://discuss.develop.com
