- Implement a machine-wide setting by adding the following registry key and value:
- Implement an application-level setting by adding (or merging) the following section to your application config file:
<NGenReserveForJumpStubs value="5" />
- The .NET Framework encodes method calls as relative 32-bit jumps for performance reasons. On a 64-bit system, caller and callee can be further apart than 2 GB (in address space). Because this exceeds the address range of a signed 32-bit offset, .NET will create a jump stub within 2 GB of the caller. This jump stub can then make the “long” jump to anywhere in the 64-bit address space.
- The JIT and NGen mitigations work slightly differently. Both of them reserve extra address space up front, but the point where this reservation is made differs between the two.
- NGenReserveForJumpStubs is a percentage of virtual NGen image size (percentReserveForJumpStubs).
- A typical jump stub is 12 bytes. For more information, see JUMP_ALLOCATE_SIZE.
- The memory is allocated and reserved close to the address where the NGen image was loaded (the exact algorithm is EEJitManager::EnsureJumpStubReserve). The memory is committed when there is a need to allocate a jump stub, and when there is no other suitable address space available.
- The previously mentioned mitigation doesn’t modify the content of NGen images. The NGen images have the same disk footprint both with and without mitigation.
- There is currently no good way to detect when the application is getting close to the limit. You must monitor for the OutOfMemoryException to determine whether the reserved space is sufficient.
- You may receive the OutOfMemoryException even if there is a lot of unused memory because this specific error is related to the availability of memory within a 2-GB address range radius of the caller.
- You shouldn’t change the default value of CodeHeapReserveForJumpStubs, because it may not be related to the issue described above. We have not seen case where the actual application would have to adjust this setting as a workaround.
- Setting NGenReserveForJumpStubs to a significantly higher value may lead to reduced performance and the risk of exposing other subtle issues.
For IT users
- This issue may also occur on other versions of the .NET Framework. However, the workaround is currently applicable only to the .NET Framework 4.6.1.
- This is a very rare issue that only affects very large workloads that have a very particular execution pattern. More than 99 percent of all workloads will ever experience this issue.
- After the application throws an OutOfMemory exception, the only recommended way to recover is to restart the application.
Article ID: 3152158 - Last Review: May 10, 2016 - Revision: 1