Skip to content

Commit

Permalink
Fix setting of DacpHeapSegmentData::highAllocMark on DAC side. (#69670)
Browse files Browse the repository at this point in the history
Fix setting of DacpHeapSegmentData::highAllocMark on DAC side. Keep some logic for backward compat in dacprivate.h, the copy here and the one in the Diagnostics repo, so that a new SOS can work correctly with an older DAC.

The PR in the diagnostics repo is this: dotnet/diagnostics#3062.
  • Loading branch information
PeterSolMS authored May 30, 2022
1 parent 5b2b6cf commit b8acc97
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,15 @@ ClrDataAccess::GetHeapSegmentData(CLRDATA_ADDRESS seg, struct DacpHeapSegmentDat
heapSegment->flags = pSegment->flags;
heapSegment->gc_heap = NULL;
heapSegment->background_allocated = (CLRDATA_ADDRESS)(ULONG_PTR)pSegment->background_allocated;

if (seg == (CLRDATA_ADDRESS)*g_gcDacGlobals->ephemeral_heap_segment)
{
heapSegment->highAllocMark = (CLRDATA_ADDRESS)*g_gcDacGlobals->alloc_allocated;
}
else
{
heapSegment->highAllocMark = heapSegment->allocated;
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/debug/daccess/request_svr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ HRESULT GetServerHeapData(CLRDATA_ADDRESS addr, DacpHeapSegmentData *pSegment)
pSegment->next = (CLRDATA_ADDRESS)dac_cast<TADDR>(pHeapSegment->next);
pSegment->gc_heap = (CLRDATA_ADDRESS)pHeapSegment->heap;

TADDR heapAddress = TO_TADDR(pSegment->gc_heap);
dac_gc_heap heap = LoadGcHeapData(heapAddress);

if (pSegment->segmentAddr == heap.ephemeral_heap_segment.GetAddr())
{
pSegment->highAllocMark = (CLRDATA_ADDRESS)(ULONG_PTR)heap.alloc_allocated;
}
else
{
pSegment->highAllocMark = pSegment->allocated;
}

return S_OK;
}

Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/inc/dacprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,13 +789,15 @@ struct MSLAYOUT DacpHeapSegmentData

HRESULT Request(ISOSDacInterface *sos, CLRDATA_ADDRESS addr, const DacpGcHeapDetails& heap)
{
// clear this here to make sure we don't get stale values
this->highAllocMark = 0;

HRESULT hr = sos->GetHeapSegmentData(addr, this);

// if this is the start segment, set highAllocMark too.
if (SUCCEEDED(hr))
// if this is the start segment, and the Dac hasn't set highAllocMark, set it here.
if (SUCCEEDED(hr) && this->highAllocMark == 0)
{
// TODO: This needs to be put on the Dac side.
if (this->segmentAddr == heap.generation_table[0].start_segment)
if (this->segmentAddr == heap.ephemeral_heap_segment)
highAllocMark = heap.alloc_allocated;
else
highAllocMark = allocated;
Expand Down

0 comments on commit b8acc97

Please sign in to comment.