Re: Garbage collection
- From: "m. Th." <a@xxxxx>
- Date: Fri, 28 Sep 2007 10:43:48 +0300
Barry Kelly (CodeGear) wrote:
Allocation policy should ideally be at the allocation site, not
associated with the type. This is a known mistake that the Microsoft
Managed C++ guys made, and fixed (syntactically if not orthogonally) for
C++/CLI: introducing 'gcnew', rather than depending on types annotated
with '__gc'.
+1 !!!
But if " you don't have nothing else to do ;-) " (TM) then perhaps it's a very nice-to-have feature (not really a must-have) to have also an GC attribute on type - to express an exclusion filter - but, imho, definitely do not rely on types _only_ to define the allocation policy. Ie. sometimes is handy to have:
TMyGCStringList = class(TStringList); auto; //<- this is GCed
....<my class definition>
end;
and to disable it when we need it:
var
objMyTSL: TMyGCStringList; explicit; //<- something like this
....but of course, usually we need to mark the objects as GCed not classes, imho.
Non-reference-counted GC typically needs to search the heap for
references in order to be sure it's safe to deallocate, and GC is almost
always invoked by an allocation request (not enough free space to
allocate -> collect and then check again -> still not enough free space,
ask OS for more).
I would see a very interesting option in triggering the GC at an end-of-scope signal, or at least a generation of it - assuming that we speak about a generational engine. This is important when we speak from behavioral POV, ie. what /the user/ does, not what the /program/. Ie. usually a end-of-scope point is usually the end of an action, and many times, at least in the actions from the presentation layer the users stops to see the results of their actions (and hence the program). Here, imho, it's quite interesting to evaluate the possibility of a lower-priority (ie. will start only if the program is (almost) idle) dedicated GC thread(s). Also, I must confess that I don't like the GC therm. What I would like to see in Delphi it's a more advanced memory manager - but, anyway, I want to praise the Pierre's achievements - having a configurable GC (see my other posts) and also, having a memory "defragmenter" to work in a separate thread in the low-activity periods of program (keyboard data entry stages / idle times aso.).
Thus, GC can start on any thread that allocates memory, and it needs to
freeze some parts of the world, or at least mark memory ranges
unmodified and search them and then use write barriers (basically mark
memory range as dirty if it's written to) to detect when they've been
modified (and thus have to be searched again). With multi-core CPUs and
especially NUMA machines, it can be better to parallelize the searching
process, and have multiple (possibly dedicated) threads for GC.
In any case, there's no big benefit to somehow trapping the thread which
made the original allocation (if it's even still alive) and getting it
specifically to do the searching.
And on the other side, since the allocation thread is blocked and can't
continue without the memory it's asking for, there's typically no big
drawback to doing some fraction (1/Total-CPU-core-count) (if not all,
especially when heap is small such as gen0 of a generational heap) of
the collection on the allocating thread, in a non-concurrent GC, since
it also saves a context switch.
Yes, the main point is to have a engine which can mitigate the performance hits by delaying the (de)allocation - and this, imho, implies a separate (dedicated) thread(s). Something like a run-time configurable memory server. Also, such a server can do other things like memory preallocation thing which would be very interesting for a certain range of applications (at least) - for ex. db apps in which it happens to work from a small amount of time.
And did I mention "configurable at runtime"? <g>
-- Barry
Nice discussion, btw.
PS: Do you are aware of
http://www.ravenbrook.com/project/mps/
and
http://www.answers.com/topic/region-inference
?
<region inference is a nice thing but implies a little bit of dedicated programming for it, imho>
hth,
--
m. th. .
- Follow-Ups:
- Re: Garbage collection
- From: m. Th.
- Re: Garbage collection
- References:
- Garbage collection
- From: Peter Morris
- Garbage collection
- Prev by Date: Re: Why Microsoft must abandon Vista to save itself
- Next by Date: Re: 64 Bit operating system trends
- Previous by thread: Re: Garbage collection
- Next by thread: Re: Garbage collection
- Index(es):
Relevant Pages
|