Skip to content
Merged
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
40 changes: 25 additions & 15 deletions src/coreclr/src/gc/gcdesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,38 @@ class CGCDesc
static size_t GetNumPointers (MethodTable* pMT, size_t ObjectSize, size_t NumComponents)
{
size_t NumOfPointers = 0;
CGCDesc* map = GetCGCDescFromMT(pMT);
CGCDescSeries* cur = map->GetHighestSeries();
ptrdiff_t cnt = (ptrdiff_t) map->GetNumSeries();

if (cnt > 0)
if (pMT->ContainsPointers())
{
CGCDescSeries* last = map->GetLowestSeries();
while (cur >= last)
CGCDesc* map = GetCGCDescFromMT(pMT);
CGCDescSeries* cur = map->GetHighestSeries();
ptrdiff_t cnt = (ptrdiff_t)map->GetNumSeries();

if (cnt >= 0)
Copy link
Member

Choose a reason for hiding this comment

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

My analysis indicates the change here to change from > to >= is a small performance optimization. From my analysis cnt == 0 can't actually happen so this is ok, but I want to verify that was the rationale.

Copy link
Member Author

Choose a reason for hiding this comment

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

My primary motivation for this was to make the conditions and flow to be more similar to the go_through_object macros, so that easier to validate that the logic in this method matches it.

You are right that the side-effect is minor perf optimization.

{
NumOfPointers += (cur->GetSeriesSize() + ObjectSize) / sizeof(JSlot);
cur--;
CGCDescSeries* last = map->GetLowestSeries();
do
{
NumOfPointers += (cur->GetSeriesSize() + ObjectSize) / sizeof(JSlot);
cur--;
}
while (cur >= last);
}
}
else
{
/* Handle the repeating case - array of valuetypes */
for (ptrdiff_t __i = 0; __i > cnt; __i--)
else
{
NumOfPointers += cur->val_serie[__i].nptrs;
/* Handle the repeating case - array of valuetypes */
for (ptrdiff_t __i = 0; __i > cnt; __i--)
{
NumOfPointers += cur->val_serie[__i].nptrs;
}

NumOfPointers *= NumComponents;
}
}

NumOfPointers *= NumComponents;
if (pMT->Collectible())
{
NumOfPointers += 1;
}

return NumOfPointers;
Expand Down