• 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/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 
27 namespace panda::ecmascript {
SetClassWithoutBarrier(JSHClass * hclass)28 inline void TaggedObject::SetClassWithoutBarrier(JSHClass *hclass)
29 {
30     class_ = reinterpret_cast<MarkWordType>(hclass);
31 }
32 
SetClass(const JSThread * thread,JSHClass * hclass)33 inline void TaggedObject::SetClass(const JSThread *thread, JSHClass *hclass)
34 {
35     Barriers::SetObject<true>(thread, this, 0, JSTaggedValue(hclass).GetRawData());
36 }
37 
SetClass(const JSThread * thread,JSHandle<JSHClass> hclass)38 inline void TaggedObject::SetClass(const JSThread *thread, JSHandle<JSHClass> hclass)
39 {
40     SetClass(thread, *hclass);
41 }
42 
SynchronizedSetClass(const JSThread * thread,JSHClass * hclass)43 inline void TaggedObject::SynchronizedSetClass(const JSThread *thread, JSHClass *hclass)
44 {
45     Barriers::SynchronizedSetClass(thread, this, JSTaggedValue(hclass).GetRawData());
46 }
47 
SynchronizedGetClass()48 inline JSHClass *TaggedObject::SynchronizedGetClass() const
49 {
50     return reinterpret_cast<JSHClass *>(
51         reinterpret_cast<volatile std::atomic<MarkWordType> *>(ToUintPtr(this))->load(std::memory_order_acquire));
52 }
53 }  //  namespace panda::ecmascript
54 
55 #endif  // ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H
56