dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.19k stars 4.72k forks source link

GcStress: choose strategy for instrumenting prejitted code #10184

Open AndyAyersMS opened 6 years ago

AndyAyersMS commented 6 years ago

GcStress currently tries to instrument NGEN precompiled methods twice: once during Module::Initialize (with a twist for the core library) and a second time during MethodDesc::PrepareILBasedCode (with a twist for prejitted IL stubs).

R2R precompiled methods are never instrumented, currently.

Seems like we should have only one strategy and it should apply to all cases of prejitted code.

Early instrumentation during module load is nice because it avoids race conditions that can plague on-demand instrumentation. But there is an upfront cost as potentially thousands of methods need to be instrumented but only a few of them will ever be executed.

Late instrumentation is more pay for play but must be done carefully so that no thread can see a partially instrumented method.

VSadov commented 1 month ago

I'd try instrumenting on module load and see what happens. If that would be more reliable. It might seem very redundant to instrument everything in the module, but it will be roughly proportional to the module size (like the load itself and any kind of relocation/fixups). Also, perhaps next to the cost of doing GC stress it might not be a big difference.