[Mono-dev] GC'able dynamic assemblies in v4

Rodrigo Kumpera kumpera at gmail.com
Tue Jan 26 15:39:36 EST 2010


Hey guys,

Here is the proposal onto how to implement collectible dynamic assembly
(CDA) support from v4.

A CDA is just like your regular dynamic assembly except it can be collected
when no more references to it exist.
Those references consist of:

1)Objects from any CDA class
2)Object from any type that has a CDA class as it's component[1]
3)Reflection objects for CDA stuff
4)Code been executed from any CDA method
5)Byrefs to objects or static data from any CDA related class

If a type from another dynamic assembly statically reference, eg. extends, a
type in a given CDA, the lifetime
of the later is extended by the former.

So the problem is how do we figure out that all those conditions hold true.
I believe can reference count
the dynamic image with the following:

-Each reflection object increase by one on creation and decrease on
finalization. This solve (3)

-Make the vtable of all CDA related types garbage collectible and make their
objects mark them. This solves (1), (2) and half of (5)
To make this work we cannot embed vtable literals in generated code, but
load them from a memory location.

We need to avoid having vtables been collected all the time as they are
pretty expensive to create.
My suggestion is to use use the number of GCs to age the vtables. We
resurrect them for, say, 4 collections before
setting the place managed code uses to load them from to null and
collecting on the next GC.


-Once reference count drops to zero we crawl all stacks for methods from the
CDA assembly and repeat it at every major
GC until it gets freed. This solves (4)
We could make the GC track this information by making method code GC
tracked, but this would be pretty hacky under Boehm as
we can't request it to allocate from rwx memory. We could later switch to
this with sgen but I don't think it's work the trouble.

-Make the static area of all CDA related types garbage collectible. Make the
Assembly object reference
all static segments and all MonoType objects reference the Assembly object -
this make sure statics won't be collected earlier. This solves (5)

None of those changes are trivial to do but I believe there isn't a simpler
way to solve it.

Any comments before I start pushing patches for review?

Cheers,
Rodrigo

[1] Given CDA class Dyn, it could be types like Dyn[] or
[mscorlib]System.Collections.Generic.List<Dyn>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20100126/db349f85/attachment.html 


More information about the Mono-devel-list mailing list