{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/8677","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/8677/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/8677/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/8677/events","html_url":"https://github.com/dotnet/coreclr/pull/8677","id":196289917,"number":8677,"title":"[WIP] Collectible Assemblies and AssemblyLoadContext","user":{"login":"xoofx","id":715038,"avatar_url":"https://avatars.githubusercontent.com/u/715038?v=3","gravatar_id":"","url":"https://api.github.com/users/xoofx","html_url":"https://github.com/xoofx","followers_url":"https://api.github.com/users/xoofx/followers","following_url":"https://api.github.com/users/xoofx/following{/other_user}","gists_url":"https://api.github.com/users/xoofx/gists{/gist_id}","starred_url":"https://api.github.com/users/xoofx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xoofx/subscriptions","organizations_url":"https://api.github.com/users/xoofx/orgs","repos_url":"https://api.github.com/users/xoofx/repos","events_url":"https://api.github.com/users/xoofx/events{/privacy}","received_events_url":"https://api.github.com/users/xoofx/received_events","type":"User","site_admin":false},"labels":[{"id":197462704,"url":"https://api.github.com/repos/dotnet/coreclr/labels/cla-already-signed","name":"cla-already-signed","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":45,"created_at":"2016-12-18T18:13:02Z","updated_at":"2016-12-28T01:05:49Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/8677","html_url":"https://github.com/dotnet/coreclr/pull/8677","diff_url":"https://github.com/dotnet/coreclr/pull/8677.diff","patch_url":"https://github.com/dotnet/coreclr/pull/8677.patch"},"body":"This is a followup of the issue #1684 (work done by @Rohansi) and the original issue #552 \r\n\r\nThis is PR is not mergeable as it is. It is a single commit for now to simplify the tracking of things that are changed. I will recommit everything once I have cleanup some bits here and there (the changes are very rough now... I haven't followed also using the define `FEATURE_COLLECTIBLE_ALC`...etc.)\r\n\r\nThe difference with #1684 is that a single `AssemblyLoaderAllocator` is now associated to the `AssemblyLoadContext`. Without changing much this class, I have added the ability to add a `DomainAssembly` (instead of the previous `SetDomainAssembly` method) to chain it to another domain assembly that is in the same ALC (via the member `DomainAssembly::m_NextDomainAssemblyInSameALC`). It allows to use the original code for single collectible assembly.\r\n\r\nAlso, the `AssemblyLoadContext` creates a weak handle on itself instead of a strong handle (otherwise it cannot self finalize). The Destroy of this context doesn't actually delete the native ALC but instead release a strong handle to the `LoaderAllocator` managed object (associated to the `AssemblyLoaderAllocator`). Then the finalizer of the `LoaderAllocator` via the `LoaderAllocatorScout` will be called, and there we will cleanup everything, including releasing the native `AssemblyLoadContext`.\r\n\r\nA simple test with an assembly loaded in loop seems to indicate that the memory is stable and nothing so far is crashing, but I expect many problems in many places, so this is really an early POC.\r\n\r\nI originally didn't use the PR #1684 and tried to perform the changes on my side, but I had to cherry pick some parts of the previous PR while encountering the same issues. One thing I'm really not happy currently is the code in the `LoaderAllocator::GCLoaderAllocators_RemoveAssemblies` (I had to fight with issues with part of the code `GC_NOTRIGGER` and others incompatible `GC_TRIGGERS`...etc.). One thing I don't like is to have multiple methods to remove all the internal caches associated to a `DomainAssembly` in the `AppDomain`. This code should be part of `AppDomain` instead. There  is also some issues with some maps that are using some `AssemblySpec` that were problematic because they were doing some GC_TRIGGERS (and the original `GCLoaderAllocators_RemoveAssemblies` was `GC_NOTRIGGER`)... so yeah, this part has to be heavily rewrite/cleanup somehow.\r\n\r\nComments are welcome (sorry if it is a bit of a mess!)\r\n\r\ncc: @jkotas @gkhanna79 @rahku \r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/269406391","html_url":"https://github.com/dotnet/coreclr/pull/8677#issuecomment-269406391","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/8677","id":269406391,"user":{"login":"kouvel","id":13499639,"avatar_url":"https://avatars.githubusercontent.com/u/13499639?v=3","gravatar_id":"","url":"https://api.github.com/users/kouvel","html_url":"https://github.com/kouvel","followers_url":"https://api.github.com/users/kouvel/followers","following_url":"https://api.github.com/users/kouvel/following{/other_user}","gists_url":"https://api.github.com/users/kouvel/gists{/gist_id}","starred_url":"https://api.github.com/users/kouvel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kouvel/subscriptions","organizations_url":"https://api.github.com/users/kouvel/orgs","repos_url":"https://api.github.com/users/kouvel/repos","events_url":"https://api.github.com/users/kouvel/events{/privacy}","received_events_url":"https://api.github.com/users/kouvel/received_events","type":"User","site_admin":false},"created_at":"2016-12-28T01:05:49Z","updated_at":"2016-12-28T01:05:49Z","body":"The version change should be in `coreclr\\bin\\obj\\BuildVersion-<latestDate>.props`"}}
{"actor":{"display_login":"kouvel"}}