@@ -15,18 +15,15 @@ class GCHeapEnumerationTests
1515 static List < object > _rootObjects = new List < object > ( ) ;
1616
1717 [ DllImport ( "Profiler" ) ]
18- private static extern void EnumerateGCHeapObjects ( ) ;
19-
20- [ DllImport ( "Profiler" ) ]
21- private static extern void EnumerateHeapObjectsInBackgroundThread ( ) ;
18+ private static extern void EnumerateGCHeapObjectsWithoutProfilerRequestedRuntimeSuspension ( ) ;
2219
2320 [ DllImport ( "Profiler" ) ]
2421 private static extern void EnumerateGCHeapObjectsWithinProfilerRequestedRuntimeSuspension ( ) ;
2522
2623 public static int EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ( )
2724 {
2825 _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
29- EnumerateGCHeapObjects ( ) ;
26+ EnumerateGCHeapObjectsWithoutProfilerRequestedRuntimeSuspension ( ) ;
3027 return 100 ;
3128 }
3229
@@ -37,39 +34,15 @@ public static int EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRunti
3734 return 100 ;
3835 }
3936
40- public static int EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ( )
37+ // Test invoking ProfToEEInterfaceImpl::EnumerateGCHeapObjects during non-profiler requested runtime suspension, e.g. during GC
38+ // ProfToEEInterfaceImpl::EnumerateGCHeapObjects should be invoked by the GarbageCollectionStarted callback
39+ public static int EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ( )
4140 {
4241 _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
43- EnumerateHeapObjectsInBackgroundThread ( ) ;
4442 GC . Collect ( ) ;
4543 return 100 ;
4644 }
4745
48- public static int EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ( )
49- {
50- ManualResetEvent startEvent = new ManualResetEvent ( false ) ;
51- Thread gcThread = new Thread ( ( ) =>
52- {
53- startEvent . WaitOne ( ) ;
54- GC . Collect ( ) ;
55- } ) ;
56- gcThread . Name = "GC.Collect" ;
57- gcThread . Start ( ) ;
58-
59- Thread enumerateThread = new Thread ( ( ) =>
60- {
61- startEvent . WaitOne ( ) ;
62- Thread . Sleep ( 1000 ) ;
63- _rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
64- EnumerateGCHeapObjects ( ) ;
65- } ) ;
66- enumerateThread . Name = "EnumerateGCHeapObjects" ;
67- enumerateThread . Start ( ) ;
68-
69- startEvent . Set ( ) ;
70- return 100 ;
71- }
72-
7346 public static int Main ( string [ ] args )
7447 {
7548 if ( args . Length > 0 && args [ 0 ] . Equals ( "RunTest" , StringComparison . OrdinalIgnoreCase ) )
@@ -82,38 +55,30 @@ public static int Main(string[] args)
8255 case nameof ( EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ) :
8356 return EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ( ) ;
8457
85- case nameof ( EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ) :
86- return EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ( ) ;
87-
8858 case nameof ( EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ) :
8959 return EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ( ) ;
9060 }
9161 }
9262
93- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ) , "FALSE" ) )
63+ if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ) , false ) )
9464 {
9565 return 101 ;
9666 }
9767
98- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ) , "FALSE" ) )
68+ if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ) , false ) )
9969 {
10070 return 102 ;
10171 }
10272
103- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ) , "TRUE" ) )
73+ if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ) , true ) )
10474 {
10575 return 103 ;
10676 }
10777
108- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ) , "FALSE" ) )
109- {
110- return 104 ;
111- }
112-
11378 return 100 ;
11479 }
11580
116- private static bool RunProfilerTest ( string testName , string shouldSetMonitorGCEventMask )
81+ private static bool RunProfilerTest ( string testName , bool shouldSetMonitorGCEventMask )
11782 {
11883 try
11984 {
@@ -123,7 +88,7 @@ private static bool RunProfilerTest(string testName, string shouldSetMonitorGCEv
12388 profileeArguments : testName ,
12489 envVars : new Dictionary < string , string >
12590 {
126- { ShouldSetMonitorGCEventMaskEnvVar , shouldSetMonitorGCEventMask } ,
91+ { ShouldSetMonitorGCEventMaskEnvVar , shouldSetMonitorGCEventMask ? "TRUE" : "FALSE" } ,
12792 }
12893 ) == 100 ;
12994 }
0 commit comments