Skip to content

[cDAC] Implement IXCLRDataProcess.EnumMethodInstancesByAddress #115131

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

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
44 changes: 44 additions & 0 deletions src/coreclr/debug/runtimeinfo/datadescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ CDAC_TYPE_FIELD(Module, /*pointer*/, Path, cdac_data<Module>::Path)
CDAC_TYPE_FIELD(Module, /*pointer*/, FileName, cdac_data<Module>::FileName)
CDAC_TYPE_FIELD(Module, /*pointer*/, ReadyToRunInfo, cdac_data<Module>::ReadyToRunInfo)
CDAC_TYPE_FIELD(Module, /*pointer*/, GrowableSymbolStream, cdac_data<Module>::GrowableSymbolStream)
CDAC_TYPE_FIELD(Module, /*pointer*/, AvailableTypeParams, offsetof(Module, m_pAvailableParamTypes))
CDAC_TYPE_FIELD(Module, /*pointer*/, InstMethodHashTable, offsetof(Module, m_pInstMethodHashTable))

CDAC_TYPE_FIELD(Module, /*pointer*/, FieldDefToDescMap, cdac_data<Module>::FieldDefToDescMap)
CDAC_TYPE_FIELD(Module, /*pointer*/, ManifestModuleReferencesMap, cdac_data<Module>::ManifestModuleReferencesMap)
Expand All @@ -249,8 +251,17 @@ CDAC_TYPE_INDETERMINATE(Assembly)
#ifdef FEATURE_COLLECTIBLE_TYPES
CDAC_TYPE_FIELD(Assembly, /*uint8*/, IsCollectible, cdac_data<Assembly>::IsCollectible)
#endif
CDAC_TYPE_FIELD(Assembly, /*pointer*/, Module, cdac_data<Assembly>::Module)
CDAC_TYPE_FIELD(Assembly, /*pointer*/, Error, cdac_data<Assembly>::Error)
CDAC_TYPE_FIELD(Assembly, /*uint32*/, NotifyFlags, cdac_data<Assembly>::NotifyFlags)
CDAC_TYPE_FIELD(Assembly, /*uint32*/, Level, cdac_data<Assembly>::Level)
CDAC_TYPE_END(Assembly)

CDAC_TYPE_BEGIN(LoaderAllocator)
CDAC_TYPE_INDETERMINATE(LoaderAllocator)
CDAC_TYPE_FIELD(LoaderAllocator, /*uint32*/, ReferenceCount, cdac_data<LoaderAllocator>::ReferenceCount)
CDAC_TYPE_END(LoaderAllocator)

CDAC_TYPE_BEGIN(PEAssembly)
CDAC_TYPE_INDETERMINATE(PEAssembly)
CDAC_TYPE_FIELD(PEAssembly, /*pointer*/, PEImage, cdac_data<PEAssembly>::PEImage)
Expand Down Expand Up @@ -282,8 +293,22 @@ CDAC_TYPE_END(ProbeExtensionResult)
CDAC_TYPE_BEGIN(AppDomain)
CDAC_TYPE_INDETERMINATE(AppDomain)
CDAC_TYPE_FIELD(AppDomain, /*pointer*/, RootAssembly, cdac_data<AppDomain>::RootAssembly)
CDAC_TYPE_FIELD(AppDomain, /*DomainAssemblyList*/, DomainAssemblyList, cdac_data<AppDomain>::DomainAssemblyList)
CDAC_TYPE_END(AppDomain)

CDAC_TYPE_BEGIN(ArrayListBase)
CDAC_TYPE_INDETERMINATE(ArrayListBase)
CDAC_TYPE_FIELD(ArrayListBase, /*uint32*/, Count, cdac_data<ArrayListBase>::Count)
CDAC_TYPE_FIELD(ArrayListBase, /*pointer*/, FirstBlock, cdac_data<ArrayListBase>::FirstBlock)
CDAC_TYPE_END(ArrayListBase)

CDAC_TYPE_BEGIN(ArrayListBlock)
CDAC_TYPE_INDETERMINATE(ArrayListBlock)
CDAC_TYPE_FIELD(ArrayListBlock, /*pointer*/, Next, cdac_data<ArrayListBase>::Next)
CDAC_TYPE_FIELD(ArrayListBlock, /*uint32*/, Size, cdac_data<ArrayListBase>::Size)
CDAC_TYPE_FIELD(ArrayListBlock, /*pointer*/, ArrayStart, cdac_data<ArrayListBase>::ArrayStart)
CDAC_TYPE_END(ArrayListBlock)

// RuntimeTypeSystem

CDAC_TYPE_BEGIN(MethodTable)
Expand All @@ -309,6 +334,7 @@ CDAC_TYPE_END(MethodTableAuxiliaryData)
CDAC_TYPE_BEGIN(EEClass)
CDAC_TYPE_INDETERMINATE(EEClass)
CDAC_TYPE_FIELD(EEClass, /*pointer*/, MethodTable, cdac_data<EEClass>::MethodTable)
CDAC_TYPE_FIELD(EEClass, /*pointer*/, MethodDescChunk, cdac_data<EEClass>::MethodDescChunk)
CDAC_TYPE_FIELD(EEClass, /*uint16*/, NumMethods, cdac_data<EEClass>::NumMethods)
CDAC_TYPE_FIELD(EEClass, /*uint32*/, CorTypeAttr, cdac_data<EEClass>::CorTypeAttr)
CDAC_TYPE_FIELD(EEClass, /*uint8*/, InternalCorElementType, cdac_data<EEClass>::InternalCorElementType)
Expand Down Expand Up @@ -787,6 +813,22 @@ CDAC_TYPE_FIELD(CalleeSavedRegisters, /*nuint*/, Lr, offsetof(CalleeSavedRegiste
#endif // Platform switch
CDAC_TYPE_END(CalleeSavedRegisters)

CDAC_TYPE_BEGIN(EETypeHashTable)
CDAC_TYPE_INDETERMINATE(EETypeHashTable)
CDAC_TYPE_FIELD(EETypeHashTable, /*pointer*/, Buckets, cdac_data<EETypeHashTable>::Buckets)
CDAC_TYPE_FIELD(EETypeHashTable, /*uint32*/, Count, cdac_data<EETypeHashTable>::Count)
CDAC_TYPE_FIELD(EETypeHashTable, /*pointer*/, VolatileEntryValue, cdac_data<EETypeHashTable>::VolatileEntryValue)
CDAC_TYPE_FIELD(EETypeHashTable, /*pointer*/, VolatileEntryNextEntry, cdac_data<EETypeHashTable>::VolatileEntryNextEntry)
CDAC_TYPE_END(EETypeHashTable)

CDAC_TYPE_BEGIN(InstMethodHashTable)
CDAC_TYPE_INDETERMINATE(InstMethodHashTable)
CDAC_TYPE_FIELD(InstMethodHashTable, /*pointer*/, Buckets, cdac_data<InstMethodHashTable>::Buckets)
CDAC_TYPE_FIELD(InstMethodHashTable, /*uint32*/, Count, cdac_data<InstMethodHashTable>::Count)
CDAC_TYPE_FIELD(InstMethodHashTable, /*pointer*/, VolatileEntryValue, cdac_data<InstMethodHashTable>::VolatileEntryValue)
CDAC_TYPE_FIELD(InstMethodHashTable, /*pointer*/, VolatileEntryNextEntry, cdac_data<InstMethodHashTable>::VolatileEntryNextEntry)
CDAC_TYPE_END(InstMethodHashTable)

CDAC_TYPES_END()

CDAC_GLOBALS_BEGIN()
Expand Down Expand Up @@ -818,6 +860,7 @@ CDAC_GLOBAL_STRING(Architecture, riscv64)
CDAC_GLOBAL_STRING(RID, RID_STRING)

CDAC_GLOBAL_POINTER(AppDomain, &AppDomain::m_pTheAppDomain)
CDAC_GLOBAL_POINTER(SystemDomain, cdac_data<SystemDomain>::SystemDomain)
CDAC_GLOBAL_POINTER(ThreadStore, &ThreadStore::s_pThreadStore)
CDAC_GLOBAL_POINTER(FinalizerThread, &::g_pFinalizerThread)
CDAC_GLOBAL_POINTER(GCThread, &::g_pSuspensionThread)
Expand Down Expand Up @@ -878,6 +921,7 @@ CDAC_GLOBAL(StressLogEnabled, uint8, 0)
CDAC_GLOBAL_POINTER(ExecutionManagerCodeRangeMapAddress, cdac_data<ExecutionManager>::CodeRangeMapAddress)
CDAC_GLOBAL_POINTER(PlatformMetadata, &::g_cdacPlatformMetadata)
CDAC_GLOBAL_POINTER(ProfilerControlBlock, &::g_profControlBlock)
CDAC_GLOBAL_POINTER(MethodDescSizeTable, &MethodDesc::s_ClassificationSizeTable)
CDAC_GLOBALS_END()

#undef CDAC_BASELINE
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/inc/arraylist.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <contract.h>
#include <stddef.h> // offsetof

// Forward Declarations
template<typename T> struct cdac_data;

//
// ArrayList is a simple class which is used to contain a growable
// list of pointers, stored in chunks. Modification is by appending
Expand Down Expand Up @@ -263,8 +266,21 @@ class ArrayListBase
return BlockIterator((ArrayListBlock *) &m_firstBlock, m_count);
}

friend struct cdac_data<ArrayListBase>;
};

template<>
struct cdac_data<ArrayListBase>
{
static constexpr size_t Count = offsetof(ArrayListBase, m_count);
static constexpr size_t FirstBlock = offsetof(ArrayListBase, m_firstBlock);

static constexpr size_t Next = offsetof(ArrayListBase::ArrayListBlock, m_next);
static constexpr size_t Size = offsetof(ArrayListBase::ArrayListBlock, m_blockSize);
static constexpr size_t ArrayStart = offsetof(ArrayListBase::ArrayListBlock, m_array);
};


class ArrayList : public ArrayListBase
{
public:
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ class AppDomain final
{
return m_array.Iterate();
}

friend struct cdac_data<AppDomain>;
}; // class DomainAssemblyList

// Conceptually a list of code:Assembly structures, protected by lock code:GetAssemblyListLock
Expand Down Expand Up @@ -1621,6 +1623,7 @@ template<>
struct cdac_data<AppDomain>
{
static constexpr size_t RootAssembly = offsetof(AppDomain, m_pRootAssembly);
static constexpr size_t DomainAssemblyList = offsetof(AppDomain, m_Assemblies) + offsetof(AppDomain::DomainAssemblyList, m_array);
};

typedef DPTR(class SystemDomain) PTR_SystemDomain;
Expand Down Expand Up @@ -1953,8 +1956,17 @@ inline static BOOL IsUnderDomainLock() { LIMITED_METHOD_CONTRACT; return m_Syste
bool enumThis);
#endif

friend struct ::cdac_data<SystemDomain>;
}; // class SystemDomain

#ifndef DACCESS_COMPILE
template<>
struct cdac_data<SystemDomain>
{
static constexpr PTR_SystemDomain* SystemDomain = &SystemDomain::m_pSystemDomain;
};
#endif // DACCESS_COMPILE

#include "comreflectioncache.inl"

#endif
4 changes: 4 additions & 0 deletions src/coreclr/vm/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,10 @@ struct cdac_data<Assembly>
#ifdef FEATURE_COLLECTIBLE_TYPES
static constexpr size_t IsCollectible = offsetof(Assembly, m_isCollectible);
#endif
static constexpr size_t Module = offsetof(Assembly, m_pModule);
static constexpr size_t Error = offsetof(Assembly, m_pError);
static constexpr size_t NotifyFlags = offsetof(Assembly, m_notifyFlags);
static constexpr size_t Level = offsetof(Assembly, m_level);
};

#ifndef DACCESS_COMPILE
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ template<> struct cdac_data<EEClass>
{
static constexpr size_t InternalCorElementType = offsetof(EEClass, m_NormType);
static constexpr size_t MethodTable = offsetof(EEClass, m_pMethodTable);
static constexpr size_t MethodDescChunk = offsetof(EEClass, m_pChunks);
static constexpr size_t NumMethods = offsetof(EEClass, m_NumMethods);
static constexpr size_t CorTypeAttr = offsetof(EEClass, m_dwAttrClass);
static constexpr size_t NumNonVirtualSlots = offsetof(EEClass, m_NumNonVirtualSlots);
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/vm/dacenumerablehash.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//
// Synchronization: It is permissable to read data from the hash without taking a lock as long as:
// 1) Any hash modifications are performed under a lock or otherwise serialized.
// 2) Any miss on a lookup is handled by taking a lock are retry-ing the lookup.
// 2) Any miss on a lookup is handled by taking a lock and retry-ing the lookup.
//
// OVERALL DESIGN
//
Expand Down Expand Up @@ -314,7 +314,7 @@ class DacEnumerableHashTable
static const int SLOT_ENDSENTINEL = 2;
// normal slots start at slot #3
static const int SKIP_SPECIAL_SLOTS = 3;

static DWORD GetLength(DPTR(PTR_VolatileEntry) buckets)
{
return (DWORD)dac_cast<TADDR>(buckets[SLOT_LENGTH]);
Expand All @@ -335,6 +335,8 @@ class DacEnumerableHashTable

DPTR(PTR_VolatileEntry) m_pBuckets; // Pointer to a simple bucket list (array of VolatileEntry pointers)
DWORD m_cEntries; // Count of elements

friend struct ::cdac_data<FINAL_CLASS>;
};

#endif // __DAC_ENUMERABLE_HASH_INCLUDED
13 changes: 13 additions & 0 deletions src/coreclr/vm/instmethhash.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define _INSTMETHHASH_H

#include "dacenumerablehash.h"
#include "cdacdata.h"

class AllocMemTracker;

Expand Down Expand Up @@ -145,6 +146,18 @@ class InstMethodHashTable : public DacEnumerableHashTable<InstMethodHashTable, I

private:
LoaderAllocator* GetLoaderAllocator();

friend struct ::cdac_data<InstMethodHashTable>;
};

