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