Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 17 | #include "monitor.h" |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 18 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 19 | #include <vector> |
| 20 | |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 21 | #include "base/mutex.h" |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 22 | #include "base/stl_util.h" |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 23 | #include "class_linker.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 24 | #include "dex_file-inl.h" |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 25 | #include "dex_instruction.h" |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 26 | #include "lock_word-inl.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 27 | #include "mirror/art_method-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 28 | #include "mirror/class-inl.h" |
Ian Rogers | 05f3057 | 2013-02-20 12:13:11 -0800 | [diff] [blame] | 29 | #include "mirror/object-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "mirror/object_array-inl.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 31 | #include "object_utils.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 32 | #include "scoped_thread_state_change.h" |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 33 | #include "thread.h" |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 34 | #include "thread_list.h" |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 35 | #include "verifier/method_verifier.h" |
Elliott Hughes | 044288f | 2012-06-25 14:46:39 -0700 | [diff] [blame] | 36 | #include "well_known_classes.h" |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 37 | |
| 38 | namespace art { |
| 39 | |
| 40 | /* |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 41 | * Every Object has a monitor associated with it, but not every Object is actually locked. Even |
| 42 | * the ones that are locked do not need a full-fledged monitor until a) there is actual contention |
| 43 | * or b) wait() is called on the Object. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 44 | * |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 45 | * For Android, we have implemented a scheme similar to the one described in Bacon et al.'s |
| 46 | * "Thin locks: featherweight synchronization for Java" (ACM 1998). Things are even easier for us, |
| 47 | * though, because we have a full 32 bits to work with. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 48 | * |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 49 | * The two states of an Object's lock are referred to as "thin" and "fat". A lock may transition |
| 50 | * from the "thin" state to the "fat" state and this transition is referred to as inflation. Once |
| 51 | * a lock has been inflated it remains in the "fat" state indefinitely. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 52 | * |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 53 | * The lock value itself is stored in mirror::Object::monitor_ and the representation is described |
| 54 | * in the LockWord value type. |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 55 | * |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 56 | * Monitors provide: |
| 57 | * - mutually exclusive access to resources |
| 58 | * - a way for multiple threads to wait for notification |
| 59 | * |
| 60 | * In effect, they fill the role of both mutexes and condition variables. |
| 61 | * |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 62 | * Only one thread can own the monitor at any time. There may be several threads waiting on it |
| 63 | * (the wait call unlocks it). One or more waiting threads may be getting interrupted or notified |
| 64 | * at any given time. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 65 | */ |
Elliott Hughes | 54e7df1 | 2011-09-16 11:47:04 -0700 | [diff] [blame] | 66 | |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 67 | bool (*Monitor::is_sensitive_thread_hook_)() = NULL; |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 68 | uint32_t Monitor::lock_profiling_threshold_ = 0; |
Elliott Hughes | 32d6e1e | 2011-10-11 14:47:44 -0700 | [diff] [blame] | 69 | |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 70 | bool Monitor::IsSensitiveThread() { |
| 71 | if (is_sensitive_thread_hook_ != NULL) { |
| 72 | return (*is_sensitive_thread_hook_)(); |
| 73 | } |
| 74 | return false; |
| 75 | } |
| 76 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 77 | void Monitor::Init(uint32_t lock_profiling_threshold, bool (*is_sensitive_thread_hook)()) { |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 78 | lock_profiling_threshold_ = lock_profiling_threshold; |
| 79 | is_sensitive_thread_hook_ = is_sensitive_thread_hook; |
Elliott Hughes | 32d6e1e | 2011-10-11 14:47:44 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 82 | Monitor::Monitor(Thread* owner, mirror::Object* obj, int32_t hash_code) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 83 | : monitor_lock_("a monitor lock", kMonitorLock), |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 84 | monitor_contenders_("monitor contenders", monitor_lock_), |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 85 | num_waiters_(0), |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 86 | owner_(owner), |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 87 | lock_count_(0), |
| 88 | obj_(obj), |
| 89 | wait_set_(NULL), |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 90 | hash_code_(hash_code), |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 91 | locking_method_(NULL), |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 92 | locking_dex_pc_(0) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 93 | // We should only inflate a lock if the owner is ourselves or suspended. This avoids a race |
| 94 | // with the owner unlocking the thin-lock. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 95 | CHECK(owner == nullptr || owner == Thread::Current() || owner->IsSuspended()); |
| 96 | // The identity hash code is set for the life time of the monitor. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 99 | int32_t Monitor::GetHashCode() { |
| 100 | while (!HasHashCode()) { |
| 101 | if (hash_code_.compare_and_swap(0, mirror::Object::GenerateIdentityHashCode())) { |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | DCHECK(HasHashCode()); |
| 106 | return hash_code_.load(); |
| 107 | } |
| 108 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 109 | bool Monitor::Install(Thread* self) { |
| 110 | MutexLock mu(self, monitor_lock_); // Uncontended mutex acquisition as monitor isn't yet public. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 111 | CHECK(owner_ == nullptr || owner_ == self || owner_->IsSuspended()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 112 | // Propagate the lock state. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 113 | LockWord lw(obj_->GetLockWord()); |
| 114 | switch (lw.GetState()) { |
| 115 | case LockWord::kThinLocked: { |
| 116 | CHECK_EQ(owner_->GetThreadId(), lw.ThinLockOwner()); |
| 117 | lock_count_ = lw.ThinLockCount(); |
| 118 | break; |
| 119 | } |
| 120 | case LockWord::kHashCode: { |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 121 | CHECK_EQ(hash_code_, static_cast<int32_t>(lw.GetHashCode())); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 122 | break; |
| 123 | } |
| 124 | case LockWord::kFatLocked: { |
| 125 | // The owner_ is suspended but another thread beat us to install a monitor. |
| 126 | return false; |
| 127 | } |
| 128 | case LockWord::kUnlocked: { |
| 129 | LOG(FATAL) << "Inflating unlocked lock word"; |
| 130 | break; |
| 131 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 132 | default: { |
| 133 | LOG(FATAL) << "Invalid monitor state " << lw.GetState(); |
| 134 | return false; |
| 135 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 136 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 137 | LockWord fat(this); |
| 138 | // Publish the updated lock word, which may race with other threads. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 139 | bool success = obj_->CasLockWord(lw, fat); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 140 | // Lock profiling. |
Mathieu Chartier | 9728f91 | 2013-10-30 09:45:13 -0700 | [diff] [blame] | 141 | if (success && owner_ != nullptr && lock_profiling_threshold_ != 0) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 142 | locking_method_ = owner_->GetCurrentMethod(&locking_dex_pc_); |
| 143 | } |
| 144 | return success; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | Monitor::~Monitor() { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 148 | // Deflated monitors have a null object. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* |
| 152 | * Links a thread into a monitor's wait set. The monitor lock must be |
| 153 | * held by the caller of this routine. |
| 154 | */ |
| 155 | void Monitor::AppendToWaitSet(Thread* thread) { |
| 156 | DCHECK(owner_ == Thread::Current()); |
| 157 | DCHECK(thread != NULL); |
Elliott Hughes | dc33ad5 | 2011-09-16 19:46:51 -0700 | [diff] [blame] | 158 | DCHECK(thread->wait_next_ == NULL) << thread->wait_next_; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 159 | if (wait_set_ == NULL) { |
| 160 | wait_set_ = thread; |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | // push_back. |
| 165 | Thread* t = wait_set_; |
| 166 | while (t->wait_next_ != NULL) { |
| 167 | t = t->wait_next_; |
| 168 | } |
| 169 | t->wait_next_ = thread; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * Unlinks a thread from a monitor's wait set. The monitor lock must |
| 174 | * be held by the caller of this routine. |
| 175 | */ |
| 176 | void Monitor::RemoveFromWaitSet(Thread *thread) { |
| 177 | DCHECK(owner_ == Thread::Current()); |
| 178 | DCHECK(thread != NULL); |
| 179 | if (wait_set_ == NULL) { |
| 180 | return; |
| 181 | } |
| 182 | if (wait_set_ == thread) { |
| 183 | wait_set_ = thread->wait_next_; |
| 184 | thread->wait_next_ = NULL; |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | Thread* t = wait_set_; |
| 189 | while (t->wait_next_ != NULL) { |
| 190 | if (t->wait_next_ == thread) { |
| 191 | t->wait_next_ = thread->wait_next_; |
| 192 | thread->wait_next_ = NULL; |
| 193 | return; |
| 194 | } |
| 195 | t = t->wait_next_; |
| 196 | } |
| 197 | } |
| 198 | |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 199 | void Monitor::SetObject(mirror::Object* object) { |
| 200 | obj_ = object; |
| 201 | } |
| 202 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 203 | void Monitor::Lock(Thread* self) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 204 | MutexLock mu(self, monitor_lock_); |
| 205 | while (true) { |
| 206 | if (owner_ == NULL) { // Unowned. |
| 207 | owner_ = self; |
| 208 | CHECK_EQ(lock_count_, 0); |
| 209 | // When debugging, save the current monitor holder for future |
| 210 | // acquisition failures to use in sampled logging. |
| 211 | if (lock_profiling_threshold_ != 0) { |
| 212 | locking_method_ = self->GetCurrentMethod(&locking_dex_pc_); |
| 213 | } |
| 214 | return; |
| 215 | } else if (owner_ == self) { // Recursive. |
| 216 | lock_count_++; |
| 217 | return; |
| 218 | } |
| 219 | // Contended. |
| 220 | const bool log_contention = (lock_profiling_threshold_ != 0); |
| 221 | uint64_t wait_start_ms = log_contention ? 0 : MilliTime(); |
| 222 | const mirror::ArtMethod* owners_method = locking_method_; |
| 223 | uint32_t owners_dex_pc = locking_dex_pc_; |
| 224 | monitor_lock_.Unlock(self); // Let go of locks in order. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 225 | { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 226 | ScopedThreadStateChange tsc(self, kBlocked); // Change to blocked and give up mutator_lock_. |
| 227 | MutexLock mu2(self, monitor_lock_); // Reacquire monitor_lock_ without mutator_lock_ for Wait. |
| 228 | if (owner_ != NULL) { // Did the owner_ give the lock up? |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 229 | ++num_waiters_; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 230 | monitor_contenders_.Wait(self); // Still contended so wait. |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 231 | --num_waiters_; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 232 | // Woken from contention. |
| 233 | if (log_contention) { |
| 234 | uint64_t wait_ms = MilliTime() - wait_start_ms; |
| 235 | uint32_t sample_percent; |
| 236 | if (wait_ms >= lock_profiling_threshold_) { |
| 237 | sample_percent = 100; |
| 238 | } else { |
| 239 | sample_percent = 100 * wait_ms / lock_profiling_threshold_; |
| 240 | } |
| 241 | if (sample_percent != 0 && (static_cast<uint32_t>(rand() % 100) < sample_percent)) { |
| 242 | const char* owners_filename; |
| 243 | uint32_t owners_line_number; |
| 244 | TranslateLocation(owners_method, owners_dex_pc, &owners_filename, &owners_line_number); |
| 245 | LogContentionEvent(self, wait_ms, sample_percent, owners_filename, owners_line_number); |
| 246 | } |
| 247 | } |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 248 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 249 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 250 | monitor_lock_.Lock(self); // Reacquire locks in order. |
Elliott Hughes | fc86162 | 2011-10-17 17:57:47 -0700 | [diff] [blame] | 251 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 254 | static void ThrowIllegalMonitorStateExceptionF(const char* fmt, ...) |
| 255 | __attribute__((format(printf, 1, 2))); |
| 256 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 257 | static void ThrowIllegalMonitorStateExceptionF(const char* fmt, ...) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 258 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 259 | va_list args; |
| 260 | va_start(args, fmt); |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 261 | Thread* self = Thread::Current(); |
| 262 | ThrowLocation throw_location = self->GetCurrentLocationForThrow(); |
| 263 | self->ThrowNewExceptionV(throw_location, "Ljava/lang/IllegalMonitorStateException;", fmt, args); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 264 | if (!Runtime::Current()->IsStarted() || VLOG_IS_ON(monitor)) { |
Brian Carlstrom | 64277f3 | 2012-03-26 23:53:34 -0700 | [diff] [blame] | 265 | std::ostringstream ss; |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 266 | self->Dump(ss); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 267 | LOG(Runtime::Current()->IsStarted() ? INFO : ERROR) |
| 268 | << self->GetException(NULL)->Dump() << "\n" << ss.str(); |
Brian Carlstrom | 64277f3 | 2012-03-26 23:53:34 -0700 | [diff] [blame] | 269 | } |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 270 | va_end(args); |
| 271 | } |
| 272 | |
Elliott Hughes | d423741 | 2012-02-21 11:24:45 -0800 | [diff] [blame] | 273 | static std::string ThreadToString(Thread* thread) { |
| 274 | if (thread == NULL) { |
| 275 | return "NULL"; |
| 276 | } |
| 277 | std::ostringstream oss; |
| 278 | // TODO: alternatively, we could just return the thread's name. |
| 279 | oss << *thread; |
| 280 | return oss.str(); |
| 281 | } |
| 282 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 283 | void Monitor::FailedUnlock(mirror::Object* o, Thread* expected_owner, Thread* found_owner, |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 284 | Monitor* monitor) { |
| 285 | Thread* current_owner = NULL; |
| 286 | std::string current_owner_string; |
| 287 | std::string expected_owner_string; |
| 288 | std::string found_owner_string; |
| 289 | { |
| 290 | // TODO: isn't this too late to prevent threads from disappearing? |
| 291 | // Acquire thread list lock so threads won't disappear from under us. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 292 | MutexLock mu(Thread::Current(), *Locks::thread_list_lock_); |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 293 | // Re-read owner now that we hold lock. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 294 | current_owner = (monitor != NULL) ? monitor->GetOwner() : NULL; |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 295 | // Get short descriptions of the threads involved. |
| 296 | current_owner_string = ThreadToString(current_owner); |
| 297 | expected_owner_string = ThreadToString(expected_owner); |
| 298 | found_owner_string = ThreadToString(found_owner); |
| 299 | } |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 300 | if (current_owner == NULL) { |
| 301 | if (found_owner == NULL) { |
| 302 | ThrowIllegalMonitorStateExceptionF("unlock of unowned monitor on object of type '%s'" |
| 303 | " on thread '%s'", |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 304 | PrettyTypeOf(o).c_str(), |
| 305 | expected_owner_string.c_str()); |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 306 | } else { |
| 307 | // Race: the original read found an owner but now there is none |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 308 | ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" |
| 309 | " (where now the monitor appears unowned) on thread '%s'", |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 310 | found_owner_string.c_str(), |
| 311 | PrettyTypeOf(o).c_str(), |
| 312 | expected_owner_string.c_str()); |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 313 | } |
| 314 | } else { |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 315 | if (found_owner == NULL) { |
| 316 | // Race: originally there was no owner, there is now |
| 317 | ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" |
| 318 | " (originally believed to be unowned) on thread '%s'", |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 319 | current_owner_string.c_str(), |
| 320 | PrettyTypeOf(o).c_str(), |
| 321 | expected_owner_string.c_str()); |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 322 | } else { |
| 323 | if (found_owner != current_owner) { |
| 324 | // Race: originally found and current owner have changed |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 325 | ThrowIllegalMonitorStateExceptionF("unlock of monitor originally owned by '%s' (now" |
| 326 | " owned by '%s') on object of type '%s' on thread '%s'", |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 327 | found_owner_string.c_str(), |
| 328 | current_owner_string.c_str(), |
| 329 | PrettyTypeOf(o).c_str(), |
| 330 | expected_owner_string.c_str()); |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 331 | } else { |
| 332 | ThrowIllegalMonitorStateExceptionF("unlock of monitor owned by '%s' on object of type '%s'" |
| 333 | " on thread '%s", |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 334 | current_owner_string.c_str(), |
| 335 | PrettyTypeOf(o).c_str(), |
| 336 | expected_owner_string.c_str()); |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 342 | bool Monitor::Unlock(Thread* self) { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 343 | DCHECK(self != NULL); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 344 | MutexLock mu(self, monitor_lock_); |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 345 | Thread* owner = owner_; |
| 346 | if (owner == self) { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 347 | // We own the monitor, so nobody else can be in here. |
| 348 | if (lock_count_ == 0) { |
| 349 | owner_ = NULL; |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 350 | locking_method_ = NULL; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 351 | locking_dex_pc_ = 0; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 352 | // Wake a contender. |
| 353 | monitor_contenders_.Signal(self); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 354 | } else { |
| 355 | --lock_count_; |
| 356 | } |
| 357 | } else { |
| 358 | // We don't own this, so we're not allowed to unlock it. |
| 359 | // The JNI spec says that we should throw IllegalMonitorStateException |
| 360 | // in this case. |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 361 | FailedUnlock(obj_, self, owner, this); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 362 | return false; |
| 363 | } |
| 364 | return true; |
| 365 | } |
| 366 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 367 | /* |
| 368 | * Wait on a monitor until timeout, interrupt, or notification. Used for |
| 369 | * Object.wait() and (somewhat indirectly) Thread.sleep() and Thread.join(). |
| 370 | * |
| 371 | * If another thread calls Thread.interrupt(), we throw InterruptedException |
| 372 | * and return immediately if one of the following are true: |
| 373 | * - blocked in wait(), wait(long), or wait(long, int) methods of Object |
| 374 | * - blocked in join(), join(long), or join(long, int) methods of Thread |
| 375 | * - blocked in sleep(long), or sleep(long, int) methods of Thread |
| 376 | * Otherwise, we set the "interrupted" flag. |
| 377 | * |
| 378 | * Checks to make sure that "ns" is in the range 0-999999 |
| 379 | * (i.e. fractions of a millisecond) and throws the appropriate |
| 380 | * exception if it isn't. |
| 381 | * |
| 382 | * The spec allows "spurious wakeups", and recommends that all code using |
| 383 | * Object.wait() do so in a loop. This appears to derive from concerns |
| 384 | * about pthread_cond_wait() on multiprocessor systems. Some commentary |
| 385 | * on the web casts doubt on whether these can/should occur. |
| 386 | * |
| 387 | * Since we're allowed to wake up "early", we clamp extremely long durations |
| 388 | * to return at the end of the 32-bit time epoch. |
| 389 | */ |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 390 | void Monitor::Wait(Thread* self, int64_t ms, int32_t ns, |
| 391 | bool interruptShouldThrow, ThreadState why) { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 392 | DCHECK(self != NULL); |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 393 | DCHECK(why == kTimedWaiting || why == kWaiting || why == kSleeping); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 394 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 395 | monitor_lock_.Lock(self); |
| 396 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 397 | // Make sure that we hold the lock. |
| 398 | if (owner_ != self) { |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 399 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()"); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 400 | monitor_lock_.Unlock(self); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 401 | return; |
| 402 | } |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 403 | |
Elliott Hughes | df42c48 | 2013-01-09 12:49:02 -0800 | [diff] [blame] | 404 | // We need to turn a zero-length timed wait into a regular wait because |
| 405 | // Object.wait(0, 0) is defined as Object.wait(0), which is defined as Object.wait(). |
| 406 | if (why == kTimedWaiting && (ms == 0 && ns == 0)) { |
| 407 | why = kWaiting; |
| 408 | } |
| 409 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 410 | // Enforce the timeout range. |
| 411 | if (ms < 0 || ns < 0 || ns > 999999) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 412 | ThrowLocation throw_location = self->GetCurrentLocationForThrow(); |
| 413 | self->ThrowNewExceptionF(throw_location, "Ljava/lang/IllegalArgumentException;", |
| 414 | "timeout arguments out of range: ms=%lld ns=%d", ms, ns); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 415 | monitor_lock_.Unlock(self); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 416 | return; |
| 417 | } |
| 418 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 419 | /* |
| 420 | * Add ourselves to the set of threads waiting on this monitor, and |
| 421 | * release our hold. We need to let it go even if we're a few levels |
| 422 | * deep in a recursive lock, and we need to restore that later. |
| 423 | * |
| 424 | * We append to the wait set ahead of clearing the count and owner |
| 425 | * fields so the subroutine can check that the calling thread owns |
| 426 | * the monitor. Aside from that, the order of member updates is |
| 427 | * not order sensitive as we hold the pthread mutex. |
| 428 | */ |
| 429 | AppendToWaitSet(self); |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 430 | int prev_lock_count = lock_count_; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 431 | lock_count_ = 0; |
| 432 | owner_ = NULL; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 433 | const mirror::ArtMethod* saved_method = locking_method_; |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 434 | locking_method_ = NULL; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 435 | uintptr_t saved_dex_pc = locking_dex_pc_; |
| 436 | locking_dex_pc_ = 0; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 437 | |
| 438 | /* |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 439 | * Update thread state. If the GC wakes up, it'll ignore us, knowing |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 440 | * that we won't touch any references in this state, and we'll check |
| 441 | * our suspend mode before we transition out. |
| 442 | */ |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 443 | self->TransitionFromRunnableToSuspended(why); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 444 | |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 445 | bool was_interrupted = false; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 446 | { |
| 447 | // Pseudo-atomically wait on self's wait_cond_ and release the monitor lock. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 448 | MutexLock mu(self, *self->wait_mutex_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 449 | |
| 450 | // Set wait_monitor_ to the monitor object we will be waiting on. When wait_monitor_ is |
| 451 | // non-NULL a notifying or interrupting thread must signal the thread's wait_cond_ to wake it |
| 452 | // up. |
| 453 | DCHECK(self->wait_monitor_ == NULL); |
| 454 | self->wait_monitor_ = this; |
| 455 | |
| 456 | // Release the monitor lock. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 457 | monitor_contenders_.Signal(self); |
| 458 | monitor_lock_.Unlock(self); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 459 | |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 460 | // Handle the case where the thread was interrupted before we called wait(). |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 461 | if (self->interrupted_) { |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 462 | was_interrupted = true; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 463 | } else { |
| 464 | // Wait for a notification or a timeout to occur. |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 465 | if (why == kWaiting) { |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 466 | self->wait_cond_->Wait(self); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 467 | } else { |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 468 | DCHECK(why == kTimedWaiting || why == kSleeping) << why; |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 469 | self->wait_cond_->TimedWait(self, ms, ns); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 470 | } |
| 471 | if (self->interrupted_) { |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 472 | was_interrupted = true; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 473 | } |
| 474 | self->interrupted_ = false; |
| 475 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 478 | // Set self->status back to kRunnable, and self-suspend if needed. |
| 479 | self->TransitionFromSuspendedToRunnable(); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 480 | |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 481 | { |
| 482 | // We reset the thread's wait_monitor_ field after transitioning back to runnable so |
| 483 | // that a thread in a waiting/sleeping state has a non-null wait_monitor_ for debugging |
| 484 | // and diagnostic purposes. (If you reset this earlier, stack dumps will claim that threads |
| 485 | // are waiting on "null".) |
| 486 | MutexLock mu(self, *self->wait_mutex_); |
| 487 | DCHECK(self->wait_monitor_ != NULL); |
| 488 | self->wait_monitor_ = NULL; |
| 489 | } |
| 490 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 491 | // Re-acquire the monitor and lock. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 492 | Lock(self); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 493 | monitor_lock_.Lock(self); |
Ian Rogers | 81d425b | 2012-09-27 16:03:43 -0700 | [diff] [blame] | 494 | self->wait_mutex_->AssertNotHeld(self); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 495 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 496 | /* |
| 497 | * We remove our thread from wait set after restoring the count |
| 498 | * and owner fields so the subroutine can check that the calling |
| 499 | * thread owns the monitor. Aside from that, the order of member |
| 500 | * updates is not order sensitive as we hold the pthread mutex. |
| 501 | */ |
| 502 | owner_ = self; |
Ian Rogers | 0399dde | 2012-06-06 17:09:28 -0700 | [diff] [blame] | 503 | lock_count_ = prev_lock_count; |
| 504 | locking_method_ = saved_method; |
| 505 | locking_dex_pc_ = saved_dex_pc; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 506 | RemoveFromWaitSet(self); |
| 507 | |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 508 | if (was_interrupted) { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 509 | /* |
| 510 | * We were interrupted while waiting, or somebody interrupted an |
| 511 | * un-interruptible thread earlier and we're bailing out immediately. |
| 512 | * |
| 513 | * The doc sayeth: "The interrupted status of the current thread is |
| 514 | * cleared when this exception is thrown." |
| 515 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 516 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 517 | MutexLock mu(self, *self->wait_mutex_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 518 | self->interrupted_ = false; |
| 519 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 520 | if (interruptShouldThrow) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 521 | ThrowLocation throw_location = self->GetCurrentLocationForThrow(); |
| 522 | self->ThrowNewException(throw_location, "Ljava/lang/InterruptedException;", NULL); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 525 | monitor_lock_.Unlock(self); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | void Monitor::Notify(Thread* self) { |
| 529 | DCHECK(self != NULL); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 530 | MutexLock mu(self, monitor_lock_); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 531 | // Make sure that we hold the lock. |
| 532 | if (owner_ != self) { |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 533 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()"); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 534 | return; |
| 535 | } |
| 536 | // Signal the first waiting thread in the wait set. |
| 537 | while (wait_set_ != NULL) { |
| 538 | Thread* thread = wait_set_; |
| 539 | wait_set_ = thread->wait_next_; |
| 540 | thread->wait_next_ = NULL; |
| 541 | |
| 542 | // Check to see if the thread is still waiting. |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 543 | MutexLock mu(self, *thread->wait_mutex_); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 544 | if (thread->wait_monitor_ != NULL) { |
Ian Rogers | c604d73 | 2012-10-14 16:09:54 -0700 | [diff] [blame] | 545 | thread->wait_cond_->Signal(self); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 546 | return; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | void Monitor::NotifyAll(Thread* self) { |
| 552 | DCHECK(self != NULL); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 553 | MutexLock mu(self, monitor_lock_); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 554 | // Make sure that we hold the lock. |
| 555 | if (owner_ != self) { |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 556 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before notifyAll()"); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 557 | return; |
| 558 | } |
| 559 | // Signal all threads in the wait set. |
| 560 | while (wait_set_ != NULL) { |
| 561 | Thread* thread = wait_set_; |
| 562 | wait_set_ = thread->wait_next_; |
| 563 | thread->wait_next_ = NULL; |
| 564 | thread->Notify(); |
| 565 | } |
| 566 | } |
| 567 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 568 | bool Monitor::Deflate(Thread* self, mirror::Object* obj) { |
| 569 | DCHECK(obj != nullptr); |
| 570 | LockWord lw(obj->GetLockWord()); |
| 571 | // If the lock isn't an inflated monitor, then we don't need to deflate anything. |
| 572 | if (lw.GetState() == LockWord::kFatLocked) { |
| 573 | Monitor* monitor = lw.FatLockMonitor(); |
| 574 | CHECK(monitor != nullptr); |
| 575 | MutexLock mu(self, monitor->monitor_lock_); |
| 576 | Thread* owner = monitor->owner_; |
| 577 | if (owner != nullptr) { |
| 578 | // Can't deflate if we are locked and have a hash code. |
| 579 | if (monitor->HasHashCode()) { |
| 580 | return false; |
| 581 | } |
| 582 | // Can't deflate if our lock count is too high. |
| 583 | if (monitor->lock_count_ > LockWord::kThinLockMaxCount) { |
| 584 | return false; |
| 585 | } |
| 586 | // Can't deflate if we have anybody waiting on the CV. |
Mathieu Chartier | 46bc778 | 2013-11-12 17:03:02 -0800 | [diff] [blame] | 587 | if (monitor->num_waiters_ > 0) { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 588 | return false; |
| 589 | } |
| 590 | // Deflate to a thin lock. |
| 591 | obj->SetLockWord(LockWord::FromThinLockId(owner->GetTid(), monitor->lock_count_)); |
| 592 | } else if (monitor->HasHashCode()) { |
| 593 | obj->SetLockWord(LockWord::FromHashCode(monitor->GetHashCode())); |
| 594 | } else { |
| 595 | // No lock and no hash, just put an empty lock word inside the object. |
| 596 | obj->SetLockWord(LockWord()); |
| 597 | } |
| 598 | // The monitor is deflated, mark the object as nullptr so that we know to delete it during the |
| 599 | // next GC. |
| 600 | monitor->obj_ = nullptr; |
| 601 | } |
| 602 | return true; |
| 603 | } |
| 604 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 605 | /* |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 606 | * Changes the shape of a monitor from thin to fat, preserving the internal lock state. The calling |
| 607 | * thread must own the lock or the owner must be suspended. There's a race with other threads |
| 608 | * inflating the lock and so the caller should read the monitor following the call. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 609 | */ |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 610 | void Monitor::Inflate(Thread* self, Thread* owner, mirror::Object* obj, int32_t hash_code) { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 611 | DCHECK(self != NULL); |
| 612 | DCHECK(obj != NULL); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 613 | // Allocate and acquire a new monitor. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 614 | UniquePtr<Monitor> m(new Monitor(owner, obj, hash_code)); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 615 | if (m->Install(self)) { |
| 616 | VLOG(monitor) << "monitor: thread " << owner->GetThreadId() |
| 617 | << " created monitor " << m.get() << " for object " << obj; |
| 618 | Runtime::Current()->GetMonitorList()->Add(m.release()); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 619 | CHECK_EQ(obj->GetLockWord().GetState(), LockWord::kFatLocked); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 620 | } |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 623 | void Monitor::InflateThinLocked(Thread* self, SirtRef<mirror::Object>& obj, LockWord lock_word, |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 624 | uint32_t hash_code) { |
| 625 | DCHECK_EQ(lock_word.GetState(), LockWord::kThinLocked); |
| 626 | uint32_t owner_thread_id = lock_word.ThinLockOwner(); |
| 627 | if (owner_thread_id == self->GetThreadId()) { |
| 628 | // We own the monitor, we can easily inflate it. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 629 | Inflate(self, self, obj.get(), hash_code); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 630 | } else { |
| 631 | ThreadList* thread_list = Runtime::Current()->GetThreadList(); |
| 632 | // Suspend the owner, inflate. First change to blocked and give up mutator_lock_. |
| 633 | ScopedThreadStateChange tsc(self, kBlocked); |
| 634 | if (lock_word == obj->GetLockWord()) { // If lock word hasn't changed. |
| 635 | bool timed_out; |
Mathieu Chartier | 5f51d4b | 2013-12-03 14:24:05 -0800 | [diff] [blame] | 636 | Thread* owner = thread_list->SuspendThreadByThreadId(owner_thread_id, false, &timed_out); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 637 | if (owner != nullptr) { |
| 638 | // We succeeded in suspending the thread, check the lock's status didn't change. |
| 639 | lock_word = obj->GetLockWord(); |
| 640 | if (lock_word.GetState() == LockWord::kThinLocked && |
| 641 | lock_word.ThinLockOwner() == owner_thread_id) { |
| 642 | // Go ahead and inflate the lock. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 643 | Inflate(self, owner, obj.get(), hash_code); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 644 | } |
| 645 | thread_list->Resume(owner, false); |
| 646 | } |
| 647 | } |
| 648 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 651 | void Monitor::MonitorEnter(Thread* self, mirror::Object* obj) { |
Elliott Hughes | 4681c80 | 2011-09-25 18:04:37 -0700 | [diff] [blame] | 652 | DCHECK(self != NULL); |
| 653 | DCHECK(obj != NULL); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 654 | uint32_t thread_id = self->GetThreadId(); |
| 655 | size_t contention_count = 0; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 656 | SirtRef<mirror::Object> sirt_obj(self, obj); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 657 | while (true) { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 658 | LockWord lock_word = sirt_obj->GetLockWord(); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 659 | switch (lock_word.GetState()) { |
| 660 | case LockWord::kUnlocked: { |
| 661 | LockWord thin_locked(LockWord::FromThinLockId(thread_id, 0)); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 662 | if (sirt_obj->CasLockWord(lock_word, thin_locked)) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 663 | return; // Success! |
| 664 | } |
| 665 | continue; // Go again. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 666 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 667 | case LockWord::kThinLocked: { |
| 668 | uint32_t owner_thread_id = lock_word.ThinLockOwner(); |
| 669 | if (owner_thread_id == thread_id) { |
| 670 | // We own the lock, increase the recursion count. |
| 671 | uint32_t new_count = lock_word.ThinLockCount() + 1; |
| 672 | if (LIKELY(new_count <= LockWord::kThinLockMaxCount)) { |
| 673 | LockWord thin_locked(LockWord::FromThinLockId(thread_id, new_count)); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 674 | sirt_obj->SetLockWord(thin_locked); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 675 | return; // Success! |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 676 | } else { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 677 | // We'd overflow the recursion count, so inflate the monitor. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 678 | InflateThinLocked(self, sirt_obj, lock_word, 0); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 679 | } |
| 680 | } else { |
| 681 | // Contention. |
| 682 | contention_count++; |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 683 | Runtime* runtime = Runtime::Current(); |
| 684 | if (contention_count <= runtime->GetMaxSpinsBeforeThinkLockInflation()) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 685 | NanoSleep(1000); // Sleep for 1us and re-attempt. |
| 686 | } else { |
| 687 | contention_count = 0; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 688 | InflateThinLocked(self, sirt_obj, lock_word, 0); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 689 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 690 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 691 | continue; // Start from the beginning. |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 692 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 693 | case LockWord::kFatLocked: { |
| 694 | Monitor* mon = lock_word.FatLockMonitor(); |
| 695 | mon->Lock(self); |
| 696 | return; // Success! |
| 697 | } |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 698 | case LockWord::kHashCode: { |
| 699 | // Inflate with the existing hashcode. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 700 | Inflate(self, nullptr, sirt_obj.get(), lock_word.GetHashCode()); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 701 | break; |
| 702 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 703 | default: { |
| 704 | LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); |
| 705 | return; |
| 706 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 707 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 711 | bool Monitor::MonitorExit(Thread* self, mirror::Object* obj) { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 712 | DCHECK(self != NULL); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 713 | DCHECK(obj != NULL); |
| 714 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 715 | LockWord lock_word = obj->GetLockWord(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 716 | SirtRef<mirror::Object> sirt_obj(self, obj); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 717 | switch (lock_word.GetState()) { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 718 | case LockWord::kHashCode: |
| 719 | // Fall-through. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 720 | case LockWord::kUnlocked: |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 721 | FailedUnlock(sirt_obj.get(), self, NULL, NULL); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 722 | return false; // Failure. |
| 723 | case LockWord::kThinLocked: { |
| 724 | uint32_t thread_id = self->GetThreadId(); |
| 725 | uint32_t owner_thread_id = lock_word.ThinLockOwner(); |
| 726 | if (owner_thread_id != thread_id) { |
| 727 | // TODO: there's a race here with the owner dying while we unlock. |
| 728 | Thread* owner = |
| 729 | Runtime::Current()->GetThreadList()->FindThreadByThreadId(lock_word.ThinLockOwner()); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 730 | FailedUnlock(sirt_obj.get(), self, owner, NULL); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 731 | return false; // Failure. |
| 732 | } else { |
| 733 | // We own the lock, decrease the recursion count. |
| 734 | if (lock_word.ThinLockCount() != 0) { |
| 735 | uint32_t new_count = lock_word.ThinLockCount() - 1; |
| 736 | LockWord thin_locked(LockWord::FromThinLockId(thread_id, new_count)); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 737 | sirt_obj->SetLockWord(thin_locked); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 738 | } else { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 739 | sirt_obj->SetLockWord(LockWord()); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 740 | } |
| 741 | return true; // Success! |
| 742 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 743 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 744 | case LockWord::kFatLocked: { |
| 745 | Monitor* mon = lock_word.FatLockMonitor(); |
| 746 | return mon->Unlock(self); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 747 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 748 | default: { |
| 749 | LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 750 | return false; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 751 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 752 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | /* |
| 756 | * Object.wait(). Also called for class init. |
| 757 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 758 | void Monitor::Wait(Thread* self, mirror::Object *obj, int64_t ms, int32_t ns, |
Elliott Hughes | 4cd121e | 2013-01-07 17:35:41 -0800 | [diff] [blame] | 759 | bool interruptShouldThrow, ThreadState why) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 760 | DCHECK(self != NULL); |
| 761 | DCHECK(obj != NULL); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 762 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 763 | LockWord lock_word = obj->GetLockWord(); |
| 764 | switch (lock_word.GetState()) { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 765 | case LockWord::kHashCode: |
| 766 | // Fall-through. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 767 | case LockWord::kUnlocked: |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 768 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()"); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 769 | return; // Failure. |
| 770 | case LockWord::kThinLocked: { |
| 771 | uint32_t thread_id = self->GetThreadId(); |
| 772 | uint32_t owner_thread_id = lock_word.ThinLockOwner(); |
| 773 | if (owner_thread_id != thread_id) { |
| 774 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before wait()"); |
| 775 | return; // Failure. |
| 776 | } else { |
| 777 | // We own the lock, inflate to enqueue ourself on the Monitor. |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 778 | Inflate(self, self, obj, 0); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 779 | lock_word = obj->GetLockWord(); |
| 780 | } |
| 781 | break; |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 782 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 783 | case LockWord::kFatLocked: |
| 784 | break; // Already set for a wait. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 785 | default: { |
| 786 | LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); |
| 787 | return; |
| 788 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 789 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 790 | Monitor* mon = lock_word.FatLockMonitor(); |
| 791 | mon->Wait(self, ms, ns, interruptShouldThrow, why); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Ian Rogers | 13c479e | 2013-10-11 07:59:01 -0700 | [diff] [blame] | 794 | void Monitor::DoNotify(Thread* self, mirror::Object* obj, bool notify_all) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 795 | DCHECK(self != NULL); |
| 796 | DCHECK(obj != NULL); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 797 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 798 | LockWord lock_word = obj->GetLockWord(); |
| 799 | switch (lock_word.GetState()) { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 800 | case LockWord::kHashCode: |
| 801 | // Fall-through. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 802 | case LockWord::kUnlocked: |
Ian Rogers | 6d0b13e | 2012-02-07 09:25:29 -0800 | [diff] [blame] | 803 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()"); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 804 | return; // Failure. |
| 805 | case LockWord::kThinLocked: { |
| 806 | uint32_t thread_id = self->GetThreadId(); |
| 807 | uint32_t owner_thread_id = lock_word.ThinLockOwner(); |
| 808 | if (owner_thread_id != thread_id) { |
| 809 | ThrowIllegalMonitorStateExceptionF("object not locked by thread before notify()"); |
| 810 | return; // Failure. |
| 811 | } else { |
| 812 | // We own the lock but there's no Monitor and therefore no waiters. |
| 813 | return; // Success. |
| 814 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 815 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 816 | case LockWord::kFatLocked: { |
| 817 | Monitor* mon = lock_word.FatLockMonitor(); |
| 818 | if (notify_all) { |
| 819 | mon->NotifyAll(self); |
| 820 | } else { |
| 821 | mon->Notify(self); |
| 822 | } |
| 823 | return; // Success. |
| 824 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 825 | default: { |
| 826 | LOG(FATAL) << "Invalid monitor state " << lock_word.GetState(); |
| 827 | return; |
| 828 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 832 | uint32_t Monitor::GetLockOwnerThreadId(mirror::Object* obj) { |
| 833 | DCHECK(obj != NULL); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 834 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 835 | LockWord lock_word = obj->GetLockWord(); |
| 836 | switch (lock_word.GetState()) { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 837 | case LockWord::kHashCode: |
| 838 | // Fall-through. |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 839 | case LockWord::kUnlocked: |
| 840 | return ThreadList::kInvalidThreadId; |
| 841 | case LockWord::kThinLocked: |
| 842 | return lock_word.ThinLockOwner(); |
| 843 | case LockWord::kFatLocked: { |
| 844 | Monitor* mon = lock_word.FatLockMonitor(); |
| 845 | return mon->GetOwnerThreadId(); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 846 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 847 | default: { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 848 | LOG(FATAL) << "Unreachable"; |
| 849 | return ThreadList::kInvalidThreadId; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 850 | } |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 854 | void Monitor::DescribeWait(std::ostream& os, const Thread* thread) { |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 855 | ThreadState state = thread->GetState(); |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 856 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 857 | int32_t object_identity_hashcode = 0; |
| 858 | uint32_t lock_owner = ThreadList::kInvalidThreadId; |
| 859 | std::string pretty_type; |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 860 | if (state == kWaiting || state == kTimedWaiting || state == kSleeping) { |
| 861 | if (state == kSleeping) { |
| 862 | os << " - sleeping on "; |
| 863 | } else { |
| 864 | os << " - waiting on "; |
| 865 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 866 | { |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 867 | Thread* self = Thread::Current(); |
| 868 | MutexLock mu(self, *thread->wait_mutex_); |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 869 | Monitor* monitor = thread->wait_monitor_; |
| 870 | if (monitor != NULL) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 871 | mirror::Object* object = monitor->obj_; |
| 872 | object_identity_hashcode = object->IdentityHashCode(); |
| 873 | pretty_type = PrettyTypeOf(object); |
Elliott Hughes | b4e94fd | 2013-01-08 14:41:26 -0800 | [diff] [blame] | 874 | } |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 875 | } |
Elliott Hughes | 34e0696 | 2012-04-09 13:55:55 -0700 | [diff] [blame] | 876 | } else if (state == kBlocked) { |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 877 | os << " - waiting to lock "; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 878 | mirror::Object* object = thread->monitor_enter_object_; |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 879 | if (object != NULL) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 880 | object_identity_hashcode = object->IdentityHashCode(); |
| 881 | lock_owner = object->GetLockOwnerThreadId(); |
| 882 | pretty_type = PrettyTypeOf(object); |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 883 | } |
| 884 | } else { |
| 885 | // We're not waiting on anything. |
| 886 | return; |
| 887 | } |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 888 | |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 889 | // - waiting on <0x6008c468> (a java.lang.Class<java.lang.ref.ReferenceQueue>) |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 890 | os << StringPrintf("<0x%08x> (a %s)", object_identity_hashcode, pretty_type.c_str()); |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 891 | |
Elliott Hughes | c5dc2ff | 2013-01-09 13:44:30 -0800 | [diff] [blame] | 892 | // - waiting to lock <0x613f83d8> (a java.lang.Object) held by thread 5 |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 893 | if (lock_owner != ThreadList::kInvalidThreadId) { |
Elliott Hughes | 8e4aac5 | 2011-09-26 17:03:36 -0700 | [diff] [blame] | 894 | os << " held by thread " << lock_owner; |
| 895 | } |
| 896 | |
| 897 | os << "\n"; |
| 898 | } |
| 899 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 900 | mirror::Object* Monitor::GetContendedMonitor(Thread* thread) { |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 901 | // This is used to implement JDWP's ThreadReference.CurrentContendedMonitor, and has a bizarre |
| 902 | // definition of contended that includes a monitor a thread is trying to enter... |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 903 | mirror::Object* result = thread->monitor_enter_object_; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 904 | if (result == NULL) { |
| 905 | // ...but also a monitor that the thread is waiting on. |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 906 | MutexLock mu(Thread::Current(), *thread->wait_mutex_); |
| 907 | Monitor* monitor = thread->wait_monitor_; |
| 908 | if (monitor != NULL) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 909 | result = monitor->GetObject(); |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 910 | } |
| 911 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 912 | return result; |
Elliott Hughes | f950170 | 2013-01-11 11:22:27 -0800 | [diff] [blame] | 913 | } |
| 914 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 915 | void Monitor::VisitLocks(StackVisitor* stack_visitor, void (*callback)(mirror::Object*, void*), |
| 916 | void* callback_context) { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 917 | mirror::ArtMethod* m = stack_visitor->GetMethod(); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 918 | CHECK(m != NULL); |
| 919 | |
| 920 | // Native methods are an easy special case. |
| 921 | // TODO: use the JNI implementation's table of explicit MonitorEnter calls and dump those too. |
| 922 | if (m->IsNative()) { |
| 923 | if (m->IsSynchronized()) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 924 | mirror::Object* jni_this = stack_visitor->GetCurrentSirt()->GetReference(0); |
Elliott Hughes | 4993bbc | 2013-01-10 15:41:25 -0800 | [diff] [blame] | 925 | callback(jni_this, callback_context); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 926 | } |
| 927 | return; |
| 928 | } |
| 929 | |
jeffhao | 61f916c | 2012-10-25 17:48:51 -0700 | [diff] [blame] | 930 | // Proxy methods should not be synchronized. |
| 931 | if (m->IsProxyMethod()) { |
| 932 | CHECK(!m->IsSynchronized()); |
| 933 | return; |
| 934 | } |
| 935 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 936 | // <clinit> is another special case. The runtime holds the class lock while calling <clinit>. |
| 937 | MethodHelper mh(m); |
| 938 | if (mh.IsClassInitializer()) { |
Elliott Hughes | 4993bbc | 2013-01-10 15:41:25 -0800 | [diff] [blame] | 939 | callback(m->GetDeclaringClass(), callback_context); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 940 | // Fall through because there might be synchronization in the user code too. |
| 941 | } |
| 942 | |
| 943 | // Is there any reason to believe there's any synchronization in this method? |
| 944 | const DexFile::CodeItem* code_item = mh.GetCodeItem(); |
Elliott Hughes | caf7654 | 2012-06-28 16:08:22 -0700 | [diff] [blame] | 945 | CHECK(code_item != NULL) << PrettyMethod(m); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 946 | if (code_item->tries_size_ == 0) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 947 | return; // No "tries" implies no synchronization, so no held locks to report. |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 950 | // Ask the verifier for the dex pcs of all the monitor-enter instructions corresponding to |
| 951 | // the locks held in this stack frame. |
| 952 | std::vector<uint32_t> monitor_enter_dex_pcs; |
| 953 | verifier::MethodVerifier::FindLocksAtDexPc(m, stack_visitor->GetDexPc(), monitor_enter_dex_pcs); |
| 954 | if (monitor_enter_dex_pcs.empty()) { |
| 955 | return; |
| 956 | } |
| 957 | |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 958 | for (size_t i = 0; i < monitor_enter_dex_pcs.size(); ++i) { |
| 959 | // The verifier works in terms of the dex pcs of the monitor-enter instructions. |
| 960 | // We want the registers used by those instructions (so we can read the values out of them). |
| 961 | uint32_t dex_pc = monitor_enter_dex_pcs[i]; |
| 962 | uint16_t monitor_enter_instruction = code_item->insns_[dex_pc]; |
| 963 | |
| 964 | // Quick sanity check. |
| 965 | if ((monitor_enter_instruction & 0xff) != Instruction::MONITOR_ENTER) { |
| 966 | LOG(FATAL) << "expected monitor-enter @" << dex_pc << "; was " |
| 967 | << reinterpret_cast<void*>(monitor_enter_instruction); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 968 | } |
| 969 | |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 970 | uint16_t monitor_register = ((monitor_enter_instruction >> 8) & 0xff); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 971 | mirror::Object* o = reinterpret_cast<mirror::Object*>(stack_visitor->GetVReg(m, monitor_register, |
| 972 | kReferenceVReg)); |
Elliott Hughes | 4993bbc | 2013-01-10 15:41:25 -0800 | [diff] [blame] | 973 | callback(o, callback_context); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 974 | } |
| 975 | } |
| 976 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 977 | bool Monitor::IsValidLockWord(LockWord lock_word) { |
| 978 | switch (lock_word.GetState()) { |
| 979 | case LockWord::kUnlocked: |
| 980 | // Nothing to check. |
| 981 | return true; |
| 982 | case LockWord::kThinLocked: |
| 983 | // Basic sanity check of owner. |
| 984 | return lock_word.ThinLockOwner() != ThreadList::kInvalidThreadId; |
| 985 | case LockWord::kFatLocked: { |
| 986 | // Check the monitor appears in the monitor list. |
| 987 | Monitor* mon = lock_word.FatLockMonitor(); |
| 988 | MonitorList* list = Runtime::Current()->GetMonitorList(); |
| 989 | MutexLock mu(Thread::Current(), list->monitor_list_lock_); |
| 990 | for (Monitor* list_mon : list->list_) { |
| 991 | if (mon == list_mon) { |
| 992 | return true; // Found our monitor. |
| 993 | } |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 994 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 995 | return false; // Fail - unowned monitor in an object. |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 996 | } |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 997 | case LockWord::kHashCode: |
| 998 | return true; |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 999 | default: |
| 1000 | LOG(FATAL) << "Unreachable"; |
| 1001 | return false; |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 1005 | bool Monitor::IsLocked() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 1006 | MutexLock mu(Thread::Current(), monitor_lock_); |
| 1007 | return owner_ != nullptr; |
| 1008 | } |
| 1009 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 1010 | void Monitor::TranslateLocation(const mirror::ArtMethod* method, uint32_t dex_pc, |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1011 | const char** source_file, uint32_t* line_number) const { |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 1012 | // If method is null, location is unknown |
| 1013 | if (method == NULL) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1014 | *source_file = ""; |
| 1015 | *line_number = 0; |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 1016 | return; |
| 1017 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 1018 | MethodHelper mh(method); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1019 | *source_file = mh.GetDeclaringClassSourceFile(); |
| 1020 | if (*source_file == NULL) { |
| 1021 | *source_file = ""; |
Elliott Hughes | 12c51e3 | 2012-01-17 20:25:05 -0800 | [diff] [blame] | 1022 | } |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1023 | *line_number = mh.GetLineNumFromDexPC(dex_pc); |
| 1024 | } |
| 1025 | |
| 1026 | uint32_t Monitor::GetOwnerThreadId() { |
| 1027 | MutexLock mu(Thread::Current(), monitor_lock_); |
| 1028 | Thread* owner = owner_; |
| 1029 | if (owner != NULL) { |
| 1030 | return owner->GetThreadId(); |
| 1031 | } else { |
| 1032 | return ThreadList::kInvalidThreadId; |
| 1033 | } |
jeffhao | 33dc771 | 2011-11-09 17:54:24 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 1036 | MonitorList::MonitorList() |
| 1037 | : allow_new_monitors_(true), monitor_list_lock_("MonitorList lock"), |
| 1038 | monitor_add_condition_("MonitorList disallow condition", monitor_list_lock_) { |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | MonitorList::~MonitorList() { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1042 | MutexLock mu(Thread::Current(), monitor_list_lock_); |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 1043 | STLDeleteElements(&list_); |
| 1044 | } |
| 1045 | |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 1046 | void MonitorList::DisallowNewMonitors() { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1047 | MutexLock mu(Thread::Current(), monitor_list_lock_); |
Mathieu Chartier | c11d9b8 | 2013-09-19 10:01:59 -0700 | [diff] [blame] | 1048 | allow_new_monitors_ = false; |
| 1049 | } |
| 1050 | |
| 1051 | void MonitorList::AllowNewMonitors() { |
| 1052 | Thread* self = Thread::Current(); |
| 1053 | MutexLock mu(self, monitor_list_lock_); |
| 1054 | allow_new_monitors_ = true; |
| 1055 | monitor_add_condition_.Broadcast(self); |
| 1056 | } |
| 1057 | |
| 1058 | void MonitorList::Add(Monitor* m) { |
| 1059 | Thread* self = Thread::Current(); |
| 1060 | MutexLock mu(self, monitor_list_lock_); |
| 1061 | while (UNLIKELY(!allow_new_monitors_)) { |
| 1062 | monitor_add_condition_.WaitHoldingLocks(self); |
| 1063 | } |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 1064 | list_.push_front(m); |
| 1065 | } |
| 1066 | |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 1067 | void MonitorList::SweepMonitorList(RootVisitor visitor, void* arg) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 1068 | MutexLock mu(Thread::Current(), monitor_list_lock_); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 1069 | for (auto it = list_.begin(); it != list_.end(); ) { |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 1070 | Monitor* m = *it; |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 1071 | mirror::Object* obj = m->GetObject(); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1072 | // The object of a monitor can be null if we have deflated it. |
| 1073 | mirror::Object* new_obj = obj != nullptr ? visitor(obj, arg) : nullptr; |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 1074 | if (new_obj == nullptr) { |
| 1075 | VLOG(monitor) << "freeing monitor " << m << " belonging to unmarked object " |
| 1076 | << m->GetObject(); |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 1077 | delete m; |
| 1078 | it = list_.erase(it); |
| 1079 | } else { |
Mathieu Chartier | 6aa3df9 | 2013-09-17 15:17:28 -0700 | [diff] [blame] | 1080 | m->SetObject(new_obj); |
Elliott Hughes | c33a32b | 2011-10-11 18:18:07 -0700 | [diff] [blame] | 1081 | ++it; |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1086 | MonitorInfo::MonitorInfo(mirror::Object* obj) : owner_(NULL), entry_count_(0) { |
| 1087 | DCHECK(obj != NULL); |
| 1088 | |
| 1089 | LockWord lock_word = obj->GetLockWord(); |
| 1090 | switch (lock_word.GetState()) { |
| 1091 | case LockWord::kUnlocked: |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 1092 | // Fall-through. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1093 | case LockWord::kForwardingAddress: |
| 1094 | // Fall-through. |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 1095 | case LockWord::kHashCode: |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1096 | break; |
| 1097 | case LockWord::kThinLocked: |
| 1098 | owner_ = Runtime::Current()->GetThreadList()->FindThreadByThreadId(lock_word.ThinLockOwner()); |
| 1099 | entry_count_ = 1 + lock_word.ThinLockCount(); |
| 1100 | // Thin locks have no waiters. |
| 1101 | break; |
| 1102 | case LockWord::kFatLocked: { |
| 1103 | Monitor* mon = lock_word.FatLockMonitor(); |
| 1104 | owner_ = mon->owner_; |
| 1105 | entry_count_ = 1 + mon->lock_count_; |
| 1106 | for (Thread* waiter = mon->wait_set_; waiter != NULL; waiter = waiter->wait_next_) { |
| 1107 | waiters_.push_back(waiter); |
| 1108 | } |
| 1109 | break; |
Elliott Hughes | f327e07 | 2013-01-09 16:01:26 -0800 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 1114 | } // namespace art |