Skip to content

Call the jit shutdown logic on crossgen2 shutdown #56187

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

Merged
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
41 changes: 38 additions & 3 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,38 @@ private struct PgoInstrumentationResults
[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;
}
Comment on lines +84 to +93
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What thread safety guarantees is the lock giving us here? I would expect a double-checked locking pattern at least.

}

[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);
Expand Down Expand Up @@ -129,9 +159,14 @@ public static void Startup()
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ 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
19 changes: 17 additions & 2 deletions src/coreclr/tools/aot/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,14 @@ private static int Main(string[] args)
#if DEBUG
try
{
return new Program().Run(args);
try
{
return new Program().Run(args);
}
finally
{
ReadyToRunCodegenCompilationBuilder.ShutdownJit();
}
}
catch (CodeGenerationFailedException ex) when (DumpReproArguments(ex))
{
Expand All @@ -992,7 +999,14 @@ private static int Main(string[] args)
#else
try
{
return new Program().Run(args);
try
{
return new Program().Run(args);
}
finally
{
ReadyToRunCodegenCompilationBuilder.ShutdownJit();
}
}
catch (Exception e)
{
Expand All @@ -1001,6 +1015,7 @@ private static int Main(string[] args)
return 1;
}
#endif

}
}
}
5 changes: 5 additions & 0 deletions src/coreclr/tools/aot/jitinterface/jitwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ DLL_EXPORT int JitCompileMethod(
return 1;
}

DLL_EXPORT void JitProcessShutdownWork(ICorJitCompiler * pJit)
{
return pJit->ProcessShutdownWork(nullptr);
}

DLL_EXPORT unsigned GetMaxIntrinsicSIMDVectorLength(
ICorJitCompiler * pJit,
CORJIT_FLAGS * flags)
Expand Down