2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ART_RUNTIME_LOCK_WORD_INL_H_
18 #define ART_RUNTIME_LOCK_WORD_INL_H_
20 #include "lock_word.h"
21 #include "monitor_pool.h"
25 inline uint32_t LockWord::ThinLockOwner() const {
26 DCHECK_EQ(GetState(), kThinLocked);
27 CheckReadBarrierState();
28 return (value_ >> kThinLockOwnerShift) & kThinLockOwnerMask;
31 inline uint32_t LockWord::ThinLockCount() const {
32 DCHECK_EQ(GetState(), kThinLocked);
33 CheckReadBarrierState();
34 return (value_ >> kThinLockCountShift) & kThinLockCountMask;
37 inline Monitor* LockWord::FatLockMonitor() const {
38 DCHECK_EQ(GetState(), kFatLocked);
39 CheckReadBarrierState();
40 MonitorId mon_id = (value_ >> kMonitorIdShift) & kMonitorIdMask;
41 return MonitorPool::MonitorFromMonitorId(mon_id);
44 inline size_t LockWord::ForwardingAddress() const {
45 DCHECK_EQ(GetState(), kForwardingAddress);
46 return value_ << kStateSize;
49 inline LockWord::LockWord() : value_(0) {
50 DCHECK_EQ(GetState(), kUnlocked);
53 inline LockWord::LockWord(Monitor* mon, uint32_t rb_state)
54 : value_(mon->GetMonitorId() | (rb_state << kReadBarrierStateShift) |
55 (kStateFat << kStateShift)) {
56 DCHECK_EQ(rb_state & ~kReadBarrierStateMask, 0U);
58 DCHECK_ALIGNED(mon, kMonitorIdAlignment);
60 DCHECK_EQ(FatLockMonitor(), mon);
61 DCHECK_LE(mon->GetMonitorId(), static_cast<uint32_t>(kMaxMonitorId));
62 CheckReadBarrierState();
65 inline int32_t LockWord::GetHashCode() const {
66 DCHECK_EQ(GetState(), kHashCode);
67 CheckReadBarrierState();
68 return (value_ >> kHashShift) & kHashMask;
73 #endif // ART_RUNTIME_LOCK_WORD_INL_H_