• 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_thread.h"
25 #include "ecmascript/mem/barriers.h"
26 #include "ecmascript/mem/visitor.h"
27 
28 namespace panda {
29 namespace ecmascript {
30 class ProfileTypeInfoCell : public TaggedObject {
31 public:
32     CAST_CHECK(ProfileTypeInfoCell, IsProfileTypeInfoCell);
33 
34     static constexpr size_t VALUE_OFFSET = TaggedObjectSize();
35     ACCESSORS(Value, VALUE_OFFSET, MACHINE_CODE_OFFSET);
36     ACCESSORS(MachineCode, MACHINE_CODE_OFFSET, HANDLE_OFFSET);
37     ACCESSORS(Handle, HANDLE_OFFSET, LAST_OFFSET);
38     DEFINE_ALIGN_SIZE(LAST_OFFSET);
39 
40     DECL_VISIT_OBJECT(VALUE_OFFSET, LAST_OFFSET);
41 
IsEmptyProfileTypeInfoCell(const JSThread * thread)42     bool IsEmptyProfileTypeInfoCell(const JSThread *thread) const
43     {
44         return this == thread->GlobalConstants()->GetEmptyProfileTypeInfoCell().GetTaggedObject();
45     }
46 
UpdateProfileTypeInfoCellType(const JSThread * thread)47     void UpdateProfileTypeInfoCellType(const JSThread *thread)
48     {
49         // ProfileTypeInfoCell0 -> Cell1 -> CellN
50         JSType jsType = GetClass()->GetObjectType();
51         if (jsType == JSType::PROFILE_TYPE_INFO_CELL_0) {
52             TransitionClassWithoutBarrier(
53                 JSHClass::Cast(thread->GlobalConstants()->GetProfileTypeInfoCell1Class().GetTaggedObject()));
54         } else if (jsType == JSType::PROFILE_TYPE_INFO_CELL_1) {
55             TransitionClassWithoutBarrier(
56                 JSHClass::Cast(thread->GlobalConstants()->GetProfileTypeInfoCellNClass().GetTaggedObject()));
57         } else {
58             ASSERT(jsType == JSType::PROFILE_TYPE_INFO_CELL_N);
59         }
60     }
61 
62     DECL_DUMP()
63 };
64 
65 }  // namespace ecmascript
66 }  // namespace panda
67 
68 #endif  // ECMASCRIPT_PROFILE_TYPE_INFO_CELL_H
69