Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetGenerationBounds under USE_REGIONS #57101

Merged
merged 9 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
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__
104 changes: 101 additions & 3 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5823,7 +5823,12 @@ 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();
cshung marked this conversation as resolved.
Show resolved Hide resolved
GCToEEInterface::DiagAddNewRegion(
gen_number,
heap_segment_mem (res),
heap_segment_allocated (res),
heap_segment_reserved (res)
);

#ifndef USE_REGIONS
#ifdef MULTIPLE_HEAPS
Expand Down Expand Up @@ -16117,18 +16122,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 @@ -21209,9 +21225,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 @@ -43154,6 +43183,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))
cshung marked this conversation as resolved.
Show resolved Hide resolved
{
generation = poh_generation;
}
}

*ppStart = heap_segment_mem (hs);
*ppAllocated = heap_segment_allocated (hs);
*ppReserved = heap_segment_reserved (hs);
cshung marked this conversation as resolved.
Show resolved Hide resolved
#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);
cshung marked this conversation as resolved.
Show resolved Hide resolved
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;
cshung marked this conversation as resolved.
Show resolved Hide resolved
*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