From 4cba0d979a11f955e6ec3c0f1bf61478af7aa810 Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Wed, 21 May 2014 21:10:23 -0700 Subject: Add a read barrier for weak roots in monitors. A weak root requires a read barrier for the to-space invariant to hold because the object pointed to by a weak root can't be marked/forwarded like the one pointed to by a strong root (GC does not know if it's alive or not at that point) and because, without a read barrier, a mutator could access it and obtain a from-space reference, which would violate the to-space invariant. TODO: do similar for the other types of weak roots. Bug: 12687968 Change-Id: I563a0fa4f875e0c21ac96f57696959454e13b15a --- runtime/monitor.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'runtime/monitor.h') diff --git a/runtime/monitor.h b/runtime/monitor.h index bc5d2e4..ed1b27b 100644 --- a/runtime/monitor.h +++ b/runtime/monitor.h @@ -27,6 +27,7 @@ #include "atomic.h" #include "base/mutex.h" #include "object_callbacks.h" +#include "read_barrier.h" #include "thread_state.h" namespace art { @@ -92,8 +93,9 @@ class Monitor { static bool IsValidLockWord(LockWord lock_word); + template mirror::Object* GetObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return obj_; + return ReadBarrier::BarrierForWeakRoot(obj_); } void SetObject(mirror::Object* object); @@ -190,7 +192,9 @@ class Monitor { // Owner's recursive lock depth. int lock_count_ GUARDED_BY(monitor_lock_); - // What object are we part of. + // What object are we part of. This is a weak root. Do not access + // this directly, use GetObject() to read it so it will be guarded + // by a read barrier. mirror::Object* obj_; // Threads currently waiting on this monitor. -- cgit v1.1