blob: 4a2a293400777b481c8f71114e327d070bfeb0d5 [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);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080027 CheckReadBarrierState();
Ian Rogersd9c4fc92013-10-01 19:45:43 -070028 return (value_ >> kThinLockOwnerShift) & kThinLockOwnerMask;
29}
30
31inline uint32_t LockWord::ThinLockCount() const {
32 DCHECK_EQ(GetState(), kThinLocked);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080033 CheckReadBarrierState();
Ian Rogersd9c4fc92013-10-01 19:45:43 -070034 return (value_ >> kThinLockCountShift) & kThinLockCountMask;
35}
36
37inline Monitor* LockWord::FatLockMonitor() const {
38 DCHECK_EQ(GetState(), kFatLocked);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080039 CheckReadBarrierState();
40 MonitorId mon_id = (value_ >> kMonitorIdShift) & kMonitorIdMask;
Ian Rogersef7d42f2014-01-06 12:55:46 -080041 return MonitorPool::MonitorFromMonitorId(mon_id);
Ian Rogersd9c4fc92013-10-01 19:45:43 -070042}
43
Mathieu Chartier590fee92013-09-13 13:46:47 -070044inline size_t LockWord::ForwardingAddress() const {
45 DCHECK_EQ(GetState(), kForwardingAddress);
Mathieu Chartier36a270a2016-07-28 18:08:51 -070046 return value_ << kForwardingAddressShift;
Mathieu Chartier590fee92013-09-13 13:46:47 -070047}
48
Ian Rogersd9c4fc92013-10-01 19:45:43 -070049inline LockWord::LockWord() : value_(0) {
50 DCHECK_EQ(GetState(), kUnlocked);
51}
52
Mathieu Chartier36a270a2016-07-28 18:08:51 -070053inline LockWord::LockWord(Monitor* mon, uint32_t gc_state)
54 : value_(mon->GetMonitorId() | (gc_state << kGCStateShift) | (kStateFat << kStateShift)) {
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080055#ifndef __LP64__
56 DCHECK_ALIGNED(mon, kMonitorIdAlignment);
57#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -070058 DCHECK_EQ(FatLockMonitor(), mon);
nikolay serdjukd8481cc2014-07-28 17:40:16 +070059 DCHECK_LE(mon->GetMonitorId(), static_cast<uint32_t>(kMaxMonitorId));
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080060 CheckReadBarrierState();
Ian Rogersd9c4fc92013-10-01 19:45:43 -070061}
62
Mathieu Chartier4e6a31e2013-10-31 10:35:05 -070063inline int32_t LockWord::GetHashCode() const {
Mathieu Chartierad2541a2013-10-25 10:05:23 -070064 DCHECK_EQ(GetState(), kHashCode);
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -080065 CheckReadBarrierState();
Mathieu Chartierad2541a2013-10-25 10:05:23 -070066 return (value_ >> kHashShift) & kHashMask;
67}
68
Ian Rogersd9c4fc92013-10-01 19:45:43 -070069} // namespace art
70
71#endif // ART_RUNTIME_LOCK_WORD_INL_H_