Repository navigation
[crossgen2] Use Alignment to calculate class Offset - #38962
Conversation
Update fork
Update fork
Use alignment to calculate class fields offsets. Fixes dotnet#38822 Signed-off-by: Timur <t.mustafin@partner.samsung.com>
|
This method mostly tries to match runtime/src/coreclr/src/vm/methodtablebuilder.cpp Line 7894 in 6072e4d in the VM. It feels like what we actually miss are runtime/src/coreclr/src/vm/methodtablebuilder.cpp Lines 8145 to 8150 in 6072e4d There's a couple other things under I'll let @davidwrighton take the "does this exactly match what the CoreCLR VM is doing?" parts since my knowledge of the CoreCLR type system is fairly limited. |
|
I've written a more comprehensive layout test (See https://github.com/davidwrighton/runtime/tree/layout_testing ) That test isn't ready to merge, as the amount of C# in the test is unreasonably large, but I believe it should be a good way to see that most of these cases are handled properly. I plan to run that test on arm32 tomorrow, or Monday, with this fix. |
davidwrighton
left a comment
There was a problem hiding this comment.
I was unable to run the layout test to completion on the arm32 hardware I have available. I repeatedly saw crashes while attempting to run the JIT_GetRuntimeType helper. However, my analysis of the situation indicates that @MichalStrehovsky is correct, handling of the FEATURE_64BIT_ALIGNMENT behavior in crossgen2 is what needs to be matched. The particular fix here looks to be correct, and appears to match up with this snippet of the type loader in coreclr.
runtime/src/coreclr/src/vm/methodtablebuilder.cpp
Lines 8113 to 8119 in 6072e4d
My analysis of the rest of the behavior of the runtime indicates that this is at least close to correct, but as I was unable to run the test suites, I could not confirm further details. If you fix the vairable use issue I mentioned here, I will approve this fix as it is strictly more correct than the previous state, but I do not have confidence that all issues have been found.
| else | ||
| { | ||
| cumulativeInstanceFieldPos = LayoutInt.AlignUp(cumulativeInstanceFieldPos, context.Target.LayoutPointerSize, context.Target); | ||
| largestAlignmentRequired = LayoutInt.Max(fieldSizeAndAlignment.Alignment, context.Target.LayoutPointerSize); |
There was a problem hiding this comment.
This value doesn't represent the largetAlignment required, so please don't re-use the variable here. Define a new variable.
There was a problem hiding this comment.
Thanks, I defined new variable AlignmentRequired.
Signed-off-by: Timur <t.mustafin@partner.samsung.com>
davidwrighton
left a comment
There was a problem hiding this comment.
As I said earlier, I'm not entirely convinced this fixes everything, but I think its a strict improvement over the current state.
ComputeAutoFieldLayout()function ignores calculatedfieldSizeAndAlignment.Alignmentand usescontext.Target.LayoutPointerSizeinstead. It produces a problems iffieldSizeAndAlignment.Alignment > context.Target.LayoutPointerSizeon arm for example.I suggest to use maximum of that values to calculate offset.
Issue #38822