Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions src/coreclr/nativeaot/Runtime/MethodTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "MethodTable.h"
#include "PalLimitedContext.h"
#include "Pal.h"
#include "ObjectLayout.h"

#include "CommonMacros.inl"
#include "MethodTable.inl"
Expand Down Expand Up @@ -105,3 +106,17 @@ MethodTable * MethodTable::GetRelatedParameterType()

return PTR_EEType(reinterpret_cast<TADDR>(m_RelatedType.m_pRelatedParameterType));
}

//-----------------------------------------------------------------------------------------------------------
uint32_t MethodTable::GetArrayRank()
{
ASSERT(IsArray());
uint32_t boundsSize = GetParameterizedTypeShape() - SZARRAY_BASE_SIZE;
if (boundsSize > 0)
{
Copy link

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an ASSERT to verify that boundsSize % (2 * sizeof(uint32_t)) == 0 to catch unexpected shape values and ensure the division yields an integer dimension count.

Suggested change
{
{
// Ensure boundsSize is divisible by (2 * sizeof(uint32_t)).
ASSERT(boundsSize % (2 * sizeof(uint32_t)) == 0);

Copilot uses AI. Check for mistakes.
// Multidim array case: Base size includes space for two Int32s
// (upper and lower bound) per each dimension of the array.
return boundsSize / (2 * sizeof(uint32_t));
}
return 1;
}
27 changes: 24 additions & 3 deletions src/coreclr/nativeaot/Runtime/eventtrace_bulktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,33 @@ int BulkTypeEventLogger::LogSingleType(MethodTable * pEEType)

if (pEEType->IsParameterizedType())
{
ASSERT(pEEType->IsArray());
// Array
pVal->fixedSizedData.Flags |= kEtwTypeFlagsArray;
if (pEEType->IsArray())
{
pVal->fixedSizedData.Flags |= kEtwTypeFlagsArray;

if (!pEEType->IsSzArray())
{
// Multidimensional arrays set the rank bits, SzArrays do not set the rank bits
uint32_t rank = pEEType->GetArrayRank();
if (rank < kEtwTypeFlagsArrayRankMax)
{
// Only ranks less than kEtwTypeFlagsArrayRankMax are supported.
// Fortunately kEtwTypeFlagsArrayRankMax should be greater than the
// number of ranks the type loader will support
rank <<= kEtwTypeFlagsArrayRankShift;
ASSERT((rank & kEtwTypeFlagsArrayRankMask) == rank);
pVal->fixedSizedData.Flags |= rank;
}
}
}

pVal->cTypeParameters = 1;
pVal->ullSingleTypeParameter = (ULONGLONG) pEEType->GetRelatedParameterType();
}
else if (pEEType->IsFunctionPointer())
{
// No extra logging for function pointers
}
else
{
// Note: For generic types, we do not necessarily know the generic parameters.
Expand Down
12 changes: 11 additions & 1 deletion src/coreclr/nativeaot/Runtime/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ enum EtwTypeFlags
kEtwTypeFlagsFinalizable = 0x2,
kEtwTypeFlagsExternallyImplementedCOMObject = 0x4,
kEtwTypeFlagsArray = 0x8,
kEtwTypeFlagsModuleBaseAddress = 0x10,
kEtwTypeFlagsModuleBaseAddress = 0x10,
kEtwTypeFlagsArrayRankBit0 = 0x100,
kEtwTypeFlagsArrayRankBit1 = 0x200,
kEtwTypeFlagsArrayRankBit2 = 0x400,
kEtwTypeFlagsArrayRankBit3 = 0x800,
kEtwTypeFlagsArrayRankBit4 = 0x1000,
kEtwTypeFlagsArrayRankBit5 = 0x2000,

kEtwTypeFlagsArrayRankMask = 0x3F00,
kEtwTypeFlagsArrayRankShift = 8,
kEtwTypeFlagsArrayRankMax = kEtwTypeFlagsArrayRankMask >> kEtwTypeFlagsArrayRankShift
};

enum EtwThreadFlags
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/nativeaot/Runtime/inc/MethodTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ class MethodTable
return m_uBaseSize & ~FunctionPointerFlagsMask;
}

uint32_t GetParameterizedTypeShape()
{
ASSERT(IsParameterizedType());
return m_uBaseSize;
}

Kinds GetKind();

bool IsArray()
Expand All @@ -208,6 +214,8 @@ class MethodTable
bool IsSzArray()
{ return GetElementType() == ElementType_SzArray; }

uint32_t GetArrayRank();

bool IsParameterizedType()
{ return (GetKind() == ParameterizedEEType); }

Expand Down
Loading