• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
17 #define ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
18 
19 #include "ecmascript/mem/tagged_object.h"
20 
21 #include <atomic>
22 
23 #include "ecmascript/ecma_vm.h"
24 #include "ecmascript/js_handle.h"
25 #include "ecmascript/js_hclass.h"
26 #include "ecmascript/mem/heap.h"
27 
28 namespace panda::ecmascript {
SetClassWithoutBarrier(JSHClass * hclass)29 inline void TaggedObject::SetClassWithoutBarrier(JSHClass *hclass)
30 {
31     class_ = reinterpret_cast<MarkWordType>(hclass);
32 }
33 
SetClass(const JSThread * thread,JSHClass * hclass)34 inline void TaggedObject::SetClass(const JSThread *thread, JSHClass *hclass)
35 {
36     Barriers::SetObject<true>(thread, this, 0, JSTaggedValue(hclass).GetRawData());
37 }
38 
SetClass(const JSThread * thread,JSHandle<JSHClass> hclass)39 inline void TaggedObject::SetClass(const JSThread *thread, JSHandle<JSHClass> hclass)
40 {
41     SetClass(thread, *hclass);
42 }
43 
GetClass()44 inline JSHClass *TaggedObject::GetClass() const
45 {
46     return reinterpret_cast<JSHClass *>(class_);
47 }
48 
SynchronizedSetClass(const JSThread * thread,JSHClass * hclass)49 inline void TaggedObject::SynchronizedSetClass(const JSThread *thread, JSHClass *hclass)
50 {
51     Barriers::SynchronizedSetClass(thread, this, JSTaggedValue(hclass).GetRawData());
52 }
53 
SynchronizedGetClass()54 inline JSHClass *TaggedObject::SynchronizedGetClass() const
55 {
56     return reinterpret_cast<JSHClass *>(
57         reinterpret_cast<volatile std::atomic<MarkWordType> *>(ToUintPtr(this))->load(std::memory_order_acquire));
58 }
59 }  //  namespace panda::ecmascript
60 
61 #endif  // ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
62