Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_OAT_WRITER_H_ |
| 18 | #define ART_COMPILER_OAT_WRITER_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include <cstddef> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 22 | #include <memory> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | |
David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 24 | #include "base/array_ref.h" |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 25 | #include "base/dchecked_vector.h" |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 26 | #include "linker/relative_patcher.h" // For linker::RelativePatcherTargetProvider. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "mem_map.h" |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 28 | #include "method_reference.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 29 | #include "mirror/class.h" |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 30 | #include "oat.h" |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 31 | #include "os.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 32 | #include "safe_map.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 36 | class BitVector; |
Andreas Gampe | 7927380 | 2014-08-05 20:21:05 -0700 | [diff] [blame] | 37 | class CompiledMethod; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 38 | class CompilerDriver; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 39 | class ImageWriter; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 40 | class OutputStream; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 41 | class TimingLogger; |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 42 | class TypeLookupTable; |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 43 | class ZipEntry; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 44 | |
David Srbecky | c5bfa97 | 2016-02-05 15:49:10 +0000 | [diff] [blame] | 45 | namespace debug { |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 46 | struct MethodDebugInfo; |
David Srbecky | c5bfa97 | 2016-02-05 15:49:10 +0000 | [diff] [blame] | 47 | } // namespace debug |
Vladimir Marko | 10c1356 | 2015-11-25 14:33:36 +0000 | [diff] [blame] | 48 | |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 49 | namespace linker { |
| 50 | class MultiOatRelativePatcher; |
| 51 | } // namespace linker |
| 52 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 53 | // OatHeader variable length with count of D OatDexFiles |
| 54 | // |
| 55 | // OatDexFile[0] one variable sized OatDexFile with offsets to Dex and OatClasses |
| 56 | // OatDexFile[1] |
| 57 | // ... |
| 58 | // OatDexFile[D] |
| 59 | // |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 60 | // TypeLookupTable[0] one descriptor to class def index hash table for each OatDexFile. |
| 61 | // TypeLookupTable[1] |
| 62 | // ... |
| 63 | // TypeLookupTable[D] |
| 64 | // |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 65 | // ClassOffsets[0] one table of OatClass offsets for each class def for each OatDexFile. |
| 66 | // ClassOffsets[1] |
| 67 | // ... |
| 68 | // ClassOffsets[D] |
| 69 | // |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 70 | // OatClass[0] one variable sized OatClass for each of C DexFile::ClassDefs |
| 71 | // OatClass[1] contains OatClass entries with class status, offsets to code, etc. |
| 72 | // ... |
| 73 | // OatClass[C] |
| 74 | // |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 75 | // GcMap one variable sized blob with GC map. |
| 76 | // GcMap GC maps are deduplicated. |
| 77 | // ... |
| 78 | // GcMap |
| 79 | // |
| 80 | // VmapTable one variable sized VmapTable blob (quick compiler only). |
| 81 | // VmapTable VmapTables are deduplicated. |
| 82 | // ... |
| 83 | // VmapTable |
| 84 | // |
| 85 | // MappingTable one variable sized blob with MappingTable (quick compiler only). |
| 86 | // MappingTable MappingTables are deduplicated. |
| 87 | // ... |
| 88 | // MappingTable |
| 89 | // |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 90 | // padding if necessary so that the following code will be page aligned |
| 91 | // |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 92 | // OatMethodHeader fixed size header for a CompiledMethod including the size of the MethodCode. |
| 93 | // MethodCode one variable sized blob with the code of a CompiledMethod. |
| 94 | // OatMethodHeader (OatMethodHeader, MethodCode) pairs are deduplicated. |
| 95 | // MethodCode |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 96 | // ... |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 97 | // OatMethodHeader |
| 98 | // MethodCode |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 99 | // |
| 100 | class OatWriter { |
| 101 | public: |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 102 | enum class CreateTypeLookupTable { |
| 103 | kCreate, |
| 104 | kDontCreate, |
| 105 | kDefault = kCreate |
| 106 | }; |
| 107 | |
| 108 | OatWriter(bool compiling_boot_image, TimingLogger* timings); |
| 109 | |
| 110 | // To produce a valid oat file, the user must first add sources with any combination of |
| 111 | // - AddDexFileSource(), |
| 112 | // - AddZippedDexFilesSource(), |
| 113 | // - AddRawDexFileSource(). |
| 114 | // Then the user must call in order |
| 115 | // - WriteAndOpenDexFiles() |
| 116 | // - PrepareLayout(), |
| 117 | // - WriteRodata(), |
| 118 | // - WriteCode(), |
| 119 | // - WriteHeader(). |
| 120 | |
| 121 | // Add dex file source(s) from a file, either a plain dex file or |
| 122 | // a zip file with one or more dex files. |
| 123 | bool AddDexFileSource( |
| 124 | const char* filename, |
| 125 | const char* location, |
| 126 | CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault); |
| 127 | // Add dex file source(s) from a zip file specified by a file handle. |
| 128 | bool AddZippedDexFilesSource( |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 129 | File&& zip_fd, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 130 | const char* location, |
| 131 | CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault); |
| 132 | // Add dex file source from raw memory. |
| 133 | bool AddRawDexFileSource( |
| 134 | const ArrayRef<const uint8_t>& data, |
| 135 | const char* location, |
| 136 | uint32_t location_checksum, |
| 137 | CreateTypeLookupTable create_type_lookup_table = CreateTypeLookupTable::kDefault); |
| 138 | dchecked_vector<const char*> GetSourceLocations() const; |
| 139 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 140 | // Write raw dex files to the vdex file, mmap the file and open the dex files from it. |
| 141 | // Supporting data structures are written into the .rodata section of the oat file. |
| 142 | // The `verify` setting dictates whether the dex file verifier should check the dex files. |
| 143 | // This is generally the case, and should only be false for tests. |
| 144 | bool WriteAndOpenDexFiles(File* vdex_file, |
| 145 | OutputStream* oat_rodata, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 146 | InstructionSet instruction_set, |
| 147 | const InstructionSetFeatures* instruction_set_features, |
| 148 | SafeMap<std::string, std::string>* key_value_store, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 149 | bool verify, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 150 | /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map, |
| 151 | /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files); |
| 152 | // Prepare layout of remaining data. |
| 153 | void PrepareLayout(const CompilerDriver* compiler, |
| 154 | ImageWriter* image_writer, |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 155 | const std::vector<const DexFile*>& dex_files, |
| 156 | linker::MultiOatRelativePatcher* relative_patcher); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 157 | // Write the rest of .rodata section (ClassOffsets[], OatClass[], maps). |
| 158 | bool WriteRodata(OutputStream* out); |
| 159 | // Write the code to the .text section. |
| 160 | bool WriteCode(OutputStream* out); |
| 161 | // Write the oat header. This finalizes the oat file. |
| 162 | bool WriteHeader(OutputStream* out, |
| 163 | uint32_t image_file_location_oat_checksum, |
| 164 | uintptr_t image_file_location_oat_begin, |
| 165 | int32_t image_patch_delta); |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 166 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 167 | // Returns whether the oat file has an associated image. |
| 168 | bool HasImage() const { |
| 169 | // Since the image is being created at the same time as the oat file, |
| 170 | // check if there's an image writer. |
| 171 | return image_writer_ != nullptr; |
| 172 | } |
| 173 | |
Mathieu Chartier | da5b28a | 2015-11-05 08:03:47 -0800 | [diff] [blame] | 174 | bool HasBootImage() const { |
| 175 | return compiling_boot_image_; |
| 176 | } |
| 177 | |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 178 | const OatHeader& GetOatHeader() const { |
| 179 | return *oat_header_; |
| 180 | } |
| 181 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 182 | size_t GetOatSize() const { |
| 183 | return oat_size_; |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 186 | size_t GetBssSize() const { |
| 187 | return bss_size_; |
| 188 | } |
| 189 | |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 190 | size_t GetOatDataOffset() const { |
| 191 | return oat_data_offset_; |
| 192 | } |
| 193 | |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 194 | ArrayRef<const uintptr_t> GetAbsolutePatchLocations() const { |
| 195 | return ArrayRef<const uintptr_t>(absolute_patch_locations_); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 198 | ~OatWriter(); |
| 199 | |
David Srbecky | 09c2a6b | 2016-03-11 17:11:44 +0000 | [diff] [blame] | 200 | void AddMethodDebugInfos(const std::vector<debug::MethodDebugInfo>& infos) { |
| 201 | method_info_.insert(method_info_.end(), infos.begin(), infos.end()); |
| 202 | } |
| 203 | |
David Srbecky | c5bfa97 | 2016-02-05 15:49:10 +0000 | [diff] [blame] | 204 | ArrayRef<const debug::MethodDebugInfo> GetMethodDebugInfo() const { |
| 205 | return ArrayRef<const debug::MethodDebugInfo>(method_info_); |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 208 | const CompilerDriver* GetCompilerDriver() { |
| 209 | return compiler_driver_; |
| 210 | } |
| 211 | |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 212 | private: |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 213 | class DexFileSource; |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 214 | class OatClass; |
| 215 | class OatDexFile; |
| 216 | |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 217 | // The function VisitDexMethods() below iterates through all the methods in all |
| 218 | // the compiled dex files in order of their definitions. The method visitor |
| 219 | // classes provide individual bits of processing for each of the passes we need to |
| 220 | // first collect the data we want to write to the oat file and then, in later passes, |
| 221 | // to actually write it. |
| 222 | class DexMethodVisitor; |
| 223 | class OatDexMethodVisitor; |
| 224 | class InitOatClassesMethodVisitor; |
| 225 | class InitCodeMethodVisitor; |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 226 | class InitMapMethodVisitor; |
| 227 | class InitImageMethodVisitor; |
| 228 | class WriteCodeMethodVisitor; |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 229 | class WriteMapMethodVisitor; |
| 230 | |
| 231 | // Visit all the methods in all the compiled dex files in their definition order |
| 232 | // with a given DexMethodVisitor. |
| 233 | bool VisitDexMethods(DexMethodVisitor* visitor); |
| 234 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 235 | bool WriteVdexHeader(OutputStream* vdex_out); |
| 236 | |
| 237 | bool WriteDexFiles(OutputStream* out, File* file); |
| 238 | bool WriteDexFile(OutputStream* out, File* file, OatDexFile* oat_dex_file); |
| 239 | bool SeekToDexFile(OutputStream* out, File* file, OatDexFile* oat_dex_file); |
| 240 | bool WriteDexFile(OutputStream* out, |
| 241 | File* file, |
| 242 | OatDexFile* oat_dex_file, |
| 243 | ZipEntry* dex_file); |
| 244 | bool WriteDexFile(OutputStream* out, |
| 245 | File* file, |
| 246 | OatDexFile* oat_dex_file, |
| 247 | File* dex_file); |
| 248 | bool WriteDexFile(OutputStream* out, OatDexFile* oat_dex_file, const uint8_t* dex_file); |
| 249 | bool OpenDexFiles(File* file, |
| 250 | bool verify, |
| 251 | /*out*/ std::unique_ptr<MemMap>* opened_dex_files_map, |
| 252 | /*out*/ std::vector<std::unique_ptr<const DexFile>>* opened_dex_files); |
| 253 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 254 | size_t InitOatHeader(InstructionSet instruction_set, |
| 255 | const InstructionSetFeatures* instruction_set_features, |
| 256 | uint32_t num_dex_files, |
| 257 | SafeMap<std::string, std::string>* key_value_store); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 258 | size_t InitOatDexFiles(size_t offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 259 | size_t InitOatClasses(size_t offset); |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 260 | size_t InitOatMaps(size_t offset); |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 261 | size_t InitOatCode(size_t offset); |
| 262 | size_t InitOatCodeDexFiles(size_t offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 263 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 264 | bool WriteClassOffsets(OutputStream* out); |
| 265 | bool WriteClasses(OutputStream* out); |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 266 | size_t WriteMaps(OutputStream* out, const size_t file_offset, size_t relative_offset); |
| 267 | size_t WriteCode(OutputStream* out, const size_t file_offset, size_t relative_offset); |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 268 | size_t WriteCodeDexFiles(OutputStream* out, const size_t file_offset, size_t relative_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 269 | |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 270 | bool RecordOatDataOffset(OutputStream* out); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 271 | bool ReadDexFileHeader(File* oat_file, OatDexFile* oat_dex_file); |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 272 | bool ValidateDexFileHeader(const uint8_t* raw_header, const char* location); |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 273 | bool WriteOatDexFiles(OutputStream* oat_rodata); |
| 274 | bool WriteTypeLookupTables(OutputStream* oat_rodata, |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 275 | const std::vector<std::unique_ptr<const DexFile>>& opened_dex_files); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 276 | bool WriteCodeAlignment(OutputStream* out, uint32_t aligned_code_delta); |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 277 | void SetMultiOatRelativePatcherAdjustment(); |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 278 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 279 | enum class WriteState { |
| 280 | kAddingDexFileSources, |
| 281 | kPrepareLayout, |
| 282 | kWriteRoData, |
| 283 | kWriteText, |
| 284 | kWriteHeader, |
| 285 | kDone |
| 286 | }; |
| 287 | |
| 288 | WriteState write_state_; |
| 289 | TimingLogger* timings_; |
| 290 | |
| 291 | std::vector<std::unique_ptr<File>> raw_dex_files_; |
| 292 | std::vector<std::unique_ptr<ZipArchive>> zip_archives_; |
| 293 | std::vector<std::unique_ptr<ZipEntry>> zipped_dex_files_; |
| 294 | |
| 295 | // Using std::list<> which doesn't move elements around on push/emplace_back(). |
| 296 | // We need this because we keep plain pointers to the strings' c_str(). |
| 297 | std::list<std::string> zipped_dex_file_locations_; |
| 298 | |
David Srbecky | c5bfa97 | 2016-02-05 15:49:10 +0000 | [diff] [blame] | 299 | dchecked_vector<debug::MethodDebugInfo> method_info_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 300 | |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 301 | const CompilerDriver* compiler_driver_; |
| 302 | ImageWriter* image_writer_; |
Mathieu Chartier | da5b28a | 2015-11-05 08:03:47 -0800 | [diff] [blame] | 303 | const bool compiling_boot_image_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 304 | |
| 305 | // note OatFile does not take ownership of the DexFiles |
| 306 | const std::vector<const DexFile*>* dex_files_; |
| 307 | |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 308 | // Size required for Vdex data structures. |
| 309 | size_t vdex_size_; |
| 310 | |
| 311 | // Offset of section holding Dex files inside Vdex. |
| 312 | size_t vdex_dex_files_offset_; |
| 313 | |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 314 | // Size required for Oat data structures. |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 315 | size_t oat_size_; |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 316 | |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 317 | // The size of the required .bss section holding the DexCache data. |
| 318 | size_t bss_size_; |
| 319 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 320 | // Offsets of the dex cache arrays for each app dex file. For the |
| 321 | // boot image, this information is provided by the ImageWriter. |
Vladimir Marko | 06d7aaa | 2015-10-16 11:23:41 +0100 | [diff] [blame] | 322 | SafeMap<const DexFile*, size_t> dex_cache_arrays_offsets_; // DexFiles not owned. |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 323 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 324 | // Offset of the oat data from the start of the mmapped region of the elf file. |
| 325 | size_t oat_data_offset_; |
| 326 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 327 | // data to write |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 328 | std::unique_ptr<OatHeader> oat_header_; |
| 329 | dchecked_vector<OatDexFile> oat_dex_files_; |
| 330 | dchecked_vector<OatClass> oat_classes_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 331 | std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 332 | std::unique_ptr<const std::vector<uint8_t>> quick_generic_jni_trampoline_; |
| 333 | std::unique_ptr<const std::vector<uint8_t>> quick_imt_conflict_trampoline_; |
| 334 | std::unique_ptr<const std::vector<uint8_t>> quick_resolution_trampoline_; |
| 335 | std::unique_ptr<const std::vector<uint8_t>> quick_to_interpreter_bridge_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 336 | |
| 337 | // output stats |
David Brazdil | 7b49e6c | 2016-09-01 11:06:18 +0100 | [diff] [blame] | 338 | uint32_t size_vdex_header_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 339 | uint32_t size_dex_file_alignment_; |
| 340 | uint32_t size_executable_offset_alignment_; |
| 341 | uint32_t size_oat_header_; |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 342 | uint32_t size_oat_header_key_value_store_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 343 | uint32_t size_dex_file_; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 344 | uint32_t size_interpreter_to_interpreter_bridge_; |
| 345 | uint32_t size_interpreter_to_compiled_code_bridge_; |
| 346 | uint32_t size_jni_dlsym_lookup_; |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 347 | uint32_t size_quick_generic_jni_trampoline_; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 348 | uint32_t size_quick_imt_conflict_trampoline_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 349 | uint32_t size_quick_resolution_trampoline_; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 350 | uint32_t size_quick_to_interpreter_bridge_; |
| 351 | uint32_t size_trampoline_alignment_; |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 352 | uint32_t size_method_header_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 353 | uint32_t size_code_; |
| 354 | uint32_t size_code_alignment_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 355 | uint32_t size_relative_call_thunks_; |
Vladimir Marko | c74658b | 2015-03-31 10:26:41 +0100 | [diff] [blame] | 356 | uint32_t size_misc_thunks_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 357 | uint32_t size_vmap_table_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 358 | uint32_t size_oat_dex_file_location_size_; |
| 359 | uint32_t size_oat_dex_file_location_data_; |
| 360 | uint32_t size_oat_dex_file_location_checksum_; |
| 361 | uint32_t size_oat_dex_file_offset_; |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 362 | uint32_t size_oat_dex_file_class_offsets_offset_; |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 363 | uint32_t size_oat_dex_file_lookup_table_offset_; |
Vladimir Marko | 49b0f45 | 2015-12-10 13:49:19 +0000 | [diff] [blame] | 364 | uint32_t size_oat_lookup_table_alignment_; |
| 365 | uint32_t size_oat_lookup_table_; |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 366 | uint32_t size_oat_class_offsets_alignment_; |
| 367 | uint32_t size_oat_class_offsets_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 368 | uint32_t size_oat_class_type_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 369 | uint32_t size_oat_class_status_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 370 | uint32_t size_oat_class_method_bitmaps_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 371 | uint32_t size_oat_class_method_offsets_; |
| 372 | |
Vladimir Marko | 944da60 | 2016-02-19 12:27:55 +0000 | [diff] [blame] | 373 | // The helper for processing relative patches is external so that we can patch across oat files. |
| 374 | linker::MultiOatRelativePatcher* relative_patcher_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 375 | |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 376 | // The locations of absolute patches relative to the start of the executable section. |
Vladimir Marko | 9bdf108 | 2016-01-21 12:15:52 +0000 | [diff] [blame] | 377 | dchecked_vector<uintptr_t> absolute_patch_locations_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 378 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 379 | DISALLOW_COPY_AND_ASSIGN(OatWriter); |
| 380 | }; |
| 381 | |
| 382 | } // namespace art |
| 383 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 384 | #endif // ART_COMPILER_OAT_WRITER_H_ |