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

Paolo Molaro lupus at ximian.com
Tue Nov 20 04:34:16 EST 2007

On 11/19/07 Zoltan Varga wrote:
>   The problem with the trampoline is that since the class to init is dynamically
> decided, there is nothing to patch, so all calls will go through the
> generic trampoline
> code, which is much slower than a simple managed-to-native transition.

No, here is again the trampoline pseudo code I described in the first
email (vtable is in a register):

	deref vtable->initialized
	condbranch slow_path:
	call class_init

We do the unmanaged transition only when the cctor has not been run yet.
The x86 implementation could be something like (with vtable in edx):

	test $INIT_BIT,initialize_offset(%edx)
	jz slow_path
	call class_init

The common path is 3 instructions, we need a single trampoline for all
the process and this works for both generics and AOT.
I think the tiny amount of arch-specific code is worth writing to avoid
the increased memory usage with the other solutions.
BTW, for AOT code we could put the above code inside the AOT image
itself, so it would be a direct call with no PLT entry involved.


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

More information about the Mono-devel-list mailing list