-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix allocation of empty array in the frozen heap for collectible types #100444
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
Merged
jkotas
merged 13 commits into
dotnet:main
from
xoofx:fix-frozen-empty-array-alloc-for-collectible-array-type
Apr 2, 2024
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9721b40
Fix allocation of empty array in the frozen heap for collectible type…
xoofx cd1ebe0
Remove Optimize from csproj
xoofx 65474a5
Fix tests
xoofx 97d9d76
Add test for generic with static
xoofx c492da0
Update src/coreclr/vm/gchelpers.cpp
jkotas 7434c15
Apply suggestions from code review
jkotas 94deb3f
Update src/coreclr/vm/gchelpers.cpp
jkotas e82d780
Better test
jkotas 2b4009b
Disable test on Mono
jkotas 051bd87
Fix test
jkotas 9a2b12a
Update src/tests/issues.targets
jkotas 24c6681
Merge branch 'main' into fix-frozen-empty-array-alloc-for-collectible…
jkotas 65618de
Disable tests on Mono
jkotas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/tests/JIT/Regression/JitBlue/Runtime_100437/Runtime_100437.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.Loader; | ||
| using Xunit; | ||
|
|
||
| public class Runtime_100437 | ||
| { | ||
| [Fact] | ||
| public static int TestCollectibleEmptyArrayNotInFrozenHeap() | ||
| { | ||
| string assemblyPath = typeof(Runtime_100437).Assembly.Location; | ||
|
|
||
| // Skip this test for single file | ||
| if (string.IsNullOrEmpty(assemblyPath)) | ||
| return 100; | ||
|
|
||
| WeakReference[] wrs = new WeakReference[10]; | ||
| for (int i = 0; i < wrs.Length; i++) | ||
| { | ||
| var alc = new MyAssemblyLoadContext(); | ||
| var a = alc.LoadFromAssemblyPath(assemblyPath); | ||
| wrs[i] = (WeakReference)a.GetType(nameof(Runtime_100437)).GetMethod(nameof(Work)).Invoke(null, null); | ||
| GC.Collect(); | ||
| } | ||
|
|
||
| int result = 0; | ||
| foreach (var wr in wrs) | ||
| { | ||
| // This is testing that the empty array from Work(), if collected, should not have been allocated on the Frozen heap | ||
| // otherwise it will result in a random crash. | ||
| result += wr.Target?.ToString()?.GetHashCode() ?? 0; | ||
| } | ||
| return (result & 100) | 100; | ||
| } | ||
|
|
||
| [Fact] | ||
| public static int TestCollectibleReadOnlyStaticWithGeneric() | ||
| { | ||
| string assemblyPath = typeof(Runtime_100437).Assembly.Location; | ||
|
|
||
| // Skip this test for single file | ||
| if (string.IsNullOrEmpty(assemblyPath)) | ||
| return 100; | ||
|
|
||
| WeakReference[] wrs = new WeakReference[10]; | ||
| for (int i = 0; i < wrs.Length; i++) | ||
| { | ||
| var alc = new MyAssemblyLoadContext(); | ||
| var a = alc.LoadFromAssemblyPath(assemblyPath); | ||
| wrs[i] = (WeakReference)a.GetType(nameof(Runtime_100437)).GetMethod(nameof(WorkForGenericCase)).Invoke(null, null); | ||
| GC.Collect(); | ||
| } | ||
|
|
||
| int result = 0; | ||
| foreach (var wr in wrs) | ||
| { | ||
| result += wr.Target?.ToString()?.GetHashCode() ?? 0; | ||
| } | ||
| return (result & 100) | 100; | ||
| } | ||
|
|
||
| public static WeakReference Work() | ||
| { | ||
| return new WeakReference(Array.Empty<Runtime_100437>()); | ||
| } | ||
|
|
||
| public static WeakReference WorkForGenericCase() | ||
| { | ||
| return new WeakReference(GenericHolder<Runtime_100437>.Singleton); | ||
| } | ||
|
|
||
| private class MyAssemblyLoadContext : AssemblyLoadContext | ||
| { | ||
| public MyAssemblyLoadContext() | ||
| : base(isCollectible: true) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| private class GenericHolder<T> | ||
| { | ||
| public static readonly object Singleton = new object(); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/tests/JIT/Regression/JitBlue/Runtime_100437/Runtime_100437.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.