• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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     bool IteratorStackMap(const RootVisitor& visitor,
42                           const RootBaseAndDerivedVisitor& derivedVisitor,
43                           uintptr_t callSiteAddr, uintptr_t callsiteFp,
44                           uintptr_t callSiteSp, uint8_t *stackmapAddr) const;
45     void GetArkDeopt(uintptr_t callSiteAddr, uint8_t *stackmapAddr, std::vector<ARKDeopt>& deopts) const;
46 private:
47     int BinaraySearch(CallsiteHeader *callsiteHead, uint32_t callsiteNum, uintptr_t callSiteAddr) const;
48     void GetArkDeopt(uint8_t *stackmapAddr, const CallsiteHeader& callsiteHead,
49                      std::vector<ARKDeopt>& deopt) const;
50     void ParseArkDeopt(const CallsiteHeader& callsiteHead, uint8_t *ptr, std::vector<ARKDeopt>& deopts) const;
51     void ParseArkStackMap(const CallsiteHeader& callsiteHead, uint8_t *ptr, ArkStackMap& stackMap) const;
52     void ParseArkStackMapAndDeopt(uint8_t *ptr, uint32_t length) const;
53     uintptr_t GetStackSlotAddress(const LLVMStackMapType::DwarfRegAndOffsetType info,
54                                   uintptr_t callSiteSp, uintptr_t callsiteFp) const;
55     friend class ArkStackMapBuilder;
56     bool enableLog_ {false};
57 };
58 }
59 #endif  // ECMASCRIPT_ARK_STACKMAP_PARSER_H