• 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_IC_RUNTIME_H
17 #define ECMASCRIPT_IC_IC_RUNTIME_H
18 
19 #include "ecmascript/ic/profile_type_info.h"
20 #include "ecmascript/accessor_data.h"
21 #include "ecmascript/ecma_vm.h"
22 #include "ecmascript/js_tagged_value.h"
23 #include "ecmascript/js_handle.h"
24 
25 namespace panda::ecmascript {
26 class ProfileTypeInfo;
27 class JSThread;
28 class ObjectOperator;
29 
30 class ICRuntime {
31 public:
ICRuntime(JSThread * thread,JSHandle<ProfileTypeInfo> profileTypeInfo,uint32_t slotId,ICKind kind)32     ICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind)
33         : thread_(thread), icAccessor_(thread, profileTypeInfo, slotId, kind)
34     {
35     }
36 
37     ~ICRuntime() = default;
38 
39     void UpdateLoadHandler(const ObjectOperator &op, JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> receiver);
40     void UpdateStoreHandler(const ObjectOperator &op, JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> receiver);
41 
GetThread()42     JSThread *GetThread() const
43     {
44         return thread_;
45     }
46 
UpdateReceiverHClass(JSHandle<JSTaggedValue> receiverHClass)47     void UpdateReceiverHClass(JSHandle<JSTaggedValue> receiverHClass)
48     {
49         receiverHClass_ = receiverHClass;
50     }
51 
GetICKind()52     ICKind GetICKind() const
53     {
54         return icAccessor_.GetKind();
55     }
56 
57     void TraceIC(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key) const;
58 
59 protected:
60     JSThread *thread_;
61     JSHandle<JSTaggedValue> receiverHClass_{};
62     ProfileTypeAccessor icAccessor_;
63 };
64 
65 class LoadICRuntime : public ICRuntime {
66 public:
LoadICRuntime(JSThread * thread,JSHandle<ProfileTypeInfo> profileTypeInfo,uint32_t slotId,ICKind kind)67     LoadICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind)
68         : ICRuntime(thread, profileTypeInfo, slotId, kind)
69     {
70     }
71 
72     ~LoadICRuntime() = default;
73 
74     JSTaggedValue LoadMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key);
75 };
76 
77 class StoreICRuntime : public ICRuntime {
78 public:
StoreICRuntime(JSThread * thread,JSHandle<ProfileTypeInfo> profileTypeInfo,uint32_t slotId,ICKind kind)79     StoreICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind)
80         : ICRuntime(thread, profileTypeInfo, slotId, kind)
81     {
82     }
83 
84     ~StoreICRuntime() = default;
85 
86     JSTaggedValue StoreMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key,
87                                  JSHandle<JSTaggedValue> value);
88 };
89 }  // namespace panda::ecmascript
90 
91 #endif  // ECMASCRIPT_IC_IC_RUNTIME_H
92