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)29inline void TaggedObject::SetClassWithoutBarrier(JSHClass *hclass) 30 { 31 class_ = reinterpret_cast<MarkWordType>(hclass); 32 } 33 SetClass(JSHClass * hclass)34inline void TaggedObject::SetClass(JSHClass *hclass) 35 { 36 Barriers::SetObject<true>(GetJSThread(), this, 0, JSTaggedValue(hclass).GetRawData()); 37 } 38 SetClass(JSHandle<JSHClass> hclass)39inline void TaggedObject::SetClass(JSHandle<JSHClass> hclass) 40 { 41 SetClass(*hclass); 42 } 43 GetClass()44inline JSHClass *TaggedObject::GetClass() const 45 { 46 return reinterpret_cast<JSHClass *>(class_); 47 } 48 SynchronizedSetClass(JSHClass * hclass)49inline void TaggedObject::SynchronizedSetClass(JSHClass *hclass) 50 { 51 Barriers::SynchronizedSetClass(this, JSTaggedValue(hclass).GetRawData()); 52 } 53 SynchronizedGetClass()54inline 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 GetJSThread()60inline JSThread *TaggedObject::GetJSThread() const 61 { 62 Region *region = Region::ObjectAddressToRange(const_cast<TaggedObject *>(this)); 63 ASSERT(region != nullptr); 64 return region->GetJSThread(); 65 } 66 } // namespace panda::ecmascript 67 68 #endif // ECMASCRIPT_TAGGED_OBJECT_HEADER_INL_H 69