Repository navigation
Open
Labels
Milestone
Description
The test being added in #90318 fails on Mono in full AOT mode:
22:14:29.962 Running test: JIT/Regression/JitBlue/Runtime_90219/Runtime_90219/Runtime_90219.dll
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.NullReferenceException: Object reference not set to an instance of an object
at Runtime_90219.MainInner(IRuntime rt)
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Runtime_90219.TestEntryPoint()
at Program.<<Main>$>g__TestExecutor335|0_336(StreamWriter tempLogSw, StreamWriter statsCsvSw, <>c__DisplayClass0_0& )
Activity
ivanpovazan commentedon Aug 16, 2023
By analysing the provided CI build and reproducing locally this seems to only fail in full AOT mode.
The tests passes on:
osx-x64 Release AllSubsets_Mono_Minijit_RuntimeTests minijithttps://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-90318-merge-cedc27ee86b44aab89/Regression_2/1/Regression_2.testResults.xml.txt?helixlogtype=resultivanpovazan commentedon Aug 16, 2023
The crash seems to be related to using custom
AssemblyLoadContextin fullAOT mode with Mono, which doesn't seem to initialize static members of the reflected type properly. Using the default ALCAssemblyLoadContext.Defaultworks properly.A smaller repro:
Running the above in full AOT mode prints:
ivanpovazan commentedon Aug 18, 2023
@vargaz do we support loading AOT images for assemblies from non-default ALC?
lambdageek commentedon Aug 18, 2023
It's a collectible ALC. So it looks like we reall dont' support it.
runtime/src/mono/mono/mini/aot-runtime.c
Lines 1965 to 1970 in 5ef2a9b
I think that
Invokeshould throw something instead of allowing the method to execute somehowUpdate but on the other hand, we apparently turn all ALCs into non-collectible ALCs??
runtime/src/mono/mono/metadata/assembly-load-context.c
Line 43 in 5ef2a9b
lambdageek commentedon Aug 18, 2023
I think
load_imagein aot-runtime.c shouldn't usemono_alc_get_ambient()which always just returnsmono_alc_get_default(). It should use the ALC of the AOT image's module.because in
decode_klass_refwe do this:so we always end up with a reference to the
MonoClass*from the default ALC. So I bet when we go to initialize static fields, we share the runtime vtable of the default ALC