• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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 
16 #ifndef PANDA_AOT_DATA_H
17 #define PANDA_AOT_DATA_H
18 
19 #include <map>
20 #include "runtime_interface.h"
21 
22 namespace panda::panda_file {
23 class File;
24 }  // namespace panda::panda_file
25 
26 namespace panda::compiler {
27 class Graph;
28 
29 class SharedSlowPathData {
30 public:
SharedSlowPathData()31     SharedSlowPathData()
32     {
33         ASSERT(std::all_of(entrypoints_offsets_.begin(), entrypoints_offsets_.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         entrypoints_offsets_[static_cast<size_t>(id)] = offset;
38     }
GetSharedSlowPathOffset(RuntimeInterface::EntrypointId id)39     uintptr_t GetSharedSlowPathOffset(RuntimeInterface::EntrypointId id)
40     {
41         return entrypoints_offsets_[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> entrypoints_offsets_ {};
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 code_addr,uint64_t * intf_inline_cache_index,std::map<std::pair<const File *,uint32_t>,int32_t> * got_plt,std::map<std::pair<const File *,uint32_t>,int32_t> * got_virt_indexes,std::map<std::pair<const File *,uint32_t>,int32_t> * got_class,std::map<std::pair<const File *,uint32_t>,int32_t> * got_string,std::map<std::pair<const File *,uint64_t>,int32_t> * got_intf_inline_cache,SharedSlowPathData * slow_path_data)57     AotData(const File *pfile, Graph *graph, AddressType code_addr, uint64_t *intf_inline_cache_index,
58             std::map<std::pair<const File *, uint32_t>, int32_t> *got_plt,
59             std::map<std::pair<const File *, uint32_t>, int32_t> *got_virt_indexes,
60             std::map<std::pair<const File *, uint32_t>, int32_t> *got_class,
61             std::map<std::pair<const File *, uint32_t>, int32_t> *got_string,
62             std::map<std::pair<const File *, uint64_t>, int32_t> *got_intf_inline_cache,
63             SharedSlowPathData *slow_path_data)
64         : pfile_(pfile),
65           graph_(graph),
66           slow_path_data_(slow_path_data),
67           code_address_(code_addr),
68           intf_inline_cache_index_(intf_inline_cache_index),
69           got_plt_(got_plt),
70           got_virt_indexes_(got_virt_indexes),
71           got_class_(got_class),
72           got_string_(got_string),
73           got_intf_inline_cache_(got_intf_inline_cache)
74     {
75     }
76 
77     intptr_t GetEpTableOffset() const;
78     intptr_t GetEntrypointOffset(uint64_t pc, int32_t slot_id) const;
79     intptr_t GetSharedSlowPathOffset(RuntimeInterface::EntrypointId id, uintptr_t pc) const;
80     void SetSharedSlowPathOffset(RuntimeInterface::EntrypointId id, uintptr_t pc);
81     intptr_t GetPltSlotOffset(uint64_t pc, uint32_t method_id);
82     intptr_t GetVirtIndexSlotOffset(uint64_t pc, uint32_t method_id);
83     intptr_t GetClassSlotOffset(uint64_t pc, uint32_t klass_id, bool init);
84     intptr_t GetStringSlotOffset(uint64_t pc, uint32_t string_id);
85     uint64_t GetInfInlineCacheSlotOffset(uint64_t pc, uint64_t index);
GetCodeOffset()86     AddressType GetCodeOffset() const
87     {
88         return code_address_;
89     }
GetUseCha()90     bool GetUseCha() const
91     {
92         return use_cha_;
93     }
SetUseCha(bool use_cha)94     void SetUseCha(bool use_cha)
95     {
96         use_cha_ = use_cha;
97     }
98 
SetIntfInlineCacheIndex(uint64_t intf_inline_cache_index)99     void SetIntfInlineCacheIndex(uint64_t intf_inline_cache_index)
100     {
101         *intf_inline_cache_index_ = intf_inline_cache_index;
102     }
103 
GetIntfInlineCacheIndex()104     uint64_t GetIntfInlineCacheIndex() const
105     {
106         return *intf_inline_cache_index_;
107     }
108 
109 private:
110     inline int32_t GetSlotId() const;
111 
112     const File *pfile_;
113     Graph *graph_ {nullptr};
114     SharedSlowPathData *slow_path_data_;
115     AddressType code_address_ {INVALID_ADDRESS};
116     uint64_t *intf_inline_cache_index_;
117     std::map<std::pair<const File *, uint32_t>, int32_t> *got_plt_;
118     std::map<std::pair<const File *, uint32_t>, int32_t> *got_virt_indexes_;
119     std::map<std::pair<const File *, uint32_t>, int32_t> *got_class_;
120     std::map<std::pair<const File *, uint32_t>, int32_t> *got_string_;
121     std::map<std::pair<const File *, uint64_t>, int32_t> *got_intf_inline_cache_;
122     bool use_cha_ {false};
123 };
124 }  // namespace panda::compiler
125 
126 #endif  // PANDA_AOT_DATA_H
127