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
Show file tree
Hide file tree
Changes from 32 commits
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
32 changes: 32 additions & 0 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52052,6 +52052,38 @@ 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);
}

// Walking the GC Heap requires that the EE is suspended and all heap allocation contexts are fixed.
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
// DiagWalkHeap is invoked only during a GC, where both requirements are met.
// So DiagWalkHeapWithACHandling facilitates a GC Heap walk outside of a GC by handling allocation contexts logic,
// and it leaves the responsibility of suspending and resuming EE to the callers.
void GCHeap::DiagWalkHeapWithACHandling (walk_fn fn, void* context, int gen_number, bool 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->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;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/gc/gcimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ 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);

virtual void DiagWalkHeapWithACHandling(walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p);
public:
Object * NextObj (Object * object);

Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/gc/gcinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// The minor version of the IGCHeap interface. Non-breaking changes are required
// to bump the minor version number. GCs and EEs with minor version number
// mismatches can still interoperate correctly, with some care.
#define GC_INTERFACE_MINOR_VERSION 2
#define GC_INTERFACE_MINOR_VERSION 3

// The major version of the IGCToCLR interface. Breaking changes to this interface
// require bumps in the major version number.
Expand Down Expand Up @@ -1025,6 +1025,9 @@ class IGCHeap {
virtual uint64_t GetGenerationBudget(int generation) PURE_VIRTUAL

virtual size_t GetLOHThreshold() PURE_VIRTUAL

// Walk the heap object by object outside of a GC.
virtual void DiagWalkHeapWithACHandling(walk_fn fn, void* context, int gen_number, bool walk_large_object_heap_p) PURE_VIRTUAL
};

#ifdef WRITE_BARRIER_CHECK
Expand Down
37 changes: 36 additions & 1 deletion src/coreclr/inc/corprof.idl
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@ typedef enum _COR_PRF_HANDLE_TYPE

typedef void** ObjectHandleID;

/*
* Callback for each object in the GC Heap
*/
typedef BOOL STDMETHODCALLTYPE (* ObjectCallback)(ObjectID object, void* callbackState);

/* -------------------------------------------------------------------------- *
* Forward declarations
* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -2651,7 +2656,6 @@ typedef enum
COR_PRF_CODEGEN_DEBUG_INFO = 0x0003,
} COR_PRF_CODEGEN_FLAGS;


/*
* The CLR implements the ICorProfilerInfo interface. This interface is
* used by a code profiler to communicate with the CLR to control event
Expand Down Expand Up @@ -4308,6 +4312,37 @@ interface ICorProfilerInfo14 : ICorProfilerInfo13
[out] EVENTPIPE_PROVIDER *pProvider);
}

[
object,
uuid(B446462D-BD22-41DD-872D-DC714C49EB56),
pointer_default(unique),
local
]
interface ICorProfilerInfo15 : ICorProfilerInfo14
{
/*
* EnumerateGCHeapObjects is a method that iterates over each object in the GC heap.
* For each object, it invokes the provided callback function which should return a bool
* indicating whether or not enumeration should continue.
* The runtime must be suspended in order to enumerate objects on the GC heap.
mdh1418 marked this conversation as resolved.
Show resolved Hide resolved
* If the profiler requested runtime suspension through SuspendRuntime and proceeds to
* invoke EnumerateGCHeapObjects, it is the responsibility of the profiler to not
* resume the runtime before EnumerateGCHeapObjects completes.
*
* Parameters:
* - callback: A function pointer to the callback function that will be invoked for each object in the GC heap.
* The callback function should accept an ObjectID and a void pointer as parameters and return a BOOL.
* - callbackState: A void pointer that can be used to pass state information to the callback function.
*
* Returns:
* - HRESULT: A code indicating the result of the operation. If the method succeeds,
* it returns S_OK. If it fails, it returns an error code.
*/
HRESULT EnumerateGCHeapObjects(
[in] ObjectCallback callback,
[in] void* callbackState);
}

/*
* This interface lets you iterate over methods in the runtime.
*/
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/pal/prebuilt/idl/corprof_i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ MIDL_DEFINE_GUID(IID, IID_ICorProfilerInfo13,0x6E6C7EE2,0x0701,0x4EC2,0x9D,0x29,
MIDL_DEFINE_GUID(IID, IID_ICorProfilerInfo14,0xF460E352,0xD76D,0x4FE9,0x83,0x5F,0xF6,0xAF,0x9D,0x6E,0x86,0x2D);


MIDL_DEFINE_GUID(IID, IID_ICorProfilerInfo15,0xB446462D,0xBD22,0x41DD,0x87,0x2D,0xDC,0x71,0x4C,0x49,0xEB,0x56);


MIDL_DEFINE_GUID(IID, IID_ICorProfilerMethodEnum,0xFCCEE788,0x0088,0x454B,0xA8,0x11,0xC9,0x9F,0x29,0x8D,0x19,0x42);


Expand Down
Loading
Loading