[DllImport(JitLibrary)]
private extern static IntPtr jitStartup(IntPtr host);
- [DllImport(JitLibrary)]
- private extern static IntPtr getJit();
+ 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()
+ {
+ if (s_jit != IntPtr.Zero)
+ {
+ JitProcessShutdownWork(s_jit);
+ }
+ }
+
+ private static IntPtr s_jit;
+ }
[DllImport(JitLibrary)]
private extern static IntPtr getLikelyClass(PgoInstrumentationSchema* schema, uint countSchemaItems, byte*pInstrumentationData, int ilOffset, out uint pLikelihood, out uint pNumberOfClasses);
jitStartup(GetJitHost(JitConfigProvider.Instance.UnmanagedInstance));
}
+ public static void ShutdownJit()
+ {
+ JitPointerAccessor.ShutdownJit();
+ }
+
public CorInfoImpl()
{
- _jit = getJit();
+ _jit = JitPointerAccessor.Get();
if (_jit == IntPtr.Zero)
{
throw new IOException("Failed to initialize JIT");
((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
{
- return new Program().Run(args);
+ try
+ {
+ return new Program().Run(args);
+ }
+ finally
+ {
+ ReadyToRunCodegenCompilationBuilder.ShutdownJit();
+ }
}
catch (CodeGenerationFailedException ex) when (DumpReproArguments(ex))
{
#else
try
{
- return new Program().Run(args);
+ try
+ {
+ return new Program().Run(args);
+ }
+ finally
+ {
+ ReadyToRunCodegenCompilationBuilder.ShutdownJit();
+ }
}
catch (Exception e)
{
return 1;
}
#endif
+
}
}
}