Skip to content

Commit e9d2838

Browse files
committed
Add ZapDisable description
Also, update some of the text, and fix an issue with the useLegacyJit config file syntax.
1 parent 768b1fe commit e9d2838

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

docs/testing-with-ryujit.md

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ in case problems occur.
1414

1515
**Note** The registry methods below use either `HKEY_LOCAL_MACHINE` or `HKEY_CURRENT_USER`. Using `HKEY_LOCAL_MACHINE` makes the setting applicable to the entire machine and all users. Using `HKEY_CURRENT_USER` makes the setting applicable to just the current user. If using the registry methods, the latter is generally preferable.
1616

17+
In general, you should choose the least impactful option. Choose a per-application setting if possible, and only move to a per-user or per-machine setting if necessary. Note that per-application settings are not available for ASP.NET applications.
18+
1719
Disable RyuJIT
1820
==============
1921

@@ -29,7 +31,7 @@ existing NGEN images that have been compiled by the new JIT continue to be used.
2931

3032
<configuration>
3133
<runtime>
32-
<useLegacyJit enabled="1">
34+
<useLegacyJit enabled="1" />
3335
</runtime>
3436
</configuration>
3537

@@ -58,17 +60,9 @@ existing NGEN images that have been compiled by the new JIT continue to be used.
5860
Disable loading NGEN Images
5961
===========================
6062

61-
If you encounter a bug when you use the new JIT, and if the bug manifests itself
62-
in an NGEN image, use any of the following methods to force certain named
63-
assemblies to be recompiled by the JIT and not use the existing native images. You
64-
will generally pair one of these methods with the same numbered method above to get an NGEN image
65-
to fall back to JIT compilation, and, in addition, do that JIT compilation with the legacy
66-
JIT.
63+
If you encounter a bug when you use the new JIT, and if the bug manifests itself in a function in an NGEN native image (see [here](https://msdn.microsoft.com/en-us/library/6t9t5wcf(v=vs.110).aspx) for details), use any of the following methods to force certain named assemblies to be recompiled by the JIT and not use the existing native images. You will generally pair one of these methods with the same numbered method above to get an NGEN image to fall back to JIT compilation, and, in addition, do that JIT compilation with the legacy JIT.
6764

68-
In the examples below, we wish to prevent using the NGEN images of three assemblies, named
69-
`assembly_one.dll`, `assembly_two.dll`, and `assembly_three.dll`. We specify the assemblies
70-
using simple assembly names (no public key token, no architecture, and so on). The assembly names
71-
are specified without using the `.dll` file name extension.
65+
In the examples below, we wish to prevent using the NGEN images of three assemblies, named `assembly_one.dll`, `assembly_two.dll`, and `assembly_three.dll`. We specify the assemblies using simple assembly names (no public key token, no architecture, and so on). The assembly names are specified without using the `.dll` file name extension.
7266

7367
* **Method 1: : per-application config file**. Add the following text to the `<app>.exe.config` file. Create
7468
the indicated sections if they do not already exist.
@@ -103,7 +97,52 @@ are specified without using the `.dll` file name extension.
10397
Value: assembly_one;assembly_two;assembly_three
10498

10599
**Note** This is a semicolon-delimited list of simple assembly names.
100+
101+
Disabling the use of all NGEN images
102+
====================================
103+
104+
To prevent any NGEN native image from being used, and force all code to be compiled with the JIT compiler, you can use the ZapDisable configuration variable, as follows. You might choose to do this as an experiment, to see if any NGEN native image contains generated code that is inducing a bug in your application. Generally, if an NGEN native image does have a problem, and the identity of that native image can be determined, using one of the `DisableNativeImageLoadList` mechanisms described above is preferable.
105+
106+
**Note** This setting applies to both the 32-bit and 64-bit JIT. Thus, setting this globally will affect all 32-bit .NET applications as well. This is particularly true for **Method 2: environment variable**.
107+
108+
**Note 2** NGEN provides significant performance improvements to .NET applications. Disabling the use of NGEN will cause the perfomance of .NET applications to be significantly worse.
109+
110+
* **Method 1: per-application config file**. Add the following text to the `<app>.exe.config` file. Create
111+
the indicated sections if they do not already exist.
112+
113+
**Note** In this file name, `<app>` represents the actual name of the
114+
application. So, for example, for `MyApp.exe`, you will have `MyApp.exe.config`.
115+
116+
<configuration>
117+
<runtime>
118+
<ZapDisable enabled="1" />
119+
</runtime>
120+
</configuration>
121+
122+
Note that Method 1 does not apply to ASP.NET websites; you cannot use this method in web.config files.
106123

124+
This method is preferable as it is scoped to just one application.
125+
126+
* **Method 2: environment variable**. Set the following environment variable:
127+
128+
COMPLUS_ZapDisable=1
129+
130+
This method affects any environment that inherits this environment variable. This might be just a single
131+
console session, or it might affect the entire machine, if you set the environment variable globally.
132+
133+
* **Method 3: registry**. Using Registry Editor (regedit.exe), find either of the following subkeys:
134+
135+
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
136+
HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework
137+
138+
Then, add the following:
139+
140+
Value name: ZapDisable
141+
Type: DWORD (32-bit) Value (also called REG_WORD)
142+
Value: 1
143+
144+
**Note** Windows has both 32-bit and 64-bit registry sections. The addresses shown above use the 64-bit registry path, so are appropriate for troubleshooting RyuJIT and not affecting 32-bit .NET applications. On a 64-bit machine, the 32-bit registry path for the `HKEY_LOCAL_MACHINE` case is `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework`.
145+
107146
Disable Tail Call Optimization
108147
==============================
109148

@@ -123,7 +162,7 @@ You can disable tail call optimization in RyuJIT with the following instructions
123162
Disabling optimization of a function
124163
====================================
125164

126-
You can selectively disable JIT optimization of a particular function by annotating that function with `MethodImplOptions.NoOptimization`. For example, in C#:
165+
If you determine that the JIT is incorrectly optimizing a particular function, you can selectively disable JIT optimization for that function by annotating that function with `MethodImplOptions.NoOptimization`. For example, in C#:
127166

128167
using System.Runtime.CompilerServices;
129168
...
@@ -136,6 +175,8 @@ You can selectively disable JIT optimization of a particular function by annotat
136175
In this case, the annotated `add` function will not be optimized. You can see more detail about `MethodImplAttribute`
137176
[here](https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimplattribute(v=vs.110).aspx).
138177

178+
This is only effective in solving a code generation problem if the incorrect code being generated by the JIT is due to optimization, as opposed to being due to unoptimized code generation.
179+
139180
Note that this method applies to all .NET JIT compilers.
140181

141182
Additional Notes

0 commit comments

Comments
 (0)