Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] Move RequiresAlign8 flag from RareFlags into ExtendedFlags #106010

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading