File tree Expand file tree Collapse file tree
src/tests/JIT/Regression/JitBlue/Runtime_100437 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT license.
3+
4+ using System ;
5+ using System . Runtime . CompilerServices ;
6+ using System . Runtime . Loader ;
7+ using Xunit ;
8+
9+ public static class Runtime_100437
10+ {
11+ [ Fact ]
12+ public int TestCollectibleEmptyArrayNotInFrozenHeap ( )
13+ {
14+ WeakReference [ ] wrs = new WeakReference [ 10 ] ;
15+ for ( int i = 0 ; i < wrs . Length ; i ++ )
16+ {
17+ var alc = new MyAssemblyLoadContext ( ) ;
18+ var a = alc . LoadFromAssemblyPath ( typeof ( Program ) . Assembly . Location ) ;
19+ wrs [ i ] = ( WeakReference ) a . GetType ( "Runtime_100437" ) . GetMethod ( "Work" ) . Invoke ( null , null ) ;
20+ GC . Collect ( ) ;
21+ }
22+
23+ int result = 0 ;
24+ foreach ( var wr in wrs )
25+ {
26+ // This is testing that the empty array from Work(), if collected, should not have been allocated on the Frozen heap
27+ // otherwise it will result in a random crash.
28+ result += wr . Target ? . ToString ( ) ? . GetHashCode ( ) ?? 0 ;
29+ }
30+ return result ;
31+ }
32+
33+ public static WeakReference Work ( )
34+ {
35+ return new WeakReference ( Array . Empty < Program > ( ) ) ;
36+ }
37+
38+ private class MyAssemblyLoadContext : AssemblyLoadContext
39+ {
40+ public MyAssemblyLoadContext ( )
41+ : base ( isCollectible : true )
42+ {
43+ }
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+ <PropertyGroup >
3+ <Optimize >True</Optimize >
4+ </PropertyGroup >
5+ <ItemGroup >
6+ <Compile Include =" $(MSBuildProjectName).cs" />
7+ </ItemGroup >
8+ </Project >
You can’t perform that action at this time.
0 commit comments