• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PANDA_AOT_DATA_H
17 #define PANDA_AOT_DATA_H
18 
19 #include <map>
20 #include "runtime_interface.h"
21 
22 namespace ark::panda_file {
23 class File;
24 }  // namespace ark::panda_file
25 
26 namespace ark::compiler {
27 class Graph;
28 
29 class SharedSlowPathData {
30 public:
SharedSlowPathData()31     SharedSlowPathData()
32     {
33         ASSERT(std::all_of(entrypointsOffsets_.begin(), entrypointsOffsets_.end(), [](auto v) { return v == 0; }));
34     }
SetSharedSlowPathOffset(RuntimeInterface::EntrypointId id,uintptr_t offset)35     void SetSharedSlowPathOffset(RuntimeInterface::EntrypointId id, uintptr_t offset)
36     {
37         entrypointsOffsets_[static_cast<size_t>(id)] = offset;
38     }
GetSharedSlowPathOffset(RuntimeInterface::EntrypointId id)39     uintptr_t GetSharedSlowPathOffset(RuntimeInterface::EntrypointId id)
40     {
41         return entrypointsOffsets_[static_cast<size_t>(id)];
42     }
43 
44 private:
45     static constexpr size_t SIZE = static_cast<size_t>(RuntimeInterface::EntrypointId::COUNT);
46     std::array<uintptr_t, SIZE> entrypointsOffsets_ {};
47 };
48 
49 class AotData {
50     static constexpr uintptr_t INVALID_ADDRESS = std::numeric_limits<uintptr_t>::max();
51     using AddressType = uintptr_t;
52     using File = const panda_file::File;
53     using MethodPtr = RuntimeInterface::MethodPtr;
54     using ClassPtr = RuntimeInterface::ClassPtr;
55 
56 public:
AotData(const File * pfile,Graph * graph,AddressType codeAddr,uint64_t * intfInlineCacheIndex,std::map<std::pair<const File *,uint32_t>,int32_t> * gotPlt,std::map<std::pair<const File *,uint32_t>,int32_t> * gotVirtIndexes,std::map<std::pair<const File *,uint32_t>,int32_t> * gotClass,std::map<std::pair<const File *,uint32_t>,int32_t> * gotString,std::map<std::pair<const File *,uint64_t>,int32_t> * gotIntfInlineCache,std::map<std::pair<const File *,uint64_t>,int32_t> * gotCommon,SharedSlowPathData * slowPathData)57     AotData(const File *pfile, Graph *graph, AddressType codeAddr, uint64_t *intfInlineCacheIndex,
58             std::map<std::pair<const File *, uint32_t>, int32_t> *gotPlt,
59             std::map<std::pair<const File *, uint32_t>, int32_t> *gotVirtIndexes,
60             std::map<std::pair<const File *, uint32_t>, int32_t> *gotClass,
61             std::map<std::pair<const File *, uint32_t>, int32_t> *gotString,
62             std::map<std::pair<const File *, uint64_t>, int32_t> *gotIntfInlineCache,
63             std::map<std::pair<const File *, uint64_t>, int32_t> *gotCommon, SharedSlowPathData *slowPathData)
64         : pfile_(pfile),
65           graph_(graph),
66           slowPathData_(slowPathData),
67           codeAddress_(codeAddr),
68           intfInlineCacheIndex_(intfInlineCacheIndex),
69           gotPlt_(gotPlt),
70           gotVirtIndexes_(gotVirtIndexes),
71           gotClass_(gotClass),
72           gotString_(gotString),
73           gotIntfInlineCache_(gotIntfInlineCache),
74           gotCommon_(gotCommon)
75     {
76     }
77 
78     intptr_t GetEpTableOffset() const;
79     intptr_t GetEntrypointOffset(uint64_t pc, int32_t slotId) const;
80     intptr_t GetSharedSlowPathOffset(RuntimeInterface::EntrypointId id, uintptr_t pc) const;
81     void SetSharedSlowPathOffset(RuntimeInterface::EntrypointId id, uintptr_t pc);
82     intptr_t GetPltSlotOffset(uint64_t pc, uint32_t methodId);
83     intptr_t GetVirtIndexSlotOffset(uint64_t pc, uint32_t methodId);
84     intptr_t GetClassSlotOffset(uint64_t pc, uint32_t klassId, bool init);
85     intptr_t GetCommonSlotOffset(uint64_t pc, uint32_t id);
86     intptr_t GetStringSlotOffset(uint64_t pc, uint32_t stringId);
87     uint64_t GetInfInlineCacheSlotOffset(uint64_t pc, uint64_t cacheIdx);
88 
89     int32_t GetClassSlotId(uint32_t klassId);
90     int32_t GetStringSlotId(uint32_t stringId);
91     int32_t GetPltSlotId(uint32_t methodId);
92     int32_t GetIntfInlineCacheSlotId(uint64_t cacheIdx);
93 
GetCodeOffset()94     AddressType GetCodeOffset() const
95     {
96         return codeAddress_;
97     }
GetUseCha()98     bool GetUseCha() const
99     {
100         return useCha_;
101     }
SetUseCha(bool useCha)102     void SetUseCha(bool useCha)
103     {
104         useCha_ = useCha;
105     }
106 
SetIntfInlineCacheIndex(uint64_t intfInlineCacheIndex)107     void SetIntfInlineCacheIndex(uint64_t intfInlineCacheIndex)
108     {
109         *intfInlineCacheIndex_ = intfInlineCacheIndex;
110     }
111 
GetIntfInlineCacheIndex()112     uint64_t GetIntfInlineCacheIndex() const
113     {
114         return *intfInlineCacheIndex_;
115     }
116 
117 private:
118     inline int32_t GetSlotId() const;
119 
120     const File *pfile_;
121     Graph *graph_ {nullptr};
122     SharedSlowPathData *slowPathData_;
123     AddressType codeAddress_ {INVALID_ADDRESS};
124     uint64_t *intfInlineCacheIndex_;
125     std::map<std::pair<const File *, uint32_t>, int32_t> *gotPlt_;
126     std::map<std::pair<const File *, uint32_t>, int32_t> *gotVirtIndexes_;
127     std::map<std::pair<const File *, uint32_t>, int32_t> *gotClass_;
128     std::map<std::pair<const File *, uint32_t>, int32_t> *gotString_;
129     std::map<std::pair<const File *, uint64_t>, int32_t> *gotIntfInlineCache_;
130     std::map<std::pair<const File *, uint64_t>, int32_t> *gotCommon_;
131     bool useCha_ {false};
132 };
133 }  // namespace ark::compiler
134 
135 #endif  // PANDA_AOT_DATA_H
136