-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Emit Async Methods in crossgen2 #124203
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
base: main
Are you sure you want to change the base?
Emit Async Methods in crossgen2 #124203
Changes from all commits
db314fe
fcf110f
e1dec2b
696b6b6
d0a228c
dea51a8
d37bfc8
af114a0
bf8f402
435c5d9
8465ceb
49101ed
5bcb9b5
17e3358
c66218c
14973b0
18754ac
4dfdfe2
a887cf6
7f36d5a
5e4a0cd
5c37396
d9af071
d0ff7c1
c1ecd59
b7604a8
5c9cd91
4fe194e
1ea81c8
eb88cc5
4df231a
61f77a1
821188c
076b1a6
1770954
0487f2c
cc6c6be
7115923
1770f85
e497dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -203,6 +203,7 @@ protected override bool CompareValueToValue(AsyncMethodVariant value1, AsyncMeth | |||||||||
| public MetadataType GetContinuationType(GCPointerMap pointerMap) | ||||||||||
| { | ||||||||||
| var cont = _continuationTypeHashtable.GetOrCreateValue(pointerMap); | ||||||||||
| _validTypes.TryAdd(cont); | ||||||||||
| return cont; | ||||||||||
|
Comment on lines
205
to
207
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ public override MethodStackTraceVisibilityFlags GetMethodVisibility(MethodDesc m | |
| if (method.HasCustomAttribute("System.Diagnostics", "StackTraceHiddenAttribute") | ||
| || (method.OwningType is MetadataType mdType && mdType.HasCustomAttribute("System.Diagnostics", "StackTraceHiddenAttribute")) | ||
| || (method is Internal.IL.Stubs.ILStubMethod) | ||
| || method.IsAsyncThunk()) // see MethodDesc::IsDiagnosticsHidden() in src/coreclr/vm/method.inl | ||
| || method.IsCompilerGeneratedILBodyForAsync()) // see MethodDesc::IsDiagnosticsHidden() in src/coreclr/vm/method.inl | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep I think |
||
| { | ||
| result |= MethodStackTraceVisibilityFlags.IsHidden; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Reflection.Metadata.Ecma335; | ||
|
|
||
| using ILCompiler.ReadyToRun.TypeSystem; | ||
| using Internal; | ||
| using Internal.NativeFormat; | ||
| using Internal.ReadyToRunConstants; | ||
|
|
@@ -67,8 +67,17 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) | |
| foreach (MethodWithGCInfo methodNode in factory.EnumerateCompiledMethods(_module, CompiledMethodCategory.All)) | ||
| { | ||
| MethodDesc[] inlinees = methodNode.InlinedMethods; | ||
| if (inlinees.Length == 0) | ||
| { | ||
| continue; | ||
| } | ||
| MethodDesc inliner = methodNode.Method; | ||
| EcmaMethod inlinerDefinition = (EcmaMethod)inliner.GetTypicalMethodDefinition(); | ||
| if (inliner.IsCompilerGeneratedILBodyForAsync()) | ||
| { | ||
| // Async thunks are generated by crossgen and diagnostic tools don't need to worry about them | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Diagnostic tools do need to worry about async thunks, e.g. debugger needs to worry about them for stepping. This comment should be more accurate. It should explain why we are not tracking methods inlined into async thunks. |
||
| continue; | ||
| } | ||
| EcmaMethod inlinerDefinition = (EcmaMethod)inliner.GetPrimaryMethodDesc().GetTypicalMethodDefinition(); | ||
|
|
||
| if (inlinerDefinition.IsNonVersionable()) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,9 +109,8 @@ public bool CanInline(MethodDesc caller, MethodDesc callee) | |
| } | ||
| } | ||
|
|
||
| if (callee.IsAsyncThunk()) | ||
| if (callee.IsCompilerGeneratedILBodyForAsync() || callee.IsAsyncCall()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| { | ||
| // Async thunks require special handling in the compiler and should not be inlined | ||
| return false; | ||
| } | ||
|
|
||
|
|
@@ -302,7 +301,7 @@ public sealed class ReadyToRunCodegenCompilation : Compilation | |
|
|
||
| private readonly ProfileDataManager _profileData; | ||
| private readonly FileLayoutOptimizer _fileLayoutOptimizer; | ||
| private readonly HashSet<EcmaMethod> _methodsWhichNeedMutableILBodies = new HashSet<EcmaMethod>(); | ||
| private readonly HashSet<MethodDesc> _methodsWhichNeedMutableILBodies = new HashSet<MethodDesc>(); | ||
| private readonly HashSet<MethodWithGCInfo> _methodsToRecompile = new HashSet<MethodWithGCInfo>(); | ||
|
|
||
| public ProfileDataManager ProfileData => _profileData; | ||
|
|
@@ -695,12 +694,15 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor | |
| if (dependency is MethodWithGCInfo methodCodeNodeNeedingCode) | ||
| { | ||
| var method = methodCodeNodeNeedingCode.Method; | ||
| if (method.GetTypicalMethodDefinition() is EcmaMethod ecmaMethod) | ||
| var typicalDef = method.GetTypicalMethodDefinition(); | ||
| if (typicalDef is EcmaMethod or AsyncMethodVariant or AsyncResumptionStub) | ||
| { | ||
| if (ilProvider.NeedsCrossModuleInlineableTokens(ecmaMethod) && | ||
| !_methodsWhichNeedMutableILBodies.Contains(ecmaMethod) && | ||
| CorInfoImpl.IsMethodCompilable(this, methodCodeNodeNeedingCode.Method)) | ||
| _methodsWhichNeedMutableILBodies.Add(ecmaMethod); | ||
| if (ilProvider.NeedsCrossModuleInlineableTokens(typicalDef) && | ||
| !_methodsWhichNeedMutableILBodies.Contains(typicalDef) && | ||
| CorInfoImpl.IsMethodCompilable(this, method)) | ||
| { | ||
| _methodsWhichNeedMutableILBodies.Add(typicalDef); | ||
| } | ||
| } | ||
|
|
||
| if (method.IsAsyncCall() | ||
|
|
@@ -748,11 +750,11 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor | |
|
|
||
| void ProcessMutableMethodBodiesList() | ||
| { | ||
| EcmaMethod[] mutableMethodBodyNeedList = new EcmaMethod[_methodsWhichNeedMutableILBodies.Count]; | ||
| MethodDesc[] mutableMethodBodyNeedList = new MethodDesc[_methodsWhichNeedMutableILBodies.Count]; | ||
| _methodsWhichNeedMutableILBodies.CopyTo(mutableMethodBodyNeedList); | ||
| _methodsWhichNeedMutableILBodies.Clear(); | ||
| TypeSystemComparer comparer = TypeSystemComparer.Instance; | ||
| Comparison<EcmaMethod> comparison = (EcmaMethod a, EcmaMethod b) => comparer.Compare(a, b); | ||
| Comparison<MethodDesc> comparison = (MethodDesc a, MethodDesc b) => comparer.Compare(a, b); | ||
| Array.Sort(mutableMethodBodyNeedList, comparison); | ||
| var ilProvider = (ReadyToRunILProvider)_methodILCache.ILProvider; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -521,7 +521,7 @@ private bool CrossModuleInlineableInternal(MethodDesc method) | |
| private bool CrossModuleInlineableUncached(MethodDesc method) | ||
| { | ||
| // Async thunks and variants cannot currently be inlined cross module | ||
| if (method.IsAsyncVariant() || method.IsAsync || method.IsAsyncThunk()) | ||
| if (method.IsAsyncVariant() || method.IsAsync || method.IsCompilerGeneratedILBodyForAsync()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IsAsyncThunk should work just fine here. |
||
| return false; | ||
|
|
||
| // Defined in corelib | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.