Skip to content

fix infinite recursion in crossgen2 on ARM - #32227

Merged
MichalStrehovsky merged 1 commit into
dotnet:masterfrom
y-yamshchikov:issue_alignment
Feb 14, 2020
Merged

MichalStrehovsky merged 1 commit into
dotnet:masterfrom
y-yamshchikov:issue_alignment

Conversation

@y-yamshchikov

Copy link
Copy Markdown
Contributor

This PR fixes #32120.

Despite it is not used in ReadyToRunMetadataFieldLayoutAlgorithm::AlignBaseOffsetIfNecessary I think we should pass proper default alignment, but I don't sure it is 4: now field's alignment requirements are tracking by MetadataFieldLayoutAlgorithm::ComputeAutoFieldLayout.

Also if we try to call TypeExtensions::RequiredAlign8(this TypeDesc) just from MetadataFieldLayoutAlgorithm's method we face missing dependency, so I decided to have virtual method to override in ReadyToRunMetadataFieldLayoutAlgorithm.

@y-yamshchikov

Copy link
Copy Markdown
Contributor Author

@jkotas @alpencolt

@jkotas

jkotas commented Feb 13, 2020

Copy link
Copy Markdown
Member

cc @dotnet/crossgen-contrib

@MichalStrehovsky

Copy link
Copy Markdown
Member

I would prefer we do what @jkotas originally suggested in the issue: "Keep track of maximum alignment in // Iterate over all fields and do the following loop in ComputeAutoFieldLayout". To do that see how we do largestAlignmentRequirement elsewhere in the file - it's just about calling ComputeFieldSizeAndAlignment and sending that value through LayoutInt.Max. Once we have the largest one, we can call type.Context.Target.GetObjectAlignment(alignment) to get the object alignment. If that value is more than 4, it's an align8 type.

I would also change the int parameter to AlignBaseOffsetIfNecessary to be a bool so that we don't have to compare with integer constants.

Computing the align8 bit will be useful later anyway. It doesn't look like ComputeAutoFieldLayout marks classes correctly as requiring 8-byte alignment right now (see the code around the // The JITs like to copy full machine words, comment - there is the same comment in the CoreCLR VM, but the logic is slightly different for FEATURE_64BIT_ALIGNMENT.

@y-yamshchikov

Copy link
Copy Markdown
Contributor Author

@MichalStrehovsky
Could you please take a look?

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.

Could you please do this in the // Iterate over all fields and do the following foreach loop?

That loop already calls ComputeFieldSizeAndAlignment in one of the branches and we can save us a call.

@y-yamshchikov y-yamshchikov Feb 14, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, I didn't notice that the comment addresses specific place in code and picked the first loop over fields in the body

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.

This check is not necessary. Calling AsInt is going to throw if the value is indeterminate. This might actually be reachable at some point. Once it is we will deal with it.

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.

This needs to go above the cascading if block, together with the line above it.

@MichalStrehovsky MichalStrehovsky 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.

Thank you!

@MichalStrehovsky
MichalStrehovsky merged commit 852c865 into dotnet:master Feb 14, 2020
@y-yamshchikov

Copy link
Copy Markdown
Contributor Author

Thank you for your help!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 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.

Infinite recursion while computing instance layout in crossgen2

4 participants