blob: 65b296154ee49c387087f64c7650c1eb7b4e2c2e [file] [log] [blame]
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +00001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_TOOLS_VERIDEX_RESOLVER_H_
18#define ART_TOOLS_VERIDEX_RESOLVER_H_
19
20#include "dex/dex_file.h"
21#include "veridex.h"
22
23namespace art {
24
Nicolas Geoffray534a0a12018-03-24 20:02:25 +000025class HiddenApi;
Nicolas Geoffraye8264772018-03-22 22:16:41 +000026class VeridexResolver;
27
28/**
29 * Map from the start of a dex file (ie DexFile::Begin()), to
30 * its corresponding resolver.
31 */
32using DexResolverMap = std::map<uintptr_t, VeridexResolver*>;
33
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000034class VeridexResolver {
35 public:
Nicolas Geoffraye8264772018-03-22 22:16:41 +000036 VeridexResolver(const DexFile& dex_file,
37 const DexResolverMap& dex_resolvers,
38 TypeMap& type_map)
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000039 : dex_file_(dex_file),
40 type_map_(type_map),
Nicolas Geoffraye8264772018-03-22 22:16:41 +000041 dex_resolvers_(dex_resolvers),
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000042 type_infos_(dex_file.NumTypeIds(), VeriClass()),
43 method_infos_(dex_file.NumMethodIds(), nullptr),
44 field_infos_(dex_file.NumFieldIds(), nullptr) {}
45
Nicolas Geoffraye8264772018-03-22 22:16:41 +000046 // Run on the defined classes of that dex file and populate our
47 // local type cache.
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000048 void Run();
49
Nicolas Geoffraye8264772018-03-22 22:16:41 +000050 // Return the class declared at `index`.
51 VeriClass* GetVeriClass(dex::TypeIndex index);
52
53 // Return the method declared at `method_index`.
54 VeriMethod GetMethod(uint32_t method_index);
55
56 // Return the field declared at `field_index`.
57 VeriField GetField(uint32_t field_index);
58
59 // Do a JLS lookup in `kls` to find a method.
60 VeriMethod LookupMethodIn(const VeriClass& kls,
61 const char* method_name,
62 const Signature& method_signature);
63
64 // Do a JLS lookup in `kls` to find a field.
65 VeriField LookupFieldIn(const VeriClass& kls,
66 const char* field_name,
67 const char* field_type);
68
Nicolas Geoffray2ebff052018-04-04 22:32:03 +010069 // Lookup a method declared in `kls`.
70 VeriMethod LookupDeclaredMethodIn(const VeriClass& kls,
71 const char* method_name,
72 const char* signature) const;
73
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010074 // Resolve all type_id/method_id/field_id.
75 void ResolveAll();
76
77 // The dex file this resolver is associated to.
78 const DexFile& GetDexFile() const {
79 return dex_file_;
80 }
Nicolas Geoffraye8264772018-03-22 22:16:41 +000081
Nicolas Geoffray909b1272018-04-23 13:43:31 +010082 const DexFile& GetDexFileOf(const VeriClass& kls) {
83 return GetResolverOf(kls)->dex_file_;
84 }
85
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000086 private:
Nicolas Geoffraye8264772018-03-22 22:16:41 +000087 // Return the resolver where `kls` is from.
88 VeridexResolver* GetResolverOf(const VeriClass& kls) const;
89
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000090 const DexFile& dex_file_;
91 TypeMap& type_map_;
Nicolas Geoffraye8264772018-03-22 22:16:41 +000092 const DexResolverMap& dex_resolvers_;
Nicolas Geoffraydd96ed32018-03-21 11:00:14 +000093 std::vector<VeriClass> type_infos_;
94 std::vector<VeriMethod> method_infos_;
95 std::vector<VeriField> field_infos_;
96};
97
98} // namespace art
99
100#endif // ART_TOOLS_VERIDEX_RESOLVER_H_