• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef PANDA_RUNTIME_MARK_WORD_CPP_
16 #define PANDA_RUNTIME_MARK_WORD_CPP_
17 
18 #include "runtime/mark_word.h"
19 
20 namespace panda {
21 
22 template <bool HashPolicy>
GetHashConfigured() const23 inline uint32_t MarkWord::GetHashConfigured() const
24 {
25     LOG_IF(GetState() != STATE_HASHED, DEBUG, RUNTIME) << "Wrong State";
26     return static_cast<uint32_t>((Value() >> HASH_SHIFT) & HASH_MASK);
27 }
28 
29 template <>
GetHashConfigured() const30 inline uint32_t MarkWord::GetHashConfigured<false>() const
31 {
32     LOG(ERROR, RUNTIME) << "Hash is not stored inside object header!";
33     return 0;
34 }
35 
GetHash() const36 uint32_t MarkWord::GetHash() const
37 {
38     return GetHashConfigured<CONFIG_IS_HASH_IN_OBJ_HEADER>();
39 }
40 
41 template <bool HashPolicy>
DecodeFromHashConfigured(uint32_t hash)42 inline MarkWord MarkWord::DecodeFromHashConfigured(uint32_t hash)
43 {
44     // Clear hash and status bits
45     markWordSize temp = Value() & (~(HASH_MASK_IN_PLACE | STATUS_MASK_IN_PLACE));
46     markWordSize hash_in_place = (static_cast<markWordSize>(hash) & HASH_MASK) << HASH_SHIFT;
47     return MarkWord(temp | hash_in_place | (STATUS_HASHED << STATUS_SHIFT));
48 }
49 
50 template <>
DecodeFromHashConfigured(uint32_t hash)51 inline MarkWord MarkWord::DecodeFromHashConfigured<false>(uint32_t hash)
52 {
53     (void)hash;
54     LOG(ERROR, RUNTIME) << "Hash is not stored inside object header!";
55     return MarkWord(0);
56 }
57 
DecodeFromHash(uint32_t hash)58 MarkWord MarkWord::DecodeFromHash(uint32_t hash)
59 {
60     return DecodeFromHashConfigured<CONFIG_IS_HASH_IN_OBJ_HEADER>(hash);
61 }
62 
63 template <bool HashPolicy>
SetHashedConfigured()64 inline MarkWord MarkWord::SetHashedConfigured()
65 {
66     LOG(ERROR, RUNTIME) << "Hash is stored inside object header and we don't use hash status bit!";
67     return MarkWord(0);
68 }
69 
70 template <>
SetHashedConfigured()71 inline MarkWord MarkWord::SetHashedConfigured<false>()
72 {
73     return MarkWord((Value() & (~HASH_STATUS_MASK_IN_PLACE)) | HASH_STATUS_MASK_IN_PLACE);
74 }
75 
SetHashed()76 inline MarkWord MarkWord::SetHashed()
77 {
78     return SetHashedConfigured<CONFIG_IS_HASH_IN_OBJ_HEADER>();
79 }
80 
81 template <bool HashPolicy>
IsHashedConfigured() const82 inline bool MarkWord::IsHashedConfigured() const
83 {
84     LOG(ERROR, RUNTIME) << "Hash is stored inside object header and we don't use hash status bit!";
85     return false;
86 }
87 
88 template <>
IsHashedConfigured() const89 inline bool MarkWord::IsHashedConfigured<false>() const
90 {
91     return (Value() & HASH_STATUS_MASK_IN_PLACE) != 0U;
92 }
93 
IsHashed() const94 inline bool MarkWord::IsHashed() const
95 {
96     return IsHashedConfigured<CONFIG_IS_HASH_IN_OBJ_HEADER>();
97 }
98 
99 }  // namespace panda
100 
101 #endif  // PANDA_RUNTIME_MARK_WORD_CPP_
102