Skip to content

Application Not Responding (ANR) when collecting GC #9795

Open
@qifu1177

Description

@qifu1177

Android framework version

net8.0-android

Affected platform version

  • VS 2022 17.12.5
  • Android version: 13
  • Device model: Galaxy Tab Active3

Expected Behavior:

_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, ...)
ANR triggered by slow operations in main thread

Description

An Application Not Responding (ANR) error on Android signifies that the application's main thread has been unresponsive for too long . The fact that the stack trace points to mono_gc_collect within libmonosgen-2.0.so strongly suggests the ANR is caused by a long-running garbage collection (GC) cycle within a Mono runtime environment.

Steps to Reproduce

  1. Run a Xamarin Android application .
  2. Run AppStartActivity(Sqlite is initialized in the actitvity)
protected override void OnResume()
{
    base.OnResume();

    var mvxApplication = Mvx.IoCProvider.Resolve<IMvxApplication>() as core.App;

    Task.Factory.StartNew(async () =>
    {
        await dbContext.Database.MigrateAsync().ConfigureAwait(false);

        RunOnUiThread(async () =>
        {
            await RunAppStartAsync(_bundle);//go to mainview
        });
    }, TaskCreationOptions.LongRunning);
}
  1. Run MainView (MainView is the main activity)

Relevant log output

0
libart.so
__aarch64_cas4_rel
1
libart.so
void art::mirror::Object::VisitReferences<true, (art::VerifyObjectFlags)0, (art::ReadBarrierOption)1, art::gc::collector::ConcurrentCopying::RefFieldsVisitor<false>, art::gc::collector::ConcurrentCopying::RefFieldsVisitor<false> >(art::gc::collector::ConcurrentCopying::RefFieldsVisitor<false> const&, art::gc::collector::ConcurrentCopying::RefFieldsVisitor<false> const&) + 952
2
libart.so
art::gc::collector::ConcurrentCopying::ProcessMarkStack() + 2156
3
libart.so
art::gc::collector::ConcurrentCopying::CopyingPhase() + 1836
4
libart.so
art::gc::collector::ConcurrentCopying::RunPhases() + 2608
5
libart.so
art::gc::collector::GarbageCollector::Run(art::gc::GcCause, bool) + 324
6
libart.so
art::gc::Heap::CollectGarbageInternal(art::gc::collector::GcType, art::gc::GcCause, bool, unsigned int) + 564
7
boot.oat
art_jni_trampoline + 112
8
boot.oat
java.lang.Runtime.gc + 168
9
libart.so
art_quick_invoke_stub + 612
10
libart.so
art::JValue art::InvokeVirtualOrInterfaceWithVarArgs<art::ArtMethod*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, art::ArtMethod*, std::__va_list) + 812
11
libart.so
art::JNI<false>::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, std::__va_list) + 192
12
libmonodroid.so
_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, ...) + 116
13
libmonodroid.so
xamarin::android::internal::OSBridge::gc_cross_references(int, MonoGCBridgeSCC**, int, MonoGCBridgeXRef*) + 224
14
libmonosgen-2.0.so
(Fehlt BuildId c7db5d00fcd3ecbca8fb4a5d7087a9c5b3c4f43f)
15
libmonosgen-2.0.so
(Fehlt BuildId c7db5d00fcd3ecbca8fb4a5d7087a9c5b3c4f43f)
16
libmonosgen-2.0.so
(Fehlt BuildId c7db5d00fcd3ecbca8fb4a5d7087a9c5b3c4f43f)
17
libmonosgen-2.0.so
(Fehlt BuildId c7db5d00fcd3ecbca8fb4a5d7087a9c5b3c4f43f)
18
libmonosgen-2.0.so
mono_gc_collect + 44

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions