blob: 9217701bc50bc5d7cfecb49ffb2a7556164e16f7 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_OAT_WRITER_H_
18#define ART_COMPILER_OAT_WRITER_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
20#include <stdint.h>
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include <cstddef>
Ian Rogers700a4022014-05-19 16:49:03 -070022#include <memory>
Brian Carlstrom7940e442013-07-12 13:46:57 -070023
David Brazdild9c90372016-09-14 16:53:55 +010024#include "base/array_ref.h"
Vladimir Marko49b0f452015-12-10 13:49:19 +000025#include "base/dchecked_vector.h"
Vladimir Markob163bb72015-03-31 21:49:49 +010026#include "linker/relative_patcher.h" // For linker::RelativePatcherTargetProvider.
Brian Carlstrom7940e442013-07-12 13:46:57 -070027#include "mem_map.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010028#include "method_reference.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "mirror/class.h"
Artem Udovichenkod9786b02015-10-14 16:36:55 +030030#include "oat.h"
Vladimir Marko9bdf1082016-01-21 12:15:52 +000031#include "os.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032#include "safe_map.h"
Vladimir Markoaad75c62016-10-03 08:46:48 +000033#include "string_reference.h"
Mathieu Chartierdbddc222017-05-24 12:04:13 -070034#include "type_reference.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070035
36namespace art {
37
Brian Carlstromba150c32013-08-27 17:31:03 -070038class BitVector;
Andreas Gampe79273802014-08-05 20:21:05 -070039class CompiledMethod;
Vladimir Marko20f85592015-03-19 10:07:02 +000040class CompilerDriver;
Vladimir Markof4da6752014-08-01 19:04:18 +010041class ImageWriter;
Jeff Hao608f2ce2016-10-19 11:17:11 -070042class ProfileCompilationInfo;
Brian Carlstrom7940e442013-07-12 13:46:57 -070043class OutputStream;
Vladimir Marko20f85592015-03-19 10:07:02 +000044class TimingLogger;
Artem Udovichenkod9786b02015-10-14 16:36:55 +030045class TypeLookupTable;
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +000046class VdexFile;
Vladimir Marko9bdf1082016-01-21 12:15:52 +000047class ZipEntry;
Brian Carlstrom7940e442013-07-12 13:46:57 -070048
David Srbeckyc5bfa972016-02-05 15:49:10 +000049namespace debug {
Vladimir Marko10c13562015-11-25 14:33:36 +000050struct MethodDebugInfo;
David Srbeckyc5bfa972016-02-05 15:49:10 +000051} // namespace debug
Vladimir Marko10c13562015-11-25 14:33:36 +000052
Vladimir Marko944da602016-02-19 12:27:55 +000053namespace linker {
54class MultiOatRelativePatcher;
55} // namespace linker
56
David Brazdil5d5a36b2016-09-14 15:34:10 +010057namespace verifier {
58 class VerifierDeps;
59} // namespace verifier
60
Brian Carlstrom7940e442013-07-12 13:46:57 -070061// OatHeader variable length with count of D OatDexFiles
62//
Artem Udovichenkod9786b02015-10-14 16:36:55 +030063// TypeLookupTable[0] one descriptor to class def index hash table for each OatDexFile.
64// TypeLookupTable[1]
65// ...
66// TypeLookupTable[D]
67//
Vladimir Marko9bdf1082016-01-21 12:15:52 +000068// ClassOffsets[0] one table of OatClass offsets for each class def for each OatDexFile.
69// ClassOffsets[1]
70// ...
71// ClassOffsets[D]
72//
Brian Carlstrom7940e442013-07-12 13:46:57 -070073// OatClass[0] one variable sized OatClass for each of C DexFile::ClassDefs
74// OatClass[1] contains OatClass entries with class status, offsets to code, etc.
75// ...
76// OatClass[C]
77//
Vladimir Marko0eb882b2017-05-15 13:39:18 +010078// MethodBssMapping one variable sized MethodBssMapping for each dex file, optional.
79// MethodBssMapping
Vladimir Marko96c6ab92014-04-08 14:00:50 +010080// ...
Vladimir Marko0eb882b2017-05-15 13:39:18 +010081// MethodBssMapping
Vladimir Marko96c6ab92014-04-08 14:00:50 +010082//
Vladimir Marko0eb882b2017-05-15 13:39:18 +010083// VmapTable one variable sized VmapTable blob (CodeInfo or QuickeningInfo).
Vladimir Marko96c6ab92014-04-08 14:00:50 +010084// VmapTable VmapTables are deduplicated.
85// ...
86// VmapTable
87//
Vladimir Marko0eb882b2017-05-15 13:39:18 +010088// MethodInfo one variable sized blob with MethodInfo.
89// MethodInfo MethodInfos are deduplicated.
Vladimir Marko96c6ab92014-04-08 14:00:50 +010090// ...
Vladimir Marko0eb882b2017-05-15 13:39:18 +010091// MethodInfo
92//
93// OatDexFile[0] one variable sized OatDexFile with offsets to Dex and OatClasses
94// OatDexFile[1]
95// ...
96// OatDexFile[D]
Vladimir Marko96c6ab92014-04-08 14:00:50 +010097//
Brian Carlstrom7940e442013-07-12 13:46:57 -070098// padding if necessary so that the following code will be page aligned
99//
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100100// OatMethodHeader fixed size header for a CompiledMethod including the size of the MethodCode.
101// MethodCode one variable sized blob with the code of a CompiledMethod.
102// OatMethodHeader (OatMethodHeader, MethodCode) pairs are deduplicated.
103// MethodCode
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104// ...
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100105// OatMethodHeader
106// MethodCode
Brian Carlstrom7940e442013-07-12 13:46:57 -0700107//
108class OatWriter {
109 public:
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000110 enum class CreateTypeLookupTable {
111 kCreate,
112 kDontCreate,
113 kDefault = kCreate
114 };
115
Jeff Hao608f2ce2016-10-19 11:17:11 -0700116 OatWriter(bool compiling_boot_image, TimingLogger* timings, ProfileCompilationInfo* info);
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000117
118 // To produce a valid oat file, the user must first add sources with any combination of
119 // - AddDexFileSource(),
120 // - AddZippedDexFilesSource(),
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000121 // - AddRawDexFileSource(),
122 // - AddVdexDexFilesSource().
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000123 // Then the user must call in order
124 // - WriteAndOpenDexFiles()
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100125 // - Initialize()
126 // - WriteVerifierDeps()
127 // - WriteQuickeningInfo()
Nicolas Geoffrayf54e5df2016-12-01 10:45:08 +0000128 // - WriteChecksumsAndVdexHeader()
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000129 // - PrepareLayout(),
130 // - WriteRodata(),
131 // - WriteCode(),
132 // - WriteHeader().
133
134 // Add dex file source(s) from a file, either a plain dex file or
135 // a zip file with one or more dex files.
136 bool AddDexFileSource(
137 const char* filename,
138 const char* location,
139 CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault);
140 // Add dex file source(s) from a zip file specified by a file handle.
141 bool AddZippedDexFilesSource(
Andreas Gampe43e10b02016-07-15 17:17:34 -0700142 File&& zip_fd,
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000143 const char* location,
144 CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault);
145 // Add dex file source from raw memory.
146 bool AddRawDexFileSource(
147 const ArrayRef<const uint8_t>& data,
148 const char* location,
149 uint32_t location_checksum,
150 CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault);
Nicolas Geoffrayb0bbe8e2016-11-19 10:42:37 +0000151 // Add dex file source(s) from a vdex file.
152 bool AddVdexDexFilesSource(
153 const VdexFile& vdex_file,
154 const char* location,
155 CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault);
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000156 dchecked_vector<const char*> GetSourceLocations() const;
157
David Brazdil7b49e6c2016-09-01 11:06:18 +0100158 // Write raw dex files to the vdex file, mmap the file and open the dex files from it.
159 // Supporting data structures are written into the .rodata section of the oat file.
160 // The `verify` setting dictates whether the dex file verifier should check the dex files.
161 // This is generally the case, and should only be false for tests.
Nicolas Geoffray81f57d12016-12-20 13:17:09 +0000162 // If `update_input_vdex` is true, then this method won't actually write the dex files,
163 // and the compiler will just re-use the existing vdex file.
David Brazdil7b49e6c2016-09-01 11:06:18 +0100164 bool WriteAndOpenDexFiles(File* vdex_file,
165 OutputStream* oat_rodata,
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000166 InstructionSet instruction_set,
167 const InstructionSetFeatures* instruction_set_features,
168 SafeMap<std::string, std::string>* key_value_store,
Andreas Gampe3a2bd292016-01-26 17:23:47 -0800169 bool verify,
Nicolas Geoffray81f57d12016-12-20 13:17:09 +0000170 bool update_input_vdex,
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000171 /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map,
172 /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100173 bool WriteQuickeningInfo(OutputStream* vdex_out);
David Brazdil5d5a36b2016-09-14 15:34:10 +0100174 bool WriteVerifierDeps(OutputStream* vdex_out, verifier::VerifierDeps* verifier_deps);
Nicolas Geoffrayf54e5df2016-12-01 10:45:08 +0000175 bool WriteChecksumsAndVdexHeader(OutputStream* vdex_out);
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100176 // Initialize the writer with the given parameters.
177 void Initialize(const CompilerDriver* compiler,
178 ImageWriter* image_writer,
179 const std::vector<const DexFile*>& dex_files) {
180 compiler_driver_ = compiler;
181 image_writer_ = image_writer;
182 dex_files_ = &dex_files;
183 }
David Brazdil5d5a36b2016-09-14 15:34:10 +0100184
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000185 // Prepare layout of remaining data.
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100186 void PrepareLayout(linker::MultiOatRelativePatcher* relative_patcher);
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000187 // Write the rest of .rodata section (ClassOffsets[], OatClass[], maps).
188 bool WriteRodata(OutputStream* out);
189 // Write the code to the .text section.
190 bool WriteCode(OutputStream* out);
191 // Write the oat header. This finalizes the oat file.
192 bool WriteHeader(OutputStream* out,
193 uint32_t image_file_location_oat_checksum,
194 uintptr_t image_file_location_oat_begin,
195 int32_t image_patch_delta);
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700196
Vladimir Marko09d09432015-09-08 13:47:48 +0100197 // Returns whether the oat file has an associated image.
198 bool HasImage() const {
199 // Since the image is being created at the same time as the oat file,
200 // check if there's an image writer.
201 return image_writer_ != nullptr;
202 }
203
Mathieu Chartierda5b28a2015-11-05 08:03:47 -0800204 bool HasBootImage() const {
205 return compiling_boot_image_;
206 }
207
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700208 const OatHeader& GetOatHeader() const {
209 return *oat_header_;
210 }
211
David Brazdil7b49e6c2016-09-01 11:06:18 +0100212 size_t GetOatSize() const {
213 return oat_size_;
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700214 }
215
Vladimir Marko5c42c292015-02-25 12:02:49 +0000216 size_t GetBssSize() const {
217 return bss_size_;
218 }
219
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100220 size_t GetBssMethodsOffset() const {
221 return bss_methods_offset_;
222 }
223
Vladimir Markoaad75c62016-10-03 08:46:48 +0000224 size_t GetBssRootsOffset() const {
225 return bss_roots_offset_;
226 }
227
Vladimir Marko944da602016-02-19 12:27:55 +0000228 size_t GetOatDataOffset() const {
229 return oat_data_offset_;
230 }
231
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232 ~OatWriter();
233
David Srbecky09c2a6b2016-03-11 17:11:44 +0000234 void AddMethodDebugInfos(const std::vector<debug::MethodDebugInfo>& infos) {
235 method_info_.insert(method_info_.end(), infos.begin(), infos.end());
236 }
237
David Srbeckyc5bfa972016-02-05 15:49:10 +0000238 ArrayRef<const debug::MethodDebugInfo> GetMethodDebugInfo() const {
239 return ArrayRef<const debug::MethodDebugInfo>(method_info_);
Mark Mendellae9fd932014-02-10 16:14:35 -0800240 }
241
Vladimir Markob163bb72015-03-31 21:49:49 +0100242 const CompilerDriver* GetCompilerDriver() {
243 return compiler_driver_;
244 }
245
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700246 private:
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000247 class DexFileSource;
Vladimir Marko49b0f452015-12-10 13:49:19 +0000248 class OatClass;
249 class OatDexFile;
250
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100251 // The function VisitDexMethods() below iterates through all the methods in all
252 // the compiled dex files in order of their definitions. The method visitor
253 // classes provide individual bits of processing for each of the passes we need to
254 // first collect the data we want to write to the oat file and then, in later passes,
255 // to actually write it.
256 class DexMethodVisitor;
257 class OatDexMethodVisitor;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100258 class InitBssLayoutMethodVisitor;
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100259 class InitOatClassesMethodVisitor;
260 class InitCodeMethodVisitor;
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100261 class InitMapMethodVisitor;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700262 class InitMethodInfoVisitor;
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100263 class InitImageMethodVisitor;
264 class WriteCodeMethodVisitor;
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100265 class WriteMapMethodVisitor;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700266 class WriteMethodInfoVisitor;
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100267 class WriteQuickeningInfoMethodVisitor;
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100268
269 // Visit all the methods in all the compiled dex files in their definition order
270 // with a given DexMethodVisitor.
271 bool VisitDexMethods(DexMethodVisitor* visitor);
272
Nicolas Geoffray81f57d12016-12-20 13:17:09 +0000273 // If `update_input_vdex` is true, then this method won't actually write the dex files,
274 // and the compiler will just re-use the existing vdex file.
275 bool WriteDexFiles(OutputStream* out, File* file, bool update_input_vdex);
276 bool WriteDexFile(OutputStream* out,
277 File* file,
278 OatDexFile* oat_dex_file,
279 bool update_input_vdex);
David Brazdil7b49e6c2016-09-01 11:06:18 +0100280 bool SeekToDexFile(OutputStream* out, File* file, OatDexFile* oat_dex_file);
Jeff Hao608f2ce2016-10-19 11:17:11 -0700281 bool LayoutAndWriteDexFile(OutputStream* out, OatDexFile* oat_dex_file);
David Brazdil7b49e6c2016-09-01 11:06:18 +0100282 bool WriteDexFile(OutputStream* out,
283 File* file,
284 OatDexFile* oat_dex_file,
285 ZipEntry* dex_file);
286 bool WriteDexFile(OutputStream* out,
287 File* file,
288 OatDexFile* oat_dex_file,
289 File* dex_file);
Nicolas Geoffray81f57d12016-12-20 13:17:09 +0000290 bool WriteDexFile(OutputStream* out,
291 OatDexFile* oat_dex_file,
292 const uint8_t* dex_file,
293 bool update_input_vdex);
David Brazdil7b49e6c2016-09-01 11:06:18 +0100294 bool OpenDexFiles(File* file,
295 bool verify,
296 /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map,
297 /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
298
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000299 size_t InitOatHeader(InstructionSet instruction_set,
300 const InstructionSetFeatures* instruction_set_features,
301 uint32_t num_dex_files,
302 SafeMap<std::string, std::string>* key_value_store);
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100303 size_t InitClassOffsets(size_t offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700304 size_t InitOatClasses(size_t offset);
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100305 size_t InitOatMaps(size_t offset);
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100306 size_t InitMethodBssMappings(size_t offset);
307 size_t InitOatDexFiles(size_t offset);
Vladimir Marko49b0f452015-12-10 13:49:19 +0000308 size_t InitOatCode(size_t offset);
309 size_t InitOatCodeDexFiles(size_t offset);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000310 void InitBssLayout(InstructionSet instruction_set);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700311
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100312 size_t WriteClassOffsets(OutputStream* out, size_t file_offset, size_t relative_offset);
313 size_t WriteClasses(OutputStream* out, size_t file_offset, size_t relative_offset);
314 size_t WriteMaps(OutputStream* out, size_t file_offset, size_t relative_offset);
315 size_t WriteMethodBssMappings(OutputStream* out, size_t file_offset, size_t relative_offset);
316 size_t WriteOatDexFiles(OutputStream* out, size_t file_offset, size_t relative_offset);
317 size_t WriteCode(OutputStream* out, size_t file_offset, size_t relative_offset);
318 size_t WriteCodeDexFiles(OutputStream* out, size_t file_offset, size_t relative_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700319
Vladimir Marko944da602016-02-19 12:27:55 +0000320 bool RecordOatDataOffset(OutputStream* out);
David Brazdil7b49e6c2016-09-01 11:06:18 +0100321 bool ReadDexFileHeader(File* oat_file, OatDexFile* oat_dex_file);
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000322 bool ValidateDexFileHeader(const uint8_t* raw_header, const char* location);
David Brazdil7b49e6c2016-09-01 11:06:18 +0100323 bool WriteTypeLookupTables(OutputStream* oat_rodata,
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000324 const std::vector<std::unique_ptr<const DexFile>>& opened_dex_files);
Vladimir Markof4da6752014-08-01 19:04:18 +0100325 bool WriteCodeAlignment(OutputStream* out, uint32_t aligned_code_delta);
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100326 bool WriteUpTo16BytesAlignment(OutputStream* out, uint32_t size, uint32_t* stat);
Vladimir Marko944da602016-02-19 12:27:55 +0000327 void SetMultiOatRelativePatcherAdjustment();
Nicolas Geoffray81f57d12016-12-20 13:17:09 +0000328 void CloseSources();
Vladimir Markof4da6752014-08-01 19:04:18 +0100329
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000330 enum class WriteState {
331 kAddingDexFileSources,
332 kPrepareLayout,
333 kWriteRoData,
334 kWriteText,
335 kWriteHeader,
336 kDone
337 };
338
339 WriteState write_state_;
340 TimingLogger* timings_;
341
342 std::vector<std::unique_ptr<File>> raw_dex_files_;
343 std::vector<std::unique_ptr<ZipArchive>> zip_archives_;
344 std::vector<std::unique_ptr<ZipEntry>> zipped_dex_files_;
345
346 // Using std::list<> which doesn't move elements around on push/emplace_back().
347 // We need this because we keep plain pointers to the strings' c_str().
348 std::list<std::string> zipped_dex_file_locations_;
349
David Srbeckyc5bfa972016-02-05 15:49:10 +0000350 dchecked_vector<debug::MethodDebugInfo> method_info_;
Mark Mendellae9fd932014-02-10 16:14:35 -0800351
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000352 const CompilerDriver* compiler_driver_;
353 ImageWriter* image_writer_;
Mathieu Chartierda5b28a2015-11-05 08:03:47 -0800354 const bool compiling_boot_image_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700355
356 // note OatFile does not take ownership of the DexFiles
357 const std::vector<const DexFile*>* dex_files_;
358
David Brazdil7b49e6c2016-09-01 11:06:18 +0100359 // Size required for Vdex data structures.
360 size_t vdex_size_;
361
362 // Offset of section holding Dex files inside Vdex.
363 size_t vdex_dex_files_offset_;
364
David Brazdil5d5a36b2016-09-14 15:34:10 +0100365 // Offset of section holding VerifierDeps inside Vdex.
366 size_t vdex_verifier_deps_offset_;
367
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100368 // Offset of section holding quickening info inside Vdex.
369 size_t vdex_quickening_info_offset_;
370
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700371 // Size required for Oat data structures.
David Brazdil7b49e6c2016-09-01 11:06:18 +0100372 size_t oat_size_;
Brian Carlstromc50d8e12013-07-23 22:35:16 -0700373
Vladimir Markoaad75c62016-10-03 08:46:48 +0000374 // The start of the required .bss section.
375 size_t bss_start_;
376
377 // The size of the required .bss section holding the DexCache data and GC roots.
Vladimir Marko5c42c292015-02-25 12:02:49 +0000378 size_t bss_size_;
379
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100380 // The offset of the methods in .bss section.
381 size_t bss_methods_offset_;
382
Vladimir Markoaad75c62016-10-03 08:46:48 +0000383 // The offset of the GC roots in .bss section.
384 size_t bss_roots_offset_;
385
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100386 // Map for recording references to ArtMethod entries in .bss.
387 SafeMap<const DexFile*, BitVector> bss_method_entry_references_;
388
389 // Map for allocating ArtMethod entries in .bss. Indexed by MethodReference for the target
390 // method in the dex file with the "method reference value comparator" for deduplication.
391 // The value is the target offset for patching, starting at `bss_start_ + bss_methods_offset_`.
392 SafeMap<MethodReference, size_t, MethodReferenceValueComparator> bss_method_entries_;
393
Vladimir Marko6bec91c2017-01-09 15:03:12 +0000394 // Map for allocating Class entries in .bss. Indexed by TypeReference for the source
395 // type in the dex file with the "type value comparator" for deduplication. The value
396 // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
397 SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_type_entries_;
398
Vladimir Markoaad75c62016-10-03 08:46:48 +0000399 // Map for allocating String entries in .bss. Indexed by StringReference for the source
400 // string in the dex file with the "string value comparator" for deduplication. The value
401 // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
402 SafeMap<StringReference, size_t, StringReferenceValueComparator> bss_string_entries_;
403
Vladimir Markof4da6752014-08-01 19:04:18 +0100404 // Offset of the oat data from the start of the mmapped region of the elf file.
405 size_t oat_data_offset_;
406
Mathieu Chartier1b868492016-11-16 16:22:37 -0800407 // Fake OatDexFiles to hold type lookup tables for the compiler.
408 std::vector<std::unique_ptr<art::OatDexFile>> type_lookup_table_oat_dex_files_;
409
Brian Carlstrom7940e442013-07-12 13:46:57 -0700410 // data to write
Vladimir Marko49b0f452015-12-10 13:49:19 +0000411 std::unique_ptr<OatHeader> oat_header_;
412 dchecked_vector<OatDexFile> oat_dex_files_;
413 dchecked_vector<OatClass> oat_classes_;
Ian Rogers700a4022014-05-19 16:49:03 -0700414 std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_;
Ian Rogers700a4022014-05-19 16:49:03 -0700415 std::unique_ptr<const std::vector<uint8_t>> quick_generic_jni_trampoline_;
416 std::unique_ptr<const std::vector<uint8_t>> quick_imt_conflict_trampoline_;
417 std::unique_ptr<const std::vector<uint8_t>> quick_resolution_trampoline_;
418 std::unique_ptr<const std::vector<uint8_t>> quick_to_interpreter_bridge_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700419
420 // output stats
David Brazdil7b49e6c2016-09-01 11:06:18 +0100421 uint32_t size_vdex_header_;
Nicolas Geoffrayf54e5df2016-12-01 10:45:08 +0000422 uint32_t size_vdex_checksums_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700423 uint32_t size_dex_file_alignment_;
424 uint32_t size_executable_offset_alignment_;
425 uint32_t size_oat_header_;
Andreas Gampe22f8e5c2014-07-09 11:38:21 -0700426 uint32_t size_oat_header_key_value_store_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700427 uint32_t size_dex_file_;
David Brazdil5d5a36b2016-09-14 15:34:10 +0100428 uint32_t size_verifier_deps_;
429 uint32_t size_verifier_deps_alignment_;
Nicolas Geoffray4acefd32016-10-24 13:14:58 +0100430 uint32_t size_quickening_info_;
431 uint32_t size_quickening_info_alignment_;
Ian Rogers468532e2013-08-05 10:56:33 -0700432 uint32_t size_interpreter_to_interpreter_bridge_;
433 uint32_t size_interpreter_to_compiled_code_bridge_;
434 uint32_t size_jni_dlsym_lookup_;
Andreas Gampe2da88232014-02-27 12:26:20 -0800435 uint32_t size_quick_generic_jni_trampoline_;
Jeff Hao88474b42013-10-23 16:24:40 -0700436 uint32_t size_quick_imt_conflict_trampoline_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700437 uint32_t size_quick_resolution_trampoline_;
Ian Rogers468532e2013-08-05 10:56:33 -0700438 uint32_t size_quick_to_interpreter_bridge_;
439 uint32_t size_trampoline_alignment_;
Vladimir Marko96c6ab92014-04-08 14:00:50 +0100440 uint32_t size_method_header_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700441 uint32_t size_code_;
442 uint32_t size_code_alignment_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100443 uint32_t size_relative_call_thunks_;
Vladimir Markoc74658b2015-03-31 10:26:41 +0100444 uint32_t size_misc_thunks_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700445 uint32_t size_vmap_table_;
Mathieu Chartiercbcedbf2017-03-12 22:24:50 -0700446 uint32_t size_method_info_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700447 uint32_t size_oat_dex_file_location_size_;
448 uint32_t size_oat_dex_file_location_data_;
449 uint32_t size_oat_dex_file_location_checksum_;
450 uint32_t size_oat_dex_file_offset_;
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000451 uint32_t size_oat_dex_file_class_offsets_offset_;
Vladimir Marko49b0f452015-12-10 13:49:19 +0000452 uint32_t size_oat_dex_file_lookup_table_offset_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100453 uint32_t size_oat_dex_file_method_bss_mapping_offset_;
Vladimir Marko49b0f452015-12-10 13:49:19 +0000454 uint32_t size_oat_lookup_table_alignment_;
455 uint32_t size_oat_lookup_table_;
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000456 uint32_t size_oat_class_offsets_alignment_;
457 uint32_t size_oat_class_offsets_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700458 uint32_t size_oat_class_type_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700459 uint32_t size_oat_class_status_;
Brian Carlstromba150c32013-08-27 17:31:03 -0700460 uint32_t size_oat_class_method_bitmaps_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700461 uint32_t size_oat_class_method_offsets_;
Vladimir Marko0eb882b2017-05-15 13:39:18 +0100462 uint32_t size_method_bss_mappings_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700463
Vladimir Marko944da602016-02-19 12:27:55 +0000464 // The helper for processing relative patches is external so that we can patch across oat files.
465 linker::MultiOatRelativePatcher* relative_patcher_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100466
David Srbeckyf8980872015-05-22 17:04:47 +0100467 // The locations of absolute patches relative to the start of the executable section.
Vladimir Marko9bdf1082016-01-21 12:15:52 +0000468 dchecked_vector<uintptr_t> absolute_patch_locations_;
Vladimir Markof4da6752014-08-01 19:04:18 +0100469
Jeff Hao608f2ce2016-10-19 11:17:11 -0700470 // Profile info used to generate new layout of files.
471 ProfileCompilationInfo* profile_compilation_info_;
472
Brian Carlstrom7940e442013-07-12 13:46:57 -0700473 DISALLOW_COPY_AND_ASSIGN(OatWriter);
474};
475
476} // namespace art
477
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700478#endif // ART_COMPILER_OAT_WRITER_H_