未验证 提交 ff492e1f 编写于 作者: J Jan Kotas 提交者: GitHub

Fix and simplify GCDescs for collectible types (#49791)

Fixes #49684
上级 c5ec2386
......@@ -161,7 +161,7 @@ public:
// If it doesn't contain pointers, there isn't a GCDesc
PTR_MethodTable mt(pMT);
_ASSERTE(mt->ContainsPointersOrCollectible());
_ASSERTE(mt->ContainsPointers());
return PTR_CGCDesc(mt);
}
......@@ -192,28 +192,38 @@ public:
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)
{
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;
......
......@@ -305,12 +305,6 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy
_ASSERTE(cbCGCDescData == CGCDesc::ComputeSizeRepeating(nSeries));
}
}
#ifdef FEATURE_COLLECTIBLE_TYPES
else if (this->IsCollectible())
{
cbCGCDescData = (DWORD)CGCDesc::ComputeSize(1);
}
#endif
DWORD dwMultipurposeSlotsMask = 0;
dwMultipurposeSlotsMask |= MethodTable::enum_flag_HasPerInstInfo;
......@@ -714,19 +708,6 @@ MethodTable* Module::CreateArrayMethodTable(TypeHandle elemTypeHnd, CorElementTy
pSeries->SetSeriesSize(-(SSIZE_T)(pMT->GetBaseSize()));
}
#ifdef FEATURE_COLLECTIBLE_TYPES
if (!pMT->ContainsPointers() && this->IsCollectible())
{
CGCDescSeries *pSeries;
// For collectible types, insert empty gc series
CGCDesc::GetCGCDescFromMT(pMT)->InitValueClassSeries(pMT, 1);
pSeries = CGCDesc::GetCGCDescFromMT(pMT)->GetHighestSeries();
pSeries->SetSeriesOffset(ArrayBase::GetDataPtrOffset(pMT));
pSeries->val_serie[0].set_val_serie_item (0, static_cast<HALF_SIZE_T>(pMT->GetComponentSize()));
}
#endif
// If we get here we are assuming that there was no truncation. If this is not the case then
// an array whose base type is not a value class was created and was larger then 0xffff (a word)
_ASSERTE(dwComponentSize == pMT->GetComponentSize());
......
......@@ -2439,7 +2439,7 @@ MethodTable::DebugDumpGCDesc(
LOG((LF_ALWAYS, LL_ALWAYS, "GC description for '%s':\n\n", pszClassName));
}
if (ContainsPointersOrCollectible())
if (ContainsPointers())
{
CGCDescSeries *pSeries;
CGCDescSeries *pHighest;
......
......@@ -3821,7 +3821,7 @@ void MethodTable::GetSavedExtent(TADDR *pStart, TADDR *pEnd)
TADDR start;
if (ContainsPointersOrCollectible())
if (ContainsPointers())
start = dac_cast<TADDR>(this) - CGCDesc::GetCGCDescFromMT(this)->GetSize();
else
start = dac_cast<TADDR>(this);
......
......@@ -8743,19 +8743,6 @@ MethodTableBuilder::HandleGCForExplicitLayout()
MethodTable *pMT = GetHalfBakedMethodTable();
#ifdef FEATURE_COLLECTIBLE_TYPES
if (bmtFP->NumGCPointerSeries == 0 && pMT->Collectible())
{
// For collectible types, insert empty gc series
CGCDescSeries *pSeries;
CGCDesc::Init( (PVOID) pMT, 1);
pSeries = ((CGCDesc*)pMT)->GetLowestSeries();
pSeries->SetSeriesSize( (size_t) (0) - (size_t) pMT->GetBaseSize());
pSeries->SetSeriesOffset(OBJECT_SIZE);
}
else
#endif // FEATURE_COLLECTIBLE_TYPES
if (bmtFP->NumGCPointerSeries != 0)
{
pMT->SetContainsPointers();
......@@ -10087,10 +10074,6 @@ MethodTableBuilder::SetupMethodTable2(
cbDictAllocSize = DictionaryLayout::GetDictionarySizeFromLayout(bmtGenerics->GetNumGenericArgs(), pClass->GetDictionaryLayout(), &cbDictSlotSize);
}
#ifdef FEATURE_COLLECTIBLE_TYPES
BOOL fCollectible = pLoaderModule->IsCollectible();
#endif // FEATURE_COLLECTIBLE_TYPES
DWORD dwGCSize;
if (bmtFP->NumGCPointerSeries > 0)
......@@ -10099,12 +10082,7 @@ MethodTableBuilder::SetupMethodTable2(
}
else
{
#ifdef FEATURE_COLLECTIBLE_TYPES
if (fCollectible)
dwGCSize = (DWORD)CGCDesc::ComputeSize(1);
else
#endif // FEATURE_COLLECTIBLE_TYPES
dwGCSize = 0;
dwGCSize = 0;
}
pClass->SetNumMethods(bmtVT->cTotalSlots);
......@@ -11200,19 +11178,6 @@ VOID MethodTableBuilder::HandleGCForValueClasses(MethodTable ** pByValueClassCac
// Note that for value classes, the following calculation is only appropriate
// when the instance is in its "boxed" state.
#ifdef FEATURE_COLLECTIBLE_TYPES
if (bmtFP->NumGCPointerSeries == 0 && pMT->Collectible())
{
// For collectible types, insert empty gc series
CGCDescSeries *pSeries;
CGCDesc::Init( (PVOID) pMT, 1);
pSeries = ((CGCDesc*)pMT)->GetLowestSeries();
pSeries->SetSeriesSize( (size_t) (0) - (size_t) pMT->GetBaseSize());
pSeries->SetSeriesOffset(OBJECT_SIZE);
}
else
#endif // FEATURE_COLLECTIBLE_TYPES
if (bmtFP->NumGCPointerSeries != 0)
{
CGCDescSeries *pSeries;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册