public static ManagedJit GetOrCreate() { lock (JitLock) { return(ManagedJitInstance ?? (ManagedJitInstance = new ManagedJit())); } }
static void Main(string[] args) { using (var clrJit = ManagedJit.GetOrCreate()) { // It will print `1 + 2 = 4!` instead of the expected 3 var result = JitReplaceAdd(1, 2); Console.WriteLine($"{nameof(JitReplaceAdd)}: 1 + 2 = {result}!"); } }
public void Dispose() { lock (JitLock) { if (_isDisposed) { return; } if (_overrideCompileMethodPtr == IntPtr.Zero) { return; } UninstallManagedJit(); _overrideCompileMethodPtr = IntPtr.Zero; _overrideCompileMethod = null; _isDisposed = true; ManagedJitInstance = null; _isHookInstalled = false; } }