This repository has been archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for eager static constructors
This looks like a lot of code just to support a rarely used feature, but a lot of this is plumbing that will let me delete some existing code in a subsequent commit. Some of this will also be needed to support the various preinitialized data attributes/general type preinitialization. * Redirecting uses of HasStaticConstructor to go through the TypeInitialization class (exposing higher level APIs "HasLazyCctor" and "HasEagerCctor") * Emitting a new table with an array of eager class constructors * Augmenting GC/nonGC/ThreadStatic and Method nodes to depend on an entry in the eager cctor table if the owning type has a cctor * Startup code addition to iterate over the list of eager cctors and call them one by one Reusable code: * ArrayOfEmbeddedPointers: we have a buch of places where we just want an array of pointers. This will let us e.g. delete StringIndirectionNode. Missing features: ordering the eager cctors. I want to think a bit about how we parse custom attribute blobs before I implement that.
- Loading branch information
1 parent
3a209ba
commit dcb6997
Showing
19 changed files
with
392 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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
106 changes: 106 additions & 0 deletions
106
src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/ArrayOfEmbeddedPointersNode.cs
This file contains 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,106 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ILCompiler.DependencyAnalysis | ||
{ | ||
/// <summary> | ||
/// Represents an array of pointers to symbols. <typeparamref name="TTarget"/> is the type | ||
/// of node each pointer within the vector points to. | ||
/// </summary> | ||
public sealed class ArrayOfEmbeddedPointersNode<TTarget> : ArrayOfEmbeddedDataNode<EmbeddedPointerIndirectionNode<TTarget>> | ||
where TTarget : ISymbolNode | ||
{ | ||
private int _nextId; | ||
private string _startSymbolMangledName; | ||
|
||
public ArrayOfEmbeddedPointersNode(string startSymbolMangledName, string endSymbolMangledName, IComparer<TTarget> nodeSorter) | ||
: base( | ||
startSymbolMangledName, | ||
endSymbolMangledName, | ||
nodeSorter != null ? new PointerIndirectionNodeComparer(nodeSorter) : null) | ||
{ | ||
_startSymbolMangledName = startSymbolMangledName; | ||
} | ||
|
||
public EmbeddedObjectNode NewNode(TTarget target) | ||
{ | ||
return new SimpleEmbeddedPointerIndirectionNode(this, target); | ||
} | ||
|
||
public EmbeddedObjectNode NewNodeWithSymbol(TTarget target) | ||
{ | ||
int id = System.Threading.Interlocked.Increment(ref _nextId); | ||
return new EmbeddedPointerIndirectionWithSymbolNode(this, target, id); | ||
} | ||
|
||
private class PointerIndirectionNodeComparer : IComparer<EmbeddedPointerIndirectionNode<TTarget>> | ||
{ | ||
private IComparer<TTarget> _innerComparer; | ||
|
||
public PointerIndirectionNodeComparer(IComparer<TTarget> innerComparer) | ||
{ | ||
_innerComparer = innerComparer; | ||
} | ||
|
||
public int Compare(EmbeddedPointerIndirectionNode<TTarget> x, EmbeddedPointerIndirectionNode<TTarget> y) | ||
{ | ||
return _innerComparer.Compare(x.Target, y.Target); | ||
} | ||
} | ||
|
||
private class SimpleEmbeddedPointerIndirectionNode : EmbeddedPointerIndirectionNode<TTarget> | ||
{ | ||
protected ArrayOfEmbeddedPointersNode<TTarget> _parentNode; | ||
|
||
public SimpleEmbeddedPointerIndirectionNode(ArrayOfEmbeddedPointersNode<TTarget> futureParent, TTarget target) | ||
: base(target) | ||
{ | ||
_parentNode = futureParent; | ||
} | ||
|
||
public override string GetName() | ||
{ | ||
return "Embedded pointer to " + Target.MangledName; | ||
} | ||
|
||
protected override void OnMarked(NodeFactory context) | ||
{ | ||
// We don't want the child in the parent collection unless it's necessary. | ||
// Only when this node gets marked, the parent node becomes the actual parent. | ||
_parentNode.AddEmbeddedObject(this); | ||
} | ||
|
||
public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory context) | ||
{ | ||
return new[] | ||
{ | ||
new DependencyListEntry(Target, "reloc"), | ||
new DependencyListEntry(_parentNode, "Pointer region") | ||
}; | ||
} | ||
} | ||
|
||
private class EmbeddedPointerIndirectionWithSymbolNode : SimpleEmbeddedPointerIndirectionNode, ISymbolNode | ||
{ | ||
private int _id; | ||
|
||
public EmbeddedPointerIndirectionWithSymbolNode(ArrayOfEmbeddedPointersNode<TTarget> futureParent, TTarget target, int id) | ||
: base(futureParent, target) | ||
{ | ||
_id = id; | ||
} | ||
|
||
public string MangledName | ||
{ | ||
get | ||
{ | ||
return String.Concat(_parentNode._startSymbolMangledName, "_", _id.ToStringInvariant()); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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
52 changes: 52 additions & 0 deletions
52
src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/EmbeddedPointerIndirectionNode.cs
This file contains 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,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ILCompiler.DependencyAnalysis | ||
{ | ||
/// <summary> | ||
/// An <see cref="EmbeddedObjectNode"/> whose sole value is a pointer to a different <see cref="ISymbolNode"/>. | ||
/// <typeparamref name="TTarget"/> represents the node type this pointer points to. | ||
/// </summary> | ||
public abstract class EmbeddedPointerIndirectionNode<TTarget> : EmbeddedObjectNode | ||
where TTarget : ISymbolNode | ||
{ | ||
private TTarget _targetNode; | ||
|
||
/// <summary> | ||
/// Target symbol this node points to. | ||
/// </summary> | ||
public TTarget Target | ||
{ | ||
get | ||
{ | ||
return _targetNode; | ||
} | ||
} | ||
|
||
internal EmbeddedPointerIndirectionNode(TTarget target) | ||
{ | ||
_targetNode = target; | ||
} | ||
|
||
public override bool StaticDependenciesAreComputed | ||
{ | ||
get | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
public override void EncodeData(ref ObjectDataBuilder dataBuilder, NodeFactory factory, bool relocsOnly) | ||
{ | ||
dataBuilder.RequirePointerAlignment(); | ||
dataBuilder.EmitPointerReloc(Target); | ||
} | ||
|
||
// At minimum, Target needs to be reported as a static dependency by inheritors. | ||
public abstract override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory context); | ||
} | ||
} |
This file contains 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
16 changes: 16 additions & 0 deletions
16
src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/IMethodNode.cs
This file contains 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,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Internal.TypeSystem; | ||
|
||
namespace ILCompiler.DependencyAnalysis | ||
{ | ||
/// <summary> | ||
/// A dependency analysis node that represents a method. | ||
/// </summary> | ||
public interface IMethodNode : ISymbolNode | ||
{ | ||
MethodDesc Method { get; } | ||
} | ||
} |
This file contains 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.