Skip to content

Commit

Permalink
Pass NodeFactory to ObjectData's Section (#77967)
Browse files Browse the repository at this point in the history
This is a preparatory change for something I'm working on, but makes sense on its own - notice several node types that had to hold on to extra state just because we didn't have context in the `Section` property. Got rid of the extra state as well. A couple bytes of memory saved here and there.
  • Loading branch information
MichalStrehovsky committed Nov 9, 2022
1 parent 2d251ae commit 18eaeb2
Show file tree
Hide file tree
Showing 93 changed files with 187 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AssemblyStubNode()
/// </summary>
protected virtual bool IsVisibleFromManagedCode => true;

public override ObjectNodeSection Section => ObjectNodeSection.TextSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.TextSection;

public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public MethodReadOnlyDataNode(MethodDesc owningMethod)
_owningMethod = owningMethod;
}

public override ObjectNodeSection Section => ObjectNodeSection.ReadOnlyDataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection;
public override bool StaticDependenciesAreComputed => _data != null;

public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ObjectData(byte[] data, Relocation[] relocs, int alignment, ISymbolDefini

public abstract ObjectData GetData(NodeFactory factory, bool relocsOnly = false);

public abstract ObjectNodeSection Section { get; }
public abstract ObjectNodeSection GetSection(NodeFactory factory);

/// <summary>
/// Should identical symbols emitted into separate object files be Comdat folded when linked together?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public int Offset => 0;
public override bool IsShareable => false;

public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);

public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void AddEmbeddedObject(TEmbedded symbol)

protected override string GetName(NodeFactory factory) => $"Region {StartSymbol.GetMangledName(factory.NameMangler)}";

public override ObjectNodeSection Section => ObjectNodeSection.DataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.DataSection;
public override bool IsShareable => false;

public override bool StaticDependenciesAreComputed => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BlobNode(Utf8String name, ObjectNodeSection section, byte[] data, int ali
_alignment = alignment;
}

public override ObjectNodeSection Section => _section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _section;
public override bool StaticDependenciesAreComputed => true;

public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public int Offset => 0;
public override bool IsShareable => false;

public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);

public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
}
public int Offset => 0;

public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool IsShareable => false;

public override bool StaticDependenciesAreComputed => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)

public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool ShouldSkipEmittingObjectNode(NodeFactory factory) => false;
public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public int Offset => 0;
public override bool IsShareable => false;

public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);

public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,12 @@ public virtual ISymbolNode NodeForLinkage(NodeFactory factory)

public TypeDesc Type => _type;

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (_type.Context.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

public int MinimumObjectSize => GetMinimumObjectSize(_type.Context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ public EETypeOptionalFieldsNode(EETypeNode owner)
_owner = owner;
}

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (_owner.Type.Context.Target.IsWindows)
return ObjectNodeSection.FoldableReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows)
return ObjectNodeSection.FoldableReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

public override bool StaticDependenciesAreComputed => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolDefinitionNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,12 @@ public uint GetIndex(ISymbolNode symbol, int delta = 0)
return index;
}

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (_nodeFactory.Target.IsWindows || _nodeFactory.Target.SupportsRelativePointers)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows || factory.Target.SupportsRelativePointers)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

public override bool StaticDependenciesAreComputed => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)

public MethodDesc Method { get; }

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (Method.Context.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

public override bool StaticDependenciesAreComputed => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public FieldRvaDataNode(EcmaField field)
_field = field;
}

public override ObjectNodeSection Section => ObjectNodeSection.ReadOnlyDataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection;
public override bool StaticDependenciesAreComputed => true;

public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ public GCStaticEETypeNode(TargetDetails target, GCPointerMap gcMap)

protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (_target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (_target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

public override bool StaticDependenciesAreComputed => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact

public override bool StaticDependenciesAreComputed => true;

public override ObjectNodeSection Section => ObjectNodeSection.DataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.DataSection;
public override bool IsShareable => EETypeNode.IsTypeNodeShareable(_type);

public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ public static string GetMangledName(TypeDesc type, NameMangler nameMangler)

public override bool StaticDependenciesAreComputed => true;

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (Type.Context.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
public override bool IsShareable => EETypeNode.IsTypeNodeShareable(_preinitializationInfo.Type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ public int Offset
}
}

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (_details.Instantiation[0].Context.Target.IsWindows)
return ObjectNodeSection.FoldableReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows)
return ObjectNodeSection.FoldableReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

public override bool IsShareable => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class GenericDictionaryNode : ObjectNode, ISymbolDefinitionNode,

int ISymbolDefinitionNode.Offset => HeaderSize;

public override ObjectNodeSection Section => GetDictionaryLayout(_factory).DictionarySection(_factory);
public override ObjectNodeSection GetSection(NodeFactory factory) => GetDictionaryLayout(_factory).DictionarySection(_factory);

public GenericDictionaryNode(NodeFactory factory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override IMethodNode CreateUnboxingStubNode(MethodDesc method)
else
{
// Otherwise we just unbox 'this' and don't touch anything else.
return new UnboxingStubNode(method, Target);
return new UnboxingStubNode(method);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)

public override bool StaticDependenciesAreComputed => true;

public override ObjectNodeSection Section
public override ObjectNodeSection GetSection(NodeFactory factory)
{
get
{
if (_type.Context.Target.IsWindows)
return ObjectNodeSection.FoldableReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
if (factory.Target.IsWindows)
return ObjectNodeSection.FoldableReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}

protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFactory factory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public ISymbolNode EndSymbol => _endSymbol;
public int Offset => 0;
public override bool IsShareable => false;
public override ObjectNodeSection Section => _externalReferences.Section;
public override ObjectNodeSection GetSection(NodeFactory factory) => _externalReferences.GetSection(factory);
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
public int Offset => 0;
public override bool IsShareable => false;

public override ObjectNodeSection Section => ObjectNodeSection.ReadOnlyDataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection;

public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public MethodAssociatedDataNode(IMethodNode methodNode)

protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);

public override ObjectNodeSection Section => ObjectNodeSection.ReadOnlyDataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection;
public override bool StaticDependenciesAreComputed => true;
public int Offset => 0;
public override bool IsShareable => _methodNode.Method is InstantiatedMethod || EETypeNode.IsTypeNodeShareable(_methodNode.Method.OwningType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MethodExceptionHandlingInfoNode(MethodDesc owningMethod, ObjectData data)
_data = new ObjectData(data.Data, data.Relocs, data.Alignment, new ISymbolDefinitionNode[] { this });
}

public override ObjectNodeSection Section => _owningMethod.Context.Target.IsWindows
public override ObjectNodeSection GetSection(NodeFactory factory) => _owningMethod.Context.Target.IsWindows
? ObjectNodeSection.FoldableReadOnlyDataSection
: ObjectNodeSection.DataSection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)

public override bool IsShareable => false;

public override ObjectNodeSection Section => ObjectNodeSection.DataSection;
public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.DataSection;

public override bool StaticDependenciesAreComputed => true;

Expand Down

0 comments on commit 18eaeb2

Please sign in to comment.