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"
24namespace panda::ecmascript {
25namespace pgo {
26class ExtraProfileTypeInfo : public TaggedObject {
27public:
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
37    JSHClass* GetReceiverHClass() const
38    {
39        return GetReceiverObject().GetHeapObject()->GetClass();
40    }
41
42    JSHClass* GetHolderHClass() const
43    {
44        return GetHolderObject().GetTaggedObject()->GetClass();
45    }
46
47    void SetReceiver(const JSThread *thread, JSTaggedValue value)
48    {
49        SetReceiverObject(thread, value);
50    }
51
52    void SetHolder(const JSThread *thread, JSTaggedValue value)
53    {
54        SetHolderObject(thread, value);
55    }
56
57    JSTaggedValue GetReceiver() const
58    {
59        return GetReceiverObject();
60    }
61
62    JSTaggedValue GetHolder() const
63    {
64        return GetHolderObject();
65    }
66
67    void Clear(const JSThread *thread)
68    {
69        SetReceiverObject(thread, JSTaggedValue::Hole());
70        SetHolderObject(thread, JSTaggedValue::Hole());
71    }
72
73    void ClearReceiver(const JSThread *thread)
74    {
75        SetReceiverObject(thread, JSTaggedValue::Hole());
76    }
77
78    void ClearHolder(const JSThread *thread)
79    {
80        SetHolderObject(thread, JSTaggedValue::Hole());
81    }
82
83    bool operator==(const ExtraProfileTypeInfo& other) const
84    {
85        return GetReceiverObject() == other.GetReceiverObject() && GetHolderObject() == other.GetHolderObject();
86    }
87
88    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