Skip to content

Commit 70f4c48

Browse files
Initial document for JIT and GC stress usage (dotnet#58147)
* Initial document for JIT and GC stress.
1 parent 618abd6 commit 70f4c48

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Investigating JIT and GC Hole stress
2+
3+
There are two stressing related features for the JIT and JIT generated GC info – JIT Stress and GC Hole Stress. These features provide a way during development to discover edge cases and more "real world" scenarios without having to develop complex applications.
4+
5+
## JIT Stress (`DEBUG` builds only – Debug and Checked)
6+
7+
Enabling JIT Stress can be done in several ways. Setting `DOTNET_JitStress` to a non-zero integer value that will generate varying levels of JIT optimizations based on a hash of the method's name or set to a value of two (for example, `DOTNET_JitStress=2`) that will apply all optimizations. Another way to enable JIT Stress is by setting `DOTNET_JitStressModeNamesOnly=1` and then requesting the stress modes, space delimited, in the `DOTNET_JitStressModeNames` variable (for example, `DOTNET_JitStressModeNames=STRESS_USE_CMOV STRESS_64RSLT_MUL STRESS_LCL_FLDS`).
8+
9+
A comprehensive list of stress modes can be found in [`compiler.h`](/src/coreclr/jit/compiler.h) – search for the `STRESS_MODES` define.
10+
11+
It is often useful to use [JIT Dump](./viewing-jit-dumps.md) in tandem with JIT Stress. Using a JIT Dump file, one can discover which stress modes were applied. An example of how to find an applied stress mode is looking for a statement similar to:
12+
13+
```
14+
*** JitStress: STRESS_NULL_OBJECT_CHECK ***
15+
```
16+
17+
## GC Hole Stress
18+
19+
Enabling GC Hole Stress causes GCs to always occur in specific locations and that helps to track down GC holes. GC Hole Stress can be enabled using the `DOTNET_GCStress` environment variable. It takes a non-zero integer value in hexadecimal format. Note these values can be or'd together (for example, `0x3 = 0x1 | 0x2`).
20+
21+
- **0x1** – GC on all allocs and 'easy' places.
22+
- **0x2** – GC on transitions to Preemptive GC.
23+
- **0x4** – GC on every allowable JITed instr.
24+
- **0x8** – GC on every allowable R2R instr.
25+
- **0xF** – GC only on a unique stack trace.
26+
27+
### Common combinations
28+
29+
**0x1 | 0x2** – 0x3 are "in the VM". Failures in 0x1 or 0x2 can be due to VM-related reasons, like lack of GC reporting/pinning in interop frames.
30+
31+
**0x4 | 0x8** – 0xC runs GC stress for each JIT generated instruction (either dynamically or AOT, in R2R). Failures in 0x4 or 0x8 typically mean a failure in GC info. Only happens once for any instruction, so can miss failures that only occur on non-first GCs. This mode replaces the target instuction with a with breakpoint instruction and that affects disassembly.

0 commit comments

Comments
 (0)