@@ -15,18 +15,15 @@ class GCHeapEnumerationTests
15
15
static List < object > _rootObjects = new List < object > ( ) ;
16
16
17
17
[ DllImport ( "Profiler" ) ]
18
- private static extern void EnumerateGCHeapObjects ( ) ;
19
-
20
- [ DllImport ( "Profiler" ) ]
21
- private static extern void EnumerateHeapObjectsInBackgroundThread ( ) ;
18
+ private static extern void EnumerateGCHeapObjectsWithoutProfilerRequestedRuntimeSuspension ( ) ;
22
19
23
20
[ DllImport ( "Profiler" ) ]
24
21
private static extern void EnumerateGCHeapObjectsWithinProfilerRequestedRuntimeSuspension ( ) ;
25
22
26
23
public static int EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ( )
27
24
{
28
25
_rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
29
- EnumerateGCHeapObjects ( ) ;
26
+ EnumerateGCHeapObjectsWithoutProfilerRequestedRuntimeSuspension ( ) ;
30
27
return 100 ;
31
28
}
32
29
@@ -37,39 +34,15 @@ public static int EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRunti
37
34
return 100 ;
38
35
}
39
36
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 ( )
41
40
{
42
41
_rootObjects . Add ( new CustomGCHeapObject ( ) ) ;
43
- EnumerateHeapObjectsInBackgroundThread ( ) ;
44
42
GC . Collect ( ) ;
45
43
return 100 ;
46
44
}
47
45
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
-
73
46
public static int Main ( string [ ] args )
74
47
{
75
48
if ( args . Length > 0 && args [ 0 ] . Equals ( "RunTest" , StringComparison . OrdinalIgnoreCase ) )
@@ -82,38 +55,30 @@ public static int Main(string[] args)
82
55
case nameof ( EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ) :
83
56
return EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ( ) ;
84
57
85
- case nameof ( EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ) :
86
- return EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ( ) ;
87
-
88
58
case nameof ( EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ) :
89
59
return EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ( ) ;
90
60
}
91
61
}
92
62
93
- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ) , "FALSE" ) )
63
+ if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadNoPriorSuspension ) , false ) )
94
64
{
95
65
return 101 ;
96
66
}
97
67
98
- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ) , "FALSE" ) )
68
+ if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsSingleThreadWithinProfilerRequestedRuntimeSuspension ) , false ) )
99
69
{
100
70
return 102 ;
101
71
}
102
72
103
- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsInBackgroundThreadWithRuntimeSuspension ) , "TRUE" ) )
73
+ if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ) , true ) )
104
74
{
105
75
return 103 ;
106
76
}
107
77
108
- if ( ! RunProfilerTest ( nameof ( EnumerateGCHeapObjectsMultiThreadWithCompetingRuntimeSuspension ) , "FALSE" ) )
109
- {
110
- return 104 ;
111
- }
112
-
113
78
return 100 ;
114
79
}
115
80
116
- private static bool RunProfilerTest ( string testName , string shouldSetMonitorGCEventMask )
81
+ private static bool RunProfilerTest ( string testName , bool shouldSetMonitorGCEventMask )
117
82
{
118
83
try
119
84
{
@@ -123,7 +88,7 @@ private static bool RunProfilerTest(string testName, string shouldSetMonitorGCEv
123
88
profileeArguments : testName ,
124
89
envVars : new Dictionary < string , string >
125
90
{
126
- { ShouldSetMonitorGCEventMaskEnvVar , shouldSetMonitorGCEventMask } ,
91
+ { ShouldSetMonitorGCEventMaskEnvVar , shouldSetMonitorGCEventMask ? "TRUE" : "FALSE" } ,
127
92
}
128
93
) == 100 ;
129
94
}
0 commit comments