template<>
struct cdac_data<InstMethodHashTable>
{
static constexpr size_t Buckets = offsetof(InstMethodHashTable, m_pBuckets);
static constexpr size_t Count = offsetof(InstMethodHashTable, m_cEntries);

static constexpr size_t VolatileEntryValue = offsetof(InstMethodHashTable::VolatileEntry, m_sValue);
static constexpr size_t VolatileEntryNextEntry = offsetof(InstMethodHashTable::VolatileEntry, m_pNextEntry);
};

#endif /* _INSTMETHHASH_H */
8 changes: 8 additions & 0 deletions src/coreclr/vm/loaderallocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,16 @@ class LoaderAllocator
virtual void UnregisterDependentHandleToNativeObjectFromCleanup(LADependentHandleToNativeObject *dependentHandle) {};
virtual void CleanupDependentHandlesToNativeObjects() {};
#endif

friend struct ::cdac_data<LoaderAllocator>;
}; // class LoaderAllocator

template<>
struct cdac_data<LoaderAllocator>
{
static constexpr size_t ReferenceCount = offsetof(LoaderAllocator, m_cReferences);
};

typedef VPTR(LoaderAllocator) PTR_LoaderAllocator;

extern "C" BOOL QCALLTYPE LoaderAllocator_Destroy(QCall::LoaderAllocatorHandle pLoaderAllocator);
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/vm/typehash.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define _TYPE_HASH_H

#include "dacenumerablehash.h"
#include "cdacdata.h"

//========================================================================================
// This hash table is used by class loaders to look up constructed types:
Expand Down Expand Up @@ -136,6 +137,18 @@ class EETypeHashTable : public DacEnumerableHashTable<EETypeHashTable, EETypeHas
BOOL CompareFnPtrType(TypeHandle t, BYTE callConv, DWORD numArgs, TypeHandle *retAndArgTypes);
BOOL GrowHashTable();
LoaderAllocator* GetLoaderAllocator();

friend struct ::cdac_data<EETypeHashTable>;
};

template<>
struct cdac_data<EETypeHashTable>
{
static constexpr size_t Buckets = offsetof(EETypeHashTable, m_pBuckets);
static constexpr size_t Count = offsetof(EETypeHashTable, m_cEntries);

static constexpr size_t VolatileEntryValue = offsetof(EETypeHashTable::VolatileEntry, m_sValue);
static constexpr size_t VolatileEntryNextEntry = offsetof(EETypeHashTable::VolatileEntry, m_pNextEntry);
};

#endif /* _TYPE_HASH_H */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ModuleHandle(TargetPointer address)
[Flags]
public enum ModuleFlags
{
Tenured = 0x00000001, // Set once we know for sure the Module will not be freed until the appdomain itself exits
EditAndContinue = 0x00000008, // Edit and Continue is enabled for this module
ReflectionEmit = 0x00000040, // Reflection.Emit was used to create this module
}
Expand All @@ -32,12 +33,34 @@ public record struct ModuleLookupTables(
TargetPointer TypeRefToMethodTable,
TargetPointer MethodDefToILCodeVersioningState);

