/* * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_IC_IC_RUNTIME_H #define ECMASCRIPT_IC_IC_RUNTIME_H #include "ecmascript/ic/profile_type_info.h" #include "ecmascript/accessor_data.h" #include "ecmascript/ecma_vm.h" #include "ecmascript/js_tagged_value.h" #include "ecmascript/js_handle.h" #include "ecmascript/object_operator.h" namespace panda::ecmascript { class ProfileTypeInfo; class JSThread; class ObjectOperator; class ICRuntime { public: ICRuntime(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) : thread_(thread), icAccessor_(thread, profileTypeInfo, slotId, kind) { } ~ICRuntime() = default; void UpdateLoadHandler(const ObjectOperator &op, JSHandle key, JSHandle receiver); void UpdateLoadStringHandler(JSHandle receiver); void UpdateTypedArrayHandler(JSHandle receiver); void UpdateStoreHandler(const ObjectOperator &op, JSHandle key, JSHandle receiver); JSThread *GetThread() const { return thread_; } void UpdateReceiverHClass(JSHandle receiverHClass) { receiverHClass_ = receiverHClass; } ICKind GetICKind() const { return icAccessor_.GetKind(); } void TraceIC(JSHandle receiver, JSHandle key) const; protected: JSThread *thread_; JSHandle receiverHClass_{}; ProfileTypeAccessor icAccessor_; }; class LoadICRuntime : public ICRuntime { public: LoadICRuntime(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) : ICRuntime(thread, profileTypeInfo, slotId, kind) { } ~LoadICRuntime() = default; JSTaggedValue LoadMiss(JSHandle receiver, JSHandle key); JSTaggedValue LoadValueMiss(JSHandle receiver, JSHandle key); JSTaggedValue LoadTypedArrayValueMiss(JSHandle receiver, JSHandle key); private: JSTaggedValue LoadOrdinaryGet(JSHandle receiver, JSHandle key); inline JSTaggedValue CallPrivateGetter(JSHandle receiver, JSHandle key); }; class StoreICRuntime : public ICRuntime { public: StoreICRuntime(JSThread *thread, JSHandle profileTypeInfo, uint32_t slotId, ICKind kind) : ICRuntime(thread, profileTypeInfo, slotId, kind) { } ~StoreICRuntime() = default; JSTaggedValue StoreMiss(JSHandle receiver, JSHandle key, JSHandle value, bool isOwn = false); JSTaggedValue StoreTypedArrayValueMiss(JSHandle receiver, JSHandle key, JSHandle value); private: inline JSTaggedValue CallPrivateSetter(JSHandle receiver, JSHandle key, JSHandle value); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_IC_IC_RUNTIME_H