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_IMAGE_WRITER_H_ |
| 18 | #define ART_COMPILER_IMAGE_WRITER_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
Andreas Gampe | 245ee00 | 2014-12-04 21:25:04 -0800 | [diff] [blame] | 21 | #include <valgrind.h> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 22 | |
| 23 | #include <cstddef> |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 24 | #include <memory> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | #include <set> |
| 26 | #include <string> |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 27 | #include <ostream> |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 28 | |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 29 | #include "base/macros.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 30 | #include "driver/compiler_driver.h" |
Mathieu Chartier | fd04b6f | 2014-11-14 19:34:18 -0800 | [diff] [blame] | 31 | #include "gc/space/space.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 32 | #include "mem_map.h" |
| 33 | #include "oat_file.h" |
| 34 | #include "mirror/dex_cache.h" |
| 35 | #include "os.h" |
| 36 | #include "safe_map.h" |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 37 | #include "gc/space/space.h" |
| 38 | #include "utils.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 39 | |
| 40 | namespace art { |
| 41 | |
| 42 | // Write a Space built during compilation for use during execution. |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 43 | class ImageWriter FINAL { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 44 | public: |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 45 | ImageWriter(const CompilerDriver& compiler_driver, uintptr_t image_begin, |
| 46 | bool compile_pic) |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 47 | : compiler_driver_(compiler_driver), image_begin_(reinterpret_cast<uint8_t*>(image_begin)), |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 48 | image_end_(0), image_objects_offset_begin_(0), image_roots_address_(0), oat_file_(nullptr), |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 49 | oat_data_begin_(nullptr), interpreter_to_interpreter_bridge_offset_(0), |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 50 | interpreter_to_compiled_code_bridge_offset_(0), jni_dlsym_lookup_offset_(0), |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 51 | quick_generic_jni_trampoline_offset_(0), |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 52 | quick_imt_conflict_trampoline_offset_(0), quick_resolution_trampoline_offset_(0), |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 53 | quick_to_interpreter_bridge_offset_(0), compile_pic_(compile_pic), |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 54 | target_ptr_size_(InstructionSetPointerSize(compiler_driver_.GetInstructionSet())), |
| 55 | bin_slot_sizes_(), bin_slot_count_() { |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 56 | CHECK_NE(image_begin, 0U); |
| 57 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 58 | |
Andreas Gampe | 245ee00 | 2014-12-04 21:25:04 -0800 | [diff] [blame] | 59 | ~ImageWriter() { |
| 60 | // For interned strings a large array is allocated to hold all the character data and avoid |
| 61 | // overhead. However, no GC is run anymore at this point. As the array is likely large, it |
| 62 | // will be allocated in the large object space, where valgrind can track every single |
| 63 | // allocation. Not explicitly freeing that array will be recognized as a leak. |
| 64 | if (RUNNING_ON_VALGRIND != 0) { |
| 65 | FreeStringDataArray(); |
| 66 | } |
| 67 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 68 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 69 | bool PrepareImageAddressSpace(); |
| 70 | |
| 71 | bool IsImageAddressSpaceReady() const { |
| 72 | return image_roots_address_ != 0u; |
| 73 | } |
| 74 | |
| 75 | mirror::Object* GetImageAddress(mirror::Object* object) const |
| 76 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 77 | if (object == nullptr) { |
| 78 | return nullptr; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 79 | } |
| 80 | return reinterpret_cast<mirror::Object*>(image_begin_ + GetImageOffset(object)); |
| 81 | } |
| 82 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 83 | uint8_t* GetOatFileBegin() const { |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 84 | return image_begin_ + RoundUp(image_end_, kPageSize); |
| 85 | } |
| 86 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 87 | bool Write(const std::string& image_filename, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 88 | const std::string& oat_filename, |
| 89 | const std::string& oat_location) |
| 90 | LOCKS_EXCLUDED(Locks::mutator_lock_); |
| 91 | |
| 92 | uintptr_t GetOatDataBegin() { |
| 93 | return reinterpret_cast<uintptr_t>(oat_data_begin_); |
| 94 | } |
| 95 | |
| 96 | private: |
| 97 | bool AllocMemory(); |
| 98 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 99 | // Mark the objects defined in this space in the given live bitmap. |
| 100 | void RecordImageAllocations() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 101 | |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 102 | // Classify different kinds of bins that objects end up getting packed into during image writing. |
| 103 | enum Bin { |
| 104 | // Likely-clean: |
| 105 | kBinString, // [String] Almost always immutable (except for obj header). |
| 106 | kBinArtMethodsManagedInitialized, // [ArtMethod] Not-native, and initialized. Unlikely to dirty |
| 107 | // Unknown mix of clean/dirty: |
| 108 | kBinRegular, |
| 109 | // Likely-dirty: |
| 110 | // All classes get their own bins since their fields often dirty |
| 111 | kBinClassInitializedFinalStatics, // Class initializers have been run, no non-final statics |
| 112 | kBinClassInitialized, // Class initializers have been run |
| 113 | kBinClassVerified, // Class verified, but initializers haven't been run |
| 114 | kBinArtMethodNative, // Art method that is actually native |
| 115 | kBinArtMethodNotInitialized, // Art method with a declaring class that wasn't initialized |
| 116 | // Don't care about other art methods since they don't dirty |
| 117 | // Add more bins here if we add more segregation code. |
| 118 | kBinSize, |
| 119 | }; |
| 120 | |
| 121 | friend std::ostream& operator<<(std::ostream& stream, const Bin& bin); |
| 122 | |
| 123 | static constexpr size_t kBinBits = MinimumBitsToStore(kBinSize - 1); |
| 124 | // uint32 = typeof(lockword_) |
| 125 | static constexpr size_t kBinShift = BitSizeOf<uint32_t>() - kBinBits; |
| 126 | // 111000.....0 |
| 127 | static constexpr size_t kBinMask = ((static_cast<size_t>(1) << kBinBits) - 1) << kBinShift; |
| 128 | |
| 129 | // We use the lock word to store the bin # and bin index of the object in the image. |
| 130 | // |
| 131 | // The struct size must be exactly sizeof(LockWord), currently 32-bits, since this will end up |
| 132 | // stored in the lock word bit-for-bit when object forwarding addresses are being calculated. |
| 133 | struct BinSlot { |
| 134 | explicit BinSlot(uint32_t lockword); |
| 135 | BinSlot(Bin bin, uint32_t index); |
| 136 | |
| 137 | // The bin an object belongs to, i.e. regular, class/verified, class/initialized, etc. |
| 138 | Bin GetBin() const; |
| 139 | // The offset in bytes from the beginning of the bin. Aligned to object size. |
| 140 | uint32_t GetIndex() const; |
| 141 | // Pack into a single uint32_t, for storing into a lock word. |
| 142 | explicit operator uint32_t() const { return lockword_; } |
| 143 | // Comparison operator for map support |
| 144 | bool operator<(const BinSlot& other) const { return lockword_ < other.lockword_; } |
| 145 | |
| 146 | private: |
| 147 | // Must be the same size as LockWord, any larger and we would truncate the data. |
| 148 | const uint32_t lockword_; |
| 149 | }; |
| 150 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 151 | // We use the lock word to store the offset of the object in the image. |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 152 | void AssignImageOffset(mirror::Object* object, BinSlot bin_slot) |
| 153 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 154 | void SetImageOffset(mirror::Object* object, BinSlot bin_slot, size_t offset) |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 155 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 156 | bool IsImageOffsetAssigned(mirror::Object* object) const |
| 157 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 158 | size_t GetImageOffset(mirror::Object* object) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 159 | |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 160 | void AssignImageBinSlot(mirror::Object* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 161 | void SetImageBinSlot(mirror::Object* object, BinSlot bin_slot) |
| 162 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 163 | bool IsImageBinSlotAssigned(mirror::Object* object) const |
| 164 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 165 | BinSlot GetImageBinSlot(mirror::Object* object) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 166 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 167 | static void* GetImageAddressCallback(void* writer, mirror::Object* obj) |
| 168 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 169 | return reinterpret_cast<ImageWriter*>(writer)->GetImageAddress(obj); |
| 170 | } |
| 171 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 172 | mirror::Object* GetLocalAddress(mirror::Object* object) const |
| 173 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 174 | size_t offset = GetImageOffset(object); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 175 | uint8_t* dst = image_->Begin() + offset; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 176 | return reinterpret_cast<mirror::Object*>(dst); |
| 177 | } |
| 178 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 179 | const uint8_t* GetOatAddress(uint32_t offset) const { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 180 | // With Quick, code is within the OatFile, as there are all in one |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 181 | // .o ELF object. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 182 | DCHECK_LT(offset, oat_file_->Size()); |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 183 | if (offset == 0u) { |
| 184 | return nullptr; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 185 | } |
| 186 | return oat_data_begin_ + offset; |
| 187 | } |
| 188 | |
| 189 | // Returns true if the class was in the original requested image classes list. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 190 | bool IsImageClass(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 191 | |
| 192 | // Debug aid that list of requested image classes. |
| 193 | void DumpImageClasses(); |
| 194 | |
| 195 | // Preinitializes some otherwise lazy fields (such as Class name) to avoid runtime image dirtying. |
| 196 | void ComputeLazyFieldsForImageClasses() |
| 197 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 198 | static bool ComputeLazyFieldsForClassesVisitor(mirror::Class* klass, void* arg) |
| 199 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 200 | |
| 201 | // Wire dex cache resolved strings to strings in the image to avoid runtime resolution. |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 202 | void ComputeEagerResolvedStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 203 | static void ComputeEagerResolvedStringsCallback(mirror::Object* obj, void* arg) |
| 204 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 205 | |
Mathieu Chartier | fd04b6f | 2014-11-14 19:34:18 -0800 | [diff] [blame] | 206 | // Combine string char arrays. |
| 207 | void ProcessStrings() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 208 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 209 | // Remove unwanted classes from various roots. |
| 210 | void PruneNonImageClasses() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 211 | static bool NonImageClassesVisitor(mirror::Class* c, void* arg) |
| 212 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 213 | |
| 214 | // Verify unwanted classes removed. |
Mathieu Chartier | fd04b6f | 2014-11-14 19:34:18 -0800 | [diff] [blame] | 215 | void CheckNonImageClassesRemoved() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 216 | static void CheckNonImageClassesRemovedCallback(mirror::Object* obj, void* arg) |
| 217 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 218 | |
| 219 | // Lays out where the image objects will be at runtime. |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 220 | void CalculateNewObjectOffsets() |
| 221 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 222 | void CreateHeader(size_t oat_loaded_size, size_t oat_data_offset) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 223 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 224 | mirror::ObjectArray<mirror::Object>* CreateImageRoots() const |
| 225 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 226 | void CalculateObjectBinSlots(mirror::Object* obj) |
| 227 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 228 | void UnbinObjectsIntoOffset(mirror::Object* obj) |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 229 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 230 | |
| 231 | void WalkInstanceFields(mirror::Object* obj, mirror::Class* klass) |
| 232 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 233 | void WalkFieldsInOrder(mirror::Object* obj) |
| 234 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 235 | static void WalkFieldsCallback(mirror::Object* obj, void* arg) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 236 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 237 | static void UnbinObjectsIntoOffsetCallback(mirror::Object* obj, void* arg) |
| 238 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 239 | |
| 240 | // Creates the contiguous image in memory and adjusts pointers. |
Mathieu Chartier | fd04b6f | 2014-11-14 19:34:18 -0800 | [diff] [blame] | 241 | void CopyAndFixupObjects() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 242 | static void CopyAndFixupObjectsCallback(mirror::Object* obj, void* arg) |
| 243 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 244 | void FixupMethod(mirror::ArtMethod* orig, mirror::ArtMethod* copy) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 245 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 246 | void FixupObject(mirror::Object* orig, mirror::Object* copy) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 247 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 248 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 249 | // Get quick code for non-resolution/imt_conflict/abstract method. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 250 | const uint8_t* GetQuickCode(mirror::ArtMethod* method, bool* quick_is_interpreted) |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 251 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 252 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 253 | const uint8_t* GetQuickEntryPoint(mirror::ArtMethod* method) |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 254 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 255 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 256 | // Patches references in OatFile to expect runtime addresses. |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 257 | void SetOatChecksumFromElfFile(File* elf_file); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 258 | |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 259 | // Calculate the sum total of the bin slot sizes in [0, up_to). Defaults to all bins. |
| 260 | size_t GetBinSizeSum(Bin up_to = kBinSize) const; |
| 261 | |
Andreas Gampe | 245ee00 | 2014-12-04 21:25:04 -0800 | [diff] [blame] | 262 | // Release the string_data_array_. |
| 263 | void FreeStringDataArray(); |
| 264 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 265 | const CompilerDriver& compiler_driver_; |
| 266 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 267 | // Beginning target image address for the output image. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 268 | uint8_t* image_begin_; |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 269 | |
| 270 | // Offset to the free space in image_. |
| 271 | size_t image_end_; |
| 272 | |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 273 | // Offset from image_begin_ to where the first object is in image_. |
| 274 | size_t image_objects_offset_begin_; |
| 275 | |
Vladimir Marko | f4da675 | 2014-08-01 19:04:18 +0100 | [diff] [blame] | 276 | // The image roots address in the image. |
| 277 | uint32_t image_roots_address_; |
| 278 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 279 | // oat file with code for this image |
| 280 | OatFile* oat_file_; |
| 281 | |
| 282 | // Memory mapped for generating the image. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 283 | std::unique_ptr<MemMap> image_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 284 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 285 | // Saved hashes (objects are inside of the image so that they don't move). |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 286 | std::vector<std::pair<mirror::Object*, uint32_t>> saved_hashes_; |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 287 | |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 288 | // Saved hashes (objects are bin slots to inside of the image, not yet allocated an address). |
| 289 | std::map<BinSlot, uint32_t> saved_hashes_map_; |
| 290 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 291 | // Beginning target oat address for the pointers from the output image to its oat file. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 292 | const uint8_t* oat_data_begin_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 293 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 294 | // Image bitmap which lets us know where the objects inside of the image reside. |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 295 | std::unique_ptr<gc::accounting::ContinuousSpaceBitmap> image_bitmap_; |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 296 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 297 | // Offset from oat_data_begin_ to the stubs. |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 298 | uint32_t interpreter_to_interpreter_bridge_offset_; |
| 299 | uint32_t interpreter_to_compiled_code_bridge_offset_; |
| 300 | uint32_t jni_dlsym_lookup_offset_; |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 301 | uint32_t quick_generic_jni_trampoline_offset_; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 302 | uint32_t quick_imt_conflict_trampoline_offset_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 303 | uint32_t quick_resolution_trampoline_offset_; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 304 | uint32_t quick_to_interpreter_bridge_offset_; |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 305 | const bool compile_pic_; |
Mathieu Chartier | b7ea3ac | 2014-03-24 16:54:46 -0700 | [diff] [blame] | 306 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 307 | // Size of pointers on the target architecture. |
| 308 | size_t target_ptr_size_; |
| 309 | |
Igor Murashkin | f5b4c50 | 2014-11-14 15:01:59 -0800 | [diff] [blame] | 310 | // Bin slot tracking for dirty object packing |
| 311 | size_t bin_slot_sizes_[kBinSize]; // Number of bytes in a bin |
| 312 | size_t bin_slot_count_[kBinSize]; // Number of objects in a bin |
| 313 | |
Andreas Gampe | 245ee00 | 2014-12-04 21:25:04 -0800 | [diff] [blame] | 314 | void* string_data_array_; // The backing for the interned strings. |
| 315 | |
Mathieu Chartier | b7ea3ac | 2014-03-24 16:54:46 -0700 | [diff] [blame] | 316 | friend class FixupVisitor; |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 317 | friend class FixupClassVisitor; |
Mathieu Chartier | b7ea3ac | 2014-03-24 16:54:46 -0700 | [diff] [blame] | 318 | DISALLOW_COPY_AND_ASSIGN(ImageWriter); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | } // namespace art |
| 322 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 323 | #endif // ART_COMPILER_IMAGE_WRITER_H_ |