[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)]
jitStartup(GetJitHost(JitConfigProvider.Instance.UnmanagedInstance));
}
- public static void ShutdownJit()
- {
- JitPointerAccessor.ShutdownJit();
- }
-
public CorInfoImpl()
{
_jit = JitPointerAccessor.Get();
((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<string> options)
{
var builder = new ArrayBuilder<KeyValuePair<string, string>>();
#if DEBUG
try
{
- try
- {
- return new Program().Run(args);
- }
- finally
- {
- ReadyToRunCodegenCompilationBuilder.ShutdownJit();
- }
+ return new Program().Run(args);
}
catch (CodeGenerationFailedException ex) when (DumpReproArguments(ex))
{
#else
try
{
- try
- {
- return new Program().Run(args);
- }
- finally
- {
- ReadyToRunCodegenCompilationBuilder.ShutdownJit();
- }
+ return new Program().Run(args);
}
catch (Exception e)
{