Skip to content

Conversation

lambdageek
Copy link
Member

@lambdageek lambdageek commented Sep 16, 2021

Add ldsdfld.w and stsfld.w opcodes to the interpreter. These are needed for some machine-generated methods in Android projects that use AndroidX, MAUI, SkiaSharp or other toolkits. The app's Resource::UpdateIdValues can grow to exceed 64k interpreter data items, which means that 16-bit data item indices will roll over.

A typical snippet from the method body:

    IL_8413:  ldc.i4     0x7f0f02fc
    IL_8418:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Style::Widget_MaterialComponents_Toolbar_Surface
    IL_841d:  ldc.i4     0x7f0f02fd
    IL_8422:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Style::Widget_MaterialComponents_Tooltip
    IL_8427:  ldc.i4     0x7f0f02fe
    IL_842c:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Style::Widget_Support_CoordinatorLayout
    IL_8431:  ldsfld     int32[] TestApp.Resource/Styleable::ActionBar
    IL_8436:  stsfld     int32[] [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Styleable::ActionBar
    IL_843b:  ldsfld     int32[] TestApp.Resource/Styleable::ActionBarLayout
    IL_8440:  stsfld     int32[] [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Styleable::ActionBarLayout
    IL_8445:  ldc.i4.0
    IL_8446:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Styleable::ActionBarLayout_android_layout_gravity

The "wide" opcodes use 32-bit data item indices.

Resolves https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1398069

For methods that require more than 64k data items, add a variant stsfld
instruction that stores data item indices as 32-bit integers instead of 16-bit.

To solve this problem in general, we need wide variants of more opcodes, but
for specific (machine generated) methods, a wide stsfld instruction is sufficient.

Resolves https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1398069
@ghost
Copy link

ghost commented Sep 16, 2021

Tagging subscribers to this area: @BrzVlad
See info in area-owners.md if you want to be subscribed.

Issue Details

Add ldsdfld.vt.w and stsfld.vt.w opcodes to the interpreter. These are needed for some machine-generated methods in Android projects that use AndroidX, MAUI, SkiaSharp or other toolkits. The app's Resource::UpdateIdValues can grow to exceed 64k interpreter data items, which means that 16-bit data item indices will roll over.

A typical snippet from the method body:

    IL_8413:  ldc.i4     0x7f0f02fc
    IL_8418:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Style::Widget_MaterialComponents_Toolbar_Surface
    IL_841d:  ldc.i4     0x7f0f02fd
    IL_8422:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Style::Widget_MaterialComponents_Tooltip
    IL_8427:  ldc.i4     0x7f0f02fe
    IL_842c:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Style::Widget_Support_CoordinatorLayout
    IL_8431:  ldsfld     int32[] TestApp.Resource/Styleable::ActionBar
    IL_8436:  stsfld     int32[] [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Styleable::ActionBar
    IL_843b:  ldsfld     int32[] TestApp.Resource/Styleable::ActionBarLayout
    IL_8440:  stsfld     int32[] [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Styleable::ActionBarLayout
    IL_8445:  ldc.i4.0
    IL_8446:  stsfld     int32 [Microsoft.Maui.Controls.Compatibility]Microsoft.Maui.Controls.Compatibility.Resource/Styleable::ActionBarLayout_android_layout_gravity

The "wide" opcodes use 32-bit data item indices.

Resolves https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1398069

Author: lambdageek
Assignees: -
Labels:

area-Codegen-Interpreter-mono

Milestone: -

@lambdageek
Copy link
Member Author

For .NET 7.0 we should investigate how to fix this in general - I made an issue #59221.

This version that just deals with UpdateIdValues methods should be backported to .NET 6.0

@lambdageek lambdageek force-pushed the fix-androidx branch 3 times, most recently from f06ce51 to 3ee598f Compare September 17, 2021 00:51
Use stackval_from_data and stackval_to_data instead of memcpy.

Don't duplicate code get_data_item_wide_index.

Only use the wide opcodes if any of the data item indices of a given
instruction need it, not just when the method total number of indices
overflows.
@lambdageek
Copy link
Member Author

Ran some local tests always using the wide opcodes and it seems like it's working. But I'd appreciate another look at the stackval_from_data/stackval_to_data in interp.c @BrzVlad

Copy link
Member

@BrzVlad BrzVlad left a comment

Choose a reason for hiding this comment

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

Looks good. Just those last nitpicks

@lambdageek
Copy link
Member Author

/backport to release/6.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/6.0-rc2: https://github.com/dotnet/runtime/actions/runs/1245567304

@lambdageek lambdageek merged commit f5e1baa into dotnet:main Sep 17, 2021
steveisok pushed a commit that referenced this pull request Sep 21, 2021
…tores (#59262)

Backport of #59220

Add ldsdfld.w and stsfld.w opcodes to the interpreter. These are needed for some machine-generated methods in Android projects that use AndroidX, MAUI, SkiaSharp or other toolkits. The app's Resource::UpdateIdValues can grow to exceed 64k interpreter data items, which means that 16-bit data item indices will roll over.

Resolves https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1398069
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
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.

2 participants