Skip to content

Commit

Permalink
Small fixes to sealed vtables (#1175)
Browse files Browse the repository at this point in the history
* Avoid double hashtable lookup
* Avoid generating empty sealed vtables (basically, emitting a bunch of unreferenced symbol definitions in the object file)
  • Loading branch information
MichalStrehovsky authored May 27, 2021
1 parent 5e1d0cc commit d707f62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public int NumSealedVTableEntries
}
}

public override bool ShouldSkipEmittingObjectNode(NodeFactory factory)
{
BuildSealedVTableSlots(factory, relocsOnly: false);
return NumSealedVTableEntries == 0;
}

/// <summary>
/// Returns the slot of a method in the sealed vtable, or -1 if not found. This API should only be called after
/// successfully building the sealed vtable slots.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public static int GetDefaultInterfaceMethodSlot(NodeFactory factory, MethodDesc
{
Debug.Assert(method.GetTypicalMethodDefinition().OwningType == interfaceOnDefinition.GetTypeDefinition());

SealedVTableNode sealedVTable = factory.SealedVTable(implType);

// Ensure the sealed vtable is built before computing the slot
factory.SealedVTable(implType).BuildSealedVTableSlots(factory, relocsOnly: false /* GetVirtualMethodSlot is called in the final emission phase */);
sealedVTable.BuildSealedVTableSlots(factory, relocsOnly: false /* GetVirtualMethodSlot is called in the final emission phase */);

int sealedVTableSlot = factory.SealedVTable(implType).ComputeDefaultInterfaceMethodSlot(method, interfaceOnDefinition);
int sealedVTableSlot = sealedVTable.ComputeDefaultInterfaceMethodSlot(method, interfaceOnDefinition);
if (sealedVTableSlot == -1)
return -1;

Expand All @@ -42,10 +44,12 @@ public static int GetVirtualMethodSlot(NodeFactory factory, MethodDesc method, T
// does not get any sealed vtable entries
Debug.Assert(!implType.IsArrayTypeWithoutGenericInterfaces());

SealedVTableNode sealedVTable = factory.SealedVTable(implType);

// Ensure the sealed vtable is built before computing the slot
factory.SealedVTable(implType).BuildSealedVTableSlots(factory, relocsOnly: false /* GetVirtualMethodSlot is called in the final emission phase */);
sealedVTable.BuildSealedVTableSlots(factory, relocsOnly: false /* GetVirtualMethodSlot is called in the final emission phase */);

int sealedVTableSlot = factory.SealedVTable(implType).ComputeSealedVTableSlot(method);
int sealedVTableSlot = sealedVTable.ComputeSealedVTableSlot(method);
if (sealedVTableSlot == -1)
return -1;

Expand Down

0 comments on commit d707f62

Please sign in to comment.