From bf95049818f3eb968345945192e9ab341429bc27 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 1 Aug 2024 19:34:39 +0200 Subject: [PATCH 1/2] Diagnose beginInlining problem --- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index cecfbe0e5d5854..2d704b4037c687 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3174,14 +3174,36 @@ private void setEHinfo(uint EHnumber, ref CORINFO_EH_CLAUSE clause) } private readonly Stack> _stashedPrecodeFixups = new Stack>(); - private readonly Stack> _stashedInlinedMethods = new Stack>(); + private readonly Stack> _stashedInlinedMethods = FailFastIfNull(new Stack>()); private void beginInlining(CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_STRUCT_* inlineeHnd) { - _stashedPrecodeFixups.Push(_precodeFixups); - _precodeFixups = null; - _stashedInlinedMethods.Push(_inlinedMethods); - _inlinedMethods = null; + try + { + _stashedPrecodeFixups.Push(_precodeFixups); + _precodeFixups = null; + _stashedInlinedMethods.Push(_inlinedMethods); + _inlinedMethods = null; + } + catch + { + Environment.FailFast("Caught exception in beginInlining"); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Stack> FailFastIfNull(Stack> s) + { + var array = Accessor>.GetArray(s); + if (array == null) + Environment.FailFast("Got null array"); + return s; + } + + class Accessor + { + [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_array")] + public extern static ref T[] GetArray(Stack stack); } private void reportInliningDecision(CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_STRUCT_* inlineeHnd, CorInfoInline inlineResult, byte* reason) From dcdb784aa32887c88bfdfba67e16a6dd07b1f92f Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Fri, 2 Aug 2024 11:42:00 +0200 Subject: [PATCH 2/2] Force inlining, do for both stacks --- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 2d704b4037c687..99f051e079ef9c 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3173,7 +3173,7 @@ private void setEHinfo(uint EHnumber, ref CORINFO_EH_CLAUSE clause) _ehClauses[EHnumber] = clause; } - private readonly Stack> _stashedPrecodeFixups = new Stack>(); + private readonly Stack> _stashedPrecodeFixups = FailFastIfNull(new Stack>()); private readonly Stack> _stashedInlinedMethods = FailFastIfNull(new Stack>()); private void beginInlining(CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_STRUCT_* inlineeHnd) @@ -3191,10 +3191,10 @@ private void beginInlining(CORINFO_METHOD_STRUCT_* inlinerHnd, CORINFO_METHOD_ST } } - [MethodImpl(MethodImplOptions.NoInlining)] - private static Stack> FailFastIfNull(Stack> s) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static Stack FailFastIfNull(Stack s) { - var array = Accessor>.GetArray(s); + var array = Accessor.GetArray(s); if (array == null) Environment.FailFast("Got null array"); return s;