1 /* 2 * Copyright (c) 2023 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_PGO_EXTRA_PROFILER_H 17 #define ECMASCRIPT_PGO_EXTRA_PROFILER_H 18 19 #include <chrono> 20 #include <memory> 21 22 #include "ecmascript/common.h" 23 #include "ecmascript/ecma_macros.h" 24 #include "ecmascript/elements.h" 25 26 namespace panda::ecmascript { 27 namespace pgo { 28 class ExtraProfileTypeInfo : public TaggedObject { 29 public: 30 CAST_CHECK(ExtraProfileTypeInfo, IsExtraProfileTypeInfo); 31 32 static constexpr size_t RECEIVER_OBJECT_OFFSET = TaggedObjectSize(); 33 ACCESSORS(ReceiverObject, RECEIVER_OBJECT_OFFSET, HOLDER_OBJECT_OFFSET); 34 ACCESSORS(HolderObject, HOLDER_OBJECT_OFFSET, LAST_OFFSET); 35 DEFINE_ALIGN_SIZE(LAST_OFFSET); 36 37 DECL_VISIT_OBJECT(RECEIVER_OBJECT_OFFSET, LAST_OFFSET); 38 GetReceiverHClass(const JSThread * thread)39 JSHClass* GetReceiverHClass(const JSThread *thread) const 40 { 41 return GetReceiverObject(thread).GetHeapObject()->GetClass(); 42 } 43 GetHolderHClass(const JSThread * thread)44 JSHClass* GetHolderHClass(const JSThread *thread) const 45 { 46 return GetHolderObject(thread).GetTaggedObject()->GetClass(); 47 } 48 SetReceiver(const JSThread * thread,JSTaggedValue value)49 void SetReceiver(const JSThread *thread, JSTaggedValue value) 50 { 51 SetReceiverObject(thread, value); 52 } 53 SetHolder(const JSThread * thread,JSTaggedValue value)54 void SetHolder(const JSThread *thread, JSTaggedValue value) 55 { 56 SetHolderObject(thread, value); 57 } 58 GetReceiver(const JSThread * thread)59 JSTaggedValue GetReceiver(const JSThread *thread) const 60 { 61 return GetReceiverObject(thread); 62 } 63 GetHolder(const JSThread * thread)64 JSTaggedValue GetHolder(const JSThread *thread) const 65 { 66 return GetHolderObject(thread); 67 } 68 Clear(const JSThread * thread)69 void Clear(const JSThread *thread) 70 { 71 SetReceiverObject(thread, JSTaggedValue::Hole()); 72 SetHolderObject(thread, JSTaggedValue::Hole()); 73 } 74 ClearReceiver(const JSThread * thread)75 void ClearReceiver(const JSThread *thread) 76 { 77 SetReceiverObject(thread, JSTaggedValue::Hole()); 78 } 79 ClearHolder(const JSThread * thread)80 void ClearHolder(const JSThread *thread) 81 { 82 SetHolderObject(thread, JSTaggedValue::Hole()); 83 } 84 EuqalTo(JSThread * thread,const ExtraProfileTypeInfo & other)85 bool EuqalTo(JSThread *thread, const ExtraProfileTypeInfo& other) const 86 { 87 return GetReceiverObject(thread) == other.GetReceiverObject(thread) && 88 GetHolderObject(thread) == other.GetHolderObject(thread); 89 } 90 IsValid(JSThread * thread)91 bool IsValid(JSThread *thread) const 92 { 93 return !GetReceiverObject(thread).IsHole() && !GetReceiverObject(thread).IsUndefined(); 94 } 95 96 DECL_DUMP() 97 }; 98 99 } // namespace pgo 100 } // namespace panda::ecmascript 101 #endif // ECMASCRIPT_PGO_EXTRA_PROFILER_H 102