Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
| 17 | #ifndef ART_RUNTIME_LOCK_WORD_INL_H_ |
| 18 | #define ART_RUNTIME_LOCK_WORD_INL_H_ |
| 19 | |
| 20 | #include "lock_word.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | inline uint32_t LockWord::ThinLockOwner() const { |
| 25 | DCHECK_EQ(GetState(), kThinLocked); |
| 26 | return (value_ >> kThinLockOwnerShift) & kThinLockOwnerMask; |
| 27 | } |
| 28 | |
| 29 | inline uint32_t LockWord::ThinLockCount() const { |
| 30 | DCHECK_EQ(GetState(), kThinLocked); |
| 31 | return (value_ >> kThinLockCountShift) & kThinLockCountMask; |
| 32 | } |
| 33 | |
| 34 | inline Monitor* LockWord::FatLockMonitor() const { |
| 35 | DCHECK_EQ(GetState(), kFatLocked); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 36 | return reinterpret_cast<Monitor*>(value_ << kStateSize); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 39 | inline size_t LockWord::ForwardingAddress() const { |
| 40 | DCHECK_EQ(GetState(), kForwardingAddress); |
| 41 | return static_cast<size_t>(value_ << kStateSize); |
| 42 | } |
| 43 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 44 | inline LockWord::LockWord() : value_(0) { |
| 45 | DCHECK_EQ(GetState(), kUnlocked); |
| 46 | } |
| 47 | |
| 48 | inline LockWord::LockWord(Monitor* mon) |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 49 | : value_((reinterpret_cast<uint32_t>(mon) >> kStateSize) | (kStateFat << kStateShift)) { |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 50 | DCHECK_EQ(FatLockMonitor(), mon); |
| 51 | } |
| 52 | |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 53 | inline int32_t LockWord::GetHashCode() const { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 54 | DCHECK_EQ(GetState(), kHashCode); |
| 55 | return (value_ >> kHashShift) & kHashMask; |
| 56 | } |
| 57 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 58 | } // namespace art |
| 59 | |
| 60 | #endif // ART_RUNTIME_LOCK_WORD_INL_H_ |