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 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #626 from nattress/interface_dispatch
Interface dispatch support
- Loading branch information
Showing
23 changed files
with
579 additions
and
100 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
48 changes: 48 additions & 0 deletions
48
src/Common/src/TypeSystem/Common/MetadataType.MethodImpls.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,48 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Internal.TypeSystem | ||
{ | ||
public struct MethodImplRecord | ||
{ | ||
public MethodDesc Decl; | ||
public MethodDesc Body; | ||
} | ||
|
||
// MethodImpl api surface for types. | ||
public partial class MetadataType | ||
{ | ||
/// <summary> | ||
/// Compute an array of all MethodImpls that pertain to overriding virtual (non-interface methods) on this type. | ||
/// May be expensive. | ||
/// </summary> | ||
protected abstract MethodImplRecord[] ComputeVirtualMethodImplsForType(); | ||
|
||
private MethodImplRecord[] _allVirtualMethodImplsForType; | ||
/// <summary> | ||
/// Get an array of all MethodImpls that pertain to overriding virtual (non-interface methods) on this type. | ||
/// Expected to cache results so this api can be used repeatedly. | ||
/// </summary> | ||
public MethodImplRecord[] VirtualMethodImplsForType | ||
{ | ||
get | ||
{ | ||
if (_allVirtualMethodImplsForType == null) | ||
{ | ||
_allVirtualMethodImplsForType = ComputeVirtualMethodImplsForType(); | ||
} | ||
|
||
return _allVirtualMethodImplsForType; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get an array of MethodImpls where the Decl method matches by name with the specified name. | ||
/// </summary> | ||
/// <param name="name"></param> | ||
/// <returns></returns> | ||
public abstract MethodImplRecord[] FindMethodsImplWithMatchingDeclName(string name); | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/InterfaceDispatchCellNode.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,87 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Internal.TypeSystem; | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace ILCompiler.DependencyAnalysis | ||
{ | ||
class InterfaceDispatchCellNode : ObjectNode, ISymbolNode | ||
{ | ||
MethodDesc _targetMethod; | ||
|
||
public InterfaceDispatchCellNode(MethodDesc targetMethod) | ||
{ | ||
Debug.Assert(targetMethod.OwningType.IsInterface); | ||
_targetMethod = targetMethod; | ||
} | ||
|
||
public string MangledName | ||
{ | ||
get | ||
{ | ||
return "__InterfaceDispatchCell_" + NodeFactory.NameMangler.GetMangledMethodName(_targetMethod); | ||
} | ||
} | ||
|
||
public override string GetName() | ||
{ | ||
return ((ISymbolNode)this).MangledName; | ||
} | ||
|
||
public int Offset | ||
{ | ||
get | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
public override string Section | ||
{ | ||
get | ||
{ | ||
return "data"; | ||
} | ||
} | ||
|
||
public override bool StaticDependenciesAreComputed | ||
{ | ||
get | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) | ||
{ | ||
ObjectDataBuilder objData = new ObjectDataBuilder(factory); | ||
// The interface dispatch cell has an alignment requirement of 2 * [Pointer size] as part of the | ||
// synchronization mechanism of the two values in the runtime. | ||
objData.Alignment = _targetMethod.Context.Target.PointerSize * 2; | ||
objData.DefinedSymbols.Add(this); | ||
|
||
objData.EmitPointerReloc(factory.ExternSymbol("RhpInitialDynamicInterfaceDispatch")); | ||
|
||
// The second cell field uses the two lower-order bits to communicate the contents. | ||
// We add 1 to signal IDC_CachePointerIsInterfacePointer. See src\Native\Runtime\inc\rhbinder.h. | ||
objData.EmitPointerReloc(factory.NecessaryTypeSymbol(_targetMethod.OwningType), 1); | ||
|
||
// End the run of dispatch cells | ||
objData.EmitZeroPointer(); | ||
|
||
int interfaceMethodSlot = VirtualMethodSlotHelper.GetVirtualMethodSlot(factory, _targetMethod); | ||
if (factory.Target.PointerSize == 8) | ||
{ | ||
objData.EmitLong(interfaceMethodSlot); | ||
} | ||
else | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
return objData.ToObjectData(); | ||
} | ||
} | ||
} |
Oops, something went wrong.