-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Insert a set of known types and methods references necessary for async thunks into the mutable module #121679
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
Merged
Merged
Changes from 28 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3dfcffa
Add known methods that may be unreferenced into the MutableModule.
jtschuster 13f7d1d
Only add types and methods outside of the version bubble, still can't…
jtschuster d638752
Fix extra changes
jtschuster 80c0a5b
Fix EntityHandle spacing and use HashSet instead of ImmutableHashSet
jtschuster 660f62c
Merge branch 'main' of https://github.com/dotnet/runtime into Mutable…
jtschuster 9d35db6
Add async helper methods to ReadyToRunHelpers
jtschuster a9eff16
Merge branch 'main' of https://github.com/dotnet/runtime into Mutable…
jtschuster 94d8de1
Fix build issues
jtschuster 430531c
Trigger recompilation for async thunks that don't have references to …
jtschuster f1082d5
Revert changes to helper method enums
jtschuster 003efb0
Revert files to updated upstream version
jtschuster 0d7a521
Use TypeSystemEntity to ensure references to types and methods
jtschuster 4833400
Remove unused file
jtschuster 305958a
Revert extraneous changes
jtschuster ccc8f9f
Fix project file, no need to use out param for thunkhelpers
jtschuster 2fa0a48
Fix build break
jtschuster 9f42a55
Merge branch 'main' of https://github.com/dotnet/runtime into Mutable…
jtschuster 7199f97
Replace AsyncHelpers enum with KnownILStubReferences
jtschuster 88a6d5d
Missed a couple references to old methods.
jtschuster 5a5dc81
Add references to mutable module before compilation, don't allow asyn…
jtschuster 90e1a52
Remove unnecessary changes
jtschuster 3297cc8
Typo: Pop should be Push
jtschuster e708947
Emit correct ldloc/ldloca for task/valuetask locals
jtschuster 61cb9cc
Merge branch 'main' into MutableModule
jtschuster 1112136
Update log message
jtschuster 70a88f6
Use ILReader to find the references in thunks
jtschuster b387f78
Remove KnownReferences enum
jtschuster 460bb27
Only locals and instatiations can use ELEMENT_TYPE_X
jtschuster 4c04d16
Account for all il opcodes, add tokens for all TypeDescs
jtschuster 456cfce
Move ILStubReferences.cs
jtschuster 4d3d68f
Fix path issue
jtschuster 94b763c
Merge branch 'main' into MutableModule
jtschuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/coreclr/tools/Common/TypeSystem/IL/ILStubReferences.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using ILCompiler; | ||
| using Internal.TypeSystem; | ||
| using Internal.TypeSystem.Ecma; | ||
|
|
||
| namespace Internal.IL | ||
| { | ||
| public class ILStubReferences | ||
| { | ||
| /// <summary> | ||
| /// Extracts all method and type references from the IL of a method. | ||
| /// This is used to find references in synthetic IL (like async thunks) that may need | ||
| /// to be added to the mutable module. | ||
| /// </summary> | ||
| public static List<TypeSystemEntity> GetNecessaryReferencesFromIL(MethodIL methodIL) | ||
| { | ||
| var references = new List<TypeSystemEntity>(); | ||
| byte[] ilBytes = methodIL.GetILBytes(); | ||
| ILReader reader = new ILReader(ilBytes); | ||
|
|
||
| while (reader.HasNext) | ||
| { | ||
| ILOpcode opcode = reader.ReadILOpcode(); | ||
|
|
||
| switch (opcode) | ||
| { | ||
| case ILOpcode.call: | ||
| case ILOpcode.callvirt: | ||
| case ILOpcode.newobj: | ||
| case ILOpcode.ldftn: | ||
| case ILOpcode.ldvirtftn: | ||
| case ILOpcode.jmp: | ||
| { | ||
| int token = reader.ReadILToken(); | ||
| object obj = methodIL.GetObject(token, NotFoundBehavior.ReturnNull); | ||
| if (obj is MethodDesc method) | ||
| { | ||
| references.Add(method); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| case ILOpcode.newarr: | ||
| case ILOpcode.castclass: | ||
| case ILOpcode.isinst: | ||
| case ILOpcode.box: | ||
| case ILOpcode.unbox: | ||
| case ILOpcode.unbox_any: | ||
| case ILOpcode.ldobj: | ||
| case ILOpcode.stobj: | ||
| case ILOpcode.cpobj: | ||
| case ILOpcode.initobj: | ||
| case ILOpcode.ldelem: | ||
| case ILOpcode.stelem: | ||
| case ILOpcode.ldelema: | ||
| case ILOpcode.constrained: | ||
| case ILOpcode.sizeof_: | ||
| case ILOpcode.mkrefany: | ||
| case ILOpcode.refanyval: | ||
| { | ||
| int token = reader.ReadILToken(); | ||
| object obj = methodIL.GetObject(token, NotFoundBehavior.ReturnNull); | ||
| if (obj is TypeDesc type) | ||
| { | ||
| references.Add(type); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| case ILOpcode.ldtoken: | ||
| { | ||
| int token = reader.ReadILToken(); | ||
| object obj = methodIL.GetObject(token, NotFoundBehavior.ReturnNull); | ||
| if (obj is MethodDesc method) | ||
| { | ||
| references.Add(method); | ||
| } | ||
| else if (obj is TypeDesc type) | ||
| { | ||
| references.Add(type); | ||
| } | ||
| break; | ||
| } | ||
|
|
||
| default: | ||
| reader.Skip(opcode); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| foreach (var region in methodIL.GetExceptionRegions()) | ||
| { | ||
| if (region.Kind == ILExceptionRegionKind.Catch && region.ClassToken != 0) | ||
| { | ||
| object obj = methodIL.GetObject(region.ClassToken, NotFoundBehavior.ReturnNull); | ||
| if (obj is TypeDesc type) | ||
| references.Add(type); | ||
| } | ||
| } | ||
|
|
||
| foreach (var local in methodIL.GetLocals()) | ||
| { | ||
| TypeDesc type = local.Type; | ||
| // These types can be represented by ELEMENT_TYPE values and don't need references. | ||
| if (!type.IsPrimitive && !type.IsVoid && !type.IsObject && !type.IsString && !type.IsTypedReference) | ||
| references.Add(type); | ||
| } | ||
|
|
||
| return references; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.