[Mono-devel-list] Trampolines...
Ben Maurer
bmaurer at ximian.com
Wed Feb 23 07:59:13 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
> ....
Totally not needed. If you call s.ToString (), the compiler does *not*
emit a box instruction, provided that typeof (s) provided an override for
.ToString.
If the override is not done, the object must be boxed because the method
provided by System.Object must be called. In the case of .ToString, this
is so rare, its not worth optimizing.
For .GetHashCode and .Equals, impls are strongly encourged to provide
their own override because the default method uses reflection. We are much
faster than msft here, because we used an icall. However, it is still
relatively slow to do the computation, especially for something like Point
where the hashcode is a matter of an xor computation.
-- Ben
More information about the Mono-devel-list
mailing list