blob: 9c887b9a17a36a3e1d21cf1369775df83d32f3d5 [file] [log] [blame]
David Sehr7629f602016-08-07 16:01:51 -07001/*
2 * Copyright (C) 2016 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 * Header file of an in-memory representation of DEX files.
17 */
18
19#ifndef ART_DEXLAYOUT_DEX_IR_H_
20#define ART_DEXLAYOUT_DEX_IR_H_
21
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070022#include <stdint.h>
23
Jeff Haoea7c6292016-11-14 18:10:16 -080024#include <map>
David Sehr7629f602016-08-07 16:01:51 -070025#include <vector>
David Sehr7629f602016-08-07 16:01:51 -070026
Andreas Gampe5678db52017-06-08 14:11:18 -070027#include "base/stl_util.h"
David Sehr853a8e12016-09-01 13:03:50 -070028#include "dex_file-inl.h"
Jeff Hao3ab96b42016-09-09 18:35:01 -070029#include "leb128.h"
Jeff Haoa8621002016-10-04 18:13:44 +000030#include "utf.h"
David Sehr7629f602016-08-07 16:01:51 -070031
32namespace art {
33namespace dex_ir {
34
35// Forward declarations for classes used in containers or pointed to.
Jeff Hao3ab96b42016-09-09 18:35:01 -070036class AnnotationItem;
David Sehr7629f602016-08-07 16:01:51 -070037class AnnotationsDirectoryItem;
38class AnnotationSetItem;
Jeff Hao3ab96b42016-09-09 18:35:01 -070039class AnnotationSetRefList;
Jeff Hao5daee902017-04-27 18:00:38 -070040class CallSiteId;
David Sehr7629f602016-08-07 16:01:51 -070041class ClassData;
42class ClassDef;
43class CodeItem;
44class DebugInfoItem;
Jeff Hao3ab96b42016-09-09 18:35:01 -070045class EncodedAnnotation;
46class EncodedArrayItem;
47class EncodedValue;
David Sehr7629f602016-08-07 16:01:51 -070048class FieldId;
49class FieldItem;
50class Header;
51class MapList;
52class MapItem;
Jeff Hao5daee902017-04-27 18:00:38 -070053class MethodHandleItem;
David Sehr7629f602016-08-07 16:01:51 -070054class MethodId;
55class MethodItem;
Jeff Hao3ab96b42016-09-09 18:35:01 -070056class ParameterAnnotation;
David Sehr7629f602016-08-07 16:01:51 -070057class ProtoId;
Jeff Hao3ab96b42016-09-09 18:35:01 -070058class StringData;
David Sehr7629f602016-08-07 16:01:51 -070059class StringId;
60class TryItem;
61class TypeId;
Jeff Hao3ab96b42016-09-09 18:35:01 -070062class TypeList;
63
64// Item size constants.
65static constexpr size_t kHeaderItemSize = 112;
66static constexpr size_t kStringIdItemSize = 4;
67static constexpr size_t kTypeIdItemSize = 4;
68static constexpr size_t kProtoIdItemSize = 12;
69static constexpr size_t kFieldIdItemSize = 8;
70static constexpr size_t kMethodIdItemSize = 8;
71static constexpr size_t kClassDefItemSize = 32;
Jeff Hao5daee902017-04-27 18:00:38 -070072static constexpr size_t kCallSiteIdItemSize = 4;
73static constexpr size_t kMethodHandleItemSize = 8;
David Sehr7629f602016-08-07 16:01:51 -070074
75// Visitor support
76class AbstractDispatcher {
77 public:
78 AbstractDispatcher() = default;
79 virtual ~AbstractDispatcher() { }
80
81 virtual void Dispatch(Header* header) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070082 virtual void Dispatch(const StringData* string_data) = 0;
David Sehr7629f602016-08-07 16:01:51 -070083 virtual void Dispatch(const StringId* string_id) = 0;
84 virtual void Dispatch(const TypeId* type_id) = 0;
85 virtual void Dispatch(const ProtoId* proto_id) = 0;
86 virtual void Dispatch(const FieldId* field_id) = 0;
87 virtual void Dispatch(const MethodId* method_id) = 0;
Jeff Hao5daee902017-04-27 18:00:38 -070088 virtual void Dispatch(const CallSiteId* call_site_id) = 0;
89 virtual void Dispatch(const MethodHandleItem* method_handle_item) = 0;
David Sehr7629f602016-08-07 16:01:51 -070090 virtual void Dispatch(ClassData* class_data) = 0;
91 virtual void Dispatch(ClassDef* class_def) = 0;
92 virtual void Dispatch(FieldItem* field_item) = 0;
93 virtual void Dispatch(MethodItem* method_item) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070094 virtual void Dispatch(EncodedArrayItem* array_item) = 0;
David Sehr7629f602016-08-07 16:01:51 -070095 virtual void Dispatch(CodeItem* code_item) = 0;
96 virtual void Dispatch(TryItem* try_item) = 0;
97 virtual void Dispatch(DebugInfoItem* debug_info_item) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070098 virtual void Dispatch(AnnotationItem* annotation_item) = 0;
David Sehr7629f602016-08-07 16:01:51 -070099 virtual void Dispatch(AnnotationSetItem* annotation_set_item) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700100 virtual void Dispatch(AnnotationSetRefList* annotation_set_ref_list) = 0;
David Sehr7629f602016-08-07 16:01:51 -0700101 virtual void Dispatch(AnnotationsDirectoryItem* annotations_directory_item) = 0;
102 virtual void Dispatch(MapList* map_list) = 0;
103 virtual void Dispatch(MapItem* map_item) = 0;
104
105 private:
106 DISALLOW_COPY_AND_ASSIGN(AbstractDispatcher);
107};
108
109// Collections become owners of the objects added by moving them into unique pointers.
Jeff Haoea7c6292016-11-14 18:10:16 -0800110template<class T> class CollectionBase {
David Sehr7629f602016-08-07 16:01:51 -0700111 public:
Jeff Haoea7c6292016-11-14 18:10:16 -0800112 CollectionBase() = default;
113
114 uint32_t GetOffset() const { return offset_; }
115 void SetOffset(uint32_t new_offset) { offset_ = new_offset; }
116
117 private:
118 uint32_t offset_ = 0;
119
120 DISALLOW_COPY_AND_ASSIGN(CollectionBase);
121};
122
123template<class T> class CollectionVector : public CollectionBase<T> {
124 public:
125 CollectionVector() = default;
126
Jeff Hao3ab96b42016-09-09 18:35:01 -0700127 void AddIndexedItem(T* object, uint32_t offset, uint32_t index) {
128 object->SetOffset(offset);
129 object->SetIndex(index);
130 collection_.push_back(std::unique_ptr<T>(object));
David Sehr7629f602016-08-07 16:01:51 -0700131 }
David Sehr7629f602016-08-07 16:01:51 -0700132 uint32_t Size() const { return collection_.size(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800133 std::vector<std::unique_ptr<T>>& Collection() { return collection_; }
David Sehr7629f602016-08-07 16:01:51 -0700134
135 private:
136 std::vector<std::unique_ptr<T>> collection_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700137
Jeff Haoea7c6292016-11-14 18:10:16 -0800138 DISALLOW_COPY_AND_ASSIGN(CollectionVector);
139};
140
141template<class T> class CollectionMap : public CollectionBase<T> {
142 public:
143 CollectionMap() = default;
144
Mathieu Chartiera2973d72017-02-14 17:12:20 -0800145 // Returns the existing item if it is already inserted, null otherwise.
146 T* GetExistingObject(uint32_t offset) {
147 auto it = collection_.find(offset);
148 return it != collection_.end() ? it->second.get() : nullptr;
149 }
150
Jeff Haoea7c6292016-11-14 18:10:16 -0800151 void AddItem(T* object, uint32_t offset) {
152 object->SetOffset(offset);
Mathieu Chartiera2973d72017-02-14 17:12:20 -0800153 auto it = collection_.emplace(offset, std::unique_ptr<T>(object));
154 CHECK(it.second) << "CollectionMap already has an object with offset " << offset << " "
155 << " and address " << it.first->second.get();
Jeff Haoea7c6292016-11-14 18:10:16 -0800156 }
157 uint32_t Size() const { return collection_.size(); }
158 std::map<uint32_t, std::unique_ptr<T>>& Collection() { return collection_; }
159
160 private:
161 std::map<uint32_t, std::unique_ptr<T>> collection_;
162
163 DISALLOW_COPY_AND_ASSIGN(CollectionMap);
David Sehr7629f602016-08-07 16:01:51 -0700164};
165
Jeff Hao3ab96b42016-09-09 18:35:01 -0700166class Collections {
167 public:
168 Collections() = default;
169
170 std::vector<std::unique_ptr<StringId>>& StringIds() { return string_ids_.Collection(); }
171 std::vector<std::unique_ptr<TypeId>>& TypeIds() { return type_ids_.Collection(); }
172 std::vector<std::unique_ptr<ProtoId>>& ProtoIds() { return proto_ids_.Collection(); }
173 std::vector<std::unique_ptr<FieldId>>& FieldIds() { return field_ids_.Collection(); }
174 std::vector<std::unique_ptr<MethodId>>& MethodIds() { return method_ids_.Collection(); }
175 std::vector<std::unique_ptr<ClassDef>>& ClassDefs() { return class_defs_.Collection(); }
Jeff Hao5daee902017-04-27 18:00:38 -0700176 std::vector<std::unique_ptr<CallSiteId>>& CallSiteIds() { return call_site_ids_.Collection(); }
177 std::vector<std::unique_ptr<MethodHandleItem>>& MethodHandleItems()
178 { return method_handle_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800179 std::map<uint32_t, std::unique_ptr<StringData>>& StringDatas()
180 { return string_datas_.Collection(); }
181 std::map<uint32_t, std::unique_ptr<TypeList>>& TypeLists() { return type_lists_.Collection(); }
182 std::map<uint32_t, std::unique_ptr<EncodedArrayItem>>& EncodedArrayItems()
Jeff Hao3ab96b42016-09-09 18:35:01 -0700183 { return encoded_array_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800184 std::map<uint32_t, std::unique_ptr<AnnotationItem>>& AnnotationItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000185 { return annotation_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800186 std::map<uint32_t, std::unique_ptr<AnnotationSetItem>>& AnnotationSetItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000187 { return annotation_set_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800188 std::map<uint32_t, std::unique_ptr<AnnotationSetRefList>>& AnnotationSetRefLists()
Jeff Haoa8621002016-10-04 18:13:44 +0000189 { return annotation_set_ref_lists_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800190 std::map<uint32_t, std::unique_ptr<AnnotationsDirectoryItem>>& AnnotationsDirectoryItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000191 { return annotations_directory_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800192 std::map<uint32_t, std::unique_ptr<DebugInfoItem>>& DebugInfoItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000193 { return debug_info_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800194 std::map<uint32_t, std::unique_ptr<CodeItem>>& CodeItems() { return code_items_.Collection(); }
195 std::map<uint32_t, std::unique_ptr<ClassData>>& ClassDatas() { return class_datas_.Collection(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700196
197 void CreateStringId(const DexFile& dex_file, uint32_t i);
198 void CreateTypeId(const DexFile& dex_file, uint32_t i);
199 void CreateProtoId(const DexFile& dex_file, uint32_t i);
200 void CreateFieldId(const DexFile& dex_file, uint32_t i);
201 void CreateMethodId(const DexFile& dex_file, uint32_t i);
202 void CreateClassDef(const DexFile& dex_file, uint32_t i);
Jeff Hao5daee902017-04-27 18:00:38 -0700203 void CreateCallSiteId(const DexFile& dex_file, uint32_t i);
204 void CreateMethodHandleItem(const DexFile& dex_file, uint32_t i);
205
206 void CreateCallSitesAndMethodHandles(const DexFile& dex_file);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700207
Jeff Haoa8621002016-10-04 18:13:44 +0000208 TypeList* CreateTypeList(const DexFile::TypeList* type_list, uint32_t offset);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700209 EncodedArrayItem* CreateEncodedArrayItem(const uint8_t* static_data, uint32_t offset);
210 AnnotationItem* CreateAnnotationItem(const DexFile::AnnotationItem* annotation, uint32_t offset);
211 AnnotationSetItem* CreateAnnotationSetItem(const DexFile& dex_file,
Jeff Haobe9b44b2017-02-16 13:34:38 -0800212 const DexFile::AnnotationSetItem* disk_annotations_item, uint32_t offset);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700213 AnnotationsDirectoryItem* CreateAnnotationsDirectoryItem(const DexFile& dex_file,
214 const DexFile::AnnotationsDirectoryItem* disk_annotations_item, uint32_t offset);
215 CodeItem* CreateCodeItem(
216 const DexFile& dex_file, const DexFile::CodeItem& disk_code_item, uint32_t offset);
217 ClassData* CreateClassData(const DexFile& dex_file, const uint8_t* encoded_data, uint32_t offset);
218
Jeff Hao9804e9e2017-06-15 14:04:51 -0700219 StringId* GetStringId(uint32_t index) {
220 CHECK_LT(index, StringIdsSize());
221 return StringIds()[index].get();
222 }
223 TypeId* GetTypeId(uint32_t index) {
224 CHECK_LT(index, TypeIdsSize());
225 return TypeIds()[index].get();
226 }
227 ProtoId* GetProtoId(uint32_t index) {
228 CHECK_LT(index, ProtoIdsSize());
229 return ProtoIds()[index].get();
230 }
231 FieldId* GetFieldId(uint32_t index) {
232 CHECK_LT(index, FieldIdsSize());
233 return FieldIds()[index].get();
234 }
235 MethodId* GetMethodId(uint32_t index) {
236 CHECK_LT(index, MethodIdsSize());
237 return MethodIds()[index].get();
238 }
239 ClassDef* GetClassDef(uint32_t index) {
240 CHECK_LT(index, ClassDefsSize());
241 return ClassDefs()[index].get();
242 }
243 CallSiteId* GetCallSiteId(uint32_t index) {
244 CHECK_LT(index, CallSiteIdsSize());
245 return CallSiteIds()[index].get();
246 }
247 MethodHandleItem* GetMethodHandle(uint32_t index) {
248 CHECK_LT(index, MethodHandleItemsSize());
249 return MethodHandleItems()[index].get();
250 }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700251
252 StringId* GetStringIdOrNullPtr(uint32_t index) {
253 return index == DexFile::kDexNoIndex ? nullptr : GetStringId(index);
254 }
255 TypeId* GetTypeIdOrNullPtr(uint16_t index) {
256 return index == DexFile::kDexNoIndex16 ? nullptr : GetTypeId(index);
257 }
258
259 uint32_t StringIdsOffset() const { return string_ids_.GetOffset(); }
260 uint32_t TypeIdsOffset() const { return type_ids_.GetOffset(); }
261 uint32_t ProtoIdsOffset() const { return proto_ids_.GetOffset(); }
262 uint32_t FieldIdsOffset() const { return field_ids_.GetOffset(); }
263 uint32_t MethodIdsOffset() const { return method_ids_.GetOffset(); }
264 uint32_t ClassDefsOffset() const { return class_defs_.GetOffset(); }
Jeff Hao5daee902017-04-27 18:00:38 -0700265 uint32_t CallSiteIdsOffset() const { return call_site_ids_.GetOffset(); }
266 uint32_t MethodHandleItemsOffset() const { return method_handle_items_.GetOffset(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700267 uint32_t StringDatasOffset() const { return string_datas_.GetOffset(); }
268 uint32_t TypeListsOffset() const { return type_lists_.GetOffset(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000269 uint32_t EncodedArrayItemsOffset() const { return encoded_array_items_.GetOffset(); }
270 uint32_t AnnotationItemsOffset() const { return annotation_items_.GetOffset(); }
271 uint32_t AnnotationSetItemsOffset() const { return annotation_set_items_.GetOffset(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700272 uint32_t AnnotationSetRefListsOffset() const { return annotation_set_ref_lists_.GetOffset(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000273 uint32_t AnnotationsDirectoryItemsOffset() const
274 { return annotations_directory_items_.GetOffset(); }
275 uint32_t DebugInfoItemsOffset() const { return debug_info_items_.GetOffset(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700276 uint32_t CodeItemsOffset() const { return code_items_.GetOffset(); }
277 uint32_t ClassDatasOffset() const { return class_datas_.GetOffset(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800278 uint32_t MapListOffset() const { return map_list_offset_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700279
280 void SetStringIdsOffset(uint32_t new_offset) { string_ids_.SetOffset(new_offset); }
281 void SetTypeIdsOffset(uint32_t new_offset) { type_ids_.SetOffset(new_offset); }
282 void SetProtoIdsOffset(uint32_t new_offset) { proto_ids_.SetOffset(new_offset); }
283 void SetFieldIdsOffset(uint32_t new_offset) { field_ids_.SetOffset(new_offset); }
284 void SetMethodIdsOffset(uint32_t new_offset) { method_ids_.SetOffset(new_offset); }
285 void SetClassDefsOffset(uint32_t new_offset) { class_defs_.SetOffset(new_offset); }
Jeff Hao5daee902017-04-27 18:00:38 -0700286 void SetCallSiteIdsOffset(uint32_t new_offset) { call_site_ids_.SetOffset(new_offset); }
287 void SetMethodHandleItemsOffset(uint32_t new_offset)
288 { method_handle_items_.SetOffset(new_offset); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700289 void SetStringDatasOffset(uint32_t new_offset) { string_datas_.SetOffset(new_offset); }
290 void SetTypeListsOffset(uint32_t new_offset) { type_lists_.SetOffset(new_offset); }
Jeff Haoa8621002016-10-04 18:13:44 +0000291 void SetEncodedArrayItemsOffset(uint32_t new_offset)
292 { encoded_array_items_.SetOffset(new_offset); }
293 void SetAnnotationItemsOffset(uint32_t new_offset) { annotation_items_.SetOffset(new_offset); }
294 void SetAnnotationSetItemsOffset(uint32_t new_offset)
295 { annotation_set_items_.SetOffset(new_offset); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700296 void SetAnnotationSetRefListsOffset(uint32_t new_offset)
297 { annotation_set_ref_lists_.SetOffset(new_offset); }
Jeff Haoa8621002016-10-04 18:13:44 +0000298 void SetAnnotationsDirectoryItemsOffset(uint32_t new_offset)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700299 { annotations_directory_items_.SetOffset(new_offset); }
Jeff Haoa8621002016-10-04 18:13:44 +0000300 void SetDebugInfoItemsOffset(uint32_t new_offset) { debug_info_items_.SetOffset(new_offset); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700301 void SetCodeItemsOffset(uint32_t new_offset) { code_items_.SetOffset(new_offset); }
302 void SetClassDatasOffset(uint32_t new_offset) { class_datas_.SetOffset(new_offset); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800303 void SetMapListOffset(uint32_t new_offset) { map_list_offset_ = new_offset; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700304
305 uint32_t StringIdsSize() const { return string_ids_.Size(); }
306 uint32_t TypeIdsSize() const { return type_ids_.Size(); }
307 uint32_t ProtoIdsSize() const { return proto_ids_.Size(); }
308 uint32_t FieldIdsSize() const { return field_ids_.Size(); }
309 uint32_t MethodIdsSize() const { return method_ids_.Size(); }
310 uint32_t ClassDefsSize() const { return class_defs_.Size(); }
Jeff Hao5daee902017-04-27 18:00:38 -0700311 uint32_t CallSiteIdsSize() const { return call_site_ids_.Size(); }
312 uint32_t MethodHandleItemsSize() const { return method_handle_items_.Size(); }
David Sehrcdcfde72016-09-26 07:44:04 -0700313 uint32_t StringDatasSize() const { return string_datas_.Size(); }
314 uint32_t TypeListsSize() const { return type_lists_.Size(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000315 uint32_t EncodedArrayItemsSize() const { return encoded_array_items_.Size(); }
316 uint32_t AnnotationItemsSize() const { return annotation_items_.Size(); }
317 uint32_t AnnotationSetItemsSize() const { return annotation_set_items_.Size(); }
David Sehrcdcfde72016-09-26 07:44:04 -0700318 uint32_t AnnotationSetRefListsSize() const { return annotation_set_ref_lists_.Size(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000319 uint32_t AnnotationsDirectoryItemsSize() const { return annotations_directory_items_.Size(); }
320 uint32_t DebugInfoItemsSize() const { return debug_info_items_.Size(); }
David Sehrcdcfde72016-09-26 07:44:04 -0700321 uint32_t CodeItemsSize() const { return code_items_.Size(); }
322 uint32_t ClassDatasSize() const { return class_datas_.Size(); }
323
Jeff Hao3ab96b42016-09-09 18:35:01 -0700324 private:
325 EncodedValue* ReadEncodedValue(const uint8_t** data);
326 EncodedValue* ReadEncodedValue(const uint8_t** data, uint8_t type, uint8_t length);
327 void ReadEncodedValue(const uint8_t** data, uint8_t type, uint8_t length, EncodedValue* item);
328
329 ParameterAnnotation* GenerateParameterAnnotation(const DexFile& dex_file, MethodId* method_id,
330 const DexFile::AnnotationSetRefList* annotation_set_ref_list, uint32_t offset);
331 MethodItem* GenerateMethodItem(const DexFile& dex_file, ClassDataItemIterator& cdii);
332
Jeff Haoea7c6292016-11-14 18:10:16 -0800333 CollectionVector<StringId> string_ids_;
334 CollectionVector<TypeId> type_ids_;
335 CollectionVector<ProtoId> proto_ids_;
336 CollectionVector<FieldId> field_ids_;
337 CollectionVector<MethodId> method_ids_;
338 CollectionVector<ClassDef> class_defs_;
Jeff Hao5daee902017-04-27 18:00:38 -0700339 CollectionVector<CallSiteId> call_site_ids_;
340 CollectionVector<MethodHandleItem> method_handle_items_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700341
Jeff Haoea7c6292016-11-14 18:10:16 -0800342 CollectionMap<StringData> string_datas_;
343 CollectionMap<TypeList> type_lists_;
344 CollectionMap<EncodedArrayItem> encoded_array_items_;
345 CollectionMap<AnnotationItem> annotation_items_;
346 CollectionMap<AnnotationSetItem> annotation_set_items_;
347 CollectionMap<AnnotationSetRefList> annotation_set_ref_lists_;
348 CollectionMap<AnnotationsDirectoryItem> annotations_directory_items_;
349 CollectionMap<DebugInfoItem> debug_info_items_;
350 CollectionMap<CodeItem> code_items_;
351 CollectionMap<ClassData> class_datas_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700352
Jeff Haoea7c6292016-11-14 18:10:16 -0800353 uint32_t map_list_offset_ = 0;
Jeff Haoa8621002016-10-04 18:13:44 +0000354
Jeff Hao3ab96b42016-09-09 18:35:01 -0700355 DISALLOW_COPY_AND_ASSIGN(Collections);
356};
357
David Sehr7629f602016-08-07 16:01:51 -0700358class Item {
359 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700360 Item() { }
David Sehr7629f602016-08-07 16:01:51 -0700361 virtual ~Item() { }
David Sehr853a8e12016-09-01 13:03:50 -0700362
David Sehr7629f602016-08-07 16:01:51 -0700363 uint32_t GetOffset() const { return offset_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700364 uint32_t GetSize() const { return size_; }
David Sehr7629f602016-08-07 16:01:51 -0700365 void SetOffset(uint32_t offset) { offset_ = offset; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700366 void SetSize(uint32_t size) { size_ = size; }
David Sehr853a8e12016-09-01 13:03:50 -0700367
David Sehr7629f602016-08-07 16:01:51 -0700368 protected:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700369 Item(uint32_t offset, uint32_t size) : offset_(offset), size_(size) { }
370
David Sehr7629f602016-08-07 16:01:51 -0700371 uint32_t offset_ = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700372 uint32_t size_ = 0;
373};
374
375class IndexedItem : public Item {
376 public:
377 IndexedItem() { }
378 virtual ~IndexedItem() { }
379
380 uint32_t GetIndex() const { return index_; }
381 void SetIndex(uint32_t index) { index_ = index; }
382
383 protected:
384 IndexedItem(uint32_t offset, uint32_t size, uint32_t index)
385 : Item(offset, size), index_(index) { }
386
387 uint32_t index_ = 0;
David Sehr7629f602016-08-07 16:01:51 -0700388};
389
390class Header : public Item {
391 public:
David Sehr853a8e12016-09-01 13:03:50 -0700392 Header(const uint8_t* magic,
393 uint32_t checksum,
394 const uint8_t* signature,
395 uint32_t endian_tag,
396 uint32_t file_size,
397 uint32_t header_size,
398 uint32_t link_size,
399 uint32_t link_offset,
400 uint32_t data_size,
401 uint32_t data_offset)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700402 : Item(0, kHeaderItemSize),
403 checksum_(checksum),
David Sehr853a8e12016-09-01 13:03:50 -0700404 endian_tag_(endian_tag),
405 file_size_(file_size),
406 header_size_(header_size),
407 link_size_(link_size),
408 link_offset_(link_offset),
409 data_size_(data_size),
410 data_offset_(data_offset) {
411 memcpy(magic_, magic, sizeof(magic_));
412 memcpy(signature_, signature, sizeof(signature_));
413 }
David Sehr7629f602016-08-07 16:01:51 -0700414 ~Header() OVERRIDE { }
415
Jeff Hao3ab96b42016-09-09 18:35:01 -0700416 static size_t ItemSize() { return kHeaderItemSize; }
417
David Sehr7629f602016-08-07 16:01:51 -0700418 const uint8_t* Magic() const { return magic_; }
419 uint32_t Checksum() const { return checksum_; }
420 const uint8_t* Signature() const { return signature_; }
421 uint32_t EndianTag() const { return endian_tag_; }
422 uint32_t FileSize() const { return file_size_; }
423 uint32_t HeaderSize() const { return header_size_; }
424 uint32_t LinkSize() const { return link_size_; }
425 uint32_t LinkOffset() const { return link_offset_; }
426 uint32_t DataSize() const { return data_size_; }
427 uint32_t DataOffset() const { return data_offset_; }
428
429 void SetChecksum(uint32_t new_checksum) { checksum_ = new_checksum; }
430 void SetSignature(const uint8_t* new_signature) {
431 memcpy(signature_, new_signature, sizeof(signature_));
432 }
433 void SetFileSize(uint32_t new_file_size) { file_size_ = new_file_size; }
434 void SetHeaderSize(uint32_t new_header_size) { header_size_ = new_header_size; }
435 void SetLinkSize(uint32_t new_link_size) { link_size_ = new_link_size; }
436 void SetLinkOffset(uint32_t new_link_offset) { link_offset_ = new_link_offset; }
437 void SetDataSize(uint32_t new_data_size) { data_size_ = new_data_size; }
438 void SetDataOffset(uint32_t new_data_offset) { data_offset_ = new_data_offset; }
439
Jeff Hao3ab96b42016-09-09 18:35:01 -0700440 Collections& GetCollections() { return collections_; }
Jeff Haoc3acfc52016-08-29 14:18:26 -0700441
David Sehr7629f602016-08-07 16:01:51 -0700442 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
443
444 private:
David Sehr7629f602016-08-07 16:01:51 -0700445 uint8_t magic_[8];
446 uint32_t checksum_;
447 uint8_t signature_[DexFile::kSha1DigestSize];
448 uint32_t endian_tag_;
449 uint32_t file_size_;
450 uint32_t header_size_;
451 uint32_t link_size_;
452 uint32_t link_offset_;
453 uint32_t data_size_;
454 uint32_t data_offset_;
455
Jeff Hao3ab96b42016-09-09 18:35:01 -0700456 Collections collections_;
457
David Sehr7629f602016-08-07 16:01:51 -0700458 DISALLOW_COPY_AND_ASSIGN(Header);
459};
460
Jeff Hao3ab96b42016-09-09 18:35:01 -0700461class StringData : public Item {
David Sehr7629f602016-08-07 16:01:51 -0700462 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700463 explicit StringData(const char* data) : data_(strdup(data)) {
Jeff Haoa8621002016-10-04 18:13:44 +0000464 size_ = UnsignedLeb128Size(CountModifiedUtf8Chars(data)) + strlen(data);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700465 }
David Sehr7629f602016-08-07 16:01:51 -0700466
467 const char* Data() const { return data_.get(); }
468
469 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
470
471 private:
Jeff Haoa8621002016-10-04 18:13:44 +0000472 UniqueCPtr<const char> data_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700473
474 DISALLOW_COPY_AND_ASSIGN(StringData);
475};
476
477class StringId : public IndexedItem {
478 public:
479 explicit StringId(StringData* string_data) : string_data_(string_data) {
480 size_ = kStringIdItemSize;
481 }
482 ~StringId() OVERRIDE { }
483
484 static size_t ItemSize() { return kStringIdItemSize; }
485
486 const char* Data() const { return string_data_->Data(); }
487 StringData* DataItem() const { return string_data_; }
488
489 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
490
491 private:
492 StringData* string_data_;
493
David Sehr7629f602016-08-07 16:01:51 -0700494 DISALLOW_COPY_AND_ASSIGN(StringId);
495};
496
Jeff Hao3ab96b42016-09-09 18:35:01 -0700497class TypeId : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700498 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700499 explicit TypeId(StringId* string_id) : string_id_(string_id) { size_ = kTypeIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700500 ~TypeId() OVERRIDE { }
501
Jeff Hao3ab96b42016-09-09 18:35:01 -0700502 static size_t ItemSize() { return kTypeIdItemSize; }
503
David Sehr7629f602016-08-07 16:01:51 -0700504 StringId* GetStringId() const { return string_id_; }
505
506 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
507
508 private:
509 StringId* string_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700510
David Sehr7629f602016-08-07 16:01:51 -0700511 DISALLOW_COPY_AND_ASSIGN(TypeId);
512};
513
David Sehr853a8e12016-09-01 13:03:50 -0700514using TypeIdVector = std::vector<const TypeId*>;
515
Jeff Hao3ab96b42016-09-09 18:35:01 -0700516class TypeList : public Item {
David Sehr7629f602016-08-07 16:01:51 -0700517 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700518 explicit TypeList(TypeIdVector* type_list) : type_list_(type_list) {
519 size_ = sizeof(uint32_t) + (type_list->size() * sizeof(uint16_t));
520 }
521 ~TypeList() OVERRIDE { }
522
523 const TypeIdVector* GetTypeList() const { return type_list_.get(); }
524
525 private:
526 std::unique_ptr<TypeIdVector> type_list_;
527
528 DISALLOW_COPY_AND_ASSIGN(TypeList);
529};
530
531class ProtoId : public IndexedItem {
532 public:
533 ProtoId(const StringId* shorty, const TypeId* return_type, TypeList* parameters)
534 : shorty_(shorty), return_type_(return_type), parameters_(parameters)
535 { size_ = kProtoIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700536 ~ProtoId() OVERRIDE { }
537
Jeff Hao3ab96b42016-09-09 18:35:01 -0700538 static size_t ItemSize() { return kProtoIdItemSize; }
539
David Sehr7629f602016-08-07 16:01:51 -0700540 const StringId* Shorty() const { return shorty_; }
541 const TypeId* ReturnType() const { return return_type_; }
Jeff Haoa8621002016-10-04 18:13:44 +0000542 const TypeList* Parameters() const { return parameters_; }
David Sehr7629f602016-08-07 16:01:51 -0700543
544 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
545
546 private:
547 const StringId* shorty_;
548 const TypeId* return_type_;
Jeff Haoa8621002016-10-04 18:13:44 +0000549 TypeList* parameters_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700550
David Sehr7629f602016-08-07 16:01:51 -0700551 DISALLOW_COPY_AND_ASSIGN(ProtoId);
552};
553
Jeff Hao3ab96b42016-09-09 18:35:01 -0700554class FieldId : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700555 public:
David Sehr853a8e12016-09-01 13:03:50 -0700556 FieldId(const TypeId* klass, const TypeId* type, const StringId* name)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700557 : class_(klass), type_(type), name_(name) { size_ = kFieldIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700558 ~FieldId() OVERRIDE { }
559
Jeff Hao3ab96b42016-09-09 18:35:01 -0700560 static size_t ItemSize() { return kFieldIdItemSize; }
561
David Sehr7629f602016-08-07 16:01:51 -0700562 const TypeId* Class() const { return class_; }
563 const TypeId* Type() const { return type_; }
564 const StringId* Name() const { return name_; }
565
566 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
567
568 private:
569 const TypeId* class_;
570 const TypeId* type_;
571 const StringId* name_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700572
David Sehr7629f602016-08-07 16:01:51 -0700573 DISALLOW_COPY_AND_ASSIGN(FieldId);
574};
575
Jeff Hao3ab96b42016-09-09 18:35:01 -0700576class MethodId : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700577 public:
David Sehr853a8e12016-09-01 13:03:50 -0700578 MethodId(const TypeId* klass, const ProtoId* proto, const StringId* name)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700579 : class_(klass), proto_(proto), name_(name) { size_ = kMethodIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700580 ~MethodId() OVERRIDE { }
581
Jeff Hao3ab96b42016-09-09 18:35:01 -0700582 static size_t ItemSize() { return kMethodIdItemSize; }
583
David Sehr7629f602016-08-07 16:01:51 -0700584 const TypeId* Class() const { return class_; }
585 const ProtoId* Proto() const { return proto_; }
586 const StringId* Name() const { return name_; }
587
588 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
589
590 private:
591 const TypeId* class_;
592 const ProtoId* proto_;
593 const StringId* name_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700594
David Sehr7629f602016-08-07 16:01:51 -0700595 DISALLOW_COPY_AND_ASSIGN(MethodId);
596};
597
598class FieldItem : public Item {
599 public:
David Sehr853a8e12016-09-01 13:03:50 -0700600 FieldItem(uint32_t access_flags, const FieldId* field_id)
601 : access_flags_(access_flags), field_id_(field_id) { }
David Sehr7629f602016-08-07 16:01:51 -0700602 ~FieldItem() OVERRIDE { }
603
604 uint32_t GetAccessFlags() const { return access_flags_; }
605 const FieldId* GetFieldId() const { return field_id_; }
606
607 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
608
609 private:
610 uint32_t access_flags_;
611 const FieldId* field_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700612
David Sehr7629f602016-08-07 16:01:51 -0700613 DISALLOW_COPY_AND_ASSIGN(FieldItem);
614};
615
David Sehr853a8e12016-09-01 13:03:50 -0700616using FieldItemVector = std::vector<std::unique_ptr<FieldItem>>;
617
David Sehr7629f602016-08-07 16:01:51 -0700618class MethodItem : public Item {
619 public:
Jeff Haoea7c6292016-11-14 18:10:16 -0800620 MethodItem(uint32_t access_flags, const MethodId* method_id, CodeItem* code)
David Sehr853a8e12016-09-01 13:03:50 -0700621 : access_flags_(access_flags), method_id_(method_id), code_(code) { }
David Sehr7629f602016-08-07 16:01:51 -0700622 ~MethodItem() OVERRIDE { }
623
624 uint32_t GetAccessFlags() const { return access_flags_; }
625 const MethodId* GetMethodId() const { return method_id_; }
Jeff Haoea7c6292016-11-14 18:10:16 -0800626 CodeItem* GetCodeItem() { return code_; }
David Sehr7629f602016-08-07 16:01:51 -0700627
628 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
629
630 private:
631 uint32_t access_flags_;
632 const MethodId* method_id_;
Jeff Haoea7c6292016-11-14 18:10:16 -0800633 CodeItem* code_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700634
David Sehr7629f602016-08-07 16:01:51 -0700635 DISALLOW_COPY_AND_ASSIGN(MethodItem);
636};
637
David Sehr853a8e12016-09-01 13:03:50 -0700638using MethodItemVector = std::vector<std::unique_ptr<MethodItem>>;
639
Jeff Hao3ab96b42016-09-09 18:35:01 -0700640class EncodedValue {
David Sehr7629f602016-08-07 16:01:51 -0700641 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700642 explicit EncodedValue(uint8_t type) : type_(type) { }
David Sehr7629f602016-08-07 16:01:51 -0700643
644 int8_t Type() const { return type_; }
David Sehr7629f602016-08-07 16:01:51 -0700645
Jeff Hao3ab96b42016-09-09 18:35:01 -0700646 void SetBoolean(bool z) { u_.bool_val_ = z; }
647 void SetByte(int8_t b) { u_.byte_val_ = b; }
648 void SetShort(int16_t s) { u_.short_val_ = s; }
649 void SetChar(uint16_t c) { u_.char_val_ = c; }
650 void SetInt(int32_t i) { u_.int_val_ = i; }
651 void SetLong(int64_t l) { u_.long_val_ = l; }
652 void SetFloat(float f) { u_.float_val_ = f; }
653 void SetDouble(double d) { u_.double_val_ = d; }
654 void SetStringId(StringId* string_id) { u_.string_val_ = string_id; }
655 void SetTypeId(TypeId* type_id) { u_.type_val_ = type_id; }
Jeff Hao5daee902017-04-27 18:00:38 -0700656 void SetProtoId(ProtoId* proto_id) { u_.proto_val_ = proto_id; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700657 void SetFieldId(FieldId* field_id) { u_.field_val_ = field_id; }
658 void SetMethodId(MethodId* method_id) { u_.method_val_ = method_id; }
Jeff Hao5daee902017-04-27 18:00:38 -0700659 void SetMethodHandle(MethodHandleItem* method_handle) { u_.method_handle_val_ = method_handle; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700660 void SetEncodedArray(EncodedArrayItem* encoded_array) { encoded_array_.reset(encoded_array); }
661 void SetEncodedAnnotation(EncodedAnnotation* encoded_annotation)
662 { encoded_annotation_.reset(encoded_annotation); }
663
664 bool GetBoolean() const { return u_.bool_val_; }
665 int8_t GetByte() const { return u_.byte_val_; }
666 int16_t GetShort() const { return u_.short_val_; }
667 uint16_t GetChar() const { return u_.char_val_; }
668 int32_t GetInt() const { return u_.int_val_; }
669 int64_t GetLong() const { return u_.long_val_; }
670 float GetFloat() const { return u_.float_val_; }
671 double GetDouble() const { return u_.double_val_; }
672 StringId* GetStringId() const { return u_.string_val_; }
673 TypeId* GetTypeId() const { return u_.type_val_; }
Jeff Hao5daee902017-04-27 18:00:38 -0700674 ProtoId* GetProtoId() const { return u_.proto_val_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700675 FieldId* GetFieldId() const { return u_.field_val_; }
676 MethodId* GetMethodId() const { return u_.method_val_; }
Jeff Hao5daee902017-04-27 18:00:38 -0700677 MethodHandleItem* GetMethodHandle() const { return u_.method_handle_val_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700678 EncodedArrayItem* GetEncodedArray() const { return encoded_array_.get(); }
679 EncodedAnnotation* GetEncodedAnnotation() const { return encoded_annotation_.get(); }
680
681 EncodedAnnotation* ReleaseEncodedAnnotation() { return encoded_annotation_.release(); }
David Sehr7629f602016-08-07 16:01:51 -0700682
683 private:
David Sehr7629f602016-08-07 16:01:51 -0700684 uint8_t type_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700685 union {
686 bool bool_val_;
687 int8_t byte_val_;
688 int16_t short_val_;
689 uint16_t char_val_;
690 int32_t int_val_;
691 int64_t long_val_;
692 float float_val_;
693 double double_val_;
694 StringId* string_val_;
695 TypeId* type_val_;
Jeff Hao5daee902017-04-27 18:00:38 -0700696 ProtoId* proto_val_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700697 FieldId* field_val_;
698 MethodId* method_val_;
Jeff Hao5daee902017-04-27 18:00:38 -0700699 MethodHandleItem* method_handle_val_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700700 } u_;
701 std::unique_ptr<EncodedArrayItem> encoded_array_;
702 std::unique_ptr<EncodedAnnotation> encoded_annotation_;
703
704 DISALLOW_COPY_AND_ASSIGN(EncodedValue);
David Sehr7629f602016-08-07 16:01:51 -0700705};
706
Jeff Hao3ab96b42016-09-09 18:35:01 -0700707using EncodedValueVector = std::vector<std::unique_ptr<EncodedValue>>;
708
709class AnnotationElement {
710 public:
711 AnnotationElement(StringId* name, EncodedValue* value) : name_(name), value_(value) { }
712
713 StringId* GetName() const { return name_; }
714 EncodedValue* GetValue() const { return value_.get(); }
715
716 private:
717 StringId* name_;
718 std::unique_ptr<EncodedValue> value_;
719
720 DISALLOW_COPY_AND_ASSIGN(AnnotationElement);
721};
722
723using AnnotationElementVector = std::vector<std::unique_ptr<AnnotationElement>>;
724
725class EncodedAnnotation {
726 public:
727 EncodedAnnotation(TypeId* type, AnnotationElementVector* elements)
728 : type_(type), elements_(elements) { }
729
730 TypeId* GetType() const { return type_; }
731 AnnotationElementVector* GetAnnotationElements() const { return elements_.get(); }
732
733 private:
734 TypeId* type_;
735 std::unique_ptr<AnnotationElementVector> elements_;
736
737 DISALLOW_COPY_AND_ASSIGN(EncodedAnnotation);
738};
739
740class EncodedArrayItem : public Item {
741 public:
742 explicit EncodedArrayItem(EncodedValueVector* encoded_values)
743 : encoded_values_(encoded_values) { }
744
745 EncodedValueVector* GetEncodedValues() const { return encoded_values_.get(); }
746
747 private:
748 std::unique_ptr<EncodedValueVector> encoded_values_;
749
750 DISALLOW_COPY_AND_ASSIGN(EncodedArrayItem);
751};
David Sehr853a8e12016-09-01 13:03:50 -0700752
David Sehr7629f602016-08-07 16:01:51 -0700753class ClassData : public Item {
754 public:
David Sehr853a8e12016-09-01 13:03:50 -0700755 ClassData(FieldItemVector* static_fields,
756 FieldItemVector* instance_fields,
757 MethodItemVector* direct_methods,
758 MethodItemVector* virtual_methods)
759 : static_fields_(static_fields),
760 instance_fields_(instance_fields),
761 direct_methods_(direct_methods),
762 virtual_methods_(virtual_methods) { }
763
David Sehr7629f602016-08-07 16:01:51 -0700764 ~ClassData() OVERRIDE = default;
David Sehr853a8e12016-09-01 13:03:50 -0700765 FieldItemVector* StaticFields() { return static_fields_.get(); }
766 FieldItemVector* InstanceFields() { return instance_fields_.get(); }
767 MethodItemVector* DirectMethods() { return direct_methods_.get(); }
768 MethodItemVector* VirtualMethods() { return virtual_methods_.get(); }
David Sehr7629f602016-08-07 16:01:51 -0700769
770 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
771
772 private:
David Sehr853a8e12016-09-01 13:03:50 -0700773 std::unique_ptr<FieldItemVector> static_fields_;
774 std::unique_ptr<FieldItemVector> instance_fields_;
775 std::unique_ptr<MethodItemVector> direct_methods_;
776 std::unique_ptr<MethodItemVector> virtual_methods_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700777
David Sehr7629f602016-08-07 16:01:51 -0700778 DISALLOW_COPY_AND_ASSIGN(ClassData);
779};
780
Jeff Hao3ab96b42016-09-09 18:35:01 -0700781class ClassDef : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700782 public:
David Sehr853a8e12016-09-01 13:03:50 -0700783 ClassDef(const TypeId* class_type,
784 uint32_t access_flags,
785 const TypeId* superclass,
Jeff Hao3ab96b42016-09-09 18:35:01 -0700786 TypeList* interfaces,
David Sehr853a8e12016-09-01 13:03:50 -0700787 const StringId* source_file,
788 AnnotationsDirectoryItem* annotations,
Jeff Hao3ab96b42016-09-09 18:35:01 -0700789 EncodedArrayItem* static_values,
David Sehr853a8e12016-09-01 13:03:50 -0700790 ClassData* class_data)
791 : class_type_(class_type),
792 access_flags_(access_flags),
793 superclass_(superclass),
794 interfaces_(interfaces),
David Sehr853a8e12016-09-01 13:03:50 -0700795 source_file_(source_file),
796 annotations_(annotations),
Jeff Haoa8621002016-10-04 18:13:44 +0000797 class_data_(class_data),
798 static_values_(static_values) { size_ = kClassDefItemSize; }
David Sehr853a8e12016-09-01 13:03:50 -0700799
David Sehr7629f602016-08-07 16:01:51 -0700800 ~ClassDef() OVERRIDE { }
801
Jeff Hao3ab96b42016-09-09 18:35:01 -0700802 static size_t ItemSize() { return kClassDefItemSize; }
803
David Sehr7629f602016-08-07 16:01:51 -0700804 const TypeId* ClassType() const { return class_type_; }
805 uint32_t GetAccessFlags() const { return access_flags_; }
806 const TypeId* Superclass() const { return superclass_; }
Jeff Haocc829592017-03-14 16:13:39 -0700807 const TypeList* Interfaces() { return interfaces_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700808 uint32_t InterfacesOffset() { return interfaces_ == nullptr ? 0 : interfaces_->GetOffset(); }
David Sehr7629f602016-08-07 16:01:51 -0700809 const StringId* SourceFile() const { return source_file_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700810 AnnotationsDirectoryItem* Annotations() const { return annotations_; }
Nicolas Geoffrayfd1a6c22016-10-04 11:01:17 +0000811 ClassData* GetClassData() { return class_data_; }
Jeff Haoa8621002016-10-04 18:13:44 +0000812 EncodedArrayItem* StaticValues() { return static_values_; }
David Sehr7629f602016-08-07 16:01:51 -0700813
Jeff Haoc3acfc52016-08-29 14:18:26 -0700814 MethodItem* GenerateMethodItem(Header& header, ClassDataItemIterator& cdii);
815
David Sehr7629f602016-08-07 16:01:51 -0700816 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
817
818 private:
819 const TypeId* class_type_;
820 uint32_t access_flags_;
Jeff Haoa8621002016-10-04 18:13:44 +0000821 const TypeId* superclass_; // This can be nullptr.
822 TypeList* interfaces_; // This can be nullptr.
823 const StringId* source_file_; // This can be nullptr.
824 AnnotationsDirectoryItem* annotations_; // This can be nullptr.
825 ClassData* class_data_; // This can be nullptr.
826 EncodedArrayItem* static_values_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700827
David Sehr7629f602016-08-07 16:01:51 -0700828 DISALLOW_COPY_AND_ASSIGN(ClassDef);
829};
830
Jeff Haoa8621002016-10-04 18:13:44 +0000831class TypeAddrPair {
David Sehr853a8e12016-09-01 13:03:50 -0700832 public:
Jeff Haoa8621002016-10-04 18:13:44 +0000833 TypeAddrPair(const TypeId* type_id, uint32_t address) : type_id_(type_id), address_(address) { }
David Sehr853a8e12016-09-01 13:03:50 -0700834
835 const TypeId* GetTypeId() const { return type_id_; }
836 uint32_t GetAddress() const { return address_; }
837
838 private:
Jeff Haocc829592017-03-14 16:13:39 -0700839 const TypeId* type_id_; // This can be nullptr.
David Sehr853a8e12016-09-01 13:03:50 -0700840 uint32_t address_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700841
Jeff Haoa8621002016-10-04 18:13:44 +0000842 DISALLOW_COPY_AND_ASSIGN(TypeAddrPair);
843};
844
845using TypeAddrPairVector = std::vector<std::unique_ptr<const TypeAddrPair>>;
846
847class CatchHandler {
848 public:
849 explicit CatchHandler(bool catch_all, uint16_t list_offset, TypeAddrPairVector* handlers)
850 : catch_all_(catch_all), list_offset_(list_offset), handlers_(handlers) { }
851
852 bool HasCatchAll() const { return catch_all_; }
853 uint16_t GetListOffset() const { return list_offset_; }
854 TypeAddrPairVector* GetHandlers() const { return handlers_.get(); }
855
856 private:
857 bool catch_all_;
858 uint16_t list_offset_;
859 std::unique_ptr<TypeAddrPairVector> handlers_;
860
David Sehr853a8e12016-09-01 13:03:50 -0700861 DISALLOW_COPY_AND_ASSIGN(CatchHandler);
862};
863
864using CatchHandlerVector = std::vector<std::unique_ptr<const CatchHandler>>;
865
866class TryItem : public Item {
867 public:
Jeff Haoa8621002016-10-04 18:13:44 +0000868 TryItem(uint32_t start_addr, uint16_t insn_count, const CatchHandler* handlers)
David Sehr853a8e12016-09-01 13:03:50 -0700869 : start_addr_(start_addr), insn_count_(insn_count), handlers_(handlers) { }
870 ~TryItem() OVERRIDE { }
871
872 uint32_t StartAddr() const { return start_addr_; }
873 uint16_t InsnCount() const { return insn_count_; }
Jeff Haoa8621002016-10-04 18:13:44 +0000874 const CatchHandler* GetHandlers() const { return handlers_; }
David Sehr853a8e12016-09-01 13:03:50 -0700875
876 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
877
878 private:
879 uint32_t start_addr_;
880 uint16_t insn_count_;
Jeff Haoa8621002016-10-04 18:13:44 +0000881 const CatchHandler* handlers_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700882
David Sehr853a8e12016-09-01 13:03:50 -0700883 DISALLOW_COPY_AND_ASSIGN(TryItem);
884};
885
886using TryItemVector = std::vector<std::unique_ptr<const TryItem>>;
887
David Sehrd1e44e22016-10-06 17:09:32 -0700888class CodeFixups {
889 public:
890 CodeFixups(std::vector<TypeId*>* type_ids,
891 std::vector<StringId*>* string_ids,
892 std::vector<MethodId*>* method_ids,
893 std::vector<FieldId*>* field_ids)
894 : type_ids_(type_ids),
895 string_ids_(string_ids),
896 method_ids_(method_ids),
897 field_ids_(field_ids) { }
898
899 std::vector<TypeId*>* TypeIds() const { return type_ids_.get(); }
900 std::vector<StringId*>* StringIds() const { return string_ids_.get(); }
901 std::vector<MethodId*>* MethodIds() const { return method_ids_.get(); }
902 std::vector<FieldId*>* FieldIds() const { return field_ids_.get(); }
903
904 private:
905 std::unique_ptr<std::vector<TypeId*>> type_ids_;
906 std::unique_ptr<std::vector<StringId*>> string_ids_;
907 std::unique_ptr<std::vector<MethodId*>> method_ids_;
908 std::unique_ptr<std::vector<FieldId*>> field_ids_;
909
910 DISALLOW_COPY_AND_ASSIGN(CodeFixups);
911};
912
David Sehr7629f602016-08-07 16:01:51 -0700913class CodeItem : public Item {
914 public:
David Sehr853a8e12016-09-01 13:03:50 -0700915 CodeItem(uint16_t registers_size,
916 uint16_t ins_size,
917 uint16_t outs_size,
918 DebugInfoItem* debug_info,
919 uint32_t insns_size,
920 uint16_t* insns,
Jeff Haoa8621002016-10-04 18:13:44 +0000921 TryItemVector* tries,
922 CatchHandlerVector* handlers)
David Sehr853a8e12016-09-01 13:03:50 -0700923 : registers_size_(registers_size),
924 ins_size_(ins_size),
925 outs_size_(outs_size),
926 debug_info_(debug_info),
927 insns_size_(insns_size),
928 insns_(insns),
Jeff Haoa8621002016-10-04 18:13:44 +0000929 tries_(tries),
930 handlers_(handlers) { }
David Sehr853a8e12016-09-01 13:03:50 -0700931
David Sehr7629f602016-08-07 16:01:51 -0700932 ~CodeItem() OVERRIDE { }
933
934 uint16_t RegistersSize() const { return registers_size_; }
935 uint16_t InsSize() const { return ins_size_; }
936 uint16_t OutsSize() const { return outs_size_; }
David Sehr853a8e12016-09-01 13:03:50 -0700937 uint16_t TriesSize() const { return tries_ == nullptr ? 0 : tries_->size(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700938 DebugInfoItem* DebugInfo() const { return debug_info_; }
David Sehr7629f602016-08-07 16:01:51 -0700939 uint32_t InsnsSize() const { return insns_size_; }
940 uint16_t* Insns() const { return insns_.get(); }
David Sehr853a8e12016-09-01 13:03:50 -0700941 TryItemVector* Tries() const { return tries_.get(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000942 CatchHandlerVector* Handlers() const { return handlers_.get(); }
David Sehr7629f602016-08-07 16:01:51 -0700943
David Sehrd1e44e22016-10-06 17:09:32 -0700944 void SetCodeFixups(CodeFixups* fixups) { fixups_.reset(fixups); }
945 CodeFixups* GetCodeFixups() const { return fixups_.get(); }
946
David Sehr7629f602016-08-07 16:01:51 -0700947 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
948
949 private:
950 uint16_t registers_size_;
951 uint16_t ins_size_;
952 uint16_t outs_size_;
Jeff Haoa8621002016-10-04 18:13:44 +0000953 DebugInfoItem* debug_info_; // This can be nullptr.
David Sehr7629f602016-08-07 16:01:51 -0700954 uint32_t insns_size_;
955 std::unique_ptr<uint16_t[]> insns_;
Jeff Haoa8621002016-10-04 18:13:44 +0000956 std::unique_ptr<TryItemVector> tries_; // This can be nullptr.
957 std::unique_ptr<CatchHandlerVector> handlers_; // This can be nullptr.
David Sehrd1e44e22016-10-06 17:09:32 -0700958 std::unique_ptr<CodeFixups> fixups_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700959
David Sehr7629f602016-08-07 16:01:51 -0700960 DISALLOW_COPY_AND_ASSIGN(CodeItem);
961};
962
David Sehr7629f602016-08-07 16:01:51 -0700963struct PositionInfo {
964 PositionInfo(uint32_t address, uint32_t line) : address_(address), line_(line) { }
965
966 uint32_t address_;
967 uint32_t line_;
968};
969
David Sehr853a8e12016-09-01 13:03:50 -0700970using PositionInfoVector = std::vector<std::unique_ptr<PositionInfo>>;
971
David Sehr7629f602016-08-07 16:01:51 -0700972struct LocalInfo {
David Sehr853a8e12016-09-01 13:03:50 -0700973 LocalInfo(const char* name,
974 const char* descriptor,
975 const char* signature,
976 uint32_t start_address,
977 uint32_t end_address,
978 uint16_t reg)
979 : name_(name),
980 descriptor_(descriptor),
981 signature_(signature),
982 start_address_(start_address),
983 end_address_(end_address),
984 reg_(reg) { }
David Sehr7629f602016-08-07 16:01:51 -0700985
986 std::string name_;
987 std::string descriptor_;
988 std::string signature_;
989 uint32_t start_address_;
990 uint32_t end_address_;
991 uint16_t reg_;
992};
993
David Sehr853a8e12016-09-01 13:03:50 -0700994using LocalInfoVector = std::vector<std::unique_ptr<LocalInfo>>;
995
David Sehr7629f602016-08-07 16:01:51 -0700996class DebugInfoItem : public Item {
997 public:
Jeff Haoa8621002016-10-04 18:13:44 +0000998 DebugInfoItem(uint32_t debug_info_size, uint8_t* debug_info)
999 : debug_info_size_(debug_info_size), debug_info_(debug_info) { }
1000
1001 uint32_t GetDebugInfoSize() const { return debug_info_size_; }
1002 uint8_t* GetDebugInfo() const { return debug_info_.get(); }
David Sehr7629f602016-08-07 16:01:51 -07001003
David Sehr853a8e12016-09-01 13:03:50 -07001004 PositionInfoVector& GetPositionInfo() { return positions_; }
1005 LocalInfoVector& GetLocalInfo() { return locals_; }
David Sehr7629f602016-08-07 16:01:51 -07001006
1007 private:
Jeff Haoa8621002016-10-04 18:13:44 +00001008 uint32_t debug_info_size_;
1009 std::unique_ptr<uint8_t[]> debug_info_;
1010
David Sehr853a8e12016-09-01 13:03:50 -07001011 PositionInfoVector positions_;
1012 LocalInfoVector locals_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001013
David Sehr7629f602016-08-07 16:01:51 -07001014 DISALLOW_COPY_AND_ASSIGN(DebugInfoItem);
1015};
1016
Jeff Hao3ab96b42016-09-09 18:35:01 -07001017class AnnotationItem : public Item {
David Sehr853a8e12016-09-01 13:03:50 -07001018 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -07001019 AnnotationItem(uint8_t visibility, EncodedAnnotation* annotation)
1020 : visibility_(visibility), annotation_(annotation) { }
David Sehr853a8e12016-09-01 13:03:50 -07001021
1022 uint8_t GetVisibility() const { return visibility_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001023 EncodedAnnotation* GetAnnotation() const { return annotation_.get(); }
David Sehr7629f602016-08-07 16:01:51 -07001024
1025 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1026
1027 private:
Jeff Hao3ab96b42016-09-09 18:35:01 -07001028 uint8_t visibility_;
1029 std::unique_ptr<EncodedAnnotation> annotation_;
1030
1031 DISALLOW_COPY_AND_ASSIGN(AnnotationItem);
1032};
1033
1034class AnnotationSetItem : public Item {
1035 public:
1036 explicit AnnotationSetItem(std::vector<AnnotationItem*>* items) : items_(items) {
1037 size_ = sizeof(uint32_t) + items->size() * sizeof(uint32_t);
1038 }
1039 ~AnnotationSetItem() OVERRIDE { }
1040
1041 std::vector<AnnotationItem*>* GetItems() { return items_.get(); }
1042
1043 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1044
1045 private:
1046 std::unique_ptr<std::vector<AnnotationItem*>> items_;
1047
David Sehr7629f602016-08-07 16:01:51 -07001048 DISALLOW_COPY_AND_ASSIGN(AnnotationSetItem);
1049};
1050
Jeff Hao3ab96b42016-09-09 18:35:01 -07001051class AnnotationSetRefList : public Item {
1052 public:
1053 explicit AnnotationSetRefList(std::vector<AnnotationSetItem*>* items) : items_(items) {
1054 size_ = sizeof(uint32_t) + items->size() * sizeof(uint32_t);
1055 }
1056 ~AnnotationSetRefList() OVERRIDE { }
1057
1058 std::vector<AnnotationSetItem*>* GetItems() { return items_.get(); }
1059
1060 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1061
1062 private:
Jeff Haoa8621002016-10-04 18:13:44 +00001063 std::unique_ptr<std::vector<AnnotationSetItem*>> items_; // Elements of vector can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -07001064
1065 DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefList);
1066};
David Sehr853a8e12016-09-01 13:03:50 -07001067
1068class FieldAnnotation {
1069 public:
1070 FieldAnnotation(FieldId* field_id, AnnotationSetItem* annotation_set_item)
1071 : field_id_(field_id), annotation_set_item_(annotation_set_item) { }
1072
1073 FieldId* GetFieldId() const { return field_id_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001074 AnnotationSetItem* GetAnnotationSetItem() const { return annotation_set_item_; }
David Sehr853a8e12016-09-01 13:03:50 -07001075
1076 private:
1077 FieldId* field_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001078 AnnotationSetItem* annotation_set_item_;
1079
David Sehr853a8e12016-09-01 13:03:50 -07001080 DISALLOW_COPY_AND_ASSIGN(FieldAnnotation);
1081};
1082
1083using FieldAnnotationVector = std::vector<std::unique_ptr<FieldAnnotation>>;
1084
1085class MethodAnnotation {
1086 public:
1087 MethodAnnotation(MethodId* method_id, AnnotationSetItem* annotation_set_item)
1088 : method_id_(method_id), annotation_set_item_(annotation_set_item) { }
1089
1090 MethodId* GetMethodId() const { return method_id_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001091 AnnotationSetItem* GetAnnotationSetItem() const { return annotation_set_item_; }
David Sehr853a8e12016-09-01 13:03:50 -07001092
1093 private:
1094 MethodId* method_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001095 AnnotationSetItem* annotation_set_item_;
1096
David Sehr853a8e12016-09-01 13:03:50 -07001097 DISALLOW_COPY_AND_ASSIGN(MethodAnnotation);
1098};
1099
1100using MethodAnnotationVector = std::vector<std::unique_ptr<MethodAnnotation>>;
1101
1102class ParameterAnnotation {
1103 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -07001104 ParameterAnnotation(MethodId* method_id, AnnotationSetRefList* annotations)
David Sehr853a8e12016-09-01 13:03:50 -07001105 : method_id_(method_id), annotations_(annotations) { }
1106
1107 MethodId* GetMethodId() const { return method_id_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001108 AnnotationSetRefList* GetAnnotations() { return annotations_; }
David Sehr853a8e12016-09-01 13:03:50 -07001109
1110 private:
1111 MethodId* method_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001112 AnnotationSetRefList* annotations_;
1113
David Sehr853a8e12016-09-01 13:03:50 -07001114 DISALLOW_COPY_AND_ASSIGN(ParameterAnnotation);
1115};
1116
1117using ParameterAnnotationVector = std::vector<std::unique_ptr<ParameterAnnotation>>;
1118
David Sehr7629f602016-08-07 16:01:51 -07001119class AnnotationsDirectoryItem : public Item {
1120 public:
David Sehr853a8e12016-09-01 13:03:50 -07001121 AnnotationsDirectoryItem(AnnotationSetItem* class_annotation,
1122 FieldAnnotationVector* field_annotations,
1123 MethodAnnotationVector* method_annotations,
1124 ParameterAnnotationVector* parameter_annotations)
1125 : class_annotation_(class_annotation),
1126 field_annotations_(field_annotations),
1127 method_annotations_(method_annotations),
1128 parameter_annotations_(parameter_annotations) { }
David Sehr7629f602016-08-07 16:01:51 -07001129
Jeff Hao3ab96b42016-09-09 18:35:01 -07001130 AnnotationSetItem* GetClassAnnotation() const { return class_annotation_; }
David Sehr853a8e12016-09-01 13:03:50 -07001131 FieldAnnotationVector* GetFieldAnnotations() { return field_annotations_.get(); }
1132 MethodAnnotationVector* GetMethodAnnotations() { return method_annotations_.get(); }
1133 ParameterAnnotationVector* GetParameterAnnotations() { return parameter_annotations_.get(); }
David Sehr7629f602016-08-07 16:01:51 -07001134
1135 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1136
1137 private:
Jeff Haoa8621002016-10-04 18:13:44 +00001138 AnnotationSetItem* class_annotation_; // This can be nullptr.
1139 std::unique_ptr<FieldAnnotationVector> field_annotations_; // This can be nullptr.
1140 std::unique_ptr<MethodAnnotationVector> method_annotations_; // This can be nullptr.
1141 std::unique_ptr<ParameterAnnotationVector> parameter_annotations_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -07001142
David Sehr7629f602016-08-07 16:01:51 -07001143 DISALLOW_COPY_AND_ASSIGN(AnnotationsDirectoryItem);
1144};
1145
Jeff Hao5daee902017-04-27 18:00:38 -07001146class CallSiteId : public IndexedItem {
1147 public:
1148 explicit CallSiteId(EncodedArrayItem* call_site_item) : call_site_item_(call_site_item) {
1149 size_ = kCallSiteIdItemSize;
1150 }
1151 ~CallSiteId() OVERRIDE { }
1152
1153 static size_t ItemSize() { return kCallSiteIdItemSize; }
1154
1155 EncodedArrayItem* CallSiteItem() const { return call_site_item_; }
1156
1157 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
1158
1159 private:
1160 EncodedArrayItem* call_site_item_;
1161
1162 DISALLOW_COPY_AND_ASSIGN(CallSiteId);
1163};
1164
1165class MethodHandleItem : public IndexedItem {
1166 public:
1167 MethodHandleItem(DexFile::MethodHandleType method_handle_type, IndexedItem* field_or_method_id)
1168 : method_handle_type_(method_handle_type),
1169 field_or_method_id_(field_or_method_id) {
1170 size_ = kMethodHandleItemSize;
1171 }
1172 ~MethodHandleItem() OVERRIDE { }
1173
1174 static size_t ItemSize() { return kMethodHandleItemSize; }
1175
1176 DexFile::MethodHandleType GetMethodHandleType() const { return method_handle_type_; }
1177 IndexedItem* GetFieldOrMethodId() const { return field_or_method_id_; }
1178
1179 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
1180
1181 private:
1182 DexFile::MethodHandleType method_handle_type_;
1183 IndexedItem* field_or_method_id_;
1184
1185 DISALLOW_COPY_AND_ASSIGN(MethodHandleItem);
1186};
1187
David Sehr7629f602016-08-07 16:01:51 -07001188// TODO(sehr): implement MapList.
1189class MapList : public Item {
1190 public:
1191 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1192
1193 private:
1194 DISALLOW_COPY_AND_ASSIGN(MapList);
1195};
1196
1197class MapItem : public Item {
1198 public:
1199 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1200
1201 private:
1202 DISALLOW_COPY_AND_ASSIGN(MapItem);
1203};
1204
David Sehr9037a3a2017-03-30 17:50:24 -07001205// Interface for building a vector of file sections for use by other clients.
1206struct DexFileSection {
1207 public:
1208 DexFileSection(const std::string& name, uint16_t type, uint32_t size, uint32_t offset)
1209 : name(name), type(type), size(size), offset(offset) { }
1210 std::string name;
1211 // The type (DexFile::MapItemType).
1212 uint16_t type;
1213 // The size (in elements, not bytes).
1214 uint32_t size;
1215 // The byte offset from the start of the file.
1216 uint32_t offset;
1217};
1218
1219enum class SortDirection {
1220 kSortAscending,
1221 kSortDescending
1222};
1223
1224std::vector<DexFileSection> GetSortedDexFileSections(dex_ir::Header* header,
1225 SortDirection direction);
1226
David Sehr7629f602016-08-07 16:01:51 -07001227} // namespace dex_ir
1228} // namespace art
1229
1230#endif // ART_DEXLAYOUT_DEX_IR_H_