Skip to content

Commit 3c4ccbc

Browse files
committed
Change all "unmanaged" (no GC fields) sequential types to have sequential layout.
1 parent 9962c10 commit 3c4ccbc

4 files changed

Lines changed: 35 additions & 22 deletions

File tree

src/coreclr/inc/readytorun.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
#define READYTORUN_SIGNATURE 0x00525452 // 'RTR'
1616

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

21-
#define MINIMUM_READYTORUN_MAJOR_VERSION 0x003
21+
#define MINIMUM_READYTORUN_MAJOR_VERSION 0x006
2222

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

2830
struct READYTORUN_CORE_HEADER
2931
{

src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal struct ReadyToRunHeaderConstants
1414
{
1515
public const uint Signature = 0x00525452; // 'RTR'
1616

17-
public const ushort CurrentMajorVersion = 5;
18-
public const ushort CurrentMinorVersion = 4;
17+
public const ushort CurrentMajorVersion = 6;
18+
public const ushort CurrentMinorVersion = 0;
1919
}
2020

2121
#pragma warning disable 0169

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunMetadataFieldLayoutAlgorithm.cs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ protected override ModuleFieldLayout CreateValueFromKey(EcmaModule module)
196196
}
197197
}
198198

199-
if (nonGcBytes[StaticIndex.Regular] != 0 ||
199+
if (nonGcBytes[StaticIndex.Regular] != 0 ||
200200
nonGcBytes[StaticIndex.ThreadLocal] != 0 ||
201-
gcBytes[StaticIndex.Regular] != 0 ||
201+
gcBytes[StaticIndex.Regular] != 0 ||
202202
gcBytes[StaticIndex.ThreadLocal] != 0)
203203
{
204204
OffsetsForType offsetsForType = new OffsetsForType(LayoutInt.Indeterminate, LayoutInt.Indeterminate, LayoutInt.Indeterminate, LayoutInt.Indeterminate);
@@ -290,14 +290,14 @@ private void GetElementTypeInfoGeneric(
290290
}
291291

292292
private void GetElementTypeInfo(
293-
EcmaModule module,
293+
EcmaModule module,
294294
FieldDesc fieldDesc,
295-
EntityHandle valueTypeHandle,
295+
EntityHandle valueTypeHandle,
296296
CorElementType elementType,
297297
int pointerSize,
298298
bool moduleLayout,
299-
out int alignment,
300-
out int size,
299+
out int alignment,
300+
out int size,
301301
out bool isGcPointerField,
302302
out bool isGcBoxedField)
303303
{
@@ -357,7 +357,7 @@ private void GetElementTypeInfo(
357357
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, fieldDesc.OwningType);
358358
break;
359359

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

525-
LayoutInt[] gcPointerFieldOffsets = new LayoutInt[StaticIndex.Count]
525+
LayoutInt[] gcPointerFieldOffsets = new LayoutInt[StaticIndex.Count]
526526
{
527527
offsetsForType.GcOffsets[StaticIndex.Regular] + new LayoutInt(gcBoxedCount[StaticIndex.Regular] * pointerSize),
528528
offsetsForType.GcOffsets[StaticIndex.ThreadLocal] + new LayoutInt(gcBoxedCount[StaticIndex.ThreadLocal] * pointerSize)
@@ -768,10 +768,10 @@ private class ModuleFieldLayout
768768
private ConcurrentDictionary<DefType, FieldAndOffset[]> _genericTypeToFieldMap;
769769

770770
public ModuleFieldLayout(
771-
EcmaModule module,
772-
StaticsBlock gcStatics,
773-
StaticsBlock nonGcStatics,
774-
StaticsBlock threadGcStatics,
771+
EcmaModule module,
772+
StaticsBlock gcStatics,
773+
StaticsBlock nonGcStatics,
774+
StaticsBlock threadGcStatics,
775775
StaticsBlock threadNonGcStatics,
776776
IReadOnlyDictionary<TypeDefinitionHandle, OffsetsForType> typeOffsets)
777777
{
@@ -814,7 +814,7 @@ protected override ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metada
814814
}
815815

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

835835
public static bool IsManagedSequentialType(TypeDesc type)
836836
{
837-
if (type.IsPointer)
837+
if (type.IsPointer || type.IsFunctionPointer)
838838
{
839839
return true;
840840
}
@@ -857,9 +857,20 @@ public static bool IsManagedSequentialType(TypeDesc type)
857857

858858
foreach (FieldDesc field in type.GetFields())
859859
{
860-
if (!field.IsStatic && !IsManagedSequentialType(field.FieldType.UnderlyingType))
860+
if (!field.IsStatic)
861861
{
862-
return false;
862+
if (type.IsPointer)
863+
{
864+
continue;
865+
}
866+
if (!type.IsValueType)
867+
{
868+
return false;
869+
}
870+
if (((DefType)type).ContainsGCPointers)
871+
{
872+
return false;
873+
}
863874
}
864875
}
865876

src/coreclr/vm/classlayoutinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ namespace
291291
pManagedPlacementInfo->m_alignment = TARGET_POINTER_SIZE;
292292
}
293293

294-
return !pNestedType.GetMethodTable()->IsManagedSequential();
294+
return !pNestedType.GetMethodTable()->ContainsPointers();
295295
}
296296

297297
// No other type permitted for ManagedSequential.

0 commit comments

Comments
 (0)