-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix allocation of empty array in the frozen heap for collectible types (
#100437) Add assert for collectible in FrozenObjectHeapManager::TryAllocateObject Fix another potential case Add test Fix test Fix test bis Fix test bis bis
- Loading branch information
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
45 changes: 45 additions & 0 deletions
45
src/tests/JIT/Regression/JitBlue/Runtime_100437/Runtime_100437.cs
This file contains 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,45 @@ | ||
// 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() | ||
{ | ||
WeakReference[] wrs = new WeakReference[10]; | ||
for (int i = 0; i < wrs.Length; i++) | ||
{ | ||
var alc = new MyAssemblyLoadContext(); | ||
var a = alc.LoadFromAssemblyPath(typeof(Runtime_100437).Assembly.Location); | ||
wrs[i] = (WeakReference)a.GetType("Runtime_100437").GetMethod("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; | ||
} | ||
|
||
public static WeakReference Work() | ||
{ | ||
return new WeakReference(Array.Empty<Runtime_100437>()); | ||
} | ||
|
||
private class MyAssemblyLoadContext : AssemblyLoadContext | ||
{ | ||
public MyAssemblyLoadContext() | ||
: base(isCollectible: true) | ||
{ | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_100437/Runtime_100437.csproj
This file contains 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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |