• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_IC_PROTOTYPE_CHANGE_DETAILS_H
17 #define ECMASCRIPT_IC_PROTOTYPE_CHANGE_DETAILS_H
18 
19 #include "ecmascript/ecma_macros.h"
20 #include "ecmascript/js_handle.h"
21 #include "ecmascript/js_tagged_value.h"
22 #include "ecmascript/weak_vector.h"
23 
24 namespace panda {
25 namespace ecmascript {
26 class ProtoChangeMarker : public TaggedObject {
27 public:
Cast(TaggedObject * object)28     static ProtoChangeMarker *Cast(TaggedObject *object)
29     {
30         ASSERT(JSTaggedValue(object).IsProtoChangeMarker());
31         return static_cast<ProtoChangeMarker *>(object);
32     }
33 
34     static constexpr size_t BIT_FIELD_OFFSET = TaggedObjectSize();
35     ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
36     DEFINE_ALIGN_SIZE(LAST_OFFSET);
37     DECL_VISIT_PRIMITIVE_OBJECT()
38 
39     // define BitField
40     static constexpr size_t HAS_CHANGED_BITS = 1;
41     static constexpr size_t ACCESSOR_HAS_CHANGED_BITS = 1;
42     static constexpr size_t NOTFOUND_HAS_CHANGED_BITS = 1;
43     FIRST_BIT_FIELD(BitField, HasChanged, bool, HAS_CHANGED_BITS);
44     NEXT_BIT_FIELD(BitField, AccessorHasChanged, bool, ACCESSOR_HAS_CHANGED_BITS, HasChanged);
45 
46     // The "NotFoundHasChanged" flag is introduced to address a specific issue. In the "RuntimeUpdateAOTHClass",
47     // the "HasChanged" flag is not modified when a key is absent from the prototype chain. However, when using
48     // the "not found" inline cache (IC), even if the key is not in the prototype chain, it might still impact
49     // the listeners' ICs.
50     // To handle this situation, we've added the `NotFoundHasChanged` flag, which is exclusively used for the
51     // "not found" ICs.
52     NEXT_BIT_FIELD(BitField, NotFoundHasChanged, bool, NOTFOUND_HAS_CHANGED_BITS, HasChanged);
53 
54     DECL_DUMP()
55 };
56 
57 class ProtoChangeDetails : public TaggedObject {
58 public:
59     static constexpr int UNREGISTERED = -1;
Cast(TaggedObject * object)60     static ProtoChangeDetails *Cast(TaggedObject *object)
61     {
62         ASSERT(JSTaggedValue(object).IsProtoChangeDetails());
63         return static_cast<ProtoChangeDetails *>(object);
64     }
65 
66     static constexpr size_t CHANGE_LISTENER_OFFSET = TaggedObjectSize();
67     ACCESSORS(ChangeListener, CHANGE_LISTENER_OFFSET, REGISTER_INDEX_OFFSET);
68     ACCESSORS_PRIMITIVE_FIELD(RegisterIndex, uint32_t, REGISTER_INDEX_OFFSET, LAST_OFFSET);
69     DEFINE_ALIGN_SIZE(LAST_OFFSET);
70 
71     DECL_VISIT_OBJECT(CHANGE_LISTENER_OFFSET, REGISTER_INDEX_OFFSET)
72     DECL_DUMP()
73 };
74 
75 class ChangeListener : public WeakVector {
76 public:
Cast(TaggedObject * object)77     static ChangeListener *Cast(TaggedObject *object)
78     {
79         return static_cast<ChangeListener *>(object);
80     }
81 
82     static JSHandle<ChangeListener> Add(const JSThread *thread, const JSHandle<ChangeListener> &array,
83                                         const JSHandle<JSHClass> &value, uint32_t *index);
84 
85     static uint32_t CheckHole(const JSHandle<ChangeListener> &array);
86 
87     JSTaggedValue Get(uint32_t index);
88 };
89 }  // namespace ecmascript
90 }  // namespace panda
91 
92 #endif  // ECMASCRIPT_IC_PROTOTYPE_CHANGE_DETAILS_H
93