Skip to content

Fix devirtualization in crossgen2 - #146

Merged
janvorli merged 2 commits into
dotnet:masterfrom
janvorli:fix-crossgen2-devirt
Nov 21, 2019
Merged

janvorli merged 2 commits into
dotnet:masterfrom
janvorli:fix-crossgen2-devirt

Conversation

@janvorli

Copy link
Copy Markdown
Member

In some casesi that are only expressible in IL, devirtualization is
choosing a wrong virtual method. This causes a failure of the
JIT\Regression\JitBlue\GitHub_19222 test.

The test uses the following class hierarchy:

class A
{
    public virtual void f() {}
}

class B : A
{
    public override void f() {}
}

class C : B
{
    public new void f() {}
}

class D : C
{
    public new void f() {}
}

Then there is a local of type C to which we assign a reference to D.
After that the following virtual call is made:

callvirt instance int32 modopt([mscorlib]System.Runtime.CompilerServices.IsLong) A::f()

Devirtualization will choose C.f to call instead of the D.f.

This change disables devirtualization in such cases. Old crossgen does
the same thing.

In some casesi that are only expressible in IL, devirtualization is
choosing a wrong virtual method. This causes a failure of the
JIT\Regression\JitBlue\GitHub_19222 test.

The test uses the following class hierarchy:
class A
{
    public virtual void f() {}
}

class B : A
{
    public override void f() {}
}

class C : B
{
    public new void f() {}
}

class D : C
{
    public new void f() {}
}

Then there is a local of type C to which we assign a reference to D.
After that the following virtual call is made:

callvirt instance int32 modopt([mscorlib]System.Runtime.CompilerServices.IsLong) A::f()

Devirtualization will choose C.f to call instead of the D.f.

This change disables devirtualization in such cases. Old crossgen does
the same thing.
@janvorli janvorli added this to the 5.0 milestone Nov 20, 2019
@janvorli
janvorli requested review from jkotas and trylek November 20, 2019 12:55
@janvorli janvorli self-assigned this Nov 20, 2019

@trylek trylek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for fixing this!

@jkotas
jkotas requested a review from davidwrighton November 20, 2019 13:51

@davidwrighton davidwrighton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix to use the slot defining method check instead of IsNewSlot and such. The technique used is incorrect if the impl method is a non-newslot method that overrides a newslot .override of the original decl method.

@janvorli

Copy link
Copy Markdown
Member Author

@davidwrighton I've fixed it based on your feedback, can you please take a look again?

@davidwrighton davidwrighton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@janvorli
janvorli merged commit 5e5a0d4 into dotnet:master Nov 21, 2019
@janvorli
janvorli deleted the fix-crossgen2-devirt branch November 21, 2019 21:44
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants