Closed Bug 1891726 Opened 6 months ago Closed 6 months ago

Thread names are overridden by JavaVM::AttachCurrentThread

Categories

(GeckoView :: General, defect)

All
Android
defect

Tracking

(firefox127 fixed)

RESOLVED FIXED
127 Branch
Tracking Status
firefox127 --- fixed

People

(Reporter: jnicol, Assigned: jnicol)

Details

Attachments

(1 file)

This has been a minor annoyance of mine for years, but never enough for me to track down the cause, until today. Some thread names appear in the Android Studio debugger as "Thread-<n>". eg the "Renderer" thread always appears as "Thread-3". We set the thread names when the threads are spawned, but they are getting overwritten, and today I captured the place this happens in a debugger:

    prctl 0x0000758b0f5e8400
    pthread_setname_np 0x0000758b0f5e71af
    art::SetThreadName(const char *) 0x0000758b0ce379a7
    art::Thread::CreatePeer(const char *, bool, _jobject *) 0x0000758b0ce08954
    art::Thread::Attach(const char *, bool, _jobject *, bool) 0x0000758b0ce073a2
    art::Runtime::AttachCurrentThread(const char *, bool, _jobject *, bool) 0x0000758b0cde8a17
    art::JII::AttachCurrentThreadInternal(_JavaVM *, _JNIEnv **, void *, bool) 0x0000758b0cc8fb59
    art::CheckJII::AttachCurrentThread(_JavaVM *, _JNIEnv **, void *) 0x0000758b0ca7e8e5
    [Inlined] _JavaVM::AttachCurrentThread(_JNIEnv **, void *) jni.h:1058
    mozilla::jni::GetEnvForThread() Utils.cpp:170
    mozilla::gl::CreateSurfaceFromNativeWindow(mozilla::gl::EglDisplay &, void *, void *) GLContextProviderEGL.cpp:184

It seems the JVM overwrites it when we first attach a thread. That was enough information to easily find the chromium bug when they encountered this issue.

Seems we can easily fix this by supplying the thread name as an arg to AttachCurrentThread()

By default, AttachCurrentThread() overwrites the existing thread name
with "Thread-<n>", making it hard to identify these threads in a
debugger. By supplying the existing thread name as an argument to
AttachCurrentThread, we ensure that the thread keeps its name as
desired.

Oh, nice, Denis and I were confused by this when we looked at a perfetto trace yesterday.

(In reply to Jeff Muizelaar [:jrmuizel] from comment #3)

I was curious where the actual Thread-<n> was coming from and it seems to be here: https://cs.android.com/android/platform/superproject/+/master:libcore/ojluni/src/main/java/java/lang/Thread.java;l=705;drc=9a73823472955a225341bbd7905200b46b280a79

The comment directly underneath that is amusing

Pushed by jnicol@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/dbc4dbc65bbc Supply thread name to JavaVM::AttachCurrentThread(). r=geckoview-reviewers,jrmuizel,m_kato
Status: NEW → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 127 Branch
Component: Core → General
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: