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

Conversation

alexey-zakharov
Copy link

@alexey-zakharov alexey-zakharov commented Jan 20, 2025

To detect AssemblyLoadContext leaks which are coming from static fields we need to be able to:

  1. Connect AsemblyLoadContext to LoaderAllocator instance which holds a special array (m_slots) with statics and other AssemblyLoadContext-specific roots.
  2. Quickly determine which AssemblyLoadContext specific class belongs to. (An ALC of a generic instance depends on ALCs of type parameters and is relatively expensive to compute)

Unfortunately there is no link in managed for both cases (AssemblyLoadContext and LoaderAllocator can't know about each other to be able to actually unload ALC). However in native there is an AssemblyBinder class which knows about both objects through a native handle, and can directly point to the ALC for a given class.

The PR introduces:

  1. coreclr_unity_profiler_assembly_load_context_get_loader_allocator_handle - api to retrieve LoaderAllocator handle for an AssemblyLoadContext instance.
  2. coreclr_unity_profiler_class_get_assembly_load_context_handle - api to return AssemblyLoadContext handle for a class instance.

It may be possible to suggest a public API to upstream in the future to support this information

…semblyLoadContext and LoaderAllocator of a class
@alexey-zakharov alexey-zakharov self-assigned this Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant