Skip to content

Commit

Permalink
Let the debugger knows DATAS is on (#107115)
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung authored Feb 3, 2025
1 parent b2a6266 commit cd1657d
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,10 @@ ClrDataAccess::QueryInterface(THIS_
{
ifaceRet = static_cast<ISOSDacInterface15*>(this);
}
else if (IsEqualIID(interfaceId, __uuidof(ISOSDacInterface16)))
{
ifaceRet = static_cast<ISOSDacInterface16*>(this);
}
else
{
*iface = NULL;
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ class ClrDataAccess
public ISOSDacInterface12,
public ISOSDacInterface13,
public ISOSDacInterface14,
public ISOSDacInterface15
public ISOSDacInterface15,
public ISOSDacInterface16
{
public:
ClrDataAccess(ICorDebugDataTarget * pTarget, ICLRDataTarget * pLegacyTarget=0);
Expand Down Expand Up @@ -1222,6 +1223,9 @@ class ClrDataAccess
// ISOSDacInterface15
virtual HRESULT STDMETHODCALLTYPE GetMethodTableSlotEnumerator(CLRDATA_ADDRESS mt, ISOSMethodEnum **enumerator);

// ISOSDacInterface16
virtual HRESULT STDMETHODCALLTYPE GetGCDynamicAdaptationMode(int* pDynamicAdaptationMode);

//
// ClrDataAccess.
//
Expand Down
18 changes: 18 additions & 0 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2908,6 +2908,24 @@ ClrDataAccess::GetGCHeapStaticData(struct DacpGcHeapDetails *detailsData)
return hr;
}

HRESULT
ClrDataAccess::GetGCDynamicAdaptationMode(int* pDynamicAdaptationMode)
{
SOSDacEnter();
if (IsDatasEnabled())
{
*pDynamicAdaptationMode = *g_gcDacGlobals->dynamic_adaptation_mode;
hr = S_OK;
}
else
{
*pDynamicAdaptationMode = -1;
hr = S_FALSE;
}
SOSDacLeave();
return hr;
}

HRESULT
ClrDataAccess::GetHeapSegmentData(CLRDATA_ADDRESS seg, struct DacpHeapSegmentData *heapSegment)
{
Expand Down
37 changes: 35 additions & 2 deletions src/coreclr/debug/daccess/request_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,47 @@ HeapTableIndex(DPTR(unused_gc_heap**) heaps, size_t index)
DacEnumMemoryRegion(p_##field_name.GetAddr(), sizeof(field_type) * array_length); \
}

inline bool UseBuildVariant()
{
int major = g_gcDacGlobals->major_version_number;
int minor = g_gcDacGlobals->minor_version_number;
return (major > 2) || (major == 2 && minor >= 4);
}

inline bool IsRegionGCEnabled()
{
return (g_gcDacGlobals->minor_version_number & 1) != 0;
if (UseBuildVariant())
{
return (*(g_gcDacGlobals->build_variant) & build_variant_use_region) != 0;
}
else
{
return (g_gcDacGlobals->minor_version_number & 1) != 0;
}
}

inline bool IsBackgroundGCEnabled()
{
return (g_gcDacGlobals->minor_version_number & 2) == 0;
if (UseBuildVariant())
{
return (*(g_gcDacGlobals->build_variant) & build_variant_background_gc) != 0;
}
else
{
return (g_gcDacGlobals->minor_version_number & 2) == 0;
}
}

inline bool IsDatasEnabled()
{
if (UseBuildVariant())
{
return (*(g_gcDacGlobals->build_variant) & build_variant_dynamic_heap_count) != 0;
}
else
{
return false;
}
}

// Load an instance of dac_gc_heap for the heap pointed by heap.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/gc/dac_gcheap_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ DEFINE_MISSING_FIELD(freeable_uoh_segment)
DEFINE_ARRAY_FIELD (free_regions, dac_region_free_list, FREE_REGION_KINDS)
#else
DEFINE_MISSING_FIELD(free_regions)
#endif // ALL_FIELDS
#endif // defined(ALL_FIELDS) || defined(USE_REGIONS)
19 changes: 16 additions & 3 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53194,6 +53194,7 @@ bool GCHeap::IsConcurrentGCEnabled()
void PopulateDacVars(GcDacVars *gcDacVars)
{
bool v2 = gcDacVars->minor_version_number >= 2;
bool v4 = gcDacVars->minor_version_number >= 4;

#define DEFINE_FIELD(field_name, field_type) offsetof(CLASS_NAME, field_name),
#define DEFINE_DPTR_FIELD(field_name, field_type) offsetof(CLASS_NAME, field_name),
Expand Down Expand Up @@ -53225,15 +53226,16 @@ void PopulateDacVars(GcDacVars *gcDacVars)
// work differently than .Net SOS. When making breaking changes here you may need to
// find NativeAOT's equivalent of SOS_BREAKING_CHANGE_VERSION and increment it.
gcDacVars->major_version_number = 2;
gcDacVars->minor_version_number = 0;
gcDacVars->minor_version_number = 4;
if (v2)
{
gcDacVars->total_bookkeeping_elements = total_bookkeeping_elements;
gcDacVars->card_table_info_size = sizeof(card_table_info);
}

g_build_variant = 0;
#ifdef USE_REGIONS
gcDacVars->minor_version_number |= 1;
g_build_variant |= build_variant_use_region;
if (v2)
{
gcDacVars->count_free_region_kinds = count_free_region_kinds;
Expand All @@ -53242,8 +53244,11 @@ void PopulateDacVars(GcDacVars *gcDacVars)
}
#endif //USE_REGIONS
#ifndef BACKGROUND_GC
gcDacVars->minor_version_number |= 2;
g_build_variant |= build_variant_background_gc;
#endif //!BACKGROUND_GC
#ifdef DYNAMIC_HEAP_COUNT
g_build_variant |= build_variant_dynamic_heap_count;
#endif //DYNAMIC_HEAP_COUNT
gcDacVars->built_with_svr = &g_built_with_svr_gc;
gcDacVars->build_variant = &g_build_variant;
gcDacVars->gc_structures_invalid_cnt = const_cast<int32_t*>(&GCScan::m_GcStructuresInvalidCnt);
Expand Down Expand Up @@ -53319,6 +53324,14 @@ void PopulateDacVars(GcDacVars *gcDacVars)
{
gcDacVars->bookkeeping_start = &gc_heap::bookkeeping_start;
}
if (v4)
{
#ifdef DYNAMIC_HEAP_COUNT
gcDacVars->dynamic_adaptation_mode = &gc_heap::dynamic_adaptation_mode;
#else
gcDacVars->dynamic_adaptation_mode = nullptr;
#endif //DYNAMIC_HEAP_COUNT
}
}

int GCHeap::RefreshMemoryLimit()
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/gc/gcinterface.dac.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ struct unused_generation
uint8_t unused;
};

#define build_variant_use_region 1
#define build_variant_background_gc 2
#define build_variant_dynamic_heap_count 4

// The DAC links against six symbols that build as part of the VM DACCESS_COMPILE
// build. These symbols are considered to be GC-private functions, but the DAC needs
// to use them in order to perform some handle-related functions. These six functions
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/gc/gcinterface.dacvars.def
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ GC_DAC_VAL (int, total_bookkeeping_elements)
GC_DAC_VAL (int, count_free_region_kinds)
GC_DAC_VAL (size_t, card_table_info_size)

// Here is where v5.4 fields starts
GC_DAC_VAR (int, dynamic_adaptation_mode)

#undef GC_DAC_VAR
#undef GC_DAC_ARRAY_VAR
#undef GC_DAC_PTR_VAR
2 changes: 1 addition & 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 3
#define GC_INTERFACE_MINOR_VERSION 4

// The major version of the IGCToCLR interface. Breaking changes to this interface
// require bumps in the major version number.
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/inc/sospriv.idl
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,13 @@ interface ISOSDacInterface15 : IUnknown
{
HRESULT GetMethodTableSlotEnumerator(CLRDATA_ADDRESS mt, ISOSMethodEnum **enumerator);
}

[
object,
local,
uuid(4ba12ff8-daac-4e43-ac56-98cf8d5c595d)
]
interface ISOSDacInterface16 : IUnknown
{
HRESULT GetGCDynamicAdaptationMode(int* pDynamicAdaptationMode);
}
3 changes: 3 additions & 0 deletions src/coreclr/pal/prebuilt/idl/sospriv_i.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ MIDL_DEFINE_GUID(IID, IID_ISOSMethodEnum,0x3c0fe725,0xc324,0x4a4f,0x81,0x00,0xd3

MIDL_DEFINE_GUID(IID, IID_ISOSDacInterface15,0x7ed81261,0x52a9,0x4a23,0xa3,0x58,0xc3,0x31,0x3d,0xea,0x30,0xa8);


MIDL_DEFINE_GUID(IID, IID_ISOSDacInterface16,0x4ba12ff8,0xdaac,0x4e43,0xac,0x56,0x98,0xcf,0x8d,0x5c,0x59,0x5d);

#undef MIDL_DEFINE_GUID

#ifdef __cplusplus
Expand Down
80 changes: 80 additions & 0 deletions src/coreclr/pal/prebuilt/inc/sospriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,86 @@ EXTERN_C const IID IID_ISOSDacInterface15;
#endif /* __ISOSDacInterface15_INTERFACE_DEFINED__ */


#ifndef __ISOSDacInterface16_INTERFACE_DEFINED__
#define __ISOSDacInterface16_INTERFACE_DEFINED__

/* interface ISOSDacInterface16 */
/* [uuid][local][object] */


EXTERN_C const IID IID_ISOSDacInterface16;

#if defined(__cplusplus) && !defined(CINTERFACE)

MIDL_INTERFACE("4ba12ff8-daac-4e43-ac56-98cf8d5c595d")
ISOSDacInterface16 : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE GetGCDynamicAdaptationMode(
int *pDynamicAdaptationMode) = 0;

};


#else /* C style interface */

typedef struct ISOSDacInterface16Vtbl
{
BEGIN_INTERFACE

HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
ISOSDacInterface16 * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);

ULONG ( STDMETHODCALLTYPE *AddRef )(
ISOSDacInterface16 * This);

ULONG ( STDMETHODCALLTYPE *Release )(
ISOSDacInterface16 * This);

HRESULT ( STDMETHODCALLTYPE *GetGCDynamicAdaptationMode )(
ISOSDacInterface16 * This,
int *pDynamicAdaptationMode);

END_INTERFACE
} ISOSDacInterface16Vtbl;

interface ISOSDacInterface16
{
CONST_VTBL struct ISOSDacInterface16Vtbl *lpVtbl;
};



#ifdef COBJMACROS


#define ISOSDacInterface16_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )

#define ISOSDacInterface16_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )

#define ISOSDacInterface16_Release(This) \
( (This)->lpVtbl -> Release(This) )


#define ISOSDacInterface16_GetGCDynamicAdaptationMode(This,pDynamicAdaptationMode) \
( (This)->lpVtbl -> GetGCDynamicAdaptationMode(This,pDynamicAdaptationMode) )

#endif /* COBJMACROS */


#endif /* C style interface */




#endif /* __ISOSDacInterface16_INTERFACE_DEFINED__ */


/* Additional Prototypes for ALL interfaces */

/* end of Additional Prototypes */
Expand Down

0 comments on commit cd1657d

Please sign in to comment.