[Flags]
public enum AssemblyIterationFlags
{
// load status flags
IncludeLoaded = 0x00000001, // include assemblies that are already loaded
// (m_level >= code:FILE_LOAD_DELIVER_EVENTS)
IncludeLoading = 0x00000002, // include assemblies that are still in the process of loading
// (all m_level values)
IncludeAvailableToProfilers = 0x00000020, // include assemblies available to profilers
// See comment at code:DomainAssembly::IsAvailableToProfilers

// Execution / introspection flags
IncludeExecution = 0x00000004, // include assemblies that are loaded for execution only

IncludeFailedToLoad = 0x00000010, // include assemblies that failed to load

// Collectible assemblies flags
ExcludeCollectible = 0x00000040, // Exclude all collectible assemblies
IncludeCollected = 0x00000080, // Include all collectible assemblies that have been collected
}

public interface ILoader : IContract
{
static string IContract.Name => nameof(Loader);

ModuleHandle GetModuleHandle(TargetPointer modulePointer) => throw new NotImplementedException();

List<ModuleHandle> GetAssemblies(TargetPointer appDomain, AssemblyIterationFlags iterationFlags) => throw new NotImplementedException();
TargetPointer GetRootAssembly() => throw new NotImplementedException();
TargetPointer GetAssembly(ModuleHandle handle) => throw new NotImplementedException();
TargetPointer GetPEAssembly(ModuleHandle handle) => throw new NotImplementedException();
Expand All @@ -47,13 +70,16 @@ public interface ILoader : IContract
ModuleFlags GetFlags(ModuleHandle handle) => throw new NotImplementedException();
string GetPath(ModuleHandle handle) => throw new NotImplementedException();
string GetFileName(ModuleHandle handle) => throw new NotImplementedException();
List<TargetPointer> GetAvailableTypeParams(ModuleHandle handle) => throw new NotImplementedException();
List<TargetPointer> GetInstantiatedMethods(ModuleHandle handle) => throw new NotImplementedException();

TargetPointer GetLoaderAllocator(ModuleHandle handle) => throw new NotImplementedException();
TargetPointer GetILBase(ModuleHandle handle) => throw new NotImplementedException();
ModuleLookupTables GetLookupTables(ModuleHandle handle) => throw new NotImplementedException();

TargetPointer GetModuleLookupMapElement(TargetPointer table, uint token, out TargetNUInt flags) => throw new NotImplementedException();
bool IsCollectible(ModuleHandle handle) => throw new NotImplementedException();
bool IsAssemblyLoaded(ModuleHandle handle) => throw new NotImplementedException();
}

public readonly struct Loader : ILoader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public interface IRuntimeTypeSystem : IContract
TargetPointer GetCanonicalMethodTable(TypeHandle typeHandle) => throw new NotImplementedException();
TargetPointer GetParentMethodTable(TypeHandle typeHandle) => throw new NotImplementedException();

MethodDescHandle GetMethodDescForSlot(TypeHandle methodTable, ushort slot) => throw new NotImplementedException();

uint GetBaseSize(TypeHandle typeHandle) => throw new NotImplementedException();
// The component size is only available for strings and arrays. It is the size of the element type of the array, or the size of an ECMA 335 character (2 bytes)
uint GetComponentSize(TypeHandle typeHandle) => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum DataType
ModuleLookupMap,
AppDomain,
Assembly,
LoaderAllocator,
PEAssembly,
PEImage,
PEImageLayout,
Expand Down Expand Up @@ -96,6 +97,11 @@ public enum DataType
MethodImpl,
NativeCodeSlot,
GCCoverageInfo,
ArrayListBase,
ArrayListBlock,
EETypeHashTable,
InstMethodHashTable,

TransitionBlock,
DebuggerEval,
CalleeSavedRegisters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class Globals
{
// See src/coreclr/debug/runtimeinfo/datadescriptor.h
public const string AppDomain = nameof(AppDomain);
public const string SystemDomain = nameof(SystemDomain);
public const string ThreadStore = nameof(ThreadStore);
public const string FinalizerThread = nameof(FinalizerThread);
public const string GCThread = nameof(GCThread);
Expand Down Expand Up @@ -54,6 +55,8 @@ public static class Globals
public const string PlatformMetadata = nameof(PlatformMetadata);
public const string ProfilerControlBlock = nameof(ProfilerControlBlock);

public const string MethodDescSizeTable = nameof(MethodDescSizeTable);

public const string HashMapSlotsPerBucket = nameof(HashMapSlotsPerBucket);
public const string HashMapValueMask = nameof(HashMapValueMask);

Expand Down
Loading
Loading