Skip to content

Commit

Permalink
[NativeAOT] Move RequiresAlign8 flag from RareFlags into ExtendedFlags (
Browse files Browse the repository at this point in the history
  • Loading branch information
filipnavara committed Aug 7, 2024
1 parent 1716c4b commit 4153092
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,14 @@ internal bool RequiresAlign8
{
get
{
return (RareFlags & EETypeRareFlags.RequiresAlign8Flag) != 0;
// NOTE: Does not work for types with HasComponentSize, ie. arrays and strings.
// Since this is called early through RhNewObject we cannot use regular Debug.Assert
// here to enforce the assumption.
#if DEBUG
if (HasComponentSize)
Debug.Fail("RequiresAlign8 called for array or string");
#endif
return (_uFlags & (uint)EETypeFlagsEx.RequiresAlign8Flag) != 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public static unsafe object RhNewArray(MethodTable* pEEType, int length)
Debug.Assert(pEEType->IsArray || pEEType->IsString);

#if FEATURE_64BIT_ALIGNMENT
if (pEEType->RequiresAlign8)
MethodTable* pEEElementType = pEEType->RelatedParameterType;
if (pEEElementType->IsValueType && pEEElementType->RequiresAlign8)
{
return InternalCalls.RhpNewArrayAlign8(pEEType, length);
}
Expand Down Expand Up @@ -381,7 +382,8 @@ internal static unsafe IntPtr RhGetRuntimeHelperForType(MethodTable* pEEType, Ru

case RuntimeHelperKind.AllocateArray:
#if FEATURE_64BIT_ALIGNMENT
if (pEEType->RequiresAlign8)
MethodTable* pEEElementType = pEEType->RelatedParameterType;
if (pEEElementType->IsValueType && pEEElementType->RequiresAlign8)
return (IntPtr)(delegate*<MethodTable*, int, object>)&InternalCalls.RhpNewArrayAlign8;
#endif // FEATURE_64BIT_ALIGNMENT

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/nativeaot/Runtime/inc/MethodTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class MethodTable
// GC depends on this bit, this type has a critical finalizer
HasCriticalFinalizerFlag = 0x0002,
IsTrackedReferenceWithFinalizerFlag = 0x0004,

// This type requires 8-byte alignment for its fields on certain platforms (ARM32, WASM)
RequiresAlign8Flag = 0x1000
};

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ mdType.Name is "WeakReference" or "WeakReference`1" &&
flagsEx |= (ushort)EETypeFlagsEx.IDynamicInterfaceCastableFlag;
}

if (type.RequiresAlign8())
{
flagsEx |= (ushort)EETypeFlagsEx.RequiresAlign8Flag;
}

return flagsEx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ internal enum EETypeFlagsEx : ushort
/// This type implements IDynamicInterfaceCastable to allow dynamic resolution of interface casts.
/// </summary>
IDynamicInterfaceCastableFlag = 0x0008,

/// <summary>
/// This type requires 8-byte alignment for its fields on certain platforms (ARM32, WASM)
/// </summary>
RequiresAlign8Flag = 0x1000
}

internal enum EETypeKind : uint
Expand Down Expand Up @@ -116,10 +121,7 @@ internal enum EETypeKind : uint
[Flags]
internal enum EETypeRareFlags : int
{
/// <summary>
/// This type requires 8-byte alignment for its fields on certain platforms (only ARM currently).
/// </summary>
RequiresAlign8Flag = 0x00000001,
// UNUSED = 0x00000001,

// UNUSED1 = 0x00000002,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,11 +1352,6 @@ private void ComputeRareFlags()
{
uint flags = 0;

if (_type.RequiresAlign8())
{
flags |= (uint)EETypeRareFlags.RequiresAlign8Flag;
}

if (_type.IsByRefLike)
{
flags |= (uint)EETypeRareFlags.IsByRefLikeFlag;
Expand Down

0 comments on commit 4153092

Please sign in to comment.