1 /* 2 * Copyright (c) 2021-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_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 #include "ecmascript/object_operator.h" 25 26 namespace panda::ecmascript { 27 class ProfileTypeInfo; 28 class JSThread; 29 class ObjectOperator; 30 31 class ICRuntime { 32 public: ICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind)33 ICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind) 34 : thread_(thread), icAccessor_(thread, profileTypeInfo, slotId, kind) 35 { 36 } 37 38 ~ICRuntime() = default; 39 40 void UpdateLoadHandler(const ObjectOperator &op, JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> receiver); 41 void UpdateLoadStringHandler(JSHandle<JSTaggedValue> receiver); 42 void UpdateTypedArrayHandler(JSHandle<JSTaggedValue> receiver); 43 void UpdateStoreHandler(const ObjectOperator &op, JSHandle<JSTaggedValue> key, JSHandle<JSTaggedValue> receiver); 44 GetThread() const45 JSThread *GetThread() const 46 { 47 return thread_; 48 } 49 UpdateReceiverHClass(JSHandle<JSTaggedValue> receiverHClass)50 void UpdateReceiverHClass(JSHandle<JSTaggedValue> receiverHClass) 51 { 52 receiverHClass_ = receiverHClass; 53 } 54 GetICKind() const55 ICKind GetICKind() const 56 { 57 return icAccessor_.GetKind(); 58 } 59 60 void TraceIC(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key) const; 61 62 protected: 63 JSThread *thread_; 64 JSHandle<JSTaggedValue> receiverHClass_{}; 65 ProfileTypeAccessor icAccessor_; 66 }; 67 68 class LoadICRuntime : public ICRuntime { 69 public: LoadICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind)70 LoadICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind) 71 : ICRuntime(thread, profileTypeInfo, slotId, kind) 72 { 73 } 74 75 ~LoadICRuntime() = default; 76 77 JSTaggedValue LoadMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key); 78 JSTaggedValue LoadValueMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key); 79 JSTaggedValue LoadTypedArrayValueMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key); 80 private: 81 JSTaggedValue LoadOrdinaryGet(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key); 82 inline JSTaggedValue CallPrivateGetter(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key); 83 }; 84 85 class StoreICRuntime : public ICRuntime { 86 public: StoreICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind)87 StoreICRuntime(JSThread *thread, JSHandle<ProfileTypeInfo> profileTypeInfo, uint32_t slotId, ICKind kind) 88 : ICRuntime(thread, profileTypeInfo, slotId, kind) 89 { 90 } 91 92 ~StoreICRuntime() = default; 93 94 JSTaggedValue StoreMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key, 95 JSHandle<JSTaggedValue> value, bool isOwn = false); 96 97 JSTaggedValue StoreTypedArrayValueMiss(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key, 98 JSHandle<JSTaggedValue> value); 99 private: 100 inline JSTaggedValue CallPrivateSetter(JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key, 101 JSHandle<JSTaggedValue> value); 102 }; 103 } // namespace panda::ecmascript 104 105 #endif // ECMASCRIPT_IC_IC_RUNTIME_H 106