Skip to content

Commit

Permalink
Address PR review.
Browse files Browse the repository at this point in the history
  • Loading branch information
teo-tsirpanis committed Aug 15, 2023
1 parent 162d15b commit 921f45f
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 75 deletions.
4 changes: 2 additions & 2 deletions docs/design/features/unloadability.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
After investigating all the details, it was decided that we won't support the following scenarios in unloadable `AssemblyLoadContext` unless we get strong feedback on a need to support those.
* Loading IJW assemblies
* Using R2R generated code from assemblies. R2R assemblies will be loaded as plain IL ones.
* ~~Implementation of the FixedAddressValueTypeAttribute~~ Support added in .NET TBD
* ~~Implementation of the FixedAddressValueTypeAttribute~~ Support added in .NET 9
## General scenarios
Based on various discussions and feedback on github, the following general scenarios were often mentioned as use cases for unloadability.
* Plugin scenarios when dynamic plugin loading and unloading is required.
Expand Down Expand Up @@ -86,7 +86,7 @@ The After the `AssemblyLoadContext` unload is initiated and the managed `LoaderA
#### FixedAddressValueTypeAttribute for fields in collectible types
The fields with `FixedAddressValueTypeAttribute` are always pinned, so their address in memory never changes. Historically for non-collectible types, these fields are held pinned by a pinned `GCHandle`. But we could not use that for collectible types, since the `MethodTable` whose pointer is stored in the respective boxed instance of the value type would prevent the managed `LoaderAllocator` from being collected.

Since .NET TBD, we always allocate these fields in the Pinned Object Heap. That way, they are pinned without being held by a handle, and are able to be collected.
Since .NET 9, we always allocate these fields in the Pinned Object Heap. That way, they are pinned without being held by a handle, and are able to be collected.
## AssemblyLoadContext unloading process
For better understanding of the unloading process, it is important to understand relations between several components that play role in the lifetime management. The picture below shows these components and the ways they reference each other.
The green marked relations and blocks are the new ones that were added to enable unloadable `AssemblyLoadContext`. The black ones were already present before.
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/vm/gchelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ inline OBJECTREF AllocateObject(MethodTable *pMT
#ifdef FEATURE_COMINTEROP
, bool fHandleCom = true
#endif
) {
)
{
return AllocateObject(pMT, GC_ALLOC_NO_FLAGS
#ifdef FEATURE_COMINTEROP
, fHandleCom
, fHandleCom
#endif
);
}
}

extern int StompWriteBarrierEphemeral(bool isRuntimeSuspended);
extern int StompWriteBarrierResize(bool isRuntimeSuspended, bool bReqUpperBoundsCheck);
Expand Down
24 changes: 0 additions & 24 deletions src/libraries/System.Runtime.Loader/System.Runtime.Loader.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.Loader.Test.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.Loader.Test.Assembly2", "tests\System.Runtime.Loader.Test.Assembly2\System.Runtime.Loader.Test.Assembly2.csproj", "{E60DD367-D1D7-4F6C-919B-DC68E8445E97}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.Loader.Test.AssemblyNotSupported", "tests\System.Runtime.Loader.Test.AssemblyNotSupported\System.Runtime.Loader.Test.AssemblyNotSupported.csproj", "{9AD657ED-396B-4BE7-BCB6-BCA130825418}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.Loader.Tests", "tests\System.Runtime.Loader.Tests.csproj", "{29E02AA9-E3D5-400C-B2C5-970B6E6D8562}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime", "..\System.Runtime\ref\System.Runtime.csproj", "{06E15C97-C87D-473E-9E44-DCE169B1CE4E}"
Expand Down Expand Up @@ -823,27 +821,6 @@ Global
{E60DD367-D1D7-4F6C-919B-DC68E8445E97}.Checked|arm64.ActiveCfg = Debug|Any CPU
{E60DD367-D1D7-4F6C-919B-DC68E8445E97}.Checked|x64.ActiveCfg = Debug|Any CPU
{E60DD367-D1D7-4F6C-919B-DC68E8445E97}.Checked|x86.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|arm.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|arm64.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|x64.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|x64.Build.0 = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|x86.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Debug|x86.Build.0 = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|Any CPU.Build.0 = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|arm.ActiveCfg = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|arm64.ActiveCfg = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|x64.ActiveCfg = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|x64.Build.0 = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|x86.ActiveCfg = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Release|x86.Build.0 = Release|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Checked|arm.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Checked|arm64.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Checked|x64.ActiveCfg = Debug|Any CPU
{9AD657ED-396B-4BE7-BCB6-BCA130825418}.Checked|x86.ActiveCfg = Debug|Any CPU
{29E02AA9-E3D5-400C-B2C5-970B6E6D8562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29E02AA9-E3D5-400C-B2C5-970B6E6D8562}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29E02AA9-E3D5-400C-B2C5-970B6E6D8562}.Debug|arm.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -920,7 +897,6 @@ Global
{44B22827-B9F0-4ADC-969C-7EC647D0B82A} = {F36F0790-5CF7-4CAD-B903-4A3EE0DC1345}
{49B0A873-5834-45A4-9495-E1063005CB82} = {F36F0790-5CF7-4CAD-B903-4A3EE0DC1345}
{E60DD367-D1D7-4F6C-919B-DC68E8445E97} = {F36F0790-5CF7-4CAD-B903-4A3EE0DC1345}
{9AD657ED-396B-4BE7-BCB6-BCA130825418} = {F36F0790-5CF7-4CAD-B903-4A3EE0DC1345}
{29E02AA9-E3D5-400C-B2C5-970B6E6D8562} = {F36F0790-5CF7-4CAD-B903-4A3EE0DC1345}
{BFED65C3-5AF6-4C81-8AE8-7CAC7E4867AE} = {153EEF5A-58CF-4A61-B712-B14F270BD32E}
{47FCBB78-4009-4B88-BC18-9DBCD4714152} = {153EEF5A-58CF-4A61-B712-B14F270BD32E}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public partial class AssemblyLoadContextTest
{
private const string TestAssembly = "System.Runtime.Loader.Test.Assembly";
private const string TestAssembly2 = "System.Runtime.Loader.Test.Assembly2";
private const string TestAssemblyNotSupported = "System.Runtime.Loader.Test.AssemblyNotSupported";

[Fact]
public static void GetAssemblyNameTest_ValidAssembly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,6 @@ public static void Unload_TwoCollectibleWithOneAssemblyAndOneInstanceReferencing
test.CheckContextUnloaded1();
}

[Fact]
[ActiveIssue("https://github.com/mono/mono/issues/15142", TestRuntimes.Mono)]
public static void Unsupported_FixedAddressValueType()
{
var asmName = new AssemblyName(TestAssemblyNotSupported);
var alc = new ResourceAssemblyLoadContext(true) { LoadBy = LoadBy.Path };
Assembly asm = alc.LoadFromAssemblyName(asmName);

Assert.NotNull(asm);

ReflectionTypeLoadException exception = Assert.Throws<ReflectionTypeLoadException>(() => asm.DefinedTypes);

// Expecting two exceptions:
// Collectible type 'System.Runtime.Loader.Tests.TestClassNotSupported_FixedAddressValueType' has unsupported FixedAddressValueTypeAttribute applied to a field
Assert.Equal(1, exception.LoaderExceptions.Length);
Assert.True(exception.LoaderExceptions.All(exp => exp is TypeLoadException));
}

private class CollectibleChecker
{
private readonly int _expectedCount;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<!-- iOS & tvOS are aot workloads and loading an embedded assembly results in some dynamic codegen, which is not allowed -->
<ProjectReference Condition="'$(TargetOS)' != 'ios' and '$(TargetOS)' != 'tvos'" Include="System.Runtime.Loader.Test.Assembly\System.Runtime.Loader.Test.Assembly.csproj" ReferenceOutputAssembly="false" OutputItemType="EmbeddedResource" />
<ProjectReference Condition="'$(TargetOS)' != 'ios' and '$(TargetOS)' != 'tvos'" Include="System.Runtime.Loader.Test.Assembly2\System.Runtime.Loader.Test.Assembly2.csproj" ReferenceOutputAssembly="false" OutputItemType="EmbeddedResource" />
<ProjectReference Condition="'$(TargetOS)' != 'ios' and '$(TargetOS)' != 'tvos'" Include="System.Runtime.Loader.Test.AssemblyNotSupported\System.Runtime.Loader.Test.AssemblyNotSupported.csproj" ReferenceOutputAssembly="false" OutputItemType="EmbeddedResource" />
<ProjectReference Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvos'" Include="System.Runtime.Loader.Test.Assembly\System.Runtime.Loader.Test.Assembly.csproj" />
<ProjectReference Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvos'" Include="System.Runtime.Loader.Test.Assembly2\System.Runtime.Loader.Test.Assembly2.csproj" />
<ProjectReference Condition="'$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvos'" Include="System.Runtime.Loader.Test.AssemblyNotSupported\System.Runtime.Loader.Test.AssemblyNotSupported.csproj" />
Expand Down

0 comments on commit 921f45f

Please sign in to comment.