Add a DCHECK in thread::GetPeer.
Motivated by https://android-review.googlesource.com/#/c/333205/.
Test: test-art-host run-jdwp-test.sh
Change-Id: I173c060324aa0dc39144db55e3a97e672c012ba8
diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc
index 268d71a..be6f7f2 100644
--- a/runtime/native/dalvik_system_VMStack.cc
+++ b/runtime/native/dalvik_system_VMStack.cc
@@ -41,7 +41,7 @@
Thread* heap_task_thread =
Runtime::Current()->GetHeap()->GetTaskProcessor()->GetRunningThread();
// heap_task_thread could be null if the daemons aren't yet started.
- if (heap_task_thread != nullptr && decoded_peer == heap_task_thread->GetPeer()) {
+ if (heap_task_thread != nullptr && decoded_peer == heap_task_thread->GetPeerFromOtherThread()) {
return nullptr;
}
// Suspend thread to build stack trace.
diff --git a/runtime/openjdkjvmti/ti_stack.cc b/runtime/openjdkjvmti/ti_stack.cc
index b5a6c6e..067c7c1 100644
--- a/runtime/openjdkjvmti/ti_stack.cc
+++ b/runtime/openjdkjvmti/ti_stack.cc
@@ -328,7 +328,7 @@
// For the time being, set the thread to null. We don't have good ScopedLocalRef
// infrastructure.
- DCHECK(self->GetPeer() != nullptr);
+ DCHECK(self->GetPeerFromOtherThread() != nullptr);
stack_info.thread = nullptr;
stack_info.state = JVMTI_THREAD_STATE_SUSPENDED;
@@ -495,7 +495,7 @@
// For the time being, set the thread to null. We don't have good ScopedLocalRef
// infrastructure.
- DCHECK(self->GetPeer() != nullptr);
+ DCHECK(self->GetPeerFromOtherThread() != nullptr);
stack_info.thread = nullptr;
stack_info.state = JVMTI_THREAD_STATE_SUSPENDED;
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 7b65404..eba8975 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -3485,7 +3485,8 @@
}
mirror::Object* Thread::GetPeerFromOtherThread() const {
- mirror::Object* peer = GetPeer();
+ DCHECK(tlsPtr_.jpeer == nullptr);
+ mirror::Object* peer = tlsPtr_.opeer;
if (kUseReadBarrier && Current()->GetIsGcMarking()) {
// We may call Thread::Dump() in the middle of the CC thread flip and this thread's stack
// may have not been flipped yet and peer may be a from-space (stale) ref. So explicitly
diff --git a/runtime/thread.h b/runtime/thread.h
index 3a1b7da..5dd6ae1 100644
--- a/runtime/thread.h
+++ b/runtime/thread.h
@@ -358,6 +358,7 @@
uint64_t GetCpuMicroTime() const;
mirror::Object* GetPeer() const REQUIRES_SHARED(Locks::mutator_lock_) {
+ DCHECK(Thread::Current() == this) << "Use GetPeerFromOtherThread instead";
CHECK(tlsPtr_.jpeer == nullptr);
return tlsPtr_.opeer;
}