Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

We defer looking at virtual methods on abstract classes and instead only look at them once we have a non-abstract class deriving from them. This lets us optimize away method bodies on abstract classes that are overriden by all descendants and therefore unreachable.

If there's no non-abstract descendant, we didn't look at any virtuals. But RyuJIT might still attempt to devirtualize into such classes. We need to prevent that to avoid compilation failures (and bloat).

…from

We defer looking at virtual methods on abstract classes and instead only look at them once we have a non-abstract class deriving from them. This lets us optimize away method bodies on abstract classes that are overriden by all descendants and therefore unreachable.

If there's no non-abstract descendant, we didn't look at any virtuals. But RyuJIT might still attempt to devirtualize into such classes. We need to prevent that to avoid compilation failures (and bloat).
@MichalStrehovsky MichalStrehovsky added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Nov 4, 2021
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Thanks

@MichalStrehovsky MichalStrehovsky merged commit f27e4ad into dotnet:feature/NativeAOT Nov 4, 2021
@MichalStrehovsky MichalStrehovsky deleted the abstractdevirt branch November 4, 2021 21:42
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Aug 12, 2022
If we were in a situation like in the regression test, we would devirtualize the `GrabObject` call to `SomeUnallocatedClass.GrabObject`. But because `SomeUnallocatedClass` was never allocated, the scanner didn't scan it, and bad things would happen.

Prevent devirtualizing into types that were not seen as allocated.

This is not a real issue for non-generic (non-shareable) types because the tentative instance method optimization generates throwing bodies for these. But tentative method optimization doesn't run for shared generics:

https://github.com/dotnet/runtime/blob/4cbe6f99d23e04c56a89251d49de1b0f14000427/src/coreclr/tools/Common/Compiler/MethodExtensions.cs#L115

This was rare enough that we haven't seen it until I did dotnet#73683 and there was one useless constructor that we stopped generating and triggered this.

This also includes what is essentially a rollback of dotnet/runtimelab#1700. This should have been rolled back with dotnet#66145 but I forgot we had this. It was not needed.
MichalStrehovsky added a commit to dotnet/runtime that referenced this pull request Aug 12, 2022
If we were in a situation like in the regression test, we would devirtualize the `GrabObject` call to `SomeUnallocatedClass.GrabObject`. But because `SomeUnallocatedClass` was never allocated, the scanner didn't scan it, and bad things would happen.

Prevent devirtualizing into types that were not seen as allocated.

This is not a real issue for non-generic (non-shareable) types because the tentative instance method optimization generates throwing bodies for these. But tentative method optimization doesn't run for shared generics:

https://github.com/dotnet/runtime/blob/4cbe6f99d23e04c56a89251d49de1b0f14000427/src/coreclr/tools/Common/Compiler/MethodExtensions.cs#L115

This was rare enough that we haven't seen it until I did #73683 and there was one useless constructor that we stopped generating and triggered this.

This also includes what is essentially a rollback of dotnet/runtimelab#1700. This should have been rolled back with #66145 but I forgot we had this. It was not needed.

* Update tests.proj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants