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

[ICorProfiler] Add new API to enumerate GC Heap objects #103735

Merged
merged 35 commits into from
Jul 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1ad4625
[ICorProfiler] Add new ICorProfilerInfo API to enumerate gc heap
mdh1418 Jun 12, 2024
4cff308
Update generated corprof.h
mdh1418 Jun 14, 2024
2a356d3
[ICorProfiler] Extend header and source files to ICorProfilerInfo15
mdh1418 Jun 17, 2024
24c79ca
[ICorProfiler] Add EnumerateGCHeapObjects skeleton
mdh1418 Jun 17, 2024
18050fd
[ICorProfiler] Add EnumerateGCHeapObjects implementation
mdh1418 Jun 17, 2024
9882860
[GC] Add IGCHeap API to enumerate GC Heap objects outside of GC
mdh1418 Jun 19, 2024
c40ecbc
Cleanup
mdh1418 Jun 17, 2024
83f1e8d
[GC] Update gc interface minor version
mdh1418 Jun 21, 2024
c6d6f7e
Match callback PascalCase
mdh1418 Jun 21, 2024
0b251ff
Address feedback - naming and description
mdh1418 Jun 26, 2024
7eec99b
Cleanup
mdh1418 Jun 26, 2024
97d29b9
Add EEToProf EnumerateGCheapObjectsCallback wrapper
mdh1418 Jun 27, 2024
c8f99ec
[Profiler][Tests] Add EnumerateGCHeapObjects unit test
mdh1418 Jul 1, 2024
9a781d8
Address feedback
mdh1418 Jul 1, 2024
2aebeea
[ICorProfiler] Mitigate runtime suspension racing with EnumerateGCHea…
mdh1418 Jul 3, 2024
924bb77
[ICorProfiler] Update Callback helper contract
mdh1418 Jul 3, 2024
463b3a1
Update test cases
mdh1418 Jul 3, 2024
e15b9d1
[ICorProfiler] Change Suspend/Resume Runtime to Asynchronous
mdh1418 Jul 3, 2024
24d3094
[Tests] Update profiler requested runtime test
mdh1418 Jul 3, 2024
0c2e62b
fixup
mdh1418 Jul 8, 2024
6055313
Add test for background EnumerateGCHeapObject
mdh1418 Jul 8, 2024
8e7d021
Set profiler requested runtime suspend flag
mdh1418 Jul 8, 2024
3492adb
Fix symbol exports
mdh1418 Jul 8, 2024
9b520cd
Try fix compiler issues
mdh1418 Jul 8, 2024
bf01bdd
Allow runtime to resume before returning
mdh1418 Jul 8, 2024
ba8d3e6
Fix compilation errors on non-windows platforms
mdh1418 Jul 8, 2024
f142e20
Lower expected object count
mdh1418 Jul 8, 2024
69ddad7
Add profiler requested runtime suspension note
mdh1418 Jul 8, 2024
c316473
[Tests] Protect custom test object from GC
mdh1418 Jul 9, 2024
cd5aee6
Fix Profiler Runtime Suspension test
mdh1418 Jul 9, 2024
a4cc7b0
Expect to resolve classes during heap walk
mdh1418 Jul 9, 2024
39716d3
Address feedback
mdh1418 Jul 9, 2024
1f8537c
Update EnumerateGCHeapObjects usage description
mdh1418 Jul 11, 2024
86c8148
Add validation to extract class fields from objects
mdh1418 Jul 11, 2024
465cf68
Cleanup
mdh1418 Jul 11, 2024
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
[GC] Add IGCHeap API to enumerate GC Heap objects outside of GC
  • Loading branch information
mdh1418 committed Jun 21, 2024
commit 9882860e4e61215a127363ef4158f1e7f0768df8
28 changes: 28 additions & 0 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
@@ -52052,6 +52052,34 @@ void GCHeap::DiagWalkHeap (walk_fn fn, void* context, int gen_number, bool walk_
gc_heap::walk_heap (fn, context, gen_number, walk_large_object_heap_p);
}

void GCHeap::DiagWalkHeapStandalone (walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p)
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
{
#ifdef MULTIPLE_HEAPS
for (int hn = 0; hn < gc_heap::n_heaps; hn++)
{
gc_heap* hp = gc_heap::g_heaps [hn];
#else
{
gc_heap* hp = pGenGCHeap;
#endif //MULTIPLE_HEAPS
hp->fix_allocation_contexts (FALSE);
}

DiagWalkHeap (fn, context, gen_number, walk_large_object_heap_p);


#ifdef MULTIPLE_HEAPS
for (int hn = 0; hn < gc_heap::n_heaps; hn++)
{
gc_heap* hp = gc_heap::g_heaps [hn];
#else
{
gc_heap* hp = pGenGCHeap;
#endif //MULTIPLE_HEAPS
hp->repair_allocation_contexts (TRUE);
}
}

void GCHeap::DiagWalkFinalizeQueue (void* gc_context, fq_walk_fn fn)
{
gc_heap* hp = (gc_heap*)gc_context;
2 changes: 2 additions & 0 deletions src/coreclr/gc/gcimpl.h
Original file line number Diff line number Diff line change
@@ -313,6 +313,8 @@ class GCHeap : public IGCHeapInternal

virtual void DiagWalkHeap(walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p);

virtual void DiagWalkHeapStandalone(walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p);

virtual void DiagGetGCSettings(EtwGCSettingsInfo* etw_settings);

virtual unsigned int GetGenerationWithRange(Object* object, uint8_t** ppStart, uint8_t** ppAllocated, uint8_t** ppReserved);
3 changes: 3 additions & 0 deletions src/coreclr/gc/gcinterface.h
Original file line number Diff line number Diff line change
@@ -932,6 +932,9 @@ class IGCHeap {
// Walk the heap object by object.
virtual void DiagWalkHeap(walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p) PURE_VIRTUAL

// Walk the heap object by object outside of a GC.
virtual void DiagWalkHeapStandalone(walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p) PURE_VIRTUAL
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved

// Walks the survivors and get the relocation information if objects have moved.
// gen_number is used when type == walk_for_uoh, otherwise ignored
virtual void DiagWalkSurvivorsWithType(void* gc_context, record_surv_fn fn, void* diag_context, walk_surv_type type, int gen_number=-1) PURE_VIRTUAL
6 changes: 3 additions & 3 deletions src/coreclr/vm/proftoeeinterfaceimpl.cpp
Original file line number Diff line number Diff line change
@@ -7656,15 +7656,15 @@ HRESULT ProfToEEInterfaceImpl::EnumerateGCHeapObjects(object_callback callback,
return CORPROF_E_RUNTIME_UNINITIALIZED;
}

// SuspendEE
if (!ThreadSuspend::SysIsSuspendInProgress() && (ThreadSuspend::GetSuspensionThread() == 0))
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
{
ThreadSuspend::SuspendEE(ThreadSuspend::SUSPEND_REASON::SUSPEND_FOR_PROFILER);
}

// Walk the GC Heap outside of GC
IGCHeap *hp = GCHeapUtilities::GetGCHeap();
unsigned max_generation = hp->GetMaxGeneration();
hp->DiagWalkHeapStandalone((walk_fn)callback, callbackState, max_generation, TRUE);

// ResumeEE
ThreadSuspend::RestartEE(FALSE /* bFinishedGC */, TRUE /* SuspendSucceeded */);

return S_OK;