[Mono-devel-list] Invoking virtual generic methods

Martin Baulig martin at ximian.com
Sat Nov 27 14:52:32 EST 2004


Hi,

just added some code to mini to allow it to invoke virtual generic
methods.

Consider the following test case (a better example is in gen-110.cs):

====
public interface IList<R>
{
        void Map<S> (R item, S item2);
}

public class List<V> : IList<V>
{
        public void Map<W> (V item, W item2)
        {
        }
}

class X
{
        static void Main ()
        {
                IList<int> list = new List<int> ();
                list.Map<string> (3, "Hello");
        }
}
=====

In the non-generic case, we'd just lookup the address of `Map' in the
class'es vtable.  However, this doesn't work in the generic case since
we need to invoke a particular instantiation.

My current code makes mini emit the following:

=====
0x409eeb56      push   %edi
0x409eeb57      push   $0x3
0x409eeb59      mov    %esi,%eax
0x409eeb5b      push   %eax
0x409eeb5c      mov    (%eax),%eax
0x409eeb5e      mov    0x10(%eax),%eax
0x409eeb61      mov    0xac(%eax),%eax
0x409eeb67      push   $0x8257380
0x409eeb6c      pushl  (%eax)
0x409eeb6e      call   0x40063930:mini_compile_generic_method
0x409eeb73      add    $0x8,%esp
0x409eeb76      call   *%eax
0x409eeb78      add    $0xc,%esp
=====

The difference to the non-generic case is 0x409eeb67-0x409eeb76 -
normally, the code would look like this:

====
push %eax
mov (%eax),%eax
mov 0x10(%eax),%eax
mov 0xac(%eax),%eax
call (%eax)
add %0xc,%esp
====

At the moment, I'm calling a special mono_arch_emit_generic_call() in
inssel.brg.  Can one of you JIT guys please have a look at this and
check whether we can do this architecture independently somehow ?

Martin









More information about the Mono-devel-list mailing list