Skip to content

Commit 9bd5682

Browse files
Make our changes to crossgen2 extra obvious
1 parent 2e12cf3 commit 9bd5682

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

src/coreclr/tools/Common/TypeSystem/Common/MetadataFieldLayoutAlgorithm.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defTyp
104104
type.Context.Target.GetWellKnownTypeAlignment(type),
105105
0,
106106
alignUpInstanceByteSize: true,
107+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
107108
ignoreLayoutAlignment: false,
109+
#endif
108110
out instanceByteSizeAndAlignment
109111
);
110112

@@ -303,7 +305,11 @@ protected ComputedInstanceFieldLayout ComputeExplicitFieldLayout(MetadataType ty
303305
LayoutInt instanceSize = cumulativeInstanceFieldPos + offsetBias;
304306

305307
var layoutMetadata = type.GetClassLayout();
308+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
306309
int packingSize = ComputePackingSize(type, layoutMetadata, false);
310+
#else
311+
int packingSize = ComputePackingSize(type, layoutMetadata);
312+
#endif
307313
LayoutInt largestAlignmentRequired = LayoutInt.One;
308314

309315
var offsets = new FieldAndOffset[numInstanceFields];
@@ -357,7 +363,9 @@ protected ComputedInstanceFieldLayout ComputeExplicitFieldLayout(MetadataType ty
357363
largestAlignmentRequired,
358364
layoutMetadata.Size,
359365
alignUpInstanceByteSize: AlignUpInstanceByteSizeForExplicitFieldLayoutCompatQuirk(type),
366+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
360367
ignoreLayoutAlignment: false,
368+
#endif
361369
out instanceByteSizeAndAlignment);
362370

363371
ComputedInstanceFieldLayout computedLayout = new ComputedInstanceFieldLayout();
@@ -378,7 +386,11 @@ private static LayoutInt AlignUpInstanceFieldOffset(TypeDesc typeWithField, Layo
378386
return LayoutInt.AlignUp(cumulativeInstanceFieldPos, alignment, target);
379387
}
380388

389+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
381390
protected ComputedInstanceFieldLayout ComputeSequentialFieldLayout(MetadataType type, int numInstanceFields, bool isSequentialWithRefs)
391+
#else
392+
protected ComputedInstanceFieldLayout ComputeSequentialFieldLayout(MetadataType type, int numInstanceFields)
393+
#endif
382394
{
383395
var offsets = new FieldAndOffset[numInstanceFields];
384396

@@ -392,7 +404,11 @@ protected ComputedInstanceFieldLayout ComputeSequentialFieldLayout(MetadataType
392404

393405
LayoutInt largestAlignmentRequirement = LayoutInt.One;
394406
int fieldOrdinal = 0;
407+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
395408
int packingSize = ComputePackingSize(type, layoutMetadata, ignoreLayoutPacking: isSequentialWithRefs);
409+
#else
410+
int packingSize = ComputePackingSize(type, layoutMetadata);
411+
#endif
396412
bool layoutAbiStable = true;
397413

398414
foreach (var field in type.GetFields())
@@ -420,7 +436,9 @@ protected ComputedInstanceFieldLayout ComputeSequentialFieldLayout(MetadataType
420436
largestAlignmentRequirement,
421437
layoutMetadata.Size,
422438
alignUpInstanceByteSize: true,
439+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
423440
ignoreLayoutAlignment: isSequentialWithRefs,
441+
#endif
424442
out instanceByteSizeAndAlignment);
425443

426444
ComputedInstanceFieldLayout computedLayout = new ComputedInstanceFieldLayout();
@@ -445,7 +463,11 @@ protected ComputedInstanceFieldLayout ComputeAutoFieldLayout(MetadataType type,
445463
bool hasLayout = type.HasLayout();
446464
var layoutMetadata = type.GetClassLayout();
447465

466+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
448467
int packingSize = ComputePackingSize(type, layoutMetadata, false);
468+
#else
469+
int packingSize = ComputePackingSize(type, layoutMetadata);
470+
#endif
449471
packingSize = Math.Min(context.Target.MaximumAutoLayoutPackingSize, packingSize);
450472

451473
var offsets = new FieldAndOffset[numInstanceFields];
@@ -709,7 +731,9 @@ protected ComputedInstanceFieldLayout ComputeAutoFieldLayout(MetadataType type,
709731
minAlign,
710732
classLayoutSize: 0,
711733
alignUpInstanceByteSize: true,
734+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
712735
ignoreLayoutAlignment: false,
736+
#endif
713737
out instanceByteSizeAndAlignment);
714738

715739
ComputedInstanceFieldLayout computedLayout = new ComputedInstanceFieldLayout();
@@ -832,15 +856,27 @@ private static SizeAndAlignment ComputeFieldSizeAndAlignment(TypeDesc fieldType,
832856
return result;
833857
}
834858

859+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
835860
private static int ComputePackingSize(MetadataType type, ClassLayoutMetadata layoutMetadata, bool ignoreLayoutPacking)
861+
#else
862+
private static int ComputePackingSize(MetadataType type, ClassLayoutMetadata layoutMetadata)
863+
#endif
836864
{
865+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
837866
if (layoutMetadata.PackingSize == 0 || ignoreLayoutPacking)
867+
#else
868+
if (layoutMetadata.PackingSize == 0)
869+
#endif
838870
return type.Context.Target.DefaultPackingSize;
839871
else
840872
return layoutMetadata.PackingSize;
841873
}
842874

875+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
843876
private static SizeAndAlignment ComputeInstanceSize(MetadataType type, LayoutInt instanceSize, LayoutInt alignment, int classLayoutSize, bool alignUpInstanceByteSize, bool ignoreLayoutAlignment, out SizeAndAlignment byteCount)
877+
#else
878+
private static SizeAndAlignment ComputeInstanceSize(MetadataType type, LayoutInt instanceSize, LayoutInt alignment, int classLayoutSize, bool alignUpInstanceByteSize, out SizeAndAlignment byteCount)
879+
#endif
844880
{
845881
SizeAndAlignment result;
846882

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,17 @@ protected override ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metada
803803
return ComputeExplicitFieldLayout(type, numInstanceFields);
804804
}
805805
else
806+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
806807
if (ShouldLayoutSequential(type, out var isSequentialWithRefs))
807808
{
808809
return ComputeSequentialFieldLayout(type, numInstanceFields, isSequentialWithRefs);
809810
}
811+
#else
812+
if (type.IsEnum || MarshalUtils.IsBlittableType(type) || IsManagedSequentialType(type))
813+
{
814+
return ComputeSequentialFieldLayout(type, numInstanceFields);
815+
}
816+
#endif
810817
else
811818
{
812819
return ComputeAutoFieldLayout(type, numInstanceFields);
@@ -866,6 +873,7 @@ public static bool IsManagedSequentialType(TypeDesc type)
866873
return true;
867874
}
868875

876+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
869877
private static bool ShouldLayoutSequential(TypeDesc type, out bool isSequentialWithRefs)
870878
{
871879
isSequentialWithRefs = false;
@@ -887,10 +895,6 @@ private static bool ShouldLayoutSequential(TypeDesc type, out bool isSequentialW
887895
return true;
888896
}
889897

890-
#if !FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
891-
return false;
892-
}
893-
#else
894898
isSequentialWithRefs = HasValidSequentialLayout(type);
895899
return isSequentialWithRefs;
896900
}

src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/ILCompiler.TypeSystem.ReadyToRun.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1717
</PropertyGroup>
1818

19+
<!-- Compilation options -->
20+
<Import Project="../../../clr.featuredefines.props" />
21+
1922
<ItemGroup>
2023
<PackageReference Include="xunit.core" Version="$(XUnitVersion)" ExcludeAssets="build" />
2124
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="$(MicrosoftDotNetXUnitExtensionsVersion)" />

src/coreclr/tools/aot/ILCompiler.TypeSystem.ReadyToRun.Tests/TestMetadataFieldLayoutAlgorithm.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ protected override ComputedInstanceFieldLayout ComputeInstanceFieldLayout(Metada
3939
}
4040
else if (type.IsSequentialLayout || type.IsEnum)
4141
{
42+
#if FEATURE_SEQUENTIAL_LAYOUT_WITH_REFS
4243
return ComputeSequentialFieldLayout(type, numInstanceFields, false);
44+
#else
45+
return ComputeSequentialFieldLayout(type, numInstanceFields);
46+
#endif
4347
}
4448
else
4549
{

0 commit comments

Comments
 (0)