Skip to content

Commit

Permalink
Change all "unmanaged" (no GC fields) sequential types to have sequen…
Browse files Browse the repository at this point in the history
…tial layout.
  • Loading branch information
jkoritzinsky committed Nov 18, 2021
1 parent 9962c10 commit 3c4ccbc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
8 changes: 5 additions & 3 deletions src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
#define READYTORUN_SIGNATURE 0x00525452 // 'RTR'

// Keep these in sync with src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs
#define READYTORUN_MAJOR_VERSION 0x0005
#define READYTORUN_MINOR_VERSION 0x0004
#define READYTORUN_MAJOR_VERSION 0x0006
#define READYTORUN_MINOR_VERSION 0x0000

#define MINIMUM_READYTORUN_MAJOR_VERSION 0x003
#define MINIMUM_READYTORUN_MAJOR_VERSION 0x006

// R2R Version 2.1 adds the InliningInfo section
// R2R Version 2.2 adds the ProfileDataInfo section
// R2R Version 3.0 changes calling conventions to correctly handle explicit structures to spec.
// R2R 3.0 is not backward compatible with 2.x.
// R2R Version 6.0 changes managed layout for sequential types with any unmanaged non-blittable fields.
// R2R 6.0 is not backward compatible with 5.x or earlier.

struct READYTORUN_CORE_HEADER
{
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ internal struct ReadyToRunHeaderConstants
{
public const uint Signature = 0x00525452; // 'RTR'

public const ushort CurrentMajorVersion = 5;
public const ushort CurrentMinorVersion = 4;
public const ushort CurrentMajorVersion = 6;
public const ushort CurrentMinorVersion = 0;
}

#pragma warning disable 0169
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ protected override ModuleFieldLayout CreateValueFromKey(EcmaModule module)
}
}

if (nonGcBytes[StaticIndex.Regular] != 0 ||
if (nonGcBytes[StaticIndex.Regular] != 0 ||
nonGcBytes[StaticIndex.ThreadLocal] != 0 ||
gcBytes[StaticIndex.Regular] != 0 ||
gcBytes[StaticIndex.Regular] != 0 ||
gcBytes[StaticIndex.ThreadLocal] != 0)
{
OffsetsForType offsetsForType = new OffsetsForType(LayoutInt.Indeterminate, LayoutInt.Indeterminate, LayoutInt.Indeterminate, LayoutInt.Indeterminate);
Expand Down Expand Up @@ -290,14 +290,14 @@ private void GetElementTypeInfoGeneric(
}

private void GetElementTypeInfo(
EcmaModule module,
EcmaModule module,
FieldDesc fieldDesc,
EntityHandle valueTypeHandle,
EntityHandle valueTypeHandle,
CorElementType elementType,
int pointerSize,
bool moduleLayout,
out int alignment,
out int size,
out int alignment,
out int size,
out bool isGcPointerField,
out bool isGcBoxedField)
{
Expand Down Expand Up @@ -357,7 +357,7 @@ private void GetElementTypeInfo(
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, fieldDesc.OwningType);
break;

// Statics for valuetypes where the valuetype is defined in this module are handled here.
// Statics for valuetypes where the valuetype is defined in this module are handled here.
// Other valuetype statics utilize the pessimistic model below.
case CorElementType.ELEMENT_TYPE_VALUETYPE:
if (IsTypeByRefLike(valueTypeHandle, module.MetadataReader))
Expand Down Expand Up @@ -522,7 +522,7 @@ public FieldAndOffset[] CalculateTypeLayout(DefType defType, EcmaModule module,
offsetsForType.GcOffsets[StaticIndex.ThreadLocal],
};

LayoutInt[] gcPointerFieldOffsets = new LayoutInt[StaticIndex.Count]
LayoutInt[] gcPointerFieldOffsets = new LayoutInt[StaticIndex.Count]
{
offsetsForType.GcOffsets[StaticIndex.Regular] + new LayoutInt(gcBoxedCount[StaticIndex.Regular] * pointerSize),
offsetsForType.GcOffsets[StaticIndex.ThreadLocal] + new LayoutInt(gcBoxedCount[StaticIndex.ThreadLocal] * pointerSize)
Expand Down Expand Up @@ -768,10 +768,10 @@ private class ModuleFieldLayout
private ConcurrentDictionary<DefType, FieldAndOffset[]> _genericTypeToFieldMap;

public ModuleFieldLayout(
EcmaModule module,
StaticsBlock gcStatics,
StaticsBlock nonGcStatics,
StaticsBlock threadGcStatics,
EcmaModule module,
StaticsBlock gcStatics,
StaticsBlock nonGcStatics,
StaticsBlock threadGcStatics,
StaticsBlock threadNonGcStatics,
IReadOnlyDictionary<TypeDefinitionHandle, OffsetsForType> typeOffsets)
{
Expand Down Expand Up @@ -814,7 +814,7 @@ protected override ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metada
}

/// <summary>
/// This method decides whether the type needs aligned base offset in order to have layout resilient to
/// This method decides whether the type needs aligned base offset in order to have layout resilient to
/// base class layout changes.
/// </summary>
protected override void AlignBaseOffsetIfNecessary(MetadataType type, ref LayoutInt baseOffset, bool requiresAlign8, bool requiresAlignedBase)
Expand All @@ -834,7 +834,7 @@ protected override bool AlignUpInstanceByteSizeForExplicitFieldLayoutCompatQuirk

public static bool IsManagedSequentialType(TypeDesc type)
{
if (type.IsPointer)
if (type.IsPointer || type.IsFunctionPointer)
{
return true;
}
Expand All @@ -857,9 +857,20 @@ public static bool IsManagedSequentialType(TypeDesc type)

foreach (FieldDesc field in type.GetFields())
{
if (!field.IsStatic && !IsManagedSequentialType(field.FieldType.UnderlyingType))
if (!field.IsStatic)
{
return false;
if (type.IsPointer)
{
continue;
}
if (!type.IsValueType)
{
return false;
}
if (((DefType)type).ContainsGCPointers)
{
return false;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/classlayoutinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ namespace
pManagedPlacementInfo->m_alignment = TARGET_POINTER_SIZE;
}

return !pNestedType.GetMethodTable()->IsManagedSequential();
return !pNestedType.GetMethodTable()->ContainsPointers();
}

// No other type permitted for ManagedSequential.
Expand Down

0 comments on commit 3c4ccbc

Please sign in to comment.