OSDN Git Service

Fix a CC crash with ThreadStress.
authorHiroshi Yamauchi <yamauchi@google.com>
Tue, 4 Oct 2016 22:20:36 +0000 (15:20 -0700)
committerHiroshi Yamauchi <yamauchi@google.com>
Tue, 4 Oct 2016 22:21:58 +0000 (15:21 -0700)
Add a read barrier on the locked object in Monitor::DescribeWait().

Bug: 31848261
Bug: 12687968
Test: test-art-host with CC and N9 libartd boot.
Change-Id: I569e1499c2aadf54d9074a8a790e5d512c2dad4f

runtime/monitor.cc

index 3bc1b06..debbdd5 100644 (file)
@@ -1123,6 +1123,13 @@ void Monitor::DescribeWait(std::ostream& os, const Thread* thread) {
     wait_message = "  - waiting to lock ";
     pretty_object = thread->GetMonitorEnterObject();
     if (pretty_object != nullptr) {
+      if (kUseReadBarrier && Thread::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 "pretty_object" may be a from-space (stale) ref, in
+        // which case the GetLockOwnerThreadId() call below will crash. So explicitly mark/forward
+        // it here.
+        pretty_object = ReadBarrier::Mark(pretty_object);
+      }
       lock_owner = pretty_object->GetLockOwnerThreadId();
     }
   }