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
Simplify loading generation
  • Loading branch information
cshung committed Aug 9, 2021
commit c8b45c7bb8f4d3fa81a8b6d6abe21b7f08b45ea4
15 changes: 5 additions & 10 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6751,16 +6751,11 @@ HRESULT DacHeapWalker::InitHeapDataWks(HeapData *&pHeaps, size_t &pCount)
if (pHeaps == NULL)
return E_OUTOFMEMORY;

TADDR pGen0 = GenerationTableIndex(g_gcDacGlobals->generation_table, 0);
TADDR pGen1 = GenerationTableIndex(g_gcDacGlobals->generation_table, 1);
TADDR pGen2 = GenerationTableIndex(g_gcDacGlobals->generation_table, 2);
TADDR pLoh = GenerationTableIndex(g_gcDacGlobals->generation_table, 3);
TADDR pPoh = GenerationTableIndex(g_gcDacGlobals->generation_table, 4);
dac_generation gen0 = LoadGeneration(pGen0);
dac_generation gen1 = LoadGeneration(pGen1);
dac_generation gen2 = LoadGeneration(pGen2);
dac_generation loh = LoadGeneration(pLoh);
dac_generation poh = LoadGeneration(pPoh);
dac_generation gen0 = GenerationTableIndex(g_gcDacGlobals->generation_table, 0);
dac_generation gen1 = GenerationTableIndex(g_gcDacGlobals->generation_table, 1);
dac_generation gen2 = GenerationTableIndex(g_gcDacGlobals->generation_table, 2);
dac_generation loh = GenerationTableIndex(g_gcDacGlobals->generation_table, 3);
dac_generation poh = GenerationTableIndex(g_gcDacGlobals->generation_table, 4);

