ART: Add marking to thread peer gathering in TI
When CC is marking, we may get stale references due to a missing
mark.
Bug: 34760612
Test: ART_TEST_JIT=true ART_TEST_GC_STRESS=true test-art-host-run-test-924-threads
Test: ART_TEST_JIT=true ART_TEST_GC_STRESS=true test-art-host-run-test-925-threadgroups
Change-Id: I1becfc188b59a3c99cc7eea07c63abaaf108fd15
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 632a380..0ea7c5a 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -65,6 +65,7 @@
#include "object_lock.h"
#include "quick_exception_handler.h"
#include "quick/quick_method_frame_info.h"
+#include "read_barrier-inl.h"
#include "reflection.h"
#include "runtime.h"
#include "runtime_callbacks.h"
@@ -1845,6 +1846,7 @@
: tls32_(daemon),
wait_monitor_(nullptr),
interrupted_(false),
+ custom_tls_(nullptr),
can_call_into_java_(true) {
wait_mutex_ = new Mutex("a thread wait mutex");
wait_cond_ = new ConditionVariable("a thread wait condition variable", *wait_mutex_);
@@ -3457,4 +3459,15 @@
return Runtime::Current()->IsAotCompiler();
}
+mirror::Object* Thread::GetPeerFromOtherThread() const {
+ mirror::Object* peer = GetPeer();
+ 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
+ // mark/forward it here.
+ peer = art::ReadBarrier::Mark(peer);
+ }
+ return peer;
+}
+
} // namespace art