Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify JIT shutdown logic in crossgen2 #56687

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -159,11 +153,6 @@ public static void Startup()
jitStartup(GetJitHost(JitConfigProvider.Instance.UnmanagedInstance));
}

public static void ShutdownJit()
{
JitPointerAccessor.ShutdownJit();
}

public CorInfoImpl()
{
_jit = JitPointerAccessor.Get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> options)
{
var builder = new ArrayBuilder<KeyValuePair<string, string>>();
Expand Down
18 changes: 2 additions & 16 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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)
{
Expand Down