• 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_LLVM_STACKMAP_PARSER_H
17 #define ECMASCRIPT_LLVM_STACKMAP_PARSER_H
18 
19 #include <iostream>
20 #include <memory>
21 #include <tuple>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "ecmascript/common.h"
26 #include "ecmascript/ecma_macros.h"
27 #include "ecmascript/interpreter/interpreter-inl.h"
28 #include "ecmascript/stackmap/ark_stackmap.h"
29 #include "ecmascript/stackmap/llvm_stackmap_type.h"
30 
31 namespace panda::ecmascript::kungfu {
32 class LLVMStackMapParser {
33 public:
34     bool PUBLIC_API CalculateStackMap(std::unique_ptr<uint8_t []> stackMapAddr);
35     bool PUBLIC_API CalculateStackMap(std::unique_ptr<uint8_t []> stackMapAddr,
36     uintptr_t hostCodeSectionAddr);
Print()37     void PUBLIC_API Print() const
38     {
39         if (IsLogEnabled()) {
40             llvmStackMap_.Print();
41         }
42     }
43     const CallSiteInfo *GetCallSiteInfoByPc(uintptr_t funcAddr) const;
IsLogEnabled()44     bool IsLogEnabled() const
45     {
46         return enableLog_;
47     }
48 
49     void PUBLIC_API CalculateFuncFpDelta(Func2FpDelta info, uint32_t moduleIndex);
50 
51     explicit LLVMStackMapParser(bool enableLog = false)
52     {
53         pc2CallSiteInfoVec_.clear();
54         fun2RecordNum_.clear();
55         dataInfo_ = nullptr;
56         enableLog_ = enableLog;
57         funAddr_.clear();
58         fun2FpDelta_.clear();
59         pc2DeoptVec_.clear();
60     }
~LLVMStackMapParser()61     ~LLVMStackMapParser()
62     {
63         pc2CallSiteInfoVec_.clear();
64         fun2RecordNum_.clear();
65         dataInfo_ = nullptr;
66         funAddr_.clear();
67         fun2FpDelta_.clear();
68         pc2DeoptVec_.clear();
69     }
GetPc2StackMapVec()70     std::vector<Pc2CallSiteInfo> PUBLIC_API GetPc2StackMapVec() const
71     {
72         return pc2CallSiteInfoVec_;
73     }
GetPc2Deopt()74     std::vector<Pc2Deopt> GetPc2Deopt() const
75     {
76         return pc2DeoptVec_;
77     }
78 private:
79     void CalcCallSite();
80     struct LLVMStackMap llvmStackMap_;
81     std::vector<Pc2CallSiteInfo> pc2CallSiteInfoVec_;
82     std::vector<std::pair<uintptr_t, uint64_t>> fun2RecordNum_;
83     [[maybe_unused]] std::unique_ptr<DataInfo> dataInfo_;
84     bool enableLog_ {false};
85     std::set<uintptr_t> funAddr_;
86     std::vector<Func2FpDelta> fun2FpDelta_;
87     std::vector<Pc2Deopt> pc2DeoptVec_;
88     std::map<uint32_t, std::vector<Func2FpDelta>> module2fun2FpDelta_;
89     std::map<uint32_t, std::set<uintptr_t>> module2funAddr_;
90 };
91 } // namespace panda::ecmascript::kungfu
92 #endif  // ECMASCRIPT_LLVM_STACKMAP_PARSER_H
93