pHeaps[0].YoungestGenPtr = (CORDB_ADDRESS)gen0.allocation_context.alloc_ptr;
pHeaps[0].YoungestGenLimit = (CORDB_ADDRESS)gen0.allocation_context.alloc_limit;
Expand Down
42 changes: 20 additions & 22 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,7 @@ ClrDataAccess::GetHeapAllocData(unsigned int count, struct DacpGenerationAllocDa
DPTR(opaque_generation) table = g_gcDacGlobals->generation_table;
for (unsigned int i=0; i < *g_gcDacGlobals->max_gen + 2; i++)
{
TADDR pEntry = GenerationTableIndex(table, i);
dac_generation entry = LoadGeneration(pEntry);
dac_generation entry = GenerationTableIndex(table, i);
data[0].allocData[i].allocBytes = (CLRDATA_ADDRESS)(ULONG_PTR) entry.allocation_context.alloc_bytes;
data[0].allocData[i].allocBytesLoh = (CLRDATA_ADDRESS)(ULONG_PTR) entry.allocation_context.alloc_bytes_uoh;
}
Expand Down Expand Up @@ -2810,12 +2809,12 @@ ClrDataAccess::GetGCHeapStaticData(struct DacpGcHeapDetails *detailsData)
// get bounds for the different generations
for (unsigned int i=0; i < DAC_NUMBERGENERATIONS; i++)
{
DPTR(dac_generation) generation = GenerationTableIndex(g_gcDacGlobals->generation_table, i);
detailsData->generation_table[i].start_segment = (CLRDATA_ADDRESS) dac_cast<TADDR>(generation->start_segment);
detailsData->generation_table[i].allocation_start = (CLRDATA_ADDRESS) generation->allocation_start;
DPTR(gc_alloc_context) alloc_context = dac_cast<TADDR>(generation) + offsetof(dac_generation, allocation_context);
detailsData->generation_table[i].allocContextPtr = (CLRDATA_ADDRESS)alloc_context->alloc_ptr;
detailsData->generation_table[i].allocContextLimit = (CLRDATA_ADDRESS)alloc_context->alloc_limit;
dac_generation generation = GenerationTableIndex(g_gcDacGlobals->generation_table, i);
detailsData->generation_table[i].start_segment = (CLRDATA_ADDRESS) dac_cast<TADDR>(generation.start_segment);
detailsData->generation_table[i].allocation_start = (CLRDATA_ADDRESS) generation.allocation_start;
gc_alloc_context alloc_context = generation.allocation_context;
detailsData->generation_table[i].allocContextPtr = (CLRDATA_ADDRESS)alloc_context.alloc_ptr;
detailsData->generation_table[i].allocContextLimit = (CLRDATA_ADDRESS)alloc_context.alloc_limit;
}

if (g_gcDacGlobals->finalize_queue.IsValid())
Expand Down Expand Up @@ -3791,8 +3790,7 @@ ClrDataAccess::EnumWksGlobalMemoryRegions(CLRDataEnumMemoryFlags flags)
// this is the convention in the GC so it is repeated here
for (ULONG i = *g_gcDacGlobals->max_gen; i <= *g_gcDacGlobals->max_gen +1; i++)
{
TADDR pGen = GenerationTableIndex(g_gcDacGlobals->generation_table, i);
dac_generation gen = LoadGeneration(pGen);
dac_generation gen = GenerationTableIndex(g_gcDacGlobals->generation_table, i);
__DPtr<dac_heap_segment> seg = dac_cast<TADDR>(gen.start_segment);
while (seg)
{
Expand Down Expand Up @@ -4621,14 +4619,14 @@ HRESULT ClrDataAccess::GetGenerationTable(unsigned int cGenerations, struct Dacp
{
for (unsigned int i = 0; i < numGenerationTableEntries; i++)
{
DPTR(dac_generation) generation = GenerationTableIndex(g_gcDacGlobals->generation_table, i);
pGenerationData[i].start_segment = (CLRDATA_ADDRESS) dac_cast<TADDR>(generation->start_segment);
dac_generation generation = GenerationTableIndex(g_gcDacGlobals->generation_table, i);
pGenerationData[i].start_segment = (CLRDATA_ADDRESS) dac_cast<TADDR>(generation.start_segment);

pGenerationData[i].allocation_start = (CLRDATA_ADDRESS) generation->allocation_start;
pGenerationData[i].allocation_start = (CLRDATA_ADDRESS) generation.allocation_start;

DPTR(gc_alloc_context) alloc_context = dac_cast<TADDR>(generation) + offsetof(dac_generation, allocation_context);
pGenerationData[i].allocContextPtr = (CLRDATA_ADDRESS)alloc_context->alloc_ptr;
pGenerationData[i].allocContextLimit = (CLRDATA_ADDRESS)alloc_context->alloc_limit;
gc_alloc_context alloc_context = generation.allocation_context;
pGenerationData[i].allocContextPtr = (CLRDATA_ADDRESS)alloc_context.alloc_ptr;
pGenerationData[i].allocContextLimit = (CLRDATA_ADDRESS)alloc_context.alloc_limit;
}
}
else
Expand Down Expand Up @@ -4711,12 +4709,12 @@ HRESULT ClrDataAccess::GetGenerationTableSvr(CLRDATA_ADDRESS heapAddr, unsigned
{
for (unsigned int i = 0; i < numGenerationTableEntries; ++i)
{
DPTR(dac_generation) generation = ServerGenerationTableIndex(heapAddress, i);
pGenerationData[i].start_segment = (CLRDATA_ADDRESS)dac_cast<TADDR>(generation->start_segment);
pGenerationData[i].allocation_start = (CLRDATA_ADDRESS)(ULONG_PTR)generation->allocation_start;
DPTR(gc_alloc_context) alloc_context = dac_cast<TADDR>(generation) + offsetof(dac_generation, allocation_context);
pGenerationData[i].allocContextPtr = (CLRDATA_ADDRESS)(ULONG_PTR) alloc_context->alloc_ptr;
pGenerationData[i].allocContextLimit = (CLRDATA_ADDRESS)(ULONG_PTR) alloc_context->alloc_limit;
dac_generation generation = ServerGenerationTableIndex(heapAddress, i);
pGenerationData[i].start_segment = (CLRDATA_ADDRESS)dac_cast<TADDR>(generation.start_segment);
pGenerationData[i].allocation_start = (CLRDATA_ADDRESS)(ULONG_PTR)generation.allocation_start;
gc_alloc_context alloc_context = generation.allocation_context;
pGenerationData[i].allocContextPtr = (CLRDATA_ADDRESS)(ULONG_PTR)alloc_context.alloc_ptr;
pGenerationData[i].allocContextLimit = (CLRDATA_ADDRESS)(ULONG_PTR)alloc_context.alloc_limit;
}
}
else
Expand Down
43 changes: 21 additions & 22 deletions src/coreclr/debug/daccess/request_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ HeapTableIndex(DPTR(opaque_gc_heap**) heaps, size_t index)
return Dereference(ptr).GetAddr();
}

// Indexes into a given generation table, returning a TADDR to the requested
// generation.
inline TADDR
GenerationTableIndex(DPTR(opaque_generation) base, size_t index)
{
return TableIndex(base, index, g_gcDacGlobals->generation_size).GetAddr();
}

// Starting .NET 6, it is possible for the gc_heap and generation object to have different
// layouts for coreclr.dll and clrgc.dll. Instead of using assuming dac_gc_heap and gc_heap
// have identical layout, we have the gc exported arrays of field offsets instead.
Expand Down Expand Up @@ -100,20 +92,6 @@ inline bool IsRegion()
return (g_gcDacGlobals->minor_version_number & 1) != 0;
}

// Indexes into a heap's generation table, given the heap instance
// and the desired index. Returns a DPTR to the requested element.
inline TADDR
ServerGenerationTableIndex(TADDR heap, size_t index)
{
DPTR(int) field_offsets = g_gcDacGlobals->gc_heap_field_offsets;
int field_index = GENERATION_TABLE_FIELD_INDEX;
#define BASE heap
LOAD_BASE (generation_table, opaque_generation);
#undef BASE
assert (generation_table_offset != -1);
return TableIndex(p_generation_table, index, g_gcDacGlobals->generation_size).GetAddr();
}

// Load an instance of dac_gc_heap for the heap pointed by heap.
// Fields that does not exist in the current gc_heap instance is zero initialized.
// Return the dac_gc_heap object.
Expand Down Expand Up @@ -170,6 +148,27 @@ LoadGeneration(TADDR generation)
return result;
}

// Indexes into a given generation table, returning a dac_generation
inline dac_generation
GenerationTableIndex(DPTR(opaque_generation) base, size_t index)
{
return LoadGeneration(TableIndex(base, index, g_gcDacGlobals->generation_size).GetAddr());
}

// Indexes into a heap's generation table, given the heap instance
// and the desired index. Returns a dac_generation
inline dac_generation
ServerGenerationTableIndex(TADDR heap, size_t index)
{
DPTR(int) field_offsets = g_gcDacGlobals->gc_heap_field_offsets;
int field_index = GENERATION_TABLE_FIELD_INDEX;
#define BASE heap
LOAD_BASE (generation_table, opaque_generation);
#undef BASE
assert (generation_table_offset != -1);
return LoadGeneration(TableIndex(p_generation_table, index, g_gcDacGlobals->generation_size).GetAddr());
}

#undef LOAD_ARRAY
#undef LOAD_DPTR
#undef LOAD
Expand Down
33 changes: 13 additions & 20 deletions src/coreclr/debug/daccess/request_svr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ HRESULT ClrDataAccess::GetServerAllocData(unsigned int count, struct DacpGenerat
TADDR pHeap = HeapTableIndex(g_gcDacGlobals->g_heaps, n);
for (int i=0;i<NUMBERGENERATIONS;i++)
{
TADDR pGeneration = ServerGenerationTableIndex(pHeap, i);
dac_generation generation = LoadGeneration(pGeneration);
dac_generation generation = ServerGenerationTableIndex(pHeap, i);
data[n].allocData[i].allocBytes = (CLRDATA_ADDRESS)(ULONG_PTR) generation.allocation_context.alloc_bytes;
data[n].allocData[i].allocBytesLoh = (CLRDATA_ADDRESS)(ULONG_PTR) generation.allocation_context.alloc_bytes_uoh;
}
Expand Down Expand Up @@ -150,12 +149,12 @@ ClrDataAccess::ServerGCHeapDetails(CLRDATA_ADDRESS heapAddr, DacpGcHeapDetails *
// get bounds for the different generations
for (unsigned int i=0; i < DAC_NUMBERGENERATIONS; i++)
{
DPTR(dac_generation) generation = ServerGenerationTableIndex(heapAddress, i);
detailsData->generation_table[i].start_segment = (CLRDATA_ADDRESS)dac_cast<TADDR>(generation->start_segment);
detailsData->generation_table[i].allocation_start = (CLRDATA_ADDRESS)(ULONG_PTR)generation->allocation_start;
DPTR(gc_alloc_context) alloc_context = dac_cast<TADDR>(generation) + offsetof(dac_generation, allocation_context);
detailsData->generation_table[i].allocContextPtr = (CLRDATA_ADDRESS)(ULONG_PTR) alloc_context->alloc_ptr;
detailsData->generation_table[i].allocContextLimit = (CLRDATA_ADDRESS)(ULONG_PTR) alloc_context->alloc_limit;
dac_generation generation = ServerGenerationTableIndex(heapAddress, i);
detailsData->generation_table[i].start_segment = (CLRDATA_ADDRESS)dac_cast<TADDR>(generation.start_segment);
detailsData->generation_table[i].allocation_start = (CLRDATA_ADDRESS)(ULONG_PTR)generation.allocation_start;
gc_alloc_context alloc_context = generation.allocation_context;
detailsData->generation_table[i].allocContextPtr = (CLRDATA_ADDRESS)(ULONG_PTR) alloc_context.alloc_ptr;
detailsData->generation_table[i].allocContextLimit = (CLRDATA_ADDRESS)(ULONG_PTR) alloc_context.alloc_limit;
}

DPTR(dac_finalize_queue) fq = pHeap->finalize_queue;
Expand Down Expand Up @@ -269,8 +268,7 @@ ClrDataAccess::EnumSvrGlobalMemoryRegions(CLRDataEnumMemoryFlags flags)
// this is the convention in the GC so it is repeated here
for (ULONG i = *g_gcDacGlobals->max_gen; i <= *g_gcDacGlobals->max_gen +1; i++)
{
TADDR pGeneration = ServerGenerationTableIndex(heapAddress, i);
dac_generation generation = LoadGeneration(pGeneration);
dac_generation generation = ServerGenerationTableIndex(heapAddress, i);
DPTR(dac_heap_segment) seg = generation.start_segment;
while (seg)
{
Expand Down Expand Up @@ -310,16 +308,11 @@ HRESULT DacHeapWalker::InitHeapDataSvr(HeapData *&pHeaps, size_t &pCount)
TADDR heapAddress = HeapTableIndex(g_gcDacGlobals->g_heaps, i);
dac_gc_heap heap = LoadGcHeapData(heapAddress);
dac_gc_heap* pHeap = &heap;
TADDR pGen0 = ServerGenerationTableIndex(heapAddress, 0);
TADDR pGen1 = ServerGenerationTableIndex(heapAddress, 1);
TADDR pGen2 = ServerGenerationTableIndex(heapAddress, 2);
TADDR pLoh = ServerGenerationTableIndex(heapAddress, 3);
TADDR pPoh = ServerGenerationTableIndex(heapAddress, 4);
dac_generation gen0 = LoadGeneration(pGen0);
dac_generation gen1 = LoadGeneration(pGen1);
dac_generation gen2 = LoadGeneration(pGen2);
dac_generation loh = LoadGeneration(pLoh);
dac_generation poh = LoadGeneration(pPoh);
dac_generation gen0 = ServerGenerationTableIndex(heapAddress, 0);
dac_generation gen1 = ServerGenerationTableIndex(heapAddress, 1);
dac_generation gen2 = ServerGenerationTableIndex(heapAddress, 2);
dac_generation loh = ServerGenerationTableIndex(heapAddress, 3);
dac_generation poh = ServerGenerationTableIndex(heapAddress, 4);

pHeaps[i].YoungestGenPtr = (CORDB_ADDRESS)gen0.allocation_context.alloc_ptr;
pHeaps[i].YoungestGenLimit = (CORDB_ADDRESS)gen0.allocation_context.alloc_limit;
Expand Down