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

Added coreclr_unity profiler api for getting AssemblyLoadContext information #278

Open
wants to merge 1 commit into
base: unity-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/dlls/mscoree/mscorwks_ntdef.src
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ EXPORTS
coreclr_unity_array_element_size
coreclr_unity_class_array_element_size
coreclr_unity_profiler_register
coreclr_unity_profiler_class_get_assembly_load_context_handle
coreclr_unity_profiler_get_managed_assembly_load_context
coreclr_unity_profiler_assembly_load_context_get_loader_allocator_handle
coreclr_unity_gc_concurrent_mode
mono_assembly_get_assemblyref
mono_class_get_name
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/dlls/mscoree/mscorwks_unixexports.src
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ coreclr_image_get_custom_attribute_data
coreclr_unity_array_element_size
coreclr_unity_class_array_element_size
coreclr_unity_profiler_register
coreclr_unity_profiler_class_get_assembly_load_context_handle
coreclr_unity_profiler_get_managed_assembly_load_context
coreclr_unity_profiler_assembly_load_context_get_loader_allocator_handle
coreclr_unity_gc_concurrent_mode
mono_assembly_get_assemblyref
mono_class_get_name
Expand Down
48 changes: 48 additions & 0 deletions src/coreclr/vm/mono/mono_coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,34 @@ extern "C" EXPORT_API void EXPORT_CC coreclr_unity_profiler_register(const CLSID
g_profControlBlock.storedProfilers.InsertHead(profilerData);
}

extern "C" EXPORT_API ObjectHandleID EXPORT_CC coreclr_unity_profiler_class_get_assembly_load_context_handle(ClassID classId)
{
STATIC_CONTRACT_NOTHROW;

TypeHandle typeHandle = TypeHandle::FromPtr((void *)classId);

if (!typeHandle.IsRestored())
return NULL;

if (classId == PROFILER_GLOBAL_CLASS)
return NULL;

Module* pModule = typeHandle.GetModule();
if (pModule == NULL)
return NULL;

Assembly *pAssembly = pModule->GetAssembly();
if (pAssembly == NULL)
return NULL;

AssemblyBinder* pAssemblyBinder = pAssembly->GetPEAssembly()->GetAssemblyBinder();
if (pAssemblyBinder->IsDefault())
return NULL;

// ManagedAssemblyLoadContext is a handle to the managed AssemblyLoadContext object
return (ObjectHandleID)pAssemblyBinder->GetManagedAssemblyLoadContext();
}

extern "C" EXPORT_API ObjectHandleID EXPORT_CC coreclr_unity_profiler_get_managed_assembly_load_context(AssemblyID assemblyID)
{
STATIC_CONTRACT_NOTHROW;
Expand All @@ -757,6 +785,26 @@ extern "C" EXPORT_API ObjectHandleID EXPORT_CC coreclr_unity_profiler_get_manage
return (ObjectHandleID)pAssemblyBinder->GetManagedAssemblyLoadContext();
}

extern "C" EXPORT_API ObjectHandleID EXPORT_CC coreclr_unity_profiler_assembly_load_context_get_loader_allocator_handle(ObjectID assemblyLoadContextObjectID)
{
STATIC_CONTRACT_NOTHROW;

ASSEMBLYLOADCONTEXTREF pAssemblyLoadContext = (ASSEMBLYLOADCONTEXTREF)assemblyLoadContextObjectID;
if (pAssemblyLoadContext == NULL)
return NULL;

AssemblyBinder* pAssemblyBinder = (AssemblyBinder*)pAssemblyLoadContext->GetNativeAssemblyBinder();
if (pAssemblyBinder == NULL)
return NULL;

LoaderAllocator* loaderAllocator = pAssemblyBinder->GetLoaderAllocator();
if (loaderAllocator == NULL)
return NULL;

// ManagedAssemblyLoadContext is a handle to the managed AssemblyLoadContext object
return (ObjectHandleID)loaderAllocator->GetLoaderAllocatorObjectHandle();
}

extern "C" EXPORT_API gboolean EXPORT_CC coreclr_unity_gc_concurrent_mode(gboolean state)
{
CONTRACTL
Expand Down