[Mono-dev] Patch: Fast virtual generic method calls

Mark Probst mark.probst at gmail.com
Thu Sep 25 13:51:03 EDT 2008


Hey everybody,

This is my second attempt at implementing fast virtual generic method
calls.  The implementation is very close to Paolo's proposal here:

  https://bugzilla.novell.com/show_bug.cgi?id=324481

The main difference is that I don't hash the methods into slots but use
the (until now unused) "normal" vtable slots for the thunks.  This is
necessary because with generic code sharing the method signature is not
known statically.

A big problem with this implementation is the memory management of the
thunks.  Since thunks become obsolete when new method instantiations are
added we have to reclaim their memory.  We can only do this safely if we
know that no thread is still executing the thunk code.  The current
solution is a hack: Freed thunks are queued until there are 50 of them,
at which point for each new freed thunk we reclaim the oldest one in the
queue.  The other problem with this approach is that if there are only a
few thunks which grow and grow we won't be able to reuse the freed small
pieces, i.e. a program can easily make us use an arbitrary amount of
memory by having a single virtual generic method which is instantiated
with a large number of different type arguments (easy to do
recursively).

One solution I have to the latter issue is by splitting the thunks into
small fixed-size code pieces, in the simplest case one piece per
decision-tree node.  Not difficult to implement.  Another solution would
be to have a code manager which permits freeing items :-)

The patch currently only supports x86.

Mark

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fast_virtual_generic_calls_new.diff
Type: text/x-patch
Size: 35996 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080925/642fafd7/attachment-0001.bin 


More information about the Mono-devel-list mailing list