Skip to content

Commit

Permalink
Fix GetGenerationBounds under USE_REGIONS (dotnet#57101)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Aug 27, 2021
1 parent a021027 commit b349426
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 153 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/gc/env/gcenv.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class GCToEEInterface
static void UpdateGCEventStatus(int publicLevel, int publicKeywords, int privateLevel, int privateKeywords);
static void LogStressMsg(unsigned level, unsigned facility, const StressLogMsg &msg);
static uint32_t GetCurrentProcessCpuCount();

static void DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved);
};

#endif // __GCENV_EE_H__
105 changes: 101 additions & 4 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5807,15 +5807,19 @@ heap_segment* gc_heap::get_segment_for_uoh (int gen_number, size_t size
gc_etw_segment_pinned_object_heap :
gc_etw_segment_large_object_heap);

GCToEEInterface::DiagUpdateGenerationBounds();

#ifndef USE_REGIONS
#ifdef MULTIPLE_HEAPS
hp->thread_uoh_segment (gen_number, res);
#else
thread_uoh_segment (gen_number, res);
#endif //MULTIPLE_HEAPS
#endif //!USE_REGIONS
GCToEEInterface::DiagAddNewRegion(
gen_number,
heap_segment_mem (res),
heap_segment_allocated (res),
heap_segment_reserved (res)
);
}

return res;
Expand Down Expand Up @@ -15904,18 +15908,29 @@ BOOL gc_heap::soh_try_fit (int gen_number,
fix_youngest_allocation_area();

heap_segment* next_seg = heap_segment_next (ephemeral_heap_segment);
bool new_seg = false;

if (!next_seg)
{
assert (ephemeral_heap_segment == generation_tail_region (generation_of (gen_number)));
next_seg = get_new_region (gen_number);
new_seg = true;
}

if (next_seg)
{
dprintf (REGIONS_LOG, ("eph seg %Ix -> next %Ix",
heap_segment_mem (ephemeral_heap_segment), heap_segment_mem (next_seg)));
ephemeral_heap_segment = next_seg;
if (new_seg)
{
GCToEEInterface::DiagAddNewRegion(
heap_segment_gen_num (next_seg),
heap_segment_mem (next_seg),
heap_segment_allocated (next_seg),
heap_segment_reserved (next_seg)
);
}
}
else
{
Expand Down Expand Up @@ -20996,9 +21011,22 @@ bool gc_heap::extend_soh_for_no_gc()
}

region = heap_segment_next (region);
if ((region == nullptr) && !(region = get_new_region (0)))
if (region == nullptr)
{
break;
region = get_new_region (0);
if (region == nullptr)
{
break;
}
else
{
GCToEEInterface::DiagAddNewRegion(
0,
heap_segment_mem (region),
heap_segment_allocated (region),
heap_segment_reserved (region)
);
}
}
}
else
Expand Down Expand Up @@ -42941,6 +42969,75 @@ unsigned int GCHeap::WhichGeneration (Object* object)
return g;
}

unsigned int GCHeap::GetGenerationWithRange (Object* object, uint8_t** ppStart, uint8_t** ppAllocated, uint8_t** ppReserved)
{
int generation = -1;
heap_segment * hs = gc_heap::find_segment ((uint8_t*)object, FALSE);
#ifdef USE_REGIONS
generation = heap_segment_gen_num (hs);
if (generation == max_generation)
{
if (heap_segment_loh_p (hs))
{
generation = loh_generation;
}
else if (heap_segment_poh_p (hs))
{
generation = poh_generation;
}
}

*ppStart = heap_segment_mem (hs);
*ppAllocated = heap_segment_allocated (hs);
*ppReserved = heap_segment_reserved (hs);
#else
#ifdef MULTIPLE_HEAPS
gc_heap* hp = heap_segment_heap (hs);
#else
gc_heap* hp = __this;
#endif //MULTIPLE_HEAPS
if (hs == hp->ephemeral_heap_segment)
{
uint8_t* reserved = heap_segment_reserved (hs);
uint8_t* end = heap_segment_allocated(hs);
for (int gen = 0; gen < max_generation; gen++)
{
uint8_t* start = generation_allocation_start (hp->generation_of (gen));
if ((uint8_t*)object >= start)
{
generation = gen;
*ppStart = start;
*ppAllocated = end;
*ppReserved = reserved;
break;
}
end = reserved = start;
}
if (generation == -1)
{
*ppStart = heap_segment_mem (hs);
*ppAllocated = *ppReserved = generation_allocation_start (hp->generation_of (max_generation - 1));
}
}
else
{
generation = max_generation;
if (heap_segment_loh_p (hs))
{
generation = loh_generation;
}
else if (heap_segment_poh_p (hs))
{
generation = poh_generation;
}
*ppStart = heap_segment_mem (hs);
*ppAllocated = heap_segment_allocated (hs);
*ppReserved = heap_segment_reserved (hs);
}
#endif //USE_REGIONS
return (unsigned int)generation;
}

