-
Notifications
You must be signed in to change notification settings - Fork 560
[NET6] Enable support for AssemblyLoadContext #5940
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
Conversation
the alc support unload? |
ALC isn't supported at all yet, waiting for this |
853fd1b
to
5046ce5
Compare
|
||
#if defined (NET6) | ||
MonoAssembly* | ||
Util::monodroid_load_assembly (MonoAssemblyLoadContextGCHandle alc_handle, const char *basename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this member function exist when it doesn't appear to be used from anywhere? Dead code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I planned to start using it in another PR, one which would review all the usage of AppDomains across the code. I don't want to do it in this PR to keep it more focused. However, since this method will be called from few places, I'll add the calls to this PR.
|
||
void | ||
EmbeddedAssemblies::install_preload_hooks () | ||
EmbeddedAssemblies::install_preload_hooks (bool early) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This somewhat "irks" me in that "early" doesn't mean anything. The fact that it's bool
implies that install_preload_hooks()
is called twice -- which it is -- but why it's called twice, or how the two call-sites differ, isn't fully implied. (One is "early", presumably; but what does that mean?)
Additionally, given that I can't see any code share between the early
and !early
blocks, I think it would be more understandable if we split this up into two separately named methods, which would allow us to use a more "meaningful" adjective than "early".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will split the method into two separate ones.
Context: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-5.0 dotnet 6 removes support for AppDomains (technically, there still exists a single AppDomain, but creation of new ones is no longer possible), replacing them (in a way) with AssemblyLoadContext, which enables scoped loading of managed assemblies. Part of the change is the new set of MonoVM functions we need to call in order to load an assembly into either the default AssemblyLoadContext (early in the startup process) or into the application-created context later on during application run time. MonoVM also adds new preload hooks which work with the `ALC` instead of the older AppDomains. This commit adds support for `ALC` preload callbacks and the new assembly load functions.
@srxqds: in all likelihood, for .NET 6 we won't support unloading binding assemblies. Other usage of |
Other related discussion links of interest which came up recently: https://discord.com/channels/732297728826277939/732297965019988138/860536362351329320
https://discord.com/channels/732297728826277939/732297965019988138/860541671933214780
https://discord.com/channels/732297728826277939/732297965019988138/860544431986966548
https://discord.com/channels/732297728826277939/732297965019988138/860549366263578624
|
Context: https://docs.microsoft.com/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-5.0
.NET Core -- and thus, .NET 5+ -- removed support for
`System.AppDomain` -- technically, there still exists
a single `AppDomain`, but creation of new ones is no longer possible
-- with [`System.Runtime.Loader.AssemblyLoadContext`][0] acting as
the replacement for *some* previous `AppDomain` functionality.
TL;DR: `AssemblyLoadContext` allows (potentially) loading and
unloading assemblies, but *doesn't* allow creating an in-process
"sandbox" like `AppDomain`s originally did (though Code-Access-Security
was deprecated by .NET Framework 4; use as a sandbox was, in
retrospect, rarely a good idea).
Commit 0cd890bd introduced partial support for using
`AssemblyLoadContext`, but it was necessarily incomplete until after
[dotnet/runtime#53308][1] and other fixes landed.
Add support for calling the new `AssemblyLoadContext`-oriented
MonoVM embedding APIs to load assemblies, instead of the legacy
`MonoDomain`-oriented APIs.
Add support for calling the new `AssemblyLoadContext`-oriented MonoVM
functions to load an assembly into either the default
`AssemblyLoadContext` (early in the startup process) or into the
application-created context later on during application run time.
MonoVM also adds new preload hooks which work with the
`AssemblyLoadContext` instead of the older AppDomains.
Also add support for `AssemblyLoadContext` preload callbacks and the
new assembly load functions.
[0]: https://docs.microsoft.com/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-5.0
[1]: https://github.com/dotnet/runtime/pull/53308 |
@grendello: should the commit message also explicitly note that all binding assemblies will be loaded into the default |
Let's leave it till a subsequent commit, there's more work to be done in related areas, maybe I'll figure something out. |
ok, thank you, I will try to support unloadable alcs later, hope it get well. |
Context: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=net-5.0
dotnet 6 removes support for AppDomains (technically, there still exists
a single AppDomain, but creation of new ones is no longer possible),
replacing them (in a way) with AssemblyLoadContext, which enables scoped
loading of managed assemblies.
Part of the change is the new set of MonoVM functions we need to call in
order to load an assembly into either the default AssemblyLoadContext
(early in the startup process) or into the application-created context
later on during application run time. MonoVM also adds new preload
hooks which work with the
ALC
instead of the older AppDomains.This commit adds support for
ALC
preload callbacks and the newassembly load functions.