@@ -185,7 +185,7 @@ private unsafe ClockSpan MeasureWithRandomStack(Action<long> action, long invoke
185
185
return clockSpan ;
186
186
}
187
187
188
- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
188
+ [ MethodImpl ( MethodImplOptions . NoInlining | CodeGenHelper . AggressiveOptimizationOption ) ]
189
189
private unsafe void Consume ( byte * _ ) { }
190
190
191
191
[ MethodImpl ( MethodImplOptions . NoInlining | CodeGenHelper . AggressiveOptimizationOption ) ]
@@ -196,6 +196,7 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
196
196
return clock . GetElapsed ( ) ;
197
197
}
198
198
199
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
199
200
private ( GcStats , ThreadingStats , double ) GetExtraStats ( IterationData data )
200
201
{
201
202
// Warm up the measurement functions before starting the actual measurement.
@@ -208,18 +209,13 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
208
209
var exceptionsStats = new ExceptionsStats ( ) ; // allocates
209
210
exceptionsStats . StartListening ( ) ; // this method might allocate
210
211
211
- #if ! NET7_0_OR_GREATER
212
- if ( JitInfo . IsTiered && CoreRuntime . TryGetVersion ( out var version ) && version . Major is >= 3 and <= 6 )
212
+ if ( JitInfo . IsTiered )
213
213
{
214
214
// #1542
215
215
// We put the current thread to sleep so tiered jit can kick in, compile its stuff,
216
216
// and NOT allocate anything on the background thread when we are measuring allocations.
217
- // This is only an issue on netcoreapp3.0 to net6.0. Tiered jit allocations were "fixed" in net7.0
218
- // (maybe not completely eliminated forever, but at least reduced to a point where measurements are much more stable),
219
- // and netcoreapp2.X uses only GetAllocatedBytesForCurrentThread which doesn't capture the tiered jit allocations.
220
- Thread . Sleep ( TimeSpan . FromMilliseconds ( 500 ) ) ;
217
+ Thread . Sleep ( JitInfo . BackgroundCompilationDelay ) ;
221
218
}
222
- #endif
223
219
224
220
// GC collect before measuring allocations.
225
221
ForceGcCollect ( ) ;
@@ -250,6 +246,7 @@ private GcStats MeasureWithGc(Action<long> action, long invokeCount)
250
246
return finalGcStats - initialGcStats ;
251
247
}
252
248
249
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
253
250
private void RandomizeManagedHeapMemory ( )
254
251
{
255
252
// invoke global cleanup before global setup
@@ -268,6 +265,7 @@ private void RandomizeManagedHeapMemory()
268
265
// we don't enforce GC.Collects here as engine does it later anyway
269
266
}
270
267
268
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
271
269
private void GcCollect ( )
272
270
{
273
271
if ( ! ForceGcCleanups )
@@ -276,6 +274,7 @@ private void GcCollect()
276
274
ForceGcCollect ( ) ;
277
275
}
278
276
277
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
279
278
internal static void ForceGcCollect ( )
280
279
{
281
280
GC . Collect ( ) ;
@@ -327,6 +326,7 @@ private sealed class Impl
327
326
private readonly object hangLock = new ( ) ;
328
327
private readonly ManualResetEventSlim enteredFinalizerEvent = new ( false ) ;
329
328
329
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
330
330
~ Impl ( )
331
331
{
332
332
lock ( hangLock )
@@ -336,14 +336,15 @@ private sealed class Impl
336
336
}
337
337
}
338
338
339
- [ MethodImpl ( MethodImplOptions . NoInlining ) ]
339
+ [ MethodImpl ( MethodImplOptions . NoInlining | CodeGenHelper . AggressiveOptimizationOption ) ]
340
340
internal static ( object hangLock , ManualResetEventSlim enteredFinalizerEvent ) CreateWeakly ( )
341
341
{
342
342
var impl = new Impl ( ) ;
343
343
return ( impl . hangLock , impl . enteredFinalizerEvent ) ;
344
344
}
345
345
}
346
346
347
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
347
348
internal static FinalizerBlocker MaybeStart ( )
348
349
{
349
350
if ( Environment . GetEnvironmentVariable ( UnitTestBlockFinalizerEnvKey ) != UnitTestBlockFinalizerEnvValue )
@@ -360,6 +361,7 @@ internal static FinalizerBlocker MaybeStart()
360
361
return new FinalizerBlocker ( hangLock ) ;
361
362
}
362
363
364
+ [ MethodImpl ( CodeGenHelper . AggressiveOptimizationOption ) ]
363
365
public void Dispose ( )
364
366
{
365
367
if ( hangLock is not null )
0 commit comments