[Mono-list] Mono Full AOT and VS2010 built events

Tyson tysonstolarski at gmail.com
Mon Nov 15 22:49:15 EST 2010


So this has come up while using MonoTouch, but it is more a general problem
with Mono AOT, hence why I am posting here.

Full-AOTing a VS2008 built .NET assembly and using an event within said
assembly works fine. However if the assembly is built in VS2010, all other
things being equal, it does JIT code during event subscription,
sSpecifically within 'Interlocked.CompareExchange<EventHandler>'.

I used reflector on two basic .NET assemblies, one built with VS2008, and
the other with VS2010, and it turns out the default generated add-remove
event methods have changed:

##### 2008 #####

public event EventHandler SomethingHappened;
[MethodImpl(MethodImplOptions.Synchronized)]
public void add_SomethingHappened(EventHandler value)
{
    this.SomethingHappened = (EventHandler)
Delegate.Combine(this.SomethingHappened, value);
}
[MethodImpl(MethodImplOptions.Synchronized)]
public void remove_SomethingHappened(EventHandler value)
{
    this.SomethingHappened = (EventHandler)
Delegate.Remove(this.SomethingHappened, value);
}

##### 2010 #####

public event EventHandler SomethingHappened
{
    add
    {
        EventHandler handler2;
        EventHandler somethingHappened = this.SomethingHappened;
        do
        {
            handler2 = somethingHappened;
            EventHandler handler3 = (EventHandler)
Delegate.Combine(handler2, value);
            somethingHappened =
Interlocked.CompareExchange<EventHandler>(ref this.SomethingHappened,
handler3, handler2);
        }
        while (somethingHappened != handler2);
    }
    remove
    {
        EventHandler handler2;
        EventHandler somethingHappened = this.SomethingHappened;
        do
        {
            handler2 = somethingHappened;
            EventHandler handler3 = (EventHandler) Delegate.Remove(handler2,
value);
            somethingHappened =
Interlocked.CompareExchange<EventHandler>(ref this.SomethingHappened,
handler3, handler2);
        }
        while (somethingHappened != handler2);
    }
}

###########

Is this a bug, or a limitation of static generic methods with full AOT? I
would assume it would be possible to determine all usages in this case? 

Even if it is a limitation, would it be possible to add a special case for
this scenario, I'm surprised I couldn't find anything regarding it already,
but I assume it is going to become more common as more 3rd party tools move
to VS2010 and these are used within MonoTouch apps.

Cheers.
Tyson.

-- 
View this message in context: http://mono.1490590.n4.nabble.com/Mono-Full-AOT-and-VS2010-built-events-tp3044190p3044190.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list