Skip to content

Commit

Permalink
Add methods to the compilation graph without a full Entrypoint (dotne…
Browse files Browse the repository at this point in the history
…t#35879)

* Add methods to the compilation graph without a full Entrypoint
- There is quite a lot of content needed to provide an actual entrypoint for a method
- These cases don't actually require the entrypoint, they simple express a desire for the method to be compiled if possible
- This change both reduces the final file size substantially as well as reduces the memory footprint of the compiler
  • Loading branch information
davidwrighton authored May 6, 2020
1 parent 5abde01 commit b70309a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto

foreach (MethodDesc method in Type.GetAllMethods())
{
if (!method.IsGenericMethodDefinition && context.CompilationModuleGroup.VersionsWithMethodBody(method))
if (!method.IsGenericMethodDefinition &&
context.CompilationModuleGroup.ContainsMethodBody(method, false))
{
dependencies.Add(context.MethodEntrypoint(method), $"Method on type {Type.ToString()}");
dependencies.Add(context.CompiledMethodNode(method), $"Method on type {Type.ToString()}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
{
// Require compilation of the canonical version for instantiating stubs
MethodDesc canonMethod = _method.Method.GetCanonMethodTarget(CanonicalFormKind.Specific);
ISymbolNode canonMethodNode = factory.MethodEntrypoint(
new MethodWithToken(canonMethod, _method.Token, constrainedType: null),
isUnboxingStub: false,
isInstantiatingStub: false,
isPrecodeImportRequired: false);
yield return new DependencyListEntry(canonMethodNode, "Canonical method for instantiating stub");
if (factory.CompilationModuleGroup.ContainsMethodBody(canonMethod, false))
{
ISymbolNode canonMethodNode = factory.CompiledMethodNode(canonMethod);
yield return new DependencyListEntry(canonMethodNode, "Canonical method for instantiating stub");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,12 @@ public void SetMarkingComplete()
_markingComplete = true;
}

public IMethodNode MethodEntrypoint(MethodDesc method)
public IMethodNode CompiledMethodNode(MethodDesc method)
{
EcmaModule module = ((EcmaMethod)method.GetTypicalMethodDefinition()).Module;
ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true);
return MethodEntrypoint(
new MethodWithToken(method, moduleToken, constrainedType: null),
isUnboxingStub: false,
isInstantiatingStub: false,
isPrecodeImportRequired: false);

return CreateMethodEntrypointNodeHelper(new MethodWithToken(method, moduleToken, constrainedType: null));
}

private NodeCache<TypeDesc, AllMethodsOnTypeNode> _allMethodsOnType;
Expand Down Expand Up @@ -427,7 +424,10 @@ public IEnumerable<MethodWithGCInfo> EnumerateCompiledMethods(EcmaModule moduleT
MethodDesc method = methodNode.Method;
MethodWithGCInfo methodCodeNode = methodNode as MethodWithGCInfo;
#if DEBUG
IMethodNode methodNodeDebug = MethodEntrypoint(method);
EcmaModule module = ((EcmaMethod)method.GetTypicalMethodDefinition()).Module;
ModuleToken moduleToken = Resolver.GetModuleTokenForMethod(method, throwIfNotFound: true);

IMethodNode methodNodeDebug = MethodEntrypoint(new MethodWithToken(method, moduleToken, constrainedType: null), false, false, false);
MethodWithGCInfo methodCodeNodeDebug = methodNodeDebug as MethodWithGCInfo;
if (methodCodeNodeDebug == null && methodNodeDebug is LocalMethodImport localMethodImport)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ public RootingServiceProvider(NodeFactory factory, RootAdder rootAdder)
public void AddCompilationRoot(MethodDesc method, string reason)
{
MethodDesc canonMethod = method.GetCanonMethodTarget(CanonicalFormKind.Specific);
IMethodNode methodEntryPoint = _factory.MethodEntrypoint(canonMethod);
_rootAdder(methodEntryPoint, reason);
if (_factory.CompilationModuleGroup.ContainsMethodBody(canonMethod, false))
{
IMethodNode methodEntryPoint = _factory.CompiledMethodNode(canonMethod);
_rootAdder(methodEntryPoint, reason);
}
}
}
}
Expand Down

0 comments on commit b70309a

Please sign in to comment.