-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common parent for frozen objects (#93773)
Frozen strings and frozen arbitrary objects were separate classes but giving them a common ancestors makes handling these easier.
- Loading branch information
1 parent
33ee130
commit 712d522
Showing
7 changed files
with
132 additions
and
143 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
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
75 changes: 75 additions & 0 deletions
75
...r/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/SerializedFrozenObjectNode.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,75 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
using Internal.Text; | ||
using Internal.TypeSystem; | ||
|
||
namespace ILCompiler.DependencyAnalysis | ||
{ | ||
/// <summary> | ||
/// Represents a frozen object that is statically preallocated within the data section | ||
/// of the executable instead of on the GC heap. | ||
/// </summary> | ||
public sealed class SerializedFrozenObjectNode : FrozenObjectNode | ||
{ | ||
private readonly MetadataType _owningType; | ||
private readonly TypePreinit.ISerializableReference _data; | ||
private readonly int _allocationSiteId; | ||
|
||
public MetadataType OwningType => _owningType; | ||
|
||
public SerializedFrozenObjectNode(MetadataType owningType, int allocationSiteId, TypePreinit.ISerializableReference data) | ||
{ | ||
_owningType = owningType; | ||
_allocationSiteId = allocationSiteId; | ||
_data = data; | ||
} | ||
|
||
public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) | ||
{ | ||
sb.Append(nameMangler.CompilationUnitPrefix).Append("__FrozenObj_") | ||
.Append(nameMangler.GetMangledTypeName(_owningType)) | ||
.Append(_allocationSiteId.ToStringInvariant()); | ||
} | ||
|
||
public override TypeDesc ObjectType => _data.Type; | ||
|
||
public override bool IsKnownImmutable => _data.IsKnownImmutable; | ||
|
||
protected override int ContentSize | ||
=> _data.Type.IsArray | ||
? _data.Type.Context.Target.PointerSize * 2 + ((ArrayType)_data.Type).ElementType.GetElementSize().AsInt * _data.ArrayLength | ||
: ((DefType)_data.Type).InstanceByteCount.AsInt + (_data.Type.IsValueType ? _data.Type.Context.Target.PointerSize : 0); | ||
|
||
public override int? ArrayLength => _data.Type.IsArray ? _data.ArrayLength : null; | ||
|
||
public override void EncodeContents(ref ObjectDataBuilder dataBuilder, NodeFactory factory, bool relocsOnly) | ||
{ | ||
// byte contents | ||
_data.WriteContent(ref dataBuilder, this, factory); | ||
} | ||
|
||
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler); | ||
|
||
public override void GetNonRelocationDependencies(ref DependencyList dependencies, NodeFactory factory) | ||
{ | ||
_data.GetNonRelocationDependencies(ref dependencies, factory); | ||
} | ||
|
||
public override int ClassCode => 1789429316; | ||
|
||
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer) | ||
{ | ||
var otherFrozenObjectNode = (SerializedFrozenObjectNode)other; | ||
int result = comparer.Compare(otherFrozenObjectNode._owningType, _owningType); | ||
if (result != 0) | ||
return result; | ||
|
||
return _allocationSiteId.CompareTo(otherFrozenObjectNode._allocationSiteId); | ||
} | ||
|
||
public override string ToString() => $"Frozen {_data.Type.GetDisplayNameWithoutNamespace()} object"; | ||
} | ||
} |
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
Oops, something went wrong.