1 /* 2 * Copyright (c) 2022 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 #ifndef ECMASCRIPT_ARK_STACKMAP_PARSER_H 16 #define ECMASCRIPT_ARK_STACKMAP_PARSER_H 17 18 #include <cstdint> 19 20 #include "ecmascript/frames.h" 21 #include "ecmascript/mem/visitor.h" 22 #include "ecmascript/stackmap/ark_stackmap.h" 23 #include "ecmascript/stackmap/llvm/llvm_stackmap_type.h" 24 25 namespace panda::ecmascript { 26 class BinaryBufferParser; 27 } 28 29 namespace panda::ecmascript::kungfu { 30 class ArkStackMapParser { 31 public: 32 explicit ArkStackMapParser(bool enableLog = false) 33 { 34 enableLog_ = enableLog; 35 } ~ArkStackMapParser()36 ~ArkStackMapParser() 37 { 38 enableLog_ = false; 39 } 40 void GetConstInfo(uintptr_t callsite, LLVMStackMapType::ConstInfo& info, uint8_t *stackmapAddr = nullptr) const; 41 void GetMethodOffsetInfo(uintptr_t callSiteAddr, std::map<uint32_t, uint32_t>& info, 42 uint8_t *stackmapAddr) const; 43 bool IteratorStackMap(RootVisitor& visitor, 44 uintptr_t callSiteAddr, uintptr_t callsiteFp, 45 uintptr_t callSiteSp, uint8_t *stackmapAddr) const; 46 void GetArkDeopt(uintptr_t callSiteAddr, uint8_t *stackmapAddr, std::vector<ARKDeopt>& deopts) const; 47 48 private: 49 static constexpr size_t DEOPT_ENTRY_SIZE = 2; 50 static constexpr size_t GC_ENTRY_SIZE = 2; 51 52 int BinaraySearch(CallsiteHeader *callsiteHead, uint32_t callsiteNum, uintptr_t callSiteAddr) const; 53 void GetArkDeopt(uint8_t *stackmapAddr, const CallsiteHeader& callsiteHead, 54 std::vector<ARKDeopt>& deopt) const; 55 void ParseArkDeopt(const CallsiteHeader& callsiteHead, uint8_t *ptr, std::vector<ARKDeopt>& deopts) const; 56 void ParseArkStackMap(const CallsiteHeader& callsiteHead, uint8_t *ptr, ArkStackMap& stackMap) const; 57 #ifndef NDEBUG 58 void ParseArkStackMapAndDeopt(uint8_t *ptr, uint32_t length) const; 59 #endif 60 uintptr_t GetStackSlotAddress(uint8_t *stackmapAddr, uintptr_t callSiteSp, uintptr_t callsiteFp, 61 uint32_t &offset) const; 62 friend class ArkStackMapBuilder; 63 bool enableLog_ {false}; 64 }; 65 } 66 #endif // ECMASCRIPT_ARK_STACKMAP_PARSER_H