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" |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 21 | #include "monitor_pool.h" |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | inline uint32_t LockWord::ThinLockOwner() const { |
| 26 | DCHECK_EQ(GetState(), kThinLocked); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 27 | CheckReadBarrierState(); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 28 | return (value_ >> kThinLockOwnerShift) & kThinLockOwnerMask; |
| 29 | } |
| 30 | |
| 31 | inline uint32_t LockWord::ThinLockCount() const { |
| 32 | DCHECK_EQ(GetState(), kThinLocked); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 33 | CheckReadBarrierState(); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 34 | return (value_ >> kThinLockCountShift) & kThinLockCountMask; |
| 35 | } |
| 36 | |
| 37 | inline Monitor* LockWord::FatLockMonitor() const { |
| 38 | DCHECK_EQ(GetState(), kFatLocked); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 39 | CheckReadBarrierState(); |
| 40 | MonitorId mon_id = (value_ >> kMonitorIdShift) & kMonitorIdMask; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 41 | return MonitorPool::MonitorFromMonitorId(mon_id); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 44 | inline size_t LockWord::ForwardingAddress() const { |
| 45 | DCHECK_EQ(GetState(), kForwardingAddress); |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 46 | return value_ << kStateSize; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 49 | inline LockWord::LockWord() : value_(0) { |
| 50 | DCHECK_EQ(GetState(), kUnlocked); |
| 51 | } |
| 52 | |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 53 | inline LockWord::LockWord(Monitor* mon, uint32_t rb_state) |
| 54 | : value_(mon->GetMonitorId() | (rb_state << kReadBarrierStateShift) | |
| 55 | (kStateFat << kStateShift)) { |
Hiroshi Yamauchi | 60f63f5 | 2015-04-23 16:12:40 -0700 | [diff] [blame] | 56 | DCHECK_EQ(rb_state & ~kReadBarrierStateMask, 0U); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 57 | #ifndef __LP64__ |
| 58 | DCHECK_ALIGNED(mon, kMonitorIdAlignment); |
| 59 | #endif |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 60 | DCHECK_EQ(FatLockMonitor(), mon); |
nikolay serdjuk | d8481cc | 2014-07-28 17:40:16 +0700 | [diff] [blame] | 61 | DCHECK_LE(mon->GetMonitorId(), static_cast<uint32_t>(kMaxMonitorId)); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 62 | CheckReadBarrierState(); |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Mathieu Chartier | 4e6a31e | 2013-10-31 10:35:05 -0700 | [diff] [blame] | 65 | inline int32_t LockWord::GetHashCode() const { |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 66 | DCHECK_EQ(GetState(), kHashCode); |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 67 | CheckReadBarrierState(); |
Mathieu Chartier | ad2541a | 2013-10-25 10:05:23 -0700 | [diff] [blame] | 68 | return (value_ >> kHashShift) & kHashMask; |
| 69 | } |
| 70 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 71 | } // namespace art |
| 72 | |
| 73 | #endif // ART_RUNTIME_LOCK_WORD_INL_H_ |