Skip to content

Commit f025132

Browse files
Generate fewer type loader templates (#72350)
1 parent aafa910 commit f025132

File tree

5 files changed

+17
-71
lines changed

5 files changed

+17
-71
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/AnalysisBasedMetadataManager.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,7 @@ void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootPr
199199
if ((pair.Value & MetadataCategory.RuntimeMapping) != 0)
200200
{
201201
FieldDesc field = pair.Key;
202-
203-
// We only care about static fields at this point. Instance fields don't need
204-
// runtime artifacts generated in the image.
205-
if (field.IsStatic && !field.IsLiteral)
206-
{
207-
if (field.IsThreadStatic)
208-
rootProvider.RootThreadStaticBaseForType(field.OwningType, reason);
209-
else if (field.HasGCStaticBase)
210-
rootProvider.RootGCStaticBaseForType(field.OwningType, reason);
211-
else
212-
rootProvider.RootNonGCStaticBaseForType(field.OwningType, reason);
213-
}
202+
rootProvider.AddReflectionRoot(field, reason);
214203
}
215204
}
216205

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,5 +666,11 @@ public int CompareTo(ConstrainedCallInfo other, TypeSystemComparer comparer)
666666
result = comparer.Compare(Method, other.Method);
667667
return result;
668668
}
669+
public override bool Equals(object obj) =>
670+
obj is ConstrainedCallInfo other
671+
&& ConstrainedType == other.ConstrainedType
672+
&& Method == other.Method;
673+
674+
public override int GetHashCode() => HashCode.Combine(ConstrainedType, Method);
669675
}
670676
}

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NativeLayoutVertexNode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ public NativeLayoutTemplateMethodLayoutVertexNode(NodeFactory factory, MethodDes
862862
{
863863
_method = method;
864864
Debug.Assert(method.HasInstantiation);
865+
Debug.Assert(!method.IsGenericMethodDefinition);
865866
Debug.Assert(method.IsCanonicalMethod(CanonicalFormKind.Any));
866867
Debug.Assert(method.GetCanonMethodTarget(CanonicalFormKind.Specific) == method, "Assert that the canonical method passed in is in standard canonical form");
867868
}

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/GeneratingMetadataManager.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -218,34 +218,5 @@ public sealed override MethodDesc GetCanonicalReflectionInvokeStub(MethodDesc me
218218

219219
return InstantiateCanonicalDynamicInvokeMethodForMethod(thunk, method);
220220
}
221-
222-
protected override void GetDependenciesDueToEETypePresence(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
223-
{
224-
if (!ConstructedEETypeNode.CreationAllowed(type))
225-
{
226-
// Both EETypeNode and ConstructedEETypeNode call into this logic. EETypeNode will only call for unconstructable
227-
// EETypes. We don't have templates for those.
228-
return;
229-
}
230-
231-
DefType closestDefType = type.GetClosestDefType();
232-
233-
// TODO-SIZE: this is overly generous in the templates we create
234-
if (_blockingPolicy is FullyBlockedMetadataBlockingPolicy)
235-
return;
236-
237-
if (closestDefType.HasInstantiation)
238-
{
239-
TypeDesc canonType = type.ConvertToCanonForm(CanonicalFormKind.Specific);
240-
TypeDesc canonClosestDefType = closestDefType.ConvertToCanonForm(CanonicalFormKind.Specific);
241-
242-
// Add a dependency on the template for this type, if the canonical type should be generated into this binary.
243-
// If the type is an array type, the check should be on its underlying Array<T> type. This is because a copy of
244-
// an array type gets placed into each module but the Array<T> type only exists in the defining module and only
245-
// one template is needed for the Array<T> type by the dynamic type loader.
246-
if (canonType.IsCanonicalSubtype(CanonicalFormKind.Any) && !factory.NecessaryTypeSymbol(canonClosestDefType).RepresentsIndirectionCell)
247-
dependencies.Add(factory.NativeLayout.TemplateTypeLayout(canonType), "Template Type Layout");
248-
}
249-
}
250221
}
251222
}

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ public void GetDependenciesDueToReflectability(ref DependencyList dependencies,
345345

346346
ReflectionInvokeSupportDependencyAlgorithm.GetDependenciesFromParamsArray(ref dependencies, factory, method);
347347
}
348+
349+
GenericMethodsTemplateMap.GetTemplateMethodDependencies(ref dependencies, factory, method);
350+
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, method.OwningType);
348351
}
349352
}
350353

@@ -359,6 +362,12 @@ public void GetDependenciesDueToReflectability(ref DependencyList dependencies,
359362
{
360363
GetMetadataDependenciesDueToReflectability(ref dependencies, factory, field);
361364
}
365+
366+
if ((category & MetadataCategory.RuntimeMapping) != 0)
367+
{
368+
TypeDesc owningCanonicalType = field.OwningType.ConvertToCanonForm(CanonicalFormKind.Specific);
369+
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, owningCanonicalType);
370+
}
362371
}
363372

364373
/// <summary>
@@ -393,8 +402,6 @@ public void GetDependenciesDueToReflectability(ref DependencyList dependencies,
393402
{
394403
GetMetadataDependenciesDueToReflectability(ref dependencies, factory, type);
395404
}
396-
397-
GetDependenciesDueToEETypePresence(ref dependencies, factory, type);
398405
}
399406

400407
protected virtual void GetMetadataDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
@@ -404,11 +411,6 @@ protected virtual void GetMetadataDependenciesDueToReflectability(ref Dependency
404411
// and property setters)
405412
}
406413

407-
protected virtual void GetDependenciesDueToEETypePresence(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
408-
{
409-
// MetadataManagers can override this to provide additional dependencies caused by the emission of an MethodTable.
410-
}
411-
412414
public virtual void GetConditionalDependenciesDueToEETypePresence(ref CombinedDependencyList dependencies, NodeFactory factory, TypeDesc type)
413415
{
414416
// MetadataManagers can override this to provide additional dependencies caused by the presence of
@@ -464,7 +466,6 @@ public void GetDependenciesDueToMethodCodePresence(ref DependencyList dependenci
464466
ExactMethodInstantiationsNode.GetExactMethodInstantiationDependenciesForMethod(ref dependencies, factory, method);
465467
}
466468

467-
GetDependenciesDueToTemplateTypeLoader(ref dependencies, factory, method);
468469
GetDependenciesDueToMethodCodePresenceInternal(ref dependencies, factory, method, methodIL);
469470
}
470471

@@ -480,28 +481,6 @@ public virtual void GetConditionalDependenciesDueToMethodCodePresence(ref Combin
480481
// method code.
481482
}
482483

483-
private void GetDependenciesDueToTemplateTypeLoader(ref DependencyList dependencies, NodeFactory factory, MethodDesc method)
484-
{
485-
// TODO-SIZE: this is overly generous in the templates we create
486-
if (_blockingPolicy is FullyBlockedMetadataBlockingPolicy)
487-
return;
488-
489-
if (method.HasInstantiation)
490-
{
491-
GenericMethodsTemplateMap.GetTemplateMethodDependencies(ref dependencies, factory, method);
492-
}
493-
else
494-
{
495-
TypeDesc owningTemplateType = method.OwningType;
496-
497-
// Unboxing and Instantiating stubs use a different type as their template
498-
if (factory.TypeSystemContext.IsSpecialUnboxingThunk(method))
499-
owningTemplateType = factory.TypeSystemContext.GetTargetOfSpecialUnboxingThunk(method).OwningType;
500-
501-
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, owningTemplateType);
502-
}
503-
}
504-
505484
protected virtual void GetDependenciesDueToMethodCodePresenceInternal(ref DependencyList dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL)
506485
{
507486
// MetadataManagers can override this to provide additional dependencies caused by the presence of a

0 commit comments

Comments
 (0)