• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 
16 #ifndef ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
17 #define ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
18 
19 #include "ecmascript/mem/barriers-inl.h"
20 #include "ecmascript/mem/tagged_object.h"
21 
22 #include <atomic>
23 
24 #include "ecmascript/ecma_vm.h"
25 #include "ecmascript/js_handle.h"
26 #include "ecmascript/js_hclass.h"
27 
28 namespace panda::ecmascript {
SetClassWithoutBarrier(JSHClass * hclass)29 inline void TaggedObject::SetClassWithoutBarrier(JSHClass *hclass)
30 {
31     state_ = 0;
32     TransitionClassWithoutBarrier(hclass);
33 }
34 
TransitionClassWithoutBarrier(JSHClass * hclass)35 inline void TaggedObject::TransitionClassWithoutBarrier(JSHClass *hclass)
36 {
37     reinterpret_cast<TaggedStateWord *>(this)->SetClass(reinterpret_cast<uintptr_t>(hclass));
38 }
39 
SetFreeObjectClass(JSHClass * hclass)40 inline void TaggedObject::SetFreeObjectClass(JSHClass *hclass)
41 {
42     ASSERT(hclass->IsFreeObject());
43     common::StateWordType state = static_cast<common::StateWordType>(ToUintPtr(hclass));
44     reinterpret_cast<TaggedStateWord *>(this)->SynchronizedSetGCStateWord(state);
45 }
46 
SetClass(const JSThread * thread,JSHClass * hclass)47 inline void TaggedObject::SetClass(const JSThread *thread, JSHClass *hclass)
48 {
49 #ifndef ARK_USE_SATB_BARRIER
50     SetClassWithoutBarrier(hclass);
51     WriteBarrier(thread, this, HCLASS_OFFSET, JSTaggedValue(hclass).GetRawData());
52 #else
53     WriteBarrier(thread, this, HCLASS_OFFSET, JSTaggedValue(hclass).GetRawData());
54     SetClassWithoutBarrier(hclass);
55 #endif
56 }
57 
SynchronizedTransitionClass(const JSThread * thread,JSHClass * hclass)58 inline void TaggedObject::SynchronizedTransitionClass(const JSThread *thread, JSHClass *hclass)
59 {
60 #ifndef ARK_USE_SATB_BARRIER
61     reinterpret_cast<TaggedStateWord *>(this)->SynchronizedSetClass(reinterpret_cast<uintptr_t>(hclass));
62     WriteBarrier(thread, this, HCLASS_OFFSET, JSTaggedValue(hclass).GetRawData());
63 #else
64     WriteBarrier(thread, this, HCLASS_OFFSET, JSTaggedValue(hclass).GetRawData());
65     reinterpret_cast<TaggedStateWord *>(this)->SynchronizedSetClass(reinterpret_cast<uintptr_t>(hclass));
66 #endif
67 }
68 
SynchronizedGetClass()69 inline JSHClass *TaggedObject::SynchronizedGetClass() const
70 {
71     return reinterpret_cast<JSHClass *>(reinterpret_cast<const TaggedStateWord *>(this)->SynchronizedGetClass());
72 }
73 
IsInSharedHeap()74 inline bool TaggedObject::IsInSharedHeap() const
75 {
76     return GetClass()->IsJSShared();
77 }
78 }  //  namespace panda::ecmascript
79 
80 #endif  // ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
81