blob: c52578f8a222da14a2bb82ddb93705cd65d289a8 [file] [log] [blame]
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001/*
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 Rogersef7d42f2014-01-06 12:55:46 -080021#include "monitor_pool.h"
Ian Rogersd9c4fc92013-10-01 19:45:43 -070022
23namespace art {
24
25inline uint32_t LockWord::ThinLockOwner() const {
26 DCHECK_EQ(GetState(), kThinLocked);
27 return (value_ >> kThinLockOwnerShift) & kThinLockOwnerMask;
28}
29
30inline uint32_t LockWord::ThinLockCount() const {
31 DCHECK_EQ(GetState(), kThinLocked);
32 return (value_ >> kThinLockCountShift) & kThinLockCountMask;
33}
34
35inline Monitor* LockWord::FatLockMonitor() const {
36 DCHECK_EQ(GetState(), kFatLocked);
Andreas Gampe277ccbd2014-11-03 21:36:10 -080037 MonitorId mon_id = value_ & ~(kStateMask << kStateShift);
Ian Rogersef7d42f2014-01-06 12:55:46 -080038 return MonitorPool::MonitorFromMonitorId(mon_id);
Ian Rogersd9c4fc92013-10-01 19:45:43 -070039}
40
Mathieu Chartier590fee92013-09-13 13:46:47 -070041inline size_t LockWord::ForwardingAddress() const {
42 DCHECK_EQ(GetState(), kForwardingAddress);
Andreas Gampe277ccbd2014-11-03 21:36:10 -080043 return value_ << kStateSize;
Mathieu Chartier590fee92013-09-13 13:46:47 -070044}
45
Ian Rogersd9c4fc92013-10-01 19:45:43 -070046inline LockWord::LockWord() : value_(0) {
47 DCHECK_EQ(GetState(), kUnlocked);
48}
49
50inline LockWord::LockWord(Monitor* mon)
Ian Rogersef7d42f2014-01-06 12:55:46 -080051 : value_(mon->GetMonitorId() | (kStateFat << kStateShift)) {
Ian Rogersd9c4fc92013-10-01 19:45:43 -070052 DCHECK_EQ(FatLockMonitor(), mon);
nikolay serdjukd8481cc2014-07-28 17:40:16 +070053 DCHECK_LE(mon->GetMonitorId(), static_cast<uint32_t>(kMaxMonitorId));
Ian Rogersd9c4fc92013-10-01 19:45:43 -070054}
55
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -070056inline int32_t LockWord::GetHashCode() const {
Mathieu Chartierad2541a2013-10-25 10:05:23 -070057 DCHECK_EQ(GetState(), kHashCode);
58 return (value_ >> kHashShift) & kHashMask;
59}
60
Ian Rogersd9c4fc92013-10-01 19:45:43 -070061} // namespace art
62
63#endif // ART_RUNTIME_LOCK_WORD_INL_H_