Skip to content

Commit

Permalink
Tweak crossgen2 so that SuperPMI should work (#42555)
Browse files Browse the repository at this point in the history
- Remove unneeded getBuiltinClass for CLASSID_ARGUMENT_HANDLE from SuperPMI
- Tweak crossgen2 single threaded compilation to reliably only use exactly 1 for compilation
  - This allows superpmi to rely on the detail that handles are unique.
  - This assumes that superpmi collection is done with the compilation options `--parallelism 1`
  • Loading branch information
davidwrighton authored Sep 22, 2020
1 parent ab05dc8 commit 0d62c36
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ CorJitResult __stdcall interceptor_ICJC::compileMethod(ICorJitInfo*
our_ICorJitInfo.getBuiltinClass(CLASSID_FIELD_HANDLE);
our_ICorJitInfo.getBuiltinClass(CLASSID_METHOD_HANDLE);
our_ICorJitInfo.getBuiltinClass(CLASSID_STRING);
our_ICorJitInfo.getBuiltinClass(CLASSID_ARGUMENT_HANDLE);
our_ICorJitInfo.getBuiltinClass(CLASSID_RUNTIME_TYPE);

#ifdef fatMC
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ private void CompileMethodCleanup()

private IntPtr ObjectToHandle(Object obj)
{
// SuperPMI relies on the handle returned from this function being stable for the lifetime of the crossgen2 process
// If handle deletion is implemented, please update SuperPMI
IntPtr handle;
if (!_objectToHandle.TryGetValue(obj, out handle))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,7 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor
{
using (PerfEventSource.StartStopEvents.JitEvents())
{
ParallelOptions options = new ParallelOptions
{
MaxDegreeOfParallelism = _parallelism
};
Parallel.ForEach(obj, options, dependency =>
Action<DependencyNodeCore<NodeFactory>> compileOneMethod = (DependencyNodeCore<NodeFactory> dependency) =>
{
MethodWithGCInfo methodCodeNodeNeedingCode = dependency as MethodWithGCInfo;
MethodDesc method = methodCodeNodeNeedingCode.Method;
Expand All @@ -486,6 +482,8 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor
{
using (PerfEventSource.StartStopEvents.JitMethodEvents())
{
// Create only 1 CorInfoImpl per thread.
// This allows SuperPMI to rely on non-reuse of handles in ObjectToHandle
CorInfoImpl corInfoImpl = _corInfoImpls.GetValue(Thread.CurrentThread, thread => new CorInfoImpl(this));
corInfoImpl.CompileMethod(methodCodeNodeNeedingCode);
}
Expand All @@ -506,7 +504,23 @@ protected override void ComputeDependencyNodeDependencies(List<DependencyNodeCor
if (Logger.IsVerbose)
Logger.Writer.WriteLine($"Warning: Method `{method}` was not compiled because `{ex.Message}` requires runtime JIT");
}
});
};

// Use only main thread to compile if parallelism is 1. This allows SuperPMI to rely on non-reuse of handles in ObjectToHandle
if (_parallelism == 1)
{
foreach (var dependency in obj)
compileOneMethod(dependency);
}
else
{
ParallelOptions options = new ParallelOptions
{
MaxDegreeOfParallelism = _parallelism
};

Parallel.ForEach(obj, options, compileOneMethod);
}
}

if (_methodILCache.Count > 1000)
Expand Down

0 comments on commit 0d62c36

Please sign in to comment.