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