From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- widget/android/jni/Utils.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'widget/android/jni/Utils.cpp') diff --git a/widget/android/jni/Utils.cpp b/widget/android/jni/Utils.cpp index 8d3800fd03..78e1ab647a 100644 --- a/widget/android/jni/Utils.cpp +++ b/widget/android/jni/Utils.cpp @@ -9,6 +9,7 @@ #include #include +#include #include "mozilla/Assertions.h" #include "mozilla/java/GeckoAppShellWrappers.h" @@ -164,10 +165,20 @@ JNIEnv* GetEnvForThread() { return env; } + // By default the VM has a nasty habit of overwriting our lovely + // thread names with "Thread-" making them hard to identify in a debugger, + // so we pass the name in AttachArgs below to prevent that from happening. + // PR_GET_NAME requires a 16 byte buffer: https://linux.die.net/man/2/prctl. + // JNI_VERSION_1_4 is required for NewDirectByteBuffer. + char threadName[16] = {'\0'}; + prctl(PR_GET_NAME, threadName); + JavaVMAttachArgs attachArgs{ + .version = JNI_VERSION_1_4, .name = threadName, .group = nullptr}; + // We don't have a saved JNIEnv, so try to get one. // AttachCurrentThread() does the same thing as GetEnv() when a thread is // already attached, so we don't have to call GetEnv() at all. - if (!sJavaVM->AttachCurrentThread(&env, nullptr)) { + if (!sJavaVM->AttachCurrentThread(&env, &attachArgs)) { MOZ_ASSERT(env); MOZ_ALWAYS_TRUE(!pthread_setspecific(sThreadEnvKey, env)); return env; -- cgit v1.2.3