diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index ff268b787e440d..d5dc33be71cf71 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -79,32 +79,26 @@ private static class JitPointerAccessor [DllImport(JitLibrary)] private extern static IntPtr getJit(); - public static IntPtr Get() - { - if (s_jit != IntPtr.Zero) - { - return s_jit; - } - - lock(typeof(JitPointerAccessor)) - { - s_jit = getJit(); - return s_jit; - } - } - [DllImport(JitSupportLibrary)] private extern static CorJitResult JitProcessShutdownWork(IntPtr jit); - public static void ShutdownJit() + static JitPointerAccessor() { + s_jit = getJit(); + if (s_jit != IntPtr.Zero) { - JitProcessShutdownWork(s_jit); + AppDomain.CurrentDomain.ProcessExit += (_, _) => JitProcessShutdownWork(s_jit); + AppDomain.CurrentDomain.UnhandledException += (_, _) => JitProcessShutdownWork(s_jit); } } - private static IntPtr s_jit; + public static IntPtr Get() + { + return s_jit; + } + + private static readonly IntPtr s_jit; } [DllImport(JitLibrary)] @@ -159,11 +153,6 @@ public static void Startup() jitStartup(GetJitHost(JitConfigProvider.Instance.UnmanagedInstance)); } - public static void ShutdownJit() - { - JitPointerAccessor.ShutdownJit(); - } - public CorInfoImpl() { _jit = JitPointerAccessor.Get(); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilationBuilder.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilationBuilder.cs index 4b5d4a7ca31684..c1207a4b5b2f00 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilationBuilder.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilationBuilder.cs @@ -65,12 +65,6 @@ public ReadyToRunCodegenCompilationBuilder( ((ReadyToRunCompilerContext)context).SetCompilationGroup(group); } - // Shutdown the Jit if it has been loaded. This must only be called once per process - public static void ShutdownJit() - { - CorInfoImpl.ShutdownJit(); - } - public override CompilationBuilder UseBackendOptions(IEnumerable options) { var builder = new ArrayBuilder>(); diff --git a/src/coreclr/tools/aot/crossgen2/Program.cs b/src/coreclr/tools/aot/crossgen2/Program.cs index d5418516e1cd16..afae84f57f6fac 100644 --- a/src/coreclr/tools/aot/crossgen2/Program.cs +++ b/src/coreclr/tools/aot/crossgen2/Program.cs @@ -989,14 +989,7 @@ private static int Main(string[] args) #if DEBUG try { - try - { - return new Program().Run(args); - } - finally - { - ReadyToRunCodegenCompilationBuilder.ShutdownJit(); - } + return new Program().Run(args); } catch (CodeGenerationFailedException ex) when (DumpReproArguments(ex)) { @@ -1005,14 +998,7 @@ private static int Main(string[] args) #else try { - try - { - return new Program().Run(args); - } - finally - { - ReadyToRunCodegenCompilationBuilder.ShutdownJit(); - } + return new Program().Run(args); } catch (Exception e) {