[Mono-dev] [PATCH] Generic sharing: Static field access

Paolo Molaro lupus at ximian.com
Mon Nov 19 09:12:05 EST 2007


On 11/19/07 Mark Probst wrote:
> >   I don't really understand why a new trampoline is needed here. Since
> > the argument
> > to the trampoline is dynamic, it is not possible to patch the caller code, so a
> > normal call to mono_runtime_class_init () would be sufficient.
> 
> To be honest, I don't see any reason why we shouldn't use an icall in
> those cases.  For some reason we defaulted to the trampoline, but it
> doesn't seem to be necessary.

The new trampoline is not strictly essential to get the code working,
but it is needed to not make it too slow (we have the same perf issue
with AOT code).
The new trampoline code would be a singleton and passing the argument in
a register allows it to be just:
	deref vtable->initialized
	compare/and
	ret
	branch to icall
so basically just 4-5 instructions executed in the common case instead
of all the cost of going to unmanaged and back.

There is an alternative solution which we could implement as well,
though this requires one additional pointer per MonoVTable.
When the MonoVTable is created this pointer is set to the icall and once
the type is initialized it is set to a tiny function that just does:

	ret
With this the initialization becomes a memory dereference and an
indirect call+ret. The runtime cost is similar to the above solution
(in AOT code we'd even avoid a PLT call), but it has the additional
memory overhead.

Other suggestions for optimizing this codepath are welcome as well.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list