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 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 24 | #include "linker/relative_patcher.h" // For linker::RelativePatcherTargetProvider. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | #include "mem_map.h" |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 26 | #include "method_reference.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "mirror/class.h" |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 28 | #include "oat.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 29 | #include "safe_map.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 33 | class BitVector; |
Andreas Gampe | 7927380 | 2014-08-05 20:21:05 -0700 | [diff] [blame] | 34 | class CompiledMethod; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 35 | class CompilerDriver; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 36 | class ImageWriter; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 37 | class OutputStream; |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 38 | class TimingLogger; |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 39 | class TypeLookupTable; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 40 | |
| 41 | // OatHeader variable length with count of D OatDexFiles |
| 42 | // |
| 43 | // OatDexFile[0] one variable sized OatDexFile with offsets to Dex and OatClasses |
| 44 | // OatDexFile[1] |
| 45 | // ... |
| 46 | // OatDexFile[D] |
| 47 | // |
| 48 | // Dex[0] one variable sized DexFile for each OatDexFile. |
| 49 | // Dex[1] these are literal copies of the input .dex files. |
| 50 | // ... |
| 51 | // Dex[D] |
| 52 | // |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 53 | // TypeLookupTable[0] one descriptor to class def index hash table for each OatDexFile. |
| 54 | // TypeLookupTable[1] |
| 55 | // ... |
| 56 | // TypeLookupTable[D] |
| 57 | // |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 58 | // OatClass[0] one variable sized OatClass for each of C DexFile::ClassDefs |
| 59 | // OatClass[1] contains OatClass entries with class status, offsets to code, etc. |
| 60 | // ... |
| 61 | // OatClass[C] |
| 62 | // |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 63 | // GcMap one variable sized blob with GC map. |
| 64 | // GcMap GC maps are deduplicated. |
| 65 | // ... |
| 66 | // GcMap |
| 67 | // |
| 68 | // VmapTable one variable sized VmapTable blob (quick compiler only). |
| 69 | // VmapTable VmapTables are deduplicated. |
| 70 | // ... |
| 71 | // VmapTable |
| 72 | // |
| 73 | // MappingTable one variable sized blob with MappingTable (quick compiler only). |
| 74 | // MappingTable MappingTables are deduplicated. |
| 75 | // ... |
| 76 | // MappingTable |
| 77 | // |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 78 | // padding if necessary so that the following code will be page aligned |
| 79 | // |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 80 | // OatMethodHeader fixed size header for a CompiledMethod including the size of the MethodCode. |
| 81 | // MethodCode one variable sized blob with the code of a CompiledMethod. |
| 82 | // OatMethodHeader (OatMethodHeader, MethodCode) pairs are deduplicated. |
| 83 | // MethodCode |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 84 | // ... |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 85 | // OatMethodHeader |
| 86 | // MethodCode |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 87 | // |
| 88 | class OatWriter { |
| 89 | public: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 90 | OatWriter(const std::vector<const DexFile*>& dex_files, |
| 91 | uint32_t image_file_location_oat_checksum, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 92 | uintptr_t image_file_location_oat_begin, |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 93 | int32_t image_patch_delta, |
Ian Rogers | ca368cb | 2013-11-15 15:52:08 -0800 | [diff] [blame] | 94 | const CompilerDriver* compiler, |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 95 | ImageWriter* image_writer, |
Mathieu Chartier | da5b28a | 2015-11-05 08:03:47 -0800 | [diff] [blame^] | 96 | bool compiling_boot_image, |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 97 | TimingLogger* timings, |
| 98 | SafeMap<std::string, std::string>* key_value_store); |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 99 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 100 | // Returns whether the oat file has an associated image. |
| 101 | bool HasImage() const { |
| 102 | // Since the image is being created at the same time as the oat file, |
| 103 | // check if there's an image writer. |
| 104 | return image_writer_ != nullptr; |
| 105 | } |
| 106 | |
Mathieu Chartier | da5b28a | 2015-11-05 08:03:47 -0800 | [diff] [blame^] | 107 | bool HasBootImage() const { |
| 108 | return compiling_boot_image_; |
| 109 | } |
| 110 | |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 111 | const OatHeader& GetOatHeader() const { |
| 112 | return *oat_header_; |
| 113 | } |
| 114 | |
| 115 | size_t GetSize() const { |
| 116 | return size_; |
| 117 | } |
| 118 | |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 119 | size_t GetBssSize() const { |
| 120 | return bss_size_; |
| 121 | } |
| 122 | |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 123 | const std::vector<uintptr_t>& GetAbsolutePatchLocations() const { |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 124 | return absolute_patch_locations_; |
| 125 | } |
| 126 | |
David Srbecky | bc90fd0 | 2015-04-22 19:40:27 +0100 | [diff] [blame] | 127 | bool WriteRodata(OutputStream* out); |
| 128 | bool WriteCode(OutputStream* out); |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 129 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 130 | ~OatWriter(); |
| 131 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 132 | struct DebugInfo { |
David Srbecky | 0df9e1f | 2015-04-07 19:02:58 +0100 | [diff] [blame] | 133 | const DexFile* dex_file_; |
| 134 | size_t class_def_index_; |
| 135 | uint32_t dex_method_index_; |
| 136 | uint32_t access_flags_; |
| 137 | const DexFile::CodeItem *code_item_; |
| 138 | bool deduped_; |
| 139 | uint32_t low_pc_; |
| 140 | uint32_t high_pc_; |
Andreas Gampe | 7927380 | 2014-08-05 20:21:05 -0700 | [diff] [blame] | 141 | CompiledMethod* compiled_method_; |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 142 | }; |
| 143 | |
David Srbecky | 3b9d57a | 2015-04-10 00:22:14 +0100 | [diff] [blame] | 144 | const std::vector<DebugInfo>& GetMethodDebugInfo() const { |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 145 | return method_info_; |
| 146 | } |
| 147 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 148 | const CompilerDriver* GetCompilerDriver() { |
| 149 | return compiler_driver_; |
| 150 | } |
| 151 | |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 152 | private: |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 153 | // The DataAccess classes are helper classes that provide access to members related to |
| 154 | // a given map, i.e. GC map, mapping table or vmap table. By abstracting these away |
| 155 | // we can share a lot of code for processing the maps with template classes below. |
| 156 | struct GcMapDataAccess; |
| 157 | struct MappingTableDataAccess; |
| 158 | struct VmapTableDataAccess; |
| 159 | |
| 160 | // The function VisitDexMethods() below iterates through all the methods in all |
| 161 | // the compiled dex files in order of their definitions. The method visitor |
| 162 | // classes provide individual bits of processing for each of the passes we need to |
| 163 | // first collect the data we want to write to the oat file and then, in later passes, |
| 164 | // to actually write it. |
| 165 | class DexMethodVisitor; |
| 166 | class OatDexMethodVisitor; |
| 167 | class InitOatClassesMethodVisitor; |
| 168 | class InitCodeMethodVisitor; |
| 169 | template <typename DataAccess> |
| 170 | class InitMapMethodVisitor; |
| 171 | class InitImageMethodVisitor; |
| 172 | class WriteCodeMethodVisitor; |
| 173 | template <typename DataAccess> |
| 174 | class WriteMapMethodVisitor; |
| 175 | |
| 176 | // Visit all the methods in all the compiled dex files in their definition order |
| 177 | // with a given DexMethodVisitor. |
| 178 | bool VisitDexMethods(DexMethodVisitor* visitor); |
| 179 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 180 | size_t InitOatHeader(); |
| 181 | size_t InitOatDexFiles(size_t offset); |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 182 | size_t InitLookupTables(size_t offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 183 | size_t InitDexFiles(size_t offset); |
| 184 | size_t InitOatClasses(size_t offset); |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 185 | size_t InitOatMaps(size_t offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 186 | size_t InitOatCode(size_t offset) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 187 | SHARED_REQUIRES(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 188 | size_t InitOatCodeDexFiles(size_t offset) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 189 | SHARED_REQUIRES(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 190 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 191 | bool WriteTables(OutputStream* out, const size_t file_offset); |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 192 | bool WriteLookupTables(OutputStream* out, const size_t file_offset); |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 193 | size_t WriteMaps(OutputStream* out, const size_t file_offset, size_t relative_offset); |
| 194 | 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] | 195 | 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] | 196 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 197 | bool WriteCodeAlignment(OutputStream* out, uint32_t aligned_code_delta); |
| 198 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 199 | class OatDexFile { |
| 200 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 201 | OatDexFile(size_t offset, const DexFile& dex_file); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 202 | size_t SizeOf() const; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 203 | void UpdateChecksum(OatHeader* oat_header) const; |
| 204 | bool Write(OatWriter* oat_writer, OutputStream* out, const size_t file_offset) const; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 205 | |
| 206 | // Offset of start of OatDexFile from beginning of OatHeader. It is |
| 207 | // used to validate file position when writing. |
| 208 | size_t offset_; |
| 209 | |
| 210 | // data to write |
| 211 | uint32_t dex_file_location_size_; |
| 212 | const uint8_t* dex_file_location_data_; |
| 213 | uint32_t dex_file_location_checksum_; |
| 214 | uint32_t dex_file_offset_; |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 215 | uint32_t lookup_table_offset_; |
| 216 | TypeLookupTable* lookup_table_; // Owned by the dex file. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 217 | std::vector<uint32_t> methods_offsets_; |
| 218 | |
| 219 | private: |
| 220 | DISALLOW_COPY_AND_ASSIGN(OatDexFile); |
| 221 | }; |
| 222 | |
| 223 | class OatClass { |
| 224 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 225 | OatClass(size_t offset, |
| 226 | const std::vector<CompiledMethod*>& compiled_methods, |
| 227 | uint32_t num_non_null_compiled_methods, |
| 228 | mirror::Class::Status status); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 229 | ~OatClass(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 230 | size_t GetOatMethodOffsetsOffsetFromOatHeader(size_t class_def_method_index_) const; |
| 231 | size_t GetOatMethodOffsetsOffsetFromOatClass(size_t class_def_method_index_) const; |
| 232 | size_t SizeOf() const; |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 233 | void UpdateChecksum(OatHeader* oat_header) const; |
| 234 | bool Write(OatWriter* oat_writer, OutputStream* out, const size_t file_offset) const; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 235 | |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 236 | CompiledMethod* GetCompiledMethod(size_t class_def_method_index) const { |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 237 | DCHECK_LT(class_def_method_index, compiled_methods_.size()); |
| 238 | return compiled_methods_[class_def_method_index]; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 241 | // Offset of start of OatClass from beginning of OatHeader. It is |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 242 | // used to validate file position when writing. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 243 | size_t offset_; |
| 244 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 245 | // CompiledMethods for each class_def_method_index, or null if no method is available. |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 246 | std::vector<CompiledMethod*> compiled_methods_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 247 | |
| 248 | // Offset from OatClass::offset_ to the OatMethodOffsets for the |
| 249 | // class_def_method_index. If 0, it means the corresponding |
| 250 | // CompiledMethod entry in OatClass::compiled_methods_ should be |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 251 | // null and that the OatClass::type_ should be kOatClassBitmap. |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 252 | std::vector<uint32_t> oat_method_offsets_offsets_from_oat_class_; |
| 253 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 254 | // data to write |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 255 | |
Andreas Gampe | 785d2f2 | 2014-11-03 22:57:30 -0800 | [diff] [blame] | 256 | static_assert(mirror::Class::Status::kStatusMax < (2 ^ 16), "class status won't fit in 16bits"); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 257 | int16_t status_; |
| 258 | |
Andreas Gampe | 785d2f2 | 2014-11-03 22:57:30 -0800 | [diff] [blame] | 259 | static_assert(OatClassType::kOatClassMax < (2 ^ 16), "oat_class type won't fit in 16bits"); |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 260 | uint16_t type_; |
| 261 | |
| 262 | uint32_t method_bitmap_size_; |
| 263 | |
| 264 | // bit vector indexed by ClassDef method index. When |
| 265 | // OatClassType::type_ is kOatClassBitmap, a set bit indicates the |
| 266 | // method has an OatMethodOffsets in methods_offsets_, otherwise |
| 267 | // the entry was ommited to save space. If OatClassType::type_ is |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 268 | // not is kOatClassBitmap, the bitmap will be null. |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 269 | BitVector* method_bitmap_; |
| 270 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 271 | // OatMethodOffsets and OatMethodHeaders for each CompiledMethod |
| 272 | // present in the OatClass. Note that some may be missing if |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 273 | // OatClass::compiled_methods_ contains null values (and |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 274 | // oat_method_offsets_offsets_from_oat_class_ should contain 0 |
| 275 | // values in this case). |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 276 | std::vector<OatMethodOffsets> method_offsets_; |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 277 | std::vector<OatQuickMethodHeader> method_headers_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 278 | |
| 279 | private: |
| 280 | DISALLOW_COPY_AND_ASSIGN(OatClass); |
| 281 | }; |
| 282 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 283 | std::vector<DebugInfo> method_info_; |
| 284 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 285 | const CompilerDriver* const compiler_driver_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 286 | ImageWriter* const image_writer_; |
Mathieu Chartier | da5b28a | 2015-11-05 08:03:47 -0800 | [diff] [blame^] | 287 | const bool compiling_boot_image_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 288 | |
| 289 | // note OatFile does not take ownership of the DexFiles |
| 290 | const std::vector<const DexFile*>* dex_files_; |
| 291 | |
Brian Carlstrom | c50d8e1 | 2013-07-23 22:35:16 -0700 | [diff] [blame] | 292 | // Size required for Oat data structures. |
| 293 | size_t size_; |
| 294 | |
Vladimir Marko | 5c42c29 | 2015-02-25 12:02:49 +0000 | [diff] [blame] | 295 | // The size of the required .bss section holding the DexCache data. |
| 296 | size_t bss_size_; |
| 297 | |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 298 | // Offsets of the dex cache arrays for each app dex file. For the |
| 299 | // boot image, this information is provided by the ImageWriter. |
Vladimir Marko | 06d7aaa | 2015-10-16 11:23:41 +0100 | [diff] [blame] | 300 | SafeMap<const DexFile*, size_t> dex_cache_arrays_offsets_; // DexFiles not owned. |
Vladimir Marko | 09d0943 | 2015-09-08 13:47:48 +0100 | [diff] [blame] | 301 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 302 | // Offset of the oat data from the start of the mmapped region of the elf file. |
| 303 | size_t oat_data_offset_; |
| 304 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 305 | // dependencies on the image. |
| 306 | uint32_t image_file_location_oat_checksum_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 307 | uintptr_t image_file_location_oat_begin_; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 308 | int32_t image_patch_delta_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 309 | |
| 310 | // data to write |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 311 | SafeMap<std::string, std::string>* key_value_store_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 312 | OatHeader* oat_header_; |
| 313 | std::vector<OatDexFile*> oat_dex_files_; |
| 314 | std::vector<OatClass*> oat_classes_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 315 | std::unique_ptr<const std::vector<uint8_t>> jni_dlsym_lookup_; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 316 | std::unique_ptr<const std::vector<uint8_t>> quick_generic_jni_trampoline_; |
| 317 | std::unique_ptr<const std::vector<uint8_t>> quick_imt_conflict_trampoline_; |
| 318 | std::unique_ptr<const std::vector<uint8_t>> quick_resolution_trampoline_; |
| 319 | std::unique_ptr<const std::vector<uint8_t>> quick_to_interpreter_bridge_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 320 | |
| 321 | // output stats |
| 322 | uint32_t size_dex_file_alignment_; |
| 323 | uint32_t size_executable_offset_alignment_; |
| 324 | uint32_t size_oat_header_; |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 325 | uint32_t size_oat_header_key_value_store_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 326 | uint32_t size_dex_file_; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 327 | uint32_t size_interpreter_to_interpreter_bridge_; |
| 328 | uint32_t size_interpreter_to_compiled_code_bridge_; |
| 329 | uint32_t size_jni_dlsym_lookup_; |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 330 | uint32_t size_quick_generic_jni_trampoline_; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 331 | uint32_t size_quick_imt_conflict_trampoline_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 332 | uint32_t size_quick_resolution_trampoline_; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 333 | uint32_t size_quick_to_interpreter_bridge_; |
| 334 | uint32_t size_trampoline_alignment_; |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 335 | uint32_t size_method_header_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 336 | uint32_t size_code_; |
| 337 | uint32_t size_code_alignment_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 338 | uint32_t size_relative_call_thunks_; |
Vladimir Marko | c74658b | 2015-03-31 10:26:41 +0100 | [diff] [blame] | 339 | uint32_t size_misc_thunks_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 340 | uint32_t size_mapping_table_; |
| 341 | uint32_t size_vmap_table_; |
| 342 | uint32_t size_gc_map_; |
| 343 | uint32_t size_oat_dex_file_location_size_; |
| 344 | uint32_t size_oat_dex_file_location_data_; |
| 345 | uint32_t size_oat_dex_file_location_checksum_; |
| 346 | uint32_t size_oat_dex_file_offset_; |
| 347 | uint32_t size_oat_dex_file_methods_offsets_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 348 | uint32_t size_oat_class_type_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 349 | uint32_t size_oat_class_status_; |
Brian Carlstrom | ba150c3 | 2013-08-27 17:31:03 -0700 | [diff] [blame] | 350 | uint32_t size_oat_class_method_bitmaps_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 351 | uint32_t size_oat_class_method_offsets_; |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 352 | uint32_t size_oat_lookup_table_alignment_; |
| 353 | uint32_t size_oat_lookup_table_offset_; |
| 354 | uint32_t size_oat_lookup_table_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 355 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 356 | std::unique_ptr<linker::RelativePatcher> relative_patcher_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 357 | |
David Srbecky | f898087 | 2015-05-22 17:04:47 +0100 | [diff] [blame] | 358 | // The locations of absolute patches relative to the start of the executable section. |
| 359 | std::vector<uintptr_t> absolute_patch_locations_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 360 | |
Vladimir Marko | b163bb7 | 2015-03-31 21:49:49 +0100 | [diff] [blame] | 361 | // Map method reference to assigned offset. |
| 362 | // Wrap the map in a class implementing linker::RelativePatcherTargetProvider. |
| 363 | class MethodOffsetMap FINAL : public linker::RelativePatcherTargetProvider { |
| 364 | public: |
| 365 | std::pair<bool, uint32_t> FindMethodOffset(MethodReference ref) OVERRIDE; |
| 366 | SafeMap<MethodReference, uint32_t, MethodReferenceComparator> map; |
| 367 | }; |
| 368 | MethodOffsetMap method_offset_map_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 369 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 370 | DISALLOW_COPY_AND_ASSIGN(OatWriter); |
| 371 | }; |
| 372 | |
| 373 | } // namespace art |
| 374 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 375 | #endif // ART_COMPILER_OAT_WRITER_H_ |