summaryrefslogtreecommitdiff
path: root/openjdkjvm/OpenjdkJvm.cc
diff options
context:
space:
mode:
author Hans Boehm <hboehm@google.com> 2022-01-28 15:07:02 -0800
committer Hans Boehm <hboehm@google.com> 2022-02-03 01:31:32 +0000
commit30bc7778e5ca5a76978b91054cb1debe6c96da06 (patch)
tree18970e9d4230a202b38d0b74fa19547c5a02564f /openjdkjvm/OpenjdkJvm.cc
parent0f71b191492cc63b9c8835e85f6016228889da2f (diff)
Remove race on cached thread-name deletion
Manage the thread name using an RCU-like scheme, in which the name is an atomic pointer to an immutable string, and readers explicitly maintain a count of active readers. Writers wait until there are no readers before deallocating a name that was just replaced. Currently this potentially blocks writers, but readers should be very fast, and relatively infrequent, so I can't imagine this is a real issue. This also replaces JVM_SetNativeThreadName with a stub. This part of the CL came from Nicolas' aosp/1706702, which this is otherwise intended to replace. Test: Build and boot AOSP. Bug: 37970289 Change-Id: I7e1d13d24adc10b4009d60ee68bc9e837ce78b34
Diffstat (limited to 'openjdkjvm/OpenjdkJvm.cc')
-rw-r--r--openjdkjvm/OpenjdkJvm.cc38
1 files changed, 6 insertions, 32 deletions
diff --git a/openjdkjvm/OpenjdkJvm.cc b/openjdkjvm/OpenjdkJvm.cc
index a9fa0fc6c7..63503f459e 100644
--- a/openjdkjvm/OpenjdkJvm.cc
+++ b/openjdkjvm/OpenjdkJvm.cc
@@ -406,38 +406,12 @@ JNIEXPORT jboolean JVM_HoldsLock(JNIEnv* env, jclass unused ATTRIBUTE_UNUSED, jo
return soa.Self()->HoldsLock(object);
}
-JNIEXPORT void JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring java_name) {
- ScopedUtfChars name(env, java_name);
- {
- art::ScopedObjectAccess soa(env);
- if (soa.Decode<art::mirror::Object>(jthread) == soa.Self()->GetPeer()) {
- soa.Self()->SetThreadName(name.c_str());
- return;
- }
- }
- // Suspend thread to avoid it from killing itself while we set its name. We don't just hold the
- // thread list lock to avoid this, as setting the thread name causes mutator to lock/unlock
- // in the DDMS send code.
- art::ThreadList* thread_list = art::Runtime::Current()->GetThreadList();
- bool timed_out;
- // Take suspend thread lock to avoid races with threads trying to suspend this one.
- art::Thread* thread;
- {
- thread = thread_list->SuspendThreadByPeer(jthread,
- art::SuspendReason::kInternal,
- &timed_out);
- }
- if (thread != nullptr) {
- {
- art::ScopedObjectAccess soa(env);
- thread->SetThreadName(name.c_str());
- }
- bool resumed = thread_list->Resume(thread, art::SuspendReason::kInternal);
- DCHECK(resumed);
- } else if (timed_out) {
- LOG(ERROR) << "Trying to set thread name to '" << name.c_str() << "' failed as the thread "
- "failed to suspend within a generous timeout.";
- }
+JNIEXPORT __attribute__((noreturn)) void JVM_SetNativeThreadName(
+ JNIEnv* env ATTRIBUTE_UNUSED,
+ jobject jthread ATTRIBUTE_UNUSED,
+ jstring java_name ATTRIBUTE_UNUSED) {
+ UNIMPLEMENTED(FATAL) << "JVM_SetNativeThreadName is not implemented";
+ UNREACHABLE();
}
JNIEXPORT __attribute__((noreturn)) jint JVM_IHashCode(JNIEnv* env ATTRIBUTE_UNUSED,