bool GCHeap::IsEphemeral (Object* object)
{
uint8_t* o = (uint8_t*)object;
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/gc/gcenv.ee.standalone.inl
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,9 @@ inline uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
return g_theGCToCLR->GetCurrentProcessCpuCount();
}

inline void GCToEEInterface::DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved)
{
g_theGCToCLR->DiagAddNewRegion(generation, rangeStart, rangeEnd, rangeEndReserved);
}

#endif // __GCTOENV_EE_STANDALONE_INL__
1 change: 1 addition & 0 deletions src/coreclr/gc/gcimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class GCHeap : public IGCHeapInternal

virtual void DiagGetGCSettings(EtwGCSettingsInfo* etw_settings);

virtual unsigned int GetGenerationWithRange(Object* object, uint8_t** ppStart, uint8_t** ppAllocated, uint8_t** ppReserved);
public:
Object * NextObj (Object * object);

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/gc/gcinterface.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ class IGCToCLR {

virtual
uint32_t GetCurrentProcessCpuCount() = 0;

virtual
void DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved) = 0;
};

#endif // _GCINTERFACE_EE_H_
4 changes: 3 additions & 1 deletion src/coreclr/gc/gcinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// The major version of the GC/EE interface. Breaking changes to this interface
// require bumps in the major version number.
#define GC_INTERFACE_MAJOR_VERSION 4
#define GC_INTERFACE_MAJOR_VERSION 5

// The minor version of the GC/EE interface. Non-breaking changes are required
// to bump the minor version number. GCs and EEs with minor version number
Expand Down Expand Up @@ -921,6 +921,8 @@ class IGCHeap {
// Enables or disables the given keyword or level on the private event provider.
virtual void ControlPrivateEvents(GCEventKeyword keyword, GCEventLevel level) = 0;

virtual unsigned int GetGenerationWithRange(Object* object, uint8_t** ppStart, uint8_t** ppAllocated, uint8_t** ppReserved) = 0;

IGCHeap() {}
virtual ~IGCHeap() {}
};
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/gc/sample/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,7 @@ uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
{
return GCToOSInterface::GetTotalProcessorCount();
}

void GCToEEInterface::DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved)
{
}
2 changes: 2 additions & 0 deletions src/coreclr/vm/eeprofinterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void __stdcall GarbageCollectionStartedCallback(int generation, BOOL induced);
void __stdcall GarbageCollectionFinishedCallback();

void __stdcall UpdateGenerationBounds();

void __stdcall ProfilerAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved);
#include "eetoprofinterfaceimpl.h"


Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/vm/gcenv.ee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1732,3 +1732,8 @@ uint32_t GCToEEInterface::GetCurrentProcessCpuCount()
{
return ::GetCurrentProcessCpuCount();
}

void GCToEEInterface::DiagAddNewRegion(int generation, uint8_t* rangeStart, uint8_t* rangeEnd, uint8_t* rangeEndReserved)
{
ProfilerAddNewRegion(generation, rangeStart, rangeEnd, rangeEndReserved);
}
2 changes: 2 additions & 0 deletions src/coreclr/vm/gcenv.ee.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class GCToEEInterface : public IGCToCLR {

void LogStressMsg(unsigned level, unsigned facility, const StressLogMsg& msg);
uint32_t GetCurrentProcessCpuCount();

void DiagAddNewRegion(int generation, BYTE * rangeStart, BYTE * rangeEnd, BYTE * rangeEndReserved);
};

} // namespace standalone
Expand Down
Loading

0 comments on commit b349426

Please sign in to comment.