• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #ifndef ART_DEX2OAT_LINKER_OAT_WRITER_H_
18 #define ART_DEX2OAT_LINKER_OAT_WRITER_H_
19 
20 #include <stdint.h>
21 #include <cstddef>
22 #include <list>
23 #include <memory>
24 #include <vector>
25 
26 #include "base/array_ref.h"
27 #include "base/dchecked_vector.h"
28 #include "base/os.h"
29 #include "base/mem_map.h"
30 #include "base/safe_map.h"
31 #include "debug/debug_info.h"
32 #include "dex/method_reference.h"
33 #include "dex/string_reference.h"
34 #include "dex/proto_reference.h"
35 #include "dex/type_reference.h"
36 #include "linker/relative_patcher.h"  // For RelativePatcherTargetProvider.
37 #include "mirror/class.h"
38 
39 namespace art {
40 
41 class BitVector;
42 class CompiledMethod;
43 class CompilerDriver;
44 class CompilerOptions;
45 class OatHeader;
46 class OutputStream;
47 class ProfileCompilationInfo;
48 class TimingLogger;
49 class TypeLookupTable;
50 class VdexFile;
51 class VerificationResults;
52 class ZipEntry;
53 
54 namespace debug {
55 struct MethodDebugInfo;
56 }  // namespace debug
57 
58 namespace verifier {
59 class VerifierDeps;
60 }  // namespace verifier
61 
62 namespace linker {
63 
64 class ImageWriter;
65 class MultiOatRelativePatcher;
66 
67 enum class CopyOption {
68   kNever,
69   kAlways,
70   kOnlyIfCompressed
71 };
72 
73 class OatKeyValueStore {
74  public:
75   // Puts a key value pair whose key is in `OatHeader::kNonDeterministicFieldsAndLengths`.
76   bool PutNonDeterministic(const std::string& k,
77                            const std::string& v,
78                            bool allow_truncation = false);
79 
80   // Puts a key value pair whose key is in `OatHeader::kDeterministicFields`.
81   void Put(const std::string& k, const std::string& v);
82 
83   // Puts a key value pair whose key is in `OatHeader::kDeterministicFields`.
84   void Put(const std::string& k, bool v);
85 
86   // Makes sure calls with `const char*` falls into the overload for `std::string`, not the one for
87   // `bool`.
Put(const std::string & k,const char * v)88   void Put(const std::string& k, const char* v) { Put(k, std::string(v)); }
89 
90  private:
91   SafeMap<std::string, std::string> map_;
92 
93   friend class OatWriter;
94 };
95 
96 // OatHeader         variable length with count of D OatDexFiles
97 //
98 // TypeLookupTable[0] one descriptor to class def index hash table for each OatDexFile.
99 // TypeLookupTable[1]
100 // ...
101 // TypeLookupTable[D]
102 //
103 // ClassOffsets[0]   one table of OatClass offsets for each class def for each OatDexFile.
104 // ClassOffsets[1]
105 // ...
106 // ClassOffsets[D]
107 //
108 // OatClass[0]       one variable sized OatClass for each of C DexFile::ClassDefs
109 // OatClass[1]       contains OatClass entries with class status, offsets to code, etc.
110 // ...
111 // OatClass[C]
112 //
113 // MethodBssMapping  one variable sized MethodBssMapping for each dex file, optional.
114 // MethodBssMapping
115 // ...
116 // MethodBssMapping
117 //
118 // VmapTable         one variable sized VmapTable blob (CodeInfo).
119 // VmapTable         VmapTables are deduplicated.
120 // ...
121 // VmapTable
122 //
123 // OatDexFile[0]     one variable sized OatDexFile with offsets to Dex and OatClasses
124 // OatDexFile[1]
125 // ...
126 // OatDexFile[D]
127 //
128 // padding           if necessary so that the following code will be page aligned
129 //
130 // OatMethodHeader   fixed size header for a CompiledMethod including the size of the MethodCode.
131 // MethodCode        one variable sized blob with the code of a CompiledMethod.
132 // OatMethodHeader   (OatMethodHeader, MethodCode) pairs are deduplicated.
133 // MethodCode
134 // ...
135 // OatMethodHeader
136 // MethodCode
137 //
138 class OatWriter {
139  public:
140   OatWriter(const CompilerOptions& compiler_options,
141             TimingLogger* timings,
142             ProfileCompilationInfo* info);
143 
144   // To produce a valid oat file, the user must first add sources with any combination of
145   //   - AddDexFileSource(),
146   //   - AddRawDexFileSource(),
147   //   - AddVdexDexFilesSource().
148   // Then the user must call in order
149   //   - WriteAndOpenDexFiles()
150   //   - StartRoData()
151   //   - FinishVdexFile()
152   //   - PrepareLayout(),
153   //   - WriteRodata(),
154   //   - WriteCode(),
155   //   - WriteDataImgRelRo() iff GetDataImgRelRoSize() != 0,
156   //   - WriteHeader().
157 
158   // Add dex file source(s) from a file, either a plain dex file or
159   // a zip file with one or more dex files.
160   bool AddDexFileSource(
161       const char* filename,
162       const char* location);
163   // Add dex file source(s) from a file specified by a file handle.
164   // Note: The `dex_file_fd` specifies a plain dex file or a zip file.
165   bool AddDexFileSource(
166       File&& dex_file_fd,
167       const char* location);
168   // Add dex file source from raw memory.
169   bool AddRawDexFileSource(const std::shared_ptr<DexFileContainer>& container,
170                            const uint8_t* dex_file_begin,
171                            const char* location,
172                            uint32_t location_checksum);
173   // Add dex file source(s) from a vdex file.
174   bool AddVdexDexFilesSource(
175       const VdexFile& vdex_file,
176       const char* location);
177   dchecked_vector<std::string> GetSourceLocations() const;
178 
179   // Write raw dex files to the vdex file, mmap the file and open the dex files from it.
180   // The `verify` setting dictates whether the dex file verifier should check the dex files.
181   // This is generally the case, and should only be false for tests.
182   // If `use_existing_vdex` is true, then this method won't actually write the dex files,
183   // and the compiler will just re-use the existing vdex file.
184   bool WriteAndOpenDexFiles(File* vdex_file,
185                             bool verify,
186                             bool use_existing_vdex,
187                             CopyOption copy_dex_files,
188                             /*out*/ std::vector<MemMap>* opened_dex_files_map,
189                             /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
190   // Start writing .rodata, including supporting data structures for dex files.
191   bool StartRoData(const std::vector<const DexFile*>& dex_files,
192                    OutputStream* oat_rodata,
193                    OatKeyValueStore* key_value_store);
194   // Initialize the writer with the given parameters.
195   void Initialize(const CompilerDriver* compiler_driver,
196                   const VerificationResults* verification_results,
197                   ImageWriter* image_writer,
198                   const std::vector<const DexFile*>& dex_files);
199   bool FinishVdexFile(File* vdex_file, verifier::VerifierDeps* verifier_deps);
200 
201   // Prepare layout of remaining data.
202   void PrepareLayout(MultiOatRelativePatcher* relative_patcher);
203   // Write the rest of .rodata section (ClassOffsets[], OatClass[], maps).
204   bool WriteRodata(OutputStream* out);
205   // Write the code to the .text section.
206   bool WriteCode(OutputStream* out);
207   // Write the image relocation data to the .data.img.rel.ro section.
208   bool WriteDataImgRelRo(OutputStream* out);
209   // Check the size of the written oat file.
210   bool CheckOatSize(OutputStream* out, size_t file_offset, size_t relative_offset);
211   // Write the oat header. This finalizes the oat file.
212   bool WriteHeader(OutputStream* out);
213 
214   // Returns whether the oat file has an associated image.
HasImage()215   bool HasImage() const {
216     // Since the image is being created at the same time as the oat file,
217     // check if there's an image writer.
218     return image_writer_ != nullptr;
219   }
220 
GetOatHeader()221   const OatHeader& GetOatHeader() const {
222     return *oat_header_;
223   }
224 
GetCodeSize()225   size_t GetCodeSize() const {
226     return code_size_;
227   }
228 
GetOatSize()229   size_t GetOatSize() const {
230     return oat_size_;
231   }
232 
GetDataImgRelRoSize()233   size_t GetDataImgRelRoSize() const {
234     return data_img_rel_ro_size_;
235   }
236 
GetDataImgRelRoAppImageOffset()237   size_t GetDataImgRelRoAppImageOffset() const {
238     return data_img_rel_ro_app_image_offset_;
239   }
240 
GetBssSize()241   size_t GetBssSize() const {
242     return bss_size_;
243   }
244 
GetBssMethodsOffset()245   size_t GetBssMethodsOffset() const {
246     return bss_methods_offset_;
247   }
248 
GetBssRootsOffset()249   size_t GetBssRootsOffset() const {
250     return bss_roots_offset_;
251   }
252 
GetVdexSize()253   size_t GetVdexSize() const {
254     return vdex_size_;
255   }
256 
GetOatDataOffset()257   size_t GetOatDataOffset() const {
258     return oat_data_offset_;
259   }
260 
261   ~OatWriter();
262 
263   debug::DebugInfo GetDebugInfo() const;
264 
GetCompilerDriver()265   const CompilerDriver* GetCompilerDriver() const {
266     return compiler_driver_;
267   }
268 
GetCompilerOptions()269   const CompilerOptions& GetCompilerOptions() const {
270     return compiler_options_;
271   }
272 
273  private:
274   struct BssMappingInfo;
275   class ChecksumUpdatingOutputStream;
276   class OatClassHeader;
277   class OatClass;
278   class OatDexFile;
279 
280   // The function VisitDexMethods() below iterates through all the methods in all
281   // the compiled dex files in order of their definitions. The method visitor
282   // classes provide individual bits of processing for each of the passes we need to
283   // first collect the data we want to write to the oat file and then, in later passes,
284   // to actually write it.
285   class DexMethodVisitor;
286   class OatDexMethodVisitor;
287   class InitOatClassesMethodVisitor;
288   class LayoutCodeMethodVisitor;
289   class LayoutReserveOffsetCodeMethodVisitor;
290   struct OrderedMethodData;
291   class OrderedMethodVisitor;
292   class InitCodeMethodVisitor;
293   template <bool kDeduplicate> class InitMapMethodVisitor;
294   class InitImageMethodVisitor;
295   class WriteCodeMethodVisitor;
296   class WriteMapMethodVisitor;
297 
298   // Visit all the methods in all the compiled dex files in their definition order
299   // with a given DexMethodVisitor.
300   bool VisitDexMethods(DexMethodVisitor* visitor);
301 
302   // If `update_input_vdex` is true, then this method won't actually write the dex files,
303   // and the compiler will just re-use the existing vdex file.
304   bool WriteDexFiles(File* file,
305                      bool verify,
306                      bool use_existing_vdex,
307                      CopyOption copy_dex_files,
308                      /*out*/ std::vector<MemMap>* opened_dex_files_map);
309   bool LayoutDexFile(OatDexFile* oat_dex_file);
310   bool OpenDexFiles(File* file,
311                     /*inout*/ std::vector<MemMap>* opened_dex_files_map,
312                     /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files);
313   void WriteTypeLookupTables(/*out*/std::vector<uint8_t>* buffer);
314   void WriteVerifierDeps(verifier::VerifierDeps* verifier_deps,
315                          /*out*/std::vector<uint8_t>* buffer);
316 
317   size_t InitOatHeader(uint32_t num_dex_files, OatKeyValueStore* key_value_store);
318   size_t InitClassOffsets(size_t offset);
319   size_t InitOatClasses(size_t offset);
320   size_t InitOatMaps(size_t offset);
321   size_t InitIndexBssMappings(size_t offset);
322   size_t InitOatDexFiles(size_t offset);
323   size_t InitBcpBssInfo(size_t offset);
324   size_t InitOatCode(size_t offset);
325   size_t InitOatCodeDexFiles(size_t offset);
326   size_t InitDataImgRelRoLayout(size_t offset);
327   void InitBssAndRelRoData();
328   void InitBssLayout(InstructionSet instruction_set);
329   void AddBssReference(const DexFileReference& ref,
330                        size_t number_of_indexes,
331                        /*inout*/ SafeMap<const DexFile*, BitVector>* references);
332 
333   size_t WriteClassOffsets(OutputStream* out, size_t file_offset, size_t relative_offset);
334   size_t WriteClasses(OutputStream* out, size_t file_offset, size_t relative_offset);
335   size_t WriteMaps(OutputStream* out, size_t file_offset, size_t relative_offset);
336   size_t WriteIndexBssMappings(OutputStream* out, size_t file_offset, size_t relative_offset);
337   size_t WriteOatDexFiles(OutputStream* out, size_t file_offset, size_t relative_offset);
338   size_t WriteBcpBssInfo(OutputStream* out, size_t file_offset, size_t relative_offset);
339   size_t WriteCode(OutputStream* out, size_t file_offset, size_t relative_offset);
340   size_t WriteCodeDexFiles(OutputStream* out, size_t file_offset, size_t relative_offset);
341   size_t WriteDataImgRelRo(OutputStream* out, size_t file_offset, size_t relative_offset);
342   // These helpers extract common code from BCP and non-BCP DexFiles from its corresponding methods.
343   size_t WriteIndexBssMappingsHelper(OutputStream* out,
344                                      size_t file_offset,
345                                      size_t relative_offset,
346                                      const DexFile* dex_file,
347                                      uint32_t method_bss_mapping_offset,
348                                      uint32_t type_bss_mapping_offset,
349                                      uint32_t public_type_bss_mapping_offset,
350                                      uint32_t package_type_bss_mapping_offset,
351                                      uint32_t string_bss_mapping_offset,
352                                      uint32_t method_type_bss_mapping_offset);
353   size_t InitIndexBssMappingsHelper(size_t offset,
354                                     const DexFile* dex_file,
355                                     /*inout*/ size_t& number_of_method_dex_files,
356                                     /*inout*/ size_t& number_of_type_dex_files,
357                                     /*inout*/ size_t& number_of_public_type_dex_files,
358                                     /*inout*/ size_t& number_of_package_type_dex_files,
359                                     /*inout*/ size_t& number_of_string_dex_files,
360                                     /*inout*/ size_t& number_of_method_type_dex_files,
361                                     /*inout*/ uint32_t& method_bss_mapping_offset,
362                                     /*inout*/ uint32_t& type_bss_mapping_offset,
363                                     /*inout*/ uint32_t& public_type_bss_mapping_offset,
364                                     /*inout*/ uint32_t& package_type_bss_mapping_offset,
365                                     /*inout*/ uint32_t& string_bss_mapping_offset,
366                                     /*inout*/ uint32_t& method_type_bss_mapping_offset);
367 
368   bool RecordOatDataOffset(OutputStream* out);
369   void InitializeTypeLookupTables(
370       const std::vector<std::unique_ptr<const DexFile>>& opened_dex_files);
371   bool WriteDexLayoutSections(OutputStream* oat_rodata,
372                               const std::vector<const DexFile*>& opened_dex_files);
373   bool WriteCodeAlignment(OutputStream* out, uint32_t aligned_code_delta);
374   bool WriteUpTo16BytesAlignment(OutputStream* out, uint32_t size, uint32_t* stat);
375   void SetMultiOatRelativePatcherAdjustment();
376   void CloseSources();
377 
378   bool MayHaveCompiledMethods() const;
379 
VdexWillContainDexFiles()380   bool VdexWillContainDexFiles() const {
381     return dex_files_ != nullptr && extract_dex_files_into_vdex_;
382   }
383 
384   // Return the file offset that corresponds to `offset_from_oat_data`.
GetFileOffset(size_t offset_from_oat_data)385   size_t GetFileOffset(size_t offset_from_oat_data) const {
386     DCHECK_NE(oat_data_offset_, 0u);
387     return offset_from_oat_data + oat_data_offset_;
388   }
389 
390   // Return the next offset (relative to the oat data) that is on or after `offset_from_oat_data`,
391   // that is aligned by `alignment` to the beginning of the file.
GetOffsetFromOatDataAlignedToFile(size_t offset_from_oat_data,size_t alignment)392   size_t GetOffsetFromOatDataAlignedToFile(size_t offset_from_oat_data, size_t alignment) const {
393     return RoundUp(GetFileOffset(offset_from_oat_data), alignment) - oat_data_offset_;
394   }
395 
396   enum class WriteState {
397     kAddingDexFileSources,
398     kStartRoData,
399     kInitialize,
400     kPrepareLayout,
401     kWriteRoData,
402     kWriteText,
403     kWriteDataImgRelRo,
404     kWriteHeader,
405     kDone
406   };
407 
408   WriteState write_state_;
409   TimingLogger* timings_;
410 
411   dchecked_vector<debug::MethodDebugInfo> method_info_;
412 
413   std::vector<uint8_t> code_info_data_;
414 
415   const CompilerDriver* compiler_driver_;
416   const CompilerOptions& compiler_options_;
417   const VerificationResults* verification_results_;
418   ImageWriter* image_writer_;
419   // Whether the dex files being compiled are going to be extracted to the vdex.
420   bool extract_dex_files_into_vdex_;
421   // The start of the vdex file section mmapped for writing dex files.
422   uint8_t* vdex_begin_;
423 
424   // note OatFile does not take ownership of the DexFiles
425   const std::vector<const DexFile*>* dex_files_;
426 
427   // Whether this is the primary oat file.
428   bool primary_oat_file_;
429 
430   // Size required for Vdex data structures.
431   size_t vdex_size_;
432 
433   // Offset of section holding Dex files inside Vdex.
434   size_t vdex_dex_files_offset_;
435 
436   // Offset of section holding VerifierDeps inside Vdex.
437   size_t vdex_verifier_deps_offset_;
438 
439   // Offset of type lookup tables inside Vdex.
440   size_t vdex_lookup_tables_offset_;
441 
442   // OAT checksum.
443   uint32_t oat_checksum_;
444 
445   // Size of the .text segment.
446   size_t code_size_;
447 
448   // Size required for Oat data structures.
449   size_t oat_size_;
450 
451   // The start of the optional .data.img.rel.ro section.
452   size_t data_img_rel_ro_start_;
453 
454   // The size of the optional .data.img.rel.ro section holding the image relocations.
455   size_t data_img_rel_ro_size_;
456 
457   // The start of app image relocations in the .data.img.rel.ro section.
458   size_t data_img_rel_ro_app_image_offset_;
459 
460   // The start of the optional .bss section.
461   size_t bss_start_;
462 
463   // The size of the optional .bss section holding the DexCache data and GC roots.
464   size_t bss_size_;
465 
466   // The offset of the methods in .bss section.
467   size_t bss_methods_offset_;
468 
469   // The offset of the GC roots in .bss section.
470   size_t bss_roots_offset_;
471 
472   // OatFile's information regarding the bss metadata for BCP DexFiles. Empty for boot image
473   // compiles.
474   std::vector<BssMappingInfo> bcp_bss_info_;
475 
476   // Map for allocating boot image .data.img.rel.ro entries. Indexed by the boot image offset
477   // of the relocation. The value is the assigned offset within the .data.img.rel.ro section.
478   SafeMap<uint32_t, size_t> boot_image_rel_ro_entries_;
479 
480   // Map for recording references to ArtMethod entries in .bss.
481   SafeMap<const DexFile*, BitVector> bss_method_entry_references_;
482 
483   // Map for recording references to GcRoot<mirror::Class> entries in .bss.
484   SafeMap<const DexFile*, BitVector> bss_type_entry_references_;
485 
486   // Map for recording references to public GcRoot<mirror::Class> entries in .bss.
487   SafeMap<const DexFile*, BitVector> bss_public_type_entry_references_;
488 
489   // Map for recording references to package GcRoot<mirror::Class> entries in .bss.
490   SafeMap<const DexFile*, BitVector> bss_package_type_entry_references_;
491 
492   // Map for recording references to GcRoot<mirror::String> entries in .bss.
493   SafeMap<const DexFile*, BitVector> bss_string_entry_references_;
494 
495   // Map for recording references to GcRoot<mirror::MethodType> entries in .bss.
496   SafeMap<const DexFile*, BitVector> bss_method_type_entry_references_;
497 
498   // Map for allocating app image ArtMethod entries in .data.img.rel.ro. Indexed by MethodReference
499   // for the target method in the dex file with the "method reference value comparator" for
500   // deduplication. The value is the target offset for patching, starting at
501   // `data_img_rel_ro_start_`.
502   SafeMap<MethodReference, size_t, MethodReferenceValueComparator> app_image_rel_ro_method_entries_;
503 
504   // Map for allocating ArtMethod entries in .bss. Indexed by MethodReference for the target
505   // method in the dex file with the "method reference value comparator" for deduplication.
506   // The value is the target offset for patching, starting at `bss_start_ + bss_methods_offset_`.
507   SafeMap<MethodReference, size_t, MethodReferenceValueComparator> bss_method_entries_;
508 
509   // Map for allocating app image Class entries in .data.img.rel.ro. Indexed by TypeReference for
510   // the source type in the dex file with the "type value comparator" for deduplication. The value
511   // is the target offset for patching, starting at `data_img_rel_ro_start_`.
512   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> app_image_rel_ro_type_entries_;
513 
514   // Map for allocating Class entries in .bss. Indexed by TypeReference for the source
515   // type in the dex file with the "type value comparator" for deduplication. The value
516   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
517   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_type_entries_;
518 
519   // Map for allocating public Class entries in .bss. Indexed by TypeReference for the source
520   // type in the dex file with the "type value comparator" for deduplication. The value
521   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
522   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_public_type_entries_;
523 
524   // Map for allocating package Class entries in .bss. Indexed by TypeReference for the source
525   // type in the dex file with the "type value comparator" for deduplication. The value
526   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
527   SafeMap<TypeReference, size_t, TypeReferenceValueComparator> bss_package_type_entries_;
528 
529   // Map for allocating String entries in .bss. Indexed by StringReference for the source
530   // string in the dex file with the "string value comparator" for deduplication. The value
531   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
532   SafeMap<StringReference, size_t, StringReferenceValueComparator> bss_string_entries_;
533 
534   // Map for allocating MethodType entries in .bss. Indexed by ProtoReference for the source
535   // proto in the dex file with the "proto value comparator" for deduplication. The value
536   // is the target offset for patching, starting at `bss_start_ + bss_roots_offset_`.
537   SafeMap<ProtoReference, size_t, ProtoReferenceValueComparator> bss_method_type_entries_;
538 
539   // Offset of the oat data from the start of the mmapped region of the elf file.
540   size_t oat_data_offset_;
541 
542   // Fake OatDexFiles to hold type lookup tables for the compiler.
543   std::vector<std::unique_ptr<art::OatDexFile>> type_lookup_table_oat_dex_files_;
544 
545   // data to write
546   OatHeader* oat_header_;
547   dchecked_vector<OatDexFile> oat_dex_files_;
548   dchecked_vector<OatClassHeader> oat_class_headers_;
549   dchecked_vector<OatClass> oat_classes_;
550   std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_trampoline_;
551   std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_critical_trampoline_;
552   std::unique_ptr<const std::vector<uint8_t>> quick_generic_jni_trampoline_;
553   std::unique_ptr<const std::vector<uint8_t>> quick_imt_conflict_trampoline_;
554   std::unique_ptr<const std::vector<uint8_t>> quick_resolution_trampoline_;
555   std::unique_ptr<const std::vector<uint8_t>> quick_to_interpreter_bridge_;
556   std::unique_ptr<const std::vector<uint8_t>> nterp_trampoline_;
557 
558   // output stats
559   uint32_t size_vdex_header_ = 0;
560   uint32_t size_vdex_checksums_ = 0;
561   uint32_t size_dex_file_alignment_ = 0;
562   uint32_t size_executable_offset_alignment_ = 0;
563   uint32_t size_oat_header_ = 0;
564   uint32_t size_oat_header_key_value_store_ = 0;
565   uint32_t size_dex_file_ = 0;
566   uint32_t size_verifier_deps_ = 0;
567   uint32_t size_verifier_deps_alignment_ = 0;
568   uint32_t size_vdex_lookup_table_alignment_ = 0;
569   uint32_t size_vdex_lookup_table_ = 0;
570   uint32_t size_interpreter_to_interpreter_bridge_ = 0;
571   uint32_t size_interpreter_to_compiled_code_bridge_ = 0;
572   uint32_t size_jni_dlsym_lookup_trampoline_ = 0;
573   uint32_t size_jni_dlsym_lookup_critical_trampoline_ = 0;
574   uint32_t size_quick_generic_jni_trampoline_ = 0;
575   uint32_t size_quick_imt_conflict_trampoline_ = 0;
576   uint32_t size_quick_resolution_trampoline_ = 0;
577   uint32_t size_quick_to_interpreter_bridge_ = 0;
578   uint32_t size_nterp_trampoline_ = 0;
579   uint32_t size_trampoline_alignment_ = 0;
580   uint32_t size_method_header_ = 0;
581   uint32_t size_code_ = 0;
582   uint32_t size_code_alignment_ = 0;
583   uint32_t size_data_img_rel_ro_ = 0;
584   uint32_t size_data_img_rel_ro_alignment_ = 0;
585   uint32_t size_relative_call_thunks_ = 0;
586   uint32_t size_misc_thunks_ = 0;
587   uint32_t size_vmap_table_ = 0;
588   uint32_t size_method_info_ = 0;
589   uint32_t size_oat_dex_file_location_size_ = 0;
590   uint32_t size_oat_dex_file_location_data_ = 0;
591   uint32_t size_oat_dex_file_magic_ = 0;
592   uint32_t size_oat_dex_file_location_checksum_ = 0;
593   uint32_t size_oat_dex_file_sha1_ = 0;
594   uint32_t size_oat_dex_file_offset_ = 0;
595   uint32_t size_oat_dex_file_class_offsets_offset_ = 0;
596   uint32_t size_oat_dex_file_lookup_table_offset_ = 0;
597   uint32_t size_oat_dex_file_dex_layout_sections_offset_ = 0;
598   uint32_t size_oat_dex_file_dex_layout_sections_ = 0;
599   uint32_t size_oat_dex_file_dex_layout_sections_alignment_ = 0;
600   uint32_t size_oat_dex_file_method_bss_mapping_offset_ = 0;
601   uint32_t size_oat_dex_file_type_bss_mapping_offset_ = 0;
602   uint32_t size_oat_dex_file_public_type_bss_mapping_offset_ = 0;
603   uint32_t size_oat_dex_file_package_type_bss_mapping_offset_ = 0;
604   uint32_t size_oat_dex_file_string_bss_mapping_offset_ = 0;
605   uint32_t size_oat_dex_file_method_type_bss_mapping_offset_ = 0;
606   uint32_t size_bcp_bss_info_size_ = 0;
607   uint32_t size_bcp_bss_info_method_bss_mapping_offset_ = 0;
608   uint32_t size_bcp_bss_info_type_bss_mapping_offset_ = 0;
609   uint32_t size_bcp_bss_info_public_type_bss_mapping_offset_ = 0;
610   uint32_t size_bcp_bss_info_package_type_bss_mapping_offset_ = 0;
611   uint32_t size_bcp_bss_info_string_bss_mapping_offset_ = 0;
612   uint32_t size_bcp_bss_info_method_type_bss_mapping_offset_ = 0;
613   uint32_t size_oat_class_offsets_alignment_ = 0;
614   uint32_t size_oat_class_offsets_ = 0;
615   uint32_t size_oat_class_type_ = 0;
616   uint32_t size_oat_class_status_ = 0;
617   uint32_t size_oat_class_num_methods_ = 0;
618   uint32_t size_oat_class_method_bitmaps_ = 0;
619   uint32_t size_oat_class_method_offsets_ = 0;
620   uint32_t size_method_bss_mappings_ = 0;
621   uint32_t size_type_bss_mappings_ = 0;
622   uint32_t size_public_type_bss_mappings_ = 0;
623   uint32_t size_package_type_bss_mappings_ = 0;
624   uint32_t size_string_bss_mappings_ = 0;
625   uint32_t size_method_type_bss_mappings_ = 0;
626 
627   // The helper for processing relative patches is external so that we can patch across oat files.
628   MultiOatRelativePatcher* relative_patcher_;
629 
630   // Profile info used to generate new layout of files.
631   ProfileCompilationInfo* profile_compilation_info_;
632 
633   using OrderedMethodList = std::vector<OrderedMethodData>;
634 
635   // List of compiled methods, sorted by the order defined in OrderedMethodData.
636   // Methods can be inserted more than once in case of duplicated methods.
637   // This pointer is only non-null after InitOatCodeDexFiles succeeds.
638   std::unique_ptr<OrderedMethodList> ordered_methods_;
639 
640   DISALLOW_COPY_AND_ASSIGN(OatWriter);
641 };
642 
643 }  // namespace linker
644 }  // namespace art
645 
646 #endif  // ART_DEX2OAT_LINKER_OAT_WRITER_H_
647