• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_PROFILE_TYPE_INFO_CELL_H
17 #define ECMASCRIPT_PROFILE_TYPE_INFO_CELL_H
18 
19 #include "ecmascript/ecma_macros.h"
20 #include "ecmascript/js_handle.h"
21 #include "ecmascript/js_hclass.h"
22 #include "ecmascript/js_tagged_value.h"
23 #include "ecmascript/tagged_dictionary.h"
24 #include "ecmascript/js_function.h"
25 #include "ecmascript/js_thread.h"
26 #include "ecmascript/mem/barriers.h"
27 #include "ecmascript/mem/visitor.h"
28 
29 namespace panda {
30 namespace ecmascript {
31 class ProfileTypeInfoCell : public TaggedObject {
32 public:
33     CAST_CHECK(ProfileTypeInfoCell, IsProfileTypeInfoCell);
34 
35     static constexpr size_t VALUE_OFFSET = TaggedObjectSize();
36     ACCESSORS(Value, VALUE_OFFSET, MACHINE_CODE_OFFSET);
37     ACCESSORS(MachineCode, MACHINE_CODE_OFFSET, EXTRA_INFO_MAP_OFFSET);
38     ACCESSORS(ExtraInfoMap, EXTRA_INFO_MAP_OFFSET, HANDLE_OFFSET);
39     ACCESSORS(Handle, HANDLE_OFFSET, LAST_OFFSET);
40     DEFINE_ALIGN_SIZE(LAST_OFFSET);
41 
42     DECL_VISIT_OBJECT(VALUE_OFFSET, LAST_OFFSET);
43 
IsEmptyProfileTypeInfoCell(const JSThread * thread)44     bool IsEmptyProfileTypeInfoCell(const JSThread *thread) const
45     {
46         return this == thread->GlobalConstants()->GetEmptyProfileTypeInfoCell().GetTaggedObject();
47     }
48 
UpdateProfileTypeInfoCellType(const JSThread * thread)49     void UpdateProfileTypeInfoCellType(const JSThread *thread)
50     {
51         // ProfileTypeInfoCell0 -> Cell1 -> CellN
52         JSType jsType = GetClass()->GetObjectType();
53         if (jsType == JSType::PROFILE_TYPE_INFO_CELL_0) {
54             SetClassWithoutBarrier(
55                 JSHClass::Cast(thread->GlobalConstants()->GetProfileTypeInfoCell1Class().GetTaggedObject()));
56         } else if (jsType == JSType::PROFILE_TYPE_INFO_CELL_1) {
57             SetClassWithoutBarrier(
58                 JSHClass::Cast(thread->GlobalConstants()->GetProfileTypeInfoCellNClass().GetTaggedObject()));
59         } else {
60             ASSERT(jsType == JSType::PROFILE_TYPE_INFO_CELL_N);
61         }
62     }
63 
CreateOrGetExtraInfoMap(const JSThread * thread,JSHandle<ProfileTypeInfoCell> profileTypeInfoCell)64     static JSHandle<NumberDictionary> CreateOrGetExtraInfoMap(const JSThread *thread,
65                                                               JSHandle<ProfileTypeInfoCell> profileTypeInfoCell)
66     {
67         if (profileTypeInfoCell->GetExtraInfoMap().IsUndefined()) {
68             JSHandle<NumberDictionary> dictJShandle = NumberDictionary::Create(thread);
69             profileTypeInfoCell->SetExtraInfoMap(thread, dictJShandle);
70             return dictJShandle;
71         }
72         JSHandle<NumberDictionary> dictJShandle(thread, profileTypeInfoCell->GetExtraInfoMap());
73         return dictJShandle;
74     }
75 
UpdateExtraInfoMap(const JSThread * thread,JSHandle<NumberDictionary> dictJShandle,JSHandle<JSTaggedValue> key,JSHandle<JSTaggedValue> receiverHClassHandle,JSHandle<JSTaggedValue> holderHClassHandle,JSHandle<ProfileTypeInfoCell> profileTypeInfoCell)76     static void UpdateExtraInfoMap(const JSThread *thread, JSHandle<NumberDictionary> dictJShandle,
77                             JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> receiverHClassHandle,
78                             JSHandle<JSTaggedValue> holderHClassHandle,
79                             JSHandle<ProfileTypeInfoCell> profileTypeInfoCell)
80     {
81         JSHandle<JSTaggedValue> info(thread->GetEcmaVM()->GetFactory()->NewExtraProfileTypeInfo());
82         JSHandle<ExtraProfileTypeInfo> infoHandle(info);
83         infoHandle->SetReceiver(thread, receiverHClassHandle.GetTaggedValue().CreateAndGetWeakRef());
84         infoHandle->SetHolder(thread, holderHClassHandle.GetTaggedValue());
85         JSHandle<NumberDictionary> dict = NumberDictionary::PutIfAbsent(thread,
86                                                                         dictJShandle,
87                                                                         key,
88                                                                         info,
89                                                                         PropertyAttributes::Default());
90         profileTypeInfoCell->SetExtraInfoMap(thread, dict);
91     }
92     DECL_DUMP()
93 };
94 
95 }  // namespace ecmascript
96 }  // namespace panda
97 
98 #endif  // ECMASCRIPT_PROFILE_TYPE_INFO_CELL_H
99