Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
SKIP_SPECIAL_SLOTS
  • Loading branch information
VSadov committed Nov 13, 2021
commit e874b3c294a6353856a9e5d96b5ab985349a8d7e
6 changes: 4 additions & 2 deletions src/coreclr/vm/dacenumerablehash.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,17 @@ class DacEnumerableHashTable
// slot [1] will contain the next version of the table if it resizes
static const int SLOT_LENGTH = 0;
static const int SLOT_NEXT = 1;

// normal slots start at slot #2
static const int SKIP_SPECIAL_SLOTS = 2;

static DWORD GetLength(DPTR(PTR_VolatileEntry) buckets)
{
return (DWORD)dac_cast<TADDR>(buckets[SLOT_LENGTH]);
}

static DPTR(PTR_VolatileEntry) GetNext(DPTR(PTR_VolatileEntry) buckets)
{
return (DPTR(PTR_VolatileEntry))dac_cast<TADDR>(buckets[SLOT_NEXT]);
return dac_cast<DPTR(PTR_VolatileEntry)>(dac_cast<TADDR>(buckets[SLOT_NEXT]));
}

// Loader heap provided at construction time. May be NULL (in which case m_pModule must *not* be NULL).
Expand Down
16 changes: 8 additions & 8 deletions src/coreclr/vm/dacenumerablehash.inl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::DacEnumerableHashTable(Module *pModu

// two extra slots - slot [0] contains the length of the table,
// slot [1] will contain the next version of the table if it resizes
S_SIZE_T cbBuckets = S_SIZE_T(sizeof(VolatileEntry*)) * (S_SIZE_T(cInitialBuckets) + S_SIZE_T(2));
S_SIZE_T cbBuckets = S_SIZE_T(sizeof(VolatileEntry*)) * (S_SIZE_T(cInitialBuckets) + S_SIZE_T(SKIP_SPECIAL_SLOTS));

m_cEntries = 0;
PTR_VolatileEntry* pBuckets = (PTR_VolatileEntry*)(void*)GetHeap()->AllocMem(cbBuckets);
Expand Down Expand Up @@ -134,7 +134,7 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::BaseInsertEntry(DacEnumerableHa
DWORD cBuckets = GetLength(curBuckets);

// Compute which bucket the entry belongs in based on the hash. (+2 to skip "length" and "next" slots)
DWORD dwBucket = iHash % cBuckets + 2;
DWORD dwBucket = iHash % cBuckets + SKIP_SPECIAL_SLOTS;

// Prepare to link the new entry at the head of the bucket chain.
pVolatileEntry->m_pNextEntry = curBuckets[dwBucket];
Expand Down Expand Up @@ -176,7 +176,7 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::GrowTable()
DWORD cNewBuckets = NextLargestPrime(cBuckets * SCALE_FACTOR);
// two extra slots - slot [0] contains the length of the table,
// slot [1] will contain the next version of the table if it resizes
S_SIZE_T cbNewBuckets = (S_SIZE_T(cNewBuckets) + S_SIZE_T(2)) * S_SIZE_T(sizeof(PTR_VolatileEntry));
S_SIZE_T cbNewBuckets = (S_SIZE_T(cNewBuckets) + S_SIZE_T(SKIP_SPECIAL_SLOTS)) * S_SIZE_T(sizeof(PTR_VolatileEntry));

PTR_VolatileEntry *pNewBuckets = (PTR_VolatileEntry*)(void*)GetHeap()->AllocMem_NoThrow(cbNewBuckets);
if (!pNewBuckets)
Expand All @@ -200,12 +200,12 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::GrowTable()
for (DWORD i = 0; i < cBuckets; i++)
{
// +2 to skip "length" and "next" slots
DWORD dwCurBucket = i + 2;
DWORD dwCurBucket = i + SKIP_SPECIAL_SLOTS;
PTR_VolatileEntry pEntry = curBuckets[dwCurBucket];

while (pEntry != NULL)
{
DWORD dwNewBucket = (pEntry->m_iHashValue % cNewBuckets) + 2;
DWORD dwNewBucket = (pEntry->m_iHashValue % cNewBuckets) + SKIP_SPECIAL_SLOTS;
PTR_VolatileEntry pNextEntry = pEntry->m_pNextEntry;

PTR_VolatileEntry pTail = pNewBuckets[dwNewBucket];
Expand Down Expand Up @@ -307,7 +307,7 @@ DPTR(VALUE) DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::BaseFindFirstEntryByHash

// Compute which bucket the entry belongs in based on the hash.
// +2 to skip "length" and "next" slots
DWORD dwBucket = iHash % cBuckets + 2;
DWORD dwBucket = iHash % cBuckets + SKIP_SPECIAL_SLOTS;

// Point at the first entry in the bucket chain which would contain any entries with the given hash code.
PTR_VolatileEntry pEntry = curBuckets[dwBucket];
Expand Down Expand Up @@ -447,7 +447,7 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::EnumMemoryRegions(CLRDataEnumMe
for (DWORD i = 0; i < cBuckets; i++)
{
//+2 to skip "length" and "next" slots
PTR_VolatileEntry pEntry = curBuckets[i + 2];
PTR_VolatileEntry pEntry = curBuckets[i + SKIP_SPECIAL_SLOTS];
while (pEntry.IsValid())
{
pEntry.EnumMem();
Expand Down Expand Up @@ -479,7 +479,7 @@ void DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>::BaseInitIterator(BaseIterator *
pIterator->m_pTable = dac_cast<DPTR(DacEnumerableHashTable<DAC_ENUM_HASH_ARGS>)>(this);
pIterator->m_pEntry = NULL;
//+2 to skip "length" and "next" slots
pIterator->m_dwBucket = 2;
pIterator->m_dwBucket = SKIP_SPECIAL_SLOTS;
}

// Returns a pointer to the next entry in the hash table or NULL once all entries have been enumerated. Once
Expand Down