Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit type layout check fixups #34927

Merged
merged 5 commits into from
Apr 21, 2020
Merged

Conversation

nattress
Copy link
Contributor

When a ready-to-run compiled method uses value types from other version bubbles, emit a precode fixup to check at runtime that the type is still compatible (same size, alignment, GC layout).

Bring over GCPointerMap*.cs from CoreRT repo to get the compute the GC layout bytes that match what the runtime expects in the layout blob.

Simplify the behavior of the Crossgen test scripting. If tests opt out of crossgen by setting <CrossGenTest>false</CrossGenTest>, skip emitting the crossgen commands into the test run script. Also, stop setting the RunCrossGen and RunCrossGen2 environment variables in the test script based on compile-time settings. These get set by runtest.py anyway. This set of tweaks allow for crossgen tests which we don't want to run the default crossgen commands on, and allow choosing either crossgen or crossgen2 as part of test execution.

@nattress
Copy link
Contributor Author

cc @dotnet/crossgen-contrib

Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thank you!

@AndyAyersMS
Copy link
Member

Do we also need to check that the struct gets the exact same ABI treatment? Eg changing from a struct of two ints to a struct of two floats we have same size / alignment / gc, but latter might get classified as an HFA and so be passed / returned differently.

@jkotas
Copy link
Member

jkotas commented Apr 15, 2020

There is READYTORUN_LAYOUT_HFA that seems to be missing here.

READYTORUN_LAYOUT_HFA may not be covering all more recent ABI cases, but that may be best to deal with in a separate PR.

flags |= ReadyToRunTypeLayoutFlags.READYTORUN_LAYOUT_GCLayout_Empty;
}

bool isHfa = defType.IsHfa && defType.Context.Target.Architecture == TargetArchitecture.ARM || defType.Context.Target.Architecture == TargetArchitecture.ARM64;
Copy link
Member

Choose a reason for hiding this comment

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

Should IsHfa rather return false except on ARM and ARM64 ? It does not sounds right to special-case it at callsites like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it into the Hfa computation algorithm

flags |= ReadyToRunTypeLayoutFlags.READYTORUN_LAYOUT_GCLayout_Empty;
}

bool isHfa = defType.IsHfa && defType.Context.Target.Architecture == TargetArchitecture.ARM || defType.Context.Target.Architecture == TargetArchitecture.ARM64;
Copy link
Member

Choose a reason for hiding this comment

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

The IsHFA computation in crossgen2 looks slightly different from what CoreCLR does.

E.g. we might need to change the implementation of ComputeValueTypeShapeCharacteristics on VectorFieldLayoutAlgorithm to account for their special HFA status.

Copy link
Member

Choose a reason for hiding this comment

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

(But it looks like a pre-existing problem that we should just track somewhere)

Copy link
Member

Choose a reason for hiding this comment

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

The IsHFA computation in crossgen2 looks slightly different from what CoreCLR does.

E.g. we might need to change the implementation of ComputeValueTypeShapeCharacteristics on VectorFieldLayoutAlgorithm to account for their special HFA status.

I have implemented that. Need to merge with this PR.

Copy link
Member

@trylek trylek left a comment

Choose a reason for hiding this comment

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

Looks great to me overall modulo a couple of nits.

src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs Outdated Show resolved Hide resolved
public partial struct GCPointerMap : IEquatable<GCPointerMap>, IComparable<GCPointerMap>
{
// Each bit in this array represents a pointer-sized cell.
private int[] _gcFlags;
Copy link
Member

Choose a reason for hiding this comment

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

Nit - uint might better convey the fact that this is bitmask.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ported this from CoreRT. I can see if we can quickly switch over to uints instead, sure.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't spend too much time on it, if it turns out to be viral for whatever reason, there's just no reason to waste time on it. Thanks for taking a look nonetheless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't that viral - I adjusted them to be uints.

When a ready-to-run compiled method uses value types from other version bubbles, emit a precode fixup to check at runtime that the type is still compatible (same size, alignment, GC layout).

Bring over `GCPointerMap*.cs` from CoreRT repo to get the compute the GC layout bytes that match what the runtime expects in the layout blob.

Simplify the behavior of the Crossgen test scripting. If tests opt out of crossgen by setting `<CrossGenTest>false</CrossGenTest>`, skip emitting the crossgen commands into the test run script. Also, stop setting the `RunCrossGen` and `RunCrossGen2` environment variables in the test script based on compile-time settings. These get set by runtest.py anyway. This set of tweaks allow for crossgen tests which we don't want to run the default crossgen commands on, and allow choosing either crossgen or crossgen2 as part of test execution.
* Move architecture filtering for Hfas to `MetadataFieldLayoutAlgorithm`
* Switch `GCPointerMap` to use `uint` for flags instead of `int`
@nattress nattress merged commit b7046a2 into dotnet:master Apr 21, 2020
@nattress nattress mentioned this pull request Apr 21, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 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.

8 participants