diff options
Diffstat (limited to 'widget/android/jni/Utils.cpp')
-rw-r--r-- | widget/android/jni/Utils.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
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 <android/log.h> #include <pthread.h> +#include <sys/prctl.h> #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-<n>" 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; |