Skip to content

SIGSEGV in art::JNI::GetObjectClass (dangling jobject) at fleet scale — race between AOT managed-to-native wrapper's GC-safe transition and handle invalidation #12765

Open

Description

@branomalovec

Android framework version

net10.0-android

Affected platform version

.NET 10, Android runtime pack Microsoft.Android.Runtime.Mono.36.android-arm64 36.1.30 (verified by SHA-256 of libmonodroid.so in shipped AAB); crash signature observed since at least May 2026 on earlier versions too. Devices: Samsung/Pixel/others, Android 12-16, arm64-v8a.

Description

Production .NET MAUI app (net10.0-android, Mono runtime, full AOT with RunAOTCompilation=true, assembly store), ~8,000-device fleet. We collect ApplicationExitInfo records (incl. native-crash tombstones). One native crash signature dominates everything else:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0        // sometimes 0x4
Crashed thread: <main thread>                                     // or ".NET TP Worker"
  #00 libart.so +0x69ecf0  art::JNI<false>::GetObjectClass(_JNIEnv*, _jobject*)
  dotnet/android#1 split_config.arm64_v8a.apk +0x59f50                         // earlier app build: +0x58be0

Frequency: ~330 crash events from ~290 distinct devices per week (~4% of the fleet weekly, ~40-60/day in steady state). It occurs on both the UI thread and thread-pool threads, across unrelated screens, elevated under GC pressure (e.g. heavy allocation right after app update: DB migration + full data sync) but persistent during completely normal use.

Frame #1 identified — shared AOT transition wrapper, race window visible

We symbolized frame #1 by recompiling Java.Interop.dll with mono-aot-cross keeping symbols (the Android SDK's AOT step passes -s in ld-flags, so shipped AOT images are always stripped) and byte-matching against the stripped image from our shipped AAB (code regions are byte-identical at the same file offsets between runtime 36.1.30 and 36.1.43):

  • Both offsets are inside Mono's shared managed-to-native native_indirect signature wrappers in libaot-Java.Interop.dll.so (wrapper_managed_to_native ... wrapper_native_indirect_...). +0x59f50 is exactly the wrapper's indirect call instruction (blr x2) for the 2-argument signature matching GetObjectClass(env, jobject) — unwinders report caller frames as LR-4. Because the wrappers are shared per signature, every caller funnels through the same address — hence exactly one offset per app build across the whole fleet.
  • The race window: the wrapper calls mono_threads_enter_gc_safe_region_unbalanced immediately before the indirect JNI call. The raw jobject was extracted from the JniObjectReference before entering GC-safe mode; a collection (and GC-bridge handle processing) running concurrently in that window can invalidate the handle, so ART dereferences a dangling jobject → SIGSEGV with fault addr 0x0/0x4.
  • IL scan of the linked assemblies shows the managed GetObjectClass callers funneling into this wrapper: JniRuntime.JniValueManager.CreatePeer, AndroidTypeManager/JavaTypeManager.CreateInstance (the Java→managed peer-creation path), JniEnvironment.Types.GetJniTypeNameFromInstance, Android.Runtime.JNIEnv.GetObjectClass/InvokeConstructor/AssertCompatibleArrayTypes, JavaConvert.GetTypeMapping.
  • Ruled out on the native side: the exact shipped libmonodroid.so (36.1.30) contains five JNIEnv->GetObjectClass call sites (init + 4 in OSBridge), none matching the crash offsets; libmonosgen-2.0.so and the crypto PAL contain none.

Possibly related: dotnet/runtime#123495 (SIGSEGV inside sgen-tarjan-bridge.c on .NET 10 Android), dotnet/runtime#112109.

Related diagnosability gap

The crashing thread's backtrace always ends at frame #1 because Mono's Android AOT emits no OS-readable unwind info — no .eh_frame/PT_GNU_EH_FRAME in the AOT images, and the LLVM AOT backend likewise generates assembly without any .cfi directives (verified with mono-aot-cross ... llvm). Consequently no Mono-based Android app can symbolize past the first managed frame in ApplicationExitInfo / Play Console / Crashlytics native crash reports. If AOT could emit CFI (even optionally), issues like this one would arrive with full stacks.

We can attach full tombstones (all threads + memory maps) and the exact shipped libmonodroid.so / libaot-*.so binaries on request, and we can measure any candidate fix at fleet scale within days via a staged rollout.

Steps to Reproduce

No deterministic repro — statistical at fleet scale (hundreds of events/week, ~4% of devices weekly). Elevated under GC pressure (first launch after app update: database migration + full sync), but occurs steadily during normal use on both UI and thread-pool threads. We are setting up a local repro rig (debuggable build + CheckJNI + small nursery GC stress + UI soak) and can run experimental builds.

Did you find any workaround?

Not yet. Evaluating MONO_GC_PARAMS=bridge-implementation=old and the latest servicing runtime (36.1.69) as mitigations; happy to report fleet-scale telemetry for either.

Relevant log output

Activity

  1. jonathanpeppers commented on Aug 11, 2026

    @jonathanpeppers
    Member

    Can you share the full logcat output, this is just a snippet:

    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0        // sometimes 0x4
    Crashed thread: <main thread>                                     // or ".NET TP Worker"
      #00 libart.so +0x69ecf0  art::JNI<false>::GetObjectClass(_JNIEnv*, _jobject*)
      dotnet/android#1 split_config.arm64_v8a.apk +0x59f50                         // earlier app build: +0x58be0
    
  2. branomalovec commented on Aug 11, 2026

    @branomalovec
    Author

    Thanks for the quick look @jonathanpeppers.

    There is unfortunately no logcat to share: these reports come from production devices via ApplicationExitInfo.getTraceInputStream() telemetry (REASON_CRASH_NATIVE → tombstone proto), not from a device we hold. The two-frame backtrace is the complete backtrace of the crashing thread as the platform produced it — nothing on our side trims it (our uploader prints up to 10 frames, and other native crashes from the same fleet do show deeper stacks, e.g. libc/e_sqlite3 ones). The unwind ends at frame #1 because the AOT images carry no unwind info (no .eh_frame/PT_GNU_EH_FRAME, and no .cfi directives even from the LLVM AOT backend), as described in the "diagnosability gap" section — the OS unwinder recovers frame #1 from LR and cannot walk past AOT code.

    What I can offer instead, immediately:

    1. Disassembly of the faulting wrapper from the shipped libaot-Java.Interop.dll.so (symbolized via a byte-identical mono-aot-cross rebuild of the same runtime version). Frame #01 = +0x59f50 is the blr x2 below. Note the shape: the call target and argument values are captured in the wrapper frame at entry, then the thread enters the GC-safe region, and only then the JNI function is invoked:

    0000000000059ec0 <wrapper_managed_to_native__Module_wrapper_native_indirect_intptr_intptr_intptr_intptr__intptr_intptr>:
       59ec0: stp  x29, x30, [sp, #-0xc0]!
       ...
       59ef0: str  x0, [x29, #0x10]     ; incoming args captured at wrapper entry
       59ef4: str  x1, [x29, #0x18]
       59ef8: str  x2, [x29, #0x20]
       ...
       59f10: bl   plt__jit_icall_mono_threads_state_poll
       ...
       59f3c: bl   plt__jit_icall_mono_threads_enter_gc_safe_region_unbalanced
       59f40: str  x0, [x29, #0xb8]
       59f44: ldr  x0, [x29, #0x18]     ; args reloaded from the frame
       59f48: ldr  x1, [x29, #0x20]
       59f4c: ldr  x2, [x29, #0x10]
       59f50: blr  x2                   ; <-- crash frame dotnet/android#1 (reported as LR-4); target = JNI GetObjectClass
       59f54: mov  x1, x0
       ...
       59f64: bl   plt__jit_icall_mono_threads_exit_gc_safe_region_unbalanced

    The jobject argument value is fixed before mono_threads_enter_gc_safe_region_unbalanced; once the thread is GC-safe, a concurrent collection + GC-bridge handle processing can invalidate that handle before/while ART dereferences it (fault addr 0x0/0x4 inside art::JNI<false>::GetObjectClass).

    2. Binaries on request: the exact shipped libmonodroid.so (runtime pack 36.1.30), the stripped libaot-Java.Interop.dll.so from our AAB, and the symbol-bearing rebuild used for the analysis — tell me the preferred way to hand them over and I'll attach a zip.

    3. Full tombstone (all threads + memory maps): stored in per-device diagnostics; we've asked support to obtain an upload from an affected device and I'll attach the first one that arrives. We're also building a local repro rig (debuggable build + CheckJNI + small-nursery GC stress + UI soak) — if it fires, I'll attach the complete logcat from that.

    We can also run any experimental build and report fleet-scale telemetry within days (staged rollout, ~330 events/week baseline).

  3. jonathanpeppers commented on Aug 11, 2026

    @jonathanpeppers
    Member

    @branomalovec so all of these are calls inside libmonosgen-2.0.so? If so, I can move this to the dotnet/runtime repo.

  4. branomalovec commented on Aug 11, 2026

    @branomalovec
    Author

    Not quite — the faulting call site is not in libmonosgen-2.0.so. To be precise about where each piece lives:

    • Frame GREF logging is broken in multi-process apps #1 (the caller of the crashing JNI call) is in libaot-Java.Interop.dll.so — the Mono AOT image compiled from Java.Interop.dll. Specifically it's the AOT-generated shared managed-to-native native_indirect wrapper (disassembly in my previous comment), i.e. code emitted by the Mono AOT compiler, not hand-written runtime code.
    • Frame #00 is libart.so (art::JNI<false>::GetObjectClass dereferencing the dangling jobject).
    • libmonosgen-2.0.so itself contains no GetObjectClass call sites (we checked), but we do also see a smaller sibling family of native crashes with frames directly inside libmonosgen-2.0.so (~15 events/week, same fleet) — consistent with runtime/GC involvement.

    So the machinery involved in the race is split:

    • the wrapper codegen, mono_threads_enter/exit_gc_safe_region_unbalanced, and SGen + GC-bridge handle processing are dotnet/runtime (src/mono) territory;
    • the calling pattern that extracts the raw IntPtr from JniObjectReference and invokes through the function-pointer table is Java.Interop (this org).

    The fix could plausibly land on either side (revalidate/pin the handle across the GC-safe transition in Java.Interop, or don't invalidate in-flight handles in the runtime's bridge processing). Given the crash mechanics are GC/wrapper-level, moving to dotnet/runtime sounds right to me — possibly related to dotnet/runtime#123495 which is already in that repo. Happy to follow the issue wherever it goes and provide binaries/telemetry there.

  5. jonathanpeppers commented on Aug 11, 2026

    @jonathanpeppers
    Member

    code emitted by the Mono AOT compiler

    This would be dotnet/runtime.

    GC-bridge handle processing are dotnet/runtime (src/mono) territory;

    👍

  6. espenrl commented on Aug 26, 2026

    @espenrl

    We have a massive amount of these reported compared to the number of device installs. And with no possibility to discover the reason why. The best details we get are the following through Google Console.

    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    pid: 0, tid: 21163 >>> <redacted> <<<
    
    backtrace:
      #00  pc 0x000000000069ecf0  /apex/com.android.art/lib64/libart.so (art::JNI<false>::GetObjectClass(_JNIEnv*, _jobject*)+280)
      dotnet/runtime#1  pc 0x0000000000024240  /data/app/~~RNWoJMC5QslrqkxYoP272A==/<redacted>-9htBHCUjDex3EemFsXq1uQ==/split_config.arm64_v8a.apk
    
  7. lateralusX commented on Sep 10, 2026

    @lateralusX
    Member

    The Mono-generated wrapper_native_indirect code appears to be behaving as intended. It enters a GC-safe region around the unmanaged JNI call and receives only raw native arguments (JNIEnv*, jobject, and the function pointer). It has no information about which managed object owns the jobject, so it cannot keep that owner alive itself.

    A plausible failure sequence is:

    1. Java.Interop reads instance.Handle.
    2. That is the last managed use of instance.
    3. Mono's AOT liveness analysis ends the managed reference's live range and may reuse its register or stack location.
    4. The raw jobject is passed to GetObjectClass.
    5. While the wrapper is GC-safe, a concurrent collection can consider instance unreachable and process or finalize its JNI peer.
    6. ART receives the now-invalid jobject and crashes in GetObjectClass.

    Adding:

    var result = Java.Lang.Object.GetObject(
        instance.Handle,
        JniHandleOwnership.DoNotTransfer,
        targetType);
    
    GC.KeepAlive(instance);
    return result;

    extends the managed reference's live range through the entire native call. Mono must then preserve instance in a GC-tracked stack slot or callee-saved register, allowing the GC-safe transition to report it as a live root.

    This is the same class of premature JNI handle-owner collection addressed by #12315. That PR fixes paths which can lead through ValueManager.GetPeer() and CreatePeer() to JniEnvironment.Types.GetObjectClass().

    A useful next step would be to deploy a build containing #12315 and compare the GetObjectClass crash rate with the existing baseline.

    @jonathanpeppers, looks like its related to not keeping JNI references alive that gets passed down through the managed->native wrapper, do you plan to backport #12315?

  8. jonathanpeppers commented on Sep 10, 2026

    @jonathanpeppers
    Member

    I did the change for #12315 because CoreCLR GC seems to be more aggressive. Some of our customers that tested CoreCLR early found changes like this were needed (and actually correct).

    @branomalovec does this problem go away in .NET 11? If so, we could look into taking this to .NET 10.

  9. branomalovec commented on Sep 10, 2026

    @branomalovec
    Author

    @jonathanpeppers Not yet — we haven't run .NET 11 anywhere. Our fleet is
    net10.0-android in production (~8k devices) and a preview build can't ship to it,
    so I can't answer "does it go away" from where we sit today.

    The harder problem is that a bench test can't answer it either. There's no
    deterministic repro — it's ~330 events/week across ~290 distinct devices (~4% of
    the fleet weekly). A local .NET 11 soak that comes back clean would only tell us
    we failed to trigger a race we can't trigger on demand. Happy to run one against
    net11.0-android as a smoke check if it's useful, but I wouldn't read much into a
    negative result.

    One thing worth settling before a backport: dotnet/runtime#12315 covers the paths through
    ValueManager.GetPeer()/CreatePeer(). The IL scan in the issue found other managed
    callers funnelling into the same shared wrapper — JNIEnv.InvokeConstructor,
    JNIEnv.AssertCompatibleArrayTypes, JavaConvert.GetTypeMapping,
    JniEnvironment.Types.GetJniTypeNameFromInstance. Are those covered as well, or
    would a dotnet/runtime#12315-only backport leave some of them exposed?

  10. jonathanpeppers commented on Sep 10, 2026

    @jonathanpeppers
    Member

    GPT 6 Astra found a couple more:

    But many models seem to find false positives on this, and I've had to argue with them. 😄

  11. lateralusX commented on Sep 11, 2026

    @lateralusX
    Member

    I did the change for dotnet/android#12315 because CoreCLR GC seems to be more aggressive. Some of our customers that tested CoreCLR early found changes like this were needed (and actually correct).

    @branomalovec does this problem go away in .NET 11? If so, we could look into taking this to .NET 10.

    It will have effect on Mono as well, but since Mono is not as aggressive as CoreCLR when it comes to consider objects unreachable within a method, it will manifest much more frequently on CoreCLR compared to Mono. Since this doesn't look like a runtime issue, but related to managed object lifetime handled by caller, in this case Java.Interop code, I move this issue over to dotnet/android repro.

  12. transferred this issue fromdotnet/runtimeon Sep 11, 2026
  13. added
    needs-triage
    on Sep 11, 2026
  14. added
    Area: App Runtime
    and removed
    needs-triage
    on Sep 11, 2026
  15. keegan-gehrig commented on Oct 30, 2026

    @keegan-gehrig

    We're hitting this crash in production on .NET 10 and want to add data in support of a .NET 10 servicing backport of PR #12315 and #12754.

    Environment
    • .NET MAUI app, .NET 10.0.7 (SDK 10.0.203), Android workload 36.1.118, Mono runtime, arm64
    • Default (Tarjan) GC bridge; Mono AOT off for Release (RunAOTCompilation=false)
    • Sentry.Maui 6.2.0 with its native (NDK) integration

    Signature
    The top crash cluster in Google Play Android vitals is SIGSEGV in libart.so, frame 0 art::JNI::GetObjectClass, the same signature reported here. Play can't unwind past the next frame (managed code), and no frame in the trace is in our code. Two sample tombstones from separate crashes:

    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    pid: 0, tid: 26107 >>> app.package.name <<<
    
    backtrace:
      #00  pc 0x000000000069287c  /apex/com.android.art/lib64/libart.so (art::JNI<false>::GetObjectClass(_JNIEnv*, _jobject*)+172)
      #01  pc 0x0000000000005884
    

    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    pid: 0, tid: 28832 >>> app.package.name <<<
    
    backtrace:
      #00  pc 0x000000000064adc4  /apex/com.android.art/lib64/libart.so (art::JNI<false>::GetObjectClass(_JNIEnv*, _jobject*)+324)
      #01  pc 0x0000000000005aa4
    

    Sentry captured the same frame-0 signature independently, including on Android 12.

    Scale (Google Play, 28 days to Oct 23, one app version)
    • This signature is 74.2% of the app's Android crashes in that version: 217 users, 472 crash events.
    • User-perceived crash rate is 4.47%, four times Play's 1.09% bad-behavior threshold. About 1,570 monthly active devices.
    • Sessions (Sentry, 30 days): 23,835 of 68,221 Android sessions (35%) ended in a crash. Sentry's unsymbolicated libart.so reports include some Mono signal-handler noise, so treat this as an upper bound; the Play figures above are the conservative view.

    Pattern
    • Foreground: users see the app close on them.
    • Across devices and OS versions: Android 12 through 17; Samsung Galaxy S22 to S25 and S24 Ultra, Google Pixel 10.
    • On the main thread and on thread-pool threads.
    • Usually within a minute of a data load or sync (median 49 seconds after the last logged action, in a sample of 184 crash events). Our sync code makes no JNI calls, but it allocates heavily, which fits a GC race that fires more often when the collector is busy.
    • Started with our move from Xamarin.Forms to .NET 10 MAUI: first release 8/17, Play crash-rate warning 9/24, present in every release since. The Xamarin.Forms app never crossed Play's threshold.

    What we've ruled out
    • An app-level workaround: the handle is dropped inside Java.Interop and Mono.Android during framework calls (peer creation, type lookup, JavaAs, exception throw). GC.KeepAlive in app code can't cover those calls.
    • AndroidEnableSGenConcurrent=false: that addresses the SGen worker crash (dotnet/maui #21479), not this one. bridge-implementation=old falls back to new on .NET 10, which doesn't target this race.
    • PRs #12315 and #12754 aren't in workload 36.1.118, the latest .NET 10 Android release.

    Why we can't show the .NET 11 result
    We don't have a local repro; the crash shows only at production scale. Moving production to .NET 11 also means moving Android to CoreCLR, a full runtime change and regression cycle that puts .NET 11 evidence months out.

    Ask
    A .NET 10 servicing backport of PRs #12315 and #12754. If a build of the .NET 10 Android workload with those changes is available, we'll ship it to a staged rollout on Play and report the crash rate before and after here.

  16. jonathanpeppers commented on Nov 9, 2026

    @jonathanpeppers
    Member

    Hello all, could you try .NET 11 and find out if things have improved? It is using CoreCLR, so a completely different runtime.

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: App Runtime

    Type

    No type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions