-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Context: https://discord.com/channels/732297728826277939/732297837953679412/1334614545871929345 PR #9716 was crashing with a stack overflow: I NativeAotFromAndroid: at Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference, JniMethodInfo, JniArgumentValue*) + 0xa8 I NativeAotFromAndroid: at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String, IJavaPeerable, JniArgumentValue*) + 0x184 I NativeAotFromAndroid: at Android.App.Application.n_OnCreate(IntPtr jnienv, IntPtr native__this) + 0xa8 I NativeAotFromAndroid: at libNativeAOT!<BaseAddress>+0x4f3e44 The cause was the topmost frame: `CallVoidMethod()`, which performs a *virtual* method invocation. The stack overflow was that Java `MainApplication.onCreate()` called C# `Application.n_OnCreate()`, which called `InvokeVirtualVoidMethod()`, which did a *virtual* invocation back on `MainApplication.onCreate()`, … `InvokeVirtualVoidMethod()` should have been calling `CallNonvirtualVoidMethod()`; why wasn't it? Further investigation showed: Created PeerReference=0x2d06/G IdentityHashCode=0x8edcb07 Instance=0x957d2a Instance.Type=Android.App.Application, Java.Type=my/MainApplication which at a glance seems correct, but isn't: the `Instance.Type` for a `Java.Type` of `my/MainApplication` should be `MainApplication`, *not* `Android.App.Application`! Because the runtime type of this value was `Application`, it was warranted and expected that `InvokeVirtualVoidMethod()` would do a virtual invocation! So, why did the avove `Created PeerReference …` line show the wrong type? Because `NativeAotTypeManager.CreatePeer()` needs to check for bindings of the the runtime type of the Java handle *before* using the `targetType` parameter, because the targetType parameter will *never* be for that of a custom subclass. Copy *lots* of code from dotnet/java-interop -- showing that this needs some major cleanup & refactoring -- so that we properly check the runtime type of `reference` + base classes when trying to determine the type of the proxy to create. This fixes the stack overflow.
- Loading branch information
Showing
2 changed files
with
151 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters