[Mono-devel-list] Trampolines...

Willibald Krenn Willibald.Krenn at gmx.at
Wed Feb 23 07:26:34 EST 2005

Zoltan Varga schrieb:
> It is possible to call the same virtual method with boxed and
> non-boxed arguments,
> like:
> SomeStruct s = new SomeStruct ();
> s.ToString ();
> object o = s;
> o.ToString ();

I understand. But how about this idea:
For virtual methods of value types, we could 'inline' the unbox 
trampoline in the method like

addq 0x10, %r_this	;unbox start
pushq %rbp		;normal start
movq  %rsp, %rbp

Normally the JIT gives the addr of pushq back as starting address. In 
the magic service routine ("get unbox trampoline") we could subtract the 
size of the addq opcode and take that as method starting address. While 
that would make virtual methods of value types still a special case (2 
entry points, so while patching one has to make sure that patching 
starts at the normal start), it would be much easier to handle and we 
would get rid of another jmp indirection...

The arch part of mini will probably need a few new 'functions' (macros):
int mono_arch_get_unbox_size ()
gpointer mono_arch_get_normal_start (gpointer code)

AFAIK the addq would be 4 bytes on AMD64 - instead of ~16 bytes (at 
least 20 bytes allocated) for the unbox tramp. Yes, not every virtual 
method of value types will have an unbox trampoline, but for one 
trampoline we get at least 4 (I assume 6 because of (20+7) & ~7) method 
inlined unbox operations plus we save the jumps.

BTW: Alternatively we could fake-box the this pointer before any call to 
a virtual value type method..


More information about the Mono-devel-list mailing list