Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [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 | */ |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 16 | |
| 17 | #include "image_writer.h" |
| 18 | |
Brian Carlstrom | 6cd40e5 | 2012-05-03 14:15:11 -0700 | [diff] [blame] | 19 | #include <sys/stat.h> |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 20 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 23 | #include "base/logging.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 24 | #include "base/unix_file/fd_file.h" |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 25 | #include "class_linker.h" |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 26 | #include "compiled_method.h" |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 27 | #include "compiler/driver/compiler_driver.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | #include "gc/card_table-inl.h" |
Mathieu Chartier | 1c23e1e | 2012-10-12 14:14:11 -0700 | [diff] [blame] | 29 | #include "gc/large_object_space.h" |
| 30 | #include "gc/space.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 31 | #include "globals.h" |
| 32 | #include "heap.h" |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 33 | #include "image.h" |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 34 | #include "intern_table.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | #include "mirror/array-inl.h" |
| 36 | #include "mirror/class-inl.h" |
| 37 | #include "mirror/class_loader.h" |
| 38 | #include "mirror/dex_cache.h" |
| 39 | #include "mirror/field-inl.h" |
| 40 | #include "mirror/abstract_method-inl.h" |
| 41 | #include "mirror/object-inl.h" |
| 42 | #include "mirror/object_array-inl.h" |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 43 | #include "oat.h" |
Logan Chien | 0c717dd | 2012-03-28 18:31:07 +0800 | [diff] [blame] | 44 | #include "oat_file.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 45 | #include "object_utils.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 46 | #include "runtime.h" |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 47 | #include "scoped_thread_state_change.h" |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 48 | #include "sirt_ref.h" |
Elliott Hughes | a168c83 | 2012-06-12 15:34:20 -0700 | [diff] [blame] | 49 | #include "UniquePtr.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 50 | #include "utils.h" |
| 51 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 52 | using namespace art::mirror; |
| 53 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 54 | namespace art { |
| 55 | |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 56 | bool ImageWriter::Write(const std::string& image_filename, |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 57 | uintptr_t image_begin, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 58 | const std::string& oat_filename, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 59 | const std::string& oat_location, |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 60 | const CompilerDriver& compiler_driver) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 61 | CHECK(!image_filename.empty()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 62 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 63 | CHECK_NE(image_begin, 0U); |
| 64 | image_begin_ = reinterpret_cast<byte*>(image_begin); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 65 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 66 | Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 67 | const Spaces& spaces = heap->GetSpaces(); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 68 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 69 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 70 | const std::vector<DexCache*>& all_dex_caches = class_linker->GetDexCaches(); |
| 71 | for (size_t i = 0; i < all_dex_caches.size(); i++) { |
| 72 | DexCache* dex_cache = all_dex_caches[i]; |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 73 | dex_caches_.insert(dex_cache); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 76 | UniquePtr<File> oat_file(OS::OpenFile(oat_filename.c_str(), true, false)); |
| 77 | if (oat_file.get() == NULL) { |
| 78 | LOG(ERROR) << "Failed to open oat file " << oat_filename << " for " << oat_location; |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 79 | return false; |
| 80 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 81 | oat_file_ = OatFile::Open(oat_file.get(), oat_location, NULL, true); |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 82 | class_linker->RegisterOatFile(*oat_file_); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 83 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 84 | { |
| 85 | Thread::Current()->TransitionFromSuspendedToRunnable(); |
| 86 | PruneNonImageClasses(); // Remove junk |
| 87 | ComputeLazyFieldsForImageClasses(); // Add useful information |
| 88 | ComputeEagerResolvedStrings(); |
| 89 | Thread::Current()->TransitionFromRunnableToSuspended(kNative); |
| 90 | } |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 91 | heap->CollectGarbage(false); // Remove garbage |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 92 | // Trim size of alloc spaces |
| 93 | // TODO: C++0x auto |
| 94 | for (Spaces::const_iterator cur = spaces.begin(); cur != spaces.end(); ++cur) { |
| 95 | if ((*cur)->IsAllocSpace()) { |
| 96 | (*cur)->AsAllocSpace()->Trim(); |
| 97 | } |
| 98 | } |
| 99 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 100 | if (!AllocMemory()) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 101 | return false; |
| 102 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 103 | #ifndef NDEBUG |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 104 | { |
| 105 | ScopedObjectAccess soa(Thread::Current()); |
| 106 | CheckNonImageClassesRemoved(); |
| 107 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 108 | #endif |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 109 | Thread::Current()->TransitionFromSuspendedToRunnable(); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 110 | size_t oat_loaded_size = 0; |
| 111 | size_t oat_data_offset = 0; |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 112 | compiler_driver.GetOatElfInformation(oat_file.get(), oat_loaded_size, oat_data_offset); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 113 | CalculateNewObjectOffsets(oat_loaded_size, oat_data_offset); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 114 | CopyAndFixupObjects(); |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 115 | PatchOatCodeAndMethods(compiler_driver); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 116 | Thread::Current()->TransitionFromRunnableToSuspended(kNative); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 117 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 118 | UniquePtr<File> image_file(OS::OpenFile(image_filename.c_str(), true)); |
| 119 | if (image_file.get() == NULL) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 120 | LOG(ERROR) << "Failed to open image file " << image_filename; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 121 | return false; |
| 122 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 123 | if (fchmod(image_file->Fd(), 0644) != 0) { |
Brian Carlstrom | 6cd40e5 | 2012-05-03 14:15:11 -0700 | [diff] [blame] | 124 | PLOG(ERROR) << "Failed to make image file world readable: " << image_filename; |
| 125 | return EXIT_FAILURE; |
| 126 | } |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 127 | bool success = image_file->WriteFully(image_->Begin(), image_end_); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 128 | if (!success) { |
| 129 | PLOG(ERROR) << "Failed to write image file " << image_filename; |
| 130 | return false; |
| 131 | } |
| 132 | return true; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 135 | bool ImageWriter::AllocMemory() { |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 136 | const Spaces& spaces = Runtime::Current()->GetHeap()->GetSpaces(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 137 | size_t size = 0; |
Mathieu Chartier | 2fde533 | 2012-09-14 14:51:54 -0700 | [diff] [blame] | 138 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
| 139 | if ((*it)->IsAllocSpace()) { |
| 140 | size += (*it)->Size(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 144 | int prot = PROT_READ | PROT_WRITE; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 145 | size_t length = RoundUp(size, kPageSize); |
Ian Rogers | a40307e | 2013-02-22 11:32:44 -0800 | [diff] [blame] | 146 | image_.reset(MemMap::MapAnonymous("image writer image", NULL, length, prot)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 147 | if (image_.get() == NULL) { |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 148 | LOG(ERROR) << "Failed to allocate memory for image file generation"; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | return true; |
| 152 | } |
| 153 | |
Ian Rogers | d418eda | 2012-01-30 12:14:28 -0800 | [diff] [blame] | 154 | void ImageWriter::ComputeLazyFieldsForImageClasses() { |
| 155 | Runtime* runtime = Runtime::Current(); |
| 156 | ClassLinker* class_linker = runtime->GetClassLinker(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 157 | class_linker->VisitClassesWithoutClassesLock(ComputeLazyFieldsForClassesVisitor, NULL); |
Ian Rogers | d418eda | 2012-01-30 12:14:28 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Elliott Hughes | 1bac54f | 2012-03-16 12:48:31 -0700 | [diff] [blame] | 160 | bool ImageWriter::ComputeLazyFieldsForClassesVisitor(Class* c, void* /*arg*/) { |
| 161 | c->ComputeName(); |
Ian Rogers | d418eda | 2012-01-30 12:14:28 -0800 | [diff] [blame] | 162 | return true; |
| 163 | } |
| 164 | |
Ian Rogers | d1f1bf0 | 2012-02-26 16:59:20 -0800 | [diff] [blame] | 165 | void ImageWriter::ComputeEagerResolvedStringsCallback(Object* obj, void* arg) { |
| 166 | if (!obj->GetClass()->IsStringClass()) { |
| 167 | return; |
| 168 | } |
| 169 | String* string = obj->AsString(); |
| 170 | std::string utf8_string(string->ToModifiedUtf8()); |
| 171 | ImageWriter* writer = reinterpret_cast<ImageWriter*>(arg); |
Ian Rogers | d1f1bf0 | 2012-02-26 16:59:20 -0800 | [diff] [blame] | 172 | typedef Set::const_iterator CacheIt; // TODO: C++0x auto |
| 173 | for (CacheIt it = writer->dex_caches_.begin(), end = writer->dex_caches_.end(); it != end; ++it) { |
| 174 | DexCache* dex_cache = *it; |
Ian Rogers | 4445a7e | 2012-10-05 17:19:13 -0700 | [diff] [blame] | 175 | const DexFile& dex_file = *dex_cache->GetDexFile(); |
Ian Rogers | d1f1bf0 | 2012-02-26 16:59:20 -0800 | [diff] [blame] | 176 | const DexFile::StringId* string_id = dex_file.FindStringId(utf8_string); |
| 177 | if (string_id != NULL) { |
| 178 | // This string occurs in this dex file, assign the dex cache entry. |
| 179 | uint32_t string_idx = dex_file.GetIndexForStringId(*string_id); |
| 180 | if (dex_cache->GetResolvedString(string_idx) == NULL) { |
| 181 | dex_cache->SetResolvedString(string_idx, string); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 187 | void ImageWriter::ComputeEagerResolvedStrings() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 188 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 189 | // TODO: Check image spaces only? |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 190 | Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 191 | WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 192 | heap->FlushAllocStack(); |
| 193 | heap->GetLiveBitmap()->Walk(ComputeEagerResolvedStringsCallback, this); |
Ian Rogers | d1f1bf0 | 2012-02-26 16:59:20 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 196 | bool ImageWriter::IsImageClass(const Class* klass) { |
| 197 | if (image_classes_ == NULL) { |
| 198 | return true; |
| 199 | } |
| 200 | while (klass->IsArrayClass()) { |
| 201 | klass = klass->GetComponentType(); |
| 202 | } |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 203 | if (klass->IsPrimitive()) { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 204 | return true; |
| 205 | } |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 206 | const std::string descriptor(ClassHelper(klass).GetDescriptor()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 207 | return image_classes_->find(descriptor) != image_classes_->end(); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | struct NonImageClasses { |
| 212 | ImageWriter* image_writer; |
| 213 | std::set<std::string>* non_image_classes; |
| 214 | }; |
| 215 | |
| 216 | void ImageWriter::PruneNonImageClasses() { |
| 217 | if (image_classes_ == NULL) { |
| 218 | return; |
| 219 | } |
| 220 | Runtime* runtime = Runtime::Current(); |
| 221 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 222 | |
| 223 | std::set<std::string> non_image_classes; |
| 224 | NonImageClasses context; |
| 225 | context.image_writer = this; |
| 226 | context.non_image_classes = &non_image_classes; |
| 227 | class_linker->VisitClasses(NonImageClassesVisitor, &context); |
| 228 | |
| 229 | typedef std::set<std::string>::const_iterator ClassIt; // TODO: C++0x auto |
| 230 | for (ClassIt it = non_image_classes.begin(), end = non_image_classes.end(); it != end; ++it) { |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 231 | class_linker->RemoveClass((*it).c_str(), NULL); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 234 | AbstractMethod* resolution_method = runtime->GetResolutionMethod(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 235 | typedef Set::const_iterator CacheIt; // TODO: C++0x auto |
| 236 | for (CacheIt it = dex_caches_.begin(), end = dex_caches_.end(); it != end; ++it) { |
| 237 | DexCache* dex_cache = *it; |
| 238 | for (size_t i = 0; i < dex_cache->NumResolvedTypes(); i++) { |
| 239 | Class* klass = dex_cache->GetResolvedType(i); |
| 240 | if (klass != NULL && !IsImageClass(klass)) { |
| 241 | dex_cache->SetResolvedType(i, NULL); |
| 242 | dex_cache->GetInitializedStaticStorage()->Set(i, NULL); |
| 243 | } |
| 244 | } |
| 245 | for (size_t i = 0; i < dex_cache->NumResolvedMethods(); i++) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 246 | AbstractMethod* method = dex_cache->GetResolvedMethod(i); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 247 | if (method != NULL && !IsImageClass(method->GetDeclaringClass())) { |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 248 | dex_cache->SetResolvedMethod(i, resolution_method); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | for (size_t i = 0; i < dex_cache->NumResolvedFields(); i++) { |
| 252 | Field* field = dex_cache->GetResolvedField(i); |
| 253 | if (field != NULL && !IsImageClass(field->GetDeclaringClass())) { |
| 254 | dex_cache->SetResolvedField(i, NULL); |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | bool ImageWriter::NonImageClassesVisitor(Class* klass, void* arg) { |
| 261 | NonImageClasses* context = reinterpret_cast<NonImageClasses*>(arg); |
| 262 | if (!context->image_writer->IsImageClass(klass)) { |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 263 | context->non_image_classes->insert(ClassHelper(klass).GetDescriptor()); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 264 | } |
| 265 | return true; |
| 266 | } |
| 267 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 268 | void ImageWriter::CheckNonImageClassesRemoved() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 269 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 270 | if (image_classes_ == NULL) { |
| 271 | return; |
| 272 | } |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 273 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 274 | Heap* heap = Runtime::Current()->GetHeap(); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 275 | Thread* self = Thread::Current(); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 276 | { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 277 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 278 | heap->FlushAllocStack(); |
| 279 | } |
| 280 | |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 281 | ReaderMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 282 | heap->GetLiveBitmap()->Walk(CheckNonImageClassesRemovedCallback, this); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void ImageWriter::CheckNonImageClassesRemovedCallback(Object* obj, void* arg) { |
| 286 | ImageWriter* image_writer = reinterpret_cast<ImageWriter*>(arg); |
| 287 | if (!obj->IsClass()) { |
| 288 | return; |
| 289 | } |
| 290 | Class* klass = obj->AsClass(); |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 291 | if (!image_writer->IsImageClass(klass)) { |
| 292 | image_writer->DumpImageClasses(); |
| 293 | CHECK(image_writer->IsImageClass(klass)) << ClassHelper(klass).GetDescriptor() |
| 294 | << " " << PrettyDescriptor(klass); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | void ImageWriter::DumpImageClasses() { |
| 299 | typedef std::set<std::string>::const_iterator It; // TODO: C++0x auto |
| 300 | for (It it = image_classes_->begin(), end = image_classes_->end(); it != end; ++it) { |
| 301 | LOG(INFO) << " " << *it; |
| 302 | } |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 305 | void ImageWriter::CalculateNewObjectOffsetsCallback(Object* obj, void* arg) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 306 | DCHECK(obj != NULL); |
| 307 | DCHECK(arg != NULL); |
| 308 | ImageWriter* image_writer = reinterpret_cast<ImageWriter*>(arg); |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 309 | |
| 310 | // if it is a string, we want to intern it if its not interned. |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 311 | if (obj->GetClass()->IsStringClass()) { |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 312 | // we must be an interned string that was forward referenced and already assigned |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 313 | if (image_writer->IsImageOffsetAssigned(obj)) { |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 314 | DCHECK_EQ(obj, obj->AsString()->Intern()); |
| 315 | return; |
| 316 | } |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 317 | SirtRef<String> interned(Thread::Current(), obj->AsString()->Intern()); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 318 | if (obj != interned.get()) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 319 | if (!image_writer->IsImageOffsetAssigned(interned.get())) { |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 320 | // interned obj is after us, allocate its location early |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 321 | image_writer->AssignImageOffset(interned.get()); |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 322 | } |
| 323 | // point those looking for this object to the interned version. |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 324 | image_writer->SetImageOffset(obj, image_writer->GetImageOffset(interned.get())); |
Brian Carlstrom | c74255f | 2011-09-11 22:47:39 -0700 | [diff] [blame] | 325 | return; |
| 326 | } |
| 327 | // else (obj == interned), nothing to do but fall through to the normal case |
| 328 | } |
| 329 | |
| 330 | image_writer->AssignImageOffset(obj); |
Brian Carlstrom | 4e777d4 | 2011-08-15 13:53:52 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 333 | ObjectArray<Object>* ImageWriter::CreateImageRoots() const { |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 334 | Runtime* runtime = Runtime::Current(); |
| 335 | ClassLinker* class_linker = runtime->GetClassLinker(); |
| 336 | Class* object_array_class = class_linker->FindSystemClass("[Ljava/lang/Object;"); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 337 | Thread* self = Thread::Current(); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 338 | |
| 339 | // build an Object[] of all the DexCaches used in the source_space_ |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 340 | ObjectArray<Object>* dex_caches = ObjectArray<Object>::Alloc(self, object_array_class, |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 341 | dex_caches_.size()); |
| 342 | int i = 0; |
| 343 | typedef Set::const_iterator It; // TODO: C++0x auto |
| 344 | for (It it = dex_caches_.begin(), end = dex_caches_.end(); it != end; ++it, ++i) { |
| 345 | dex_caches->Set(i, *it); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | // build an Object[] of the roots needed to restore the runtime |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 349 | SirtRef<ObjectArray<Object> > |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 350 | image_roots(self, |
| 351 | ObjectArray<Object>::Alloc(self, object_array_class, |
| 352 | ImageHeader::kImageRootsMax)); |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 353 | image_roots->Set(ImageHeader::kJniStubArray, runtime->GetJniDlsymLookupStub()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 354 | image_roots->Set(ImageHeader::kAbstractMethodErrorStubArray, |
| 355 | runtime->GetAbstractMethodErrorStubArray()); |
Ian Rogers | 1cb0a1d | 2011-10-06 15:24:35 -0700 | [diff] [blame] | 356 | image_roots->Set(ImageHeader::kStaticResolutionStubArray, |
| 357 | runtime->GetResolutionStubArray(Runtime::kStaticMethod)); |
| 358 | image_roots->Set(ImageHeader::kUnknownMethodResolutionStubArray, |
| 359 | runtime->GetResolutionStubArray(Runtime::kUnknownMethod)); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 360 | image_roots->Set(ImageHeader::kResolutionMethod, runtime->GetResolutionMethod()); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 361 | image_roots->Set(ImageHeader::kCalleeSaveMethod, |
| 362 | runtime->GetCalleeSaveMethod(Runtime::kSaveAll)); |
| 363 | image_roots->Set(ImageHeader::kRefsOnlySaveMethod, |
| 364 | runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)); |
| 365 | image_roots->Set(ImageHeader::kRefsAndArgsSaveMethod, |
| 366 | runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 367 | image_roots->Set(ImageHeader::kOatLocation, |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 368 | String::AllocFromModifiedUtf8(self, oat_file_->GetLocation().c_str())); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 369 | image_roots->Set(ImageHeader::kDexCaches, |
| 370 | dex_caches); |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 371 | image_roots->Set(ImageHeader::kClassRoots, |
| 372 | class_linker->GetClassRoots()); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 373 | for (int i = 0; i < ImageHeader::kImageRootsMax; i++) { |
| 374 | CHECK(image_roots->Get(i) != NULL); |
| 375 | } |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 376 | return image_roots.get(); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 379 | void ImageWriter::CalculateNewObjectOffsets(size_t oat_loaded_size, size_t oat_data_offset) { |
| 380 | CHECK_NE(0U, oat_loaded_size); |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 381 | Thread* self = Thread::Current(); |
| 382 | SirtRef<ObjectArray<Object> > image_roots(self, CreateImageRoots()); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 383 | |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 384 | Heap* heap = Runtime::Current()->GetHeap(); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 385 | const Spaces& spaces = heap->GetSpaces(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 386 | DCHECK(!spaces.empty()); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 387 | DCHECK_EQ(0U, image_end_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 388 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 389 | // leave space for the header, but do not write it yet, we need to |
| 390 | // know where image_roots is going to end up |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 391 | image_end_ += RoundUp(sizeof(ImageHeader), 8); // 64-bit-alignment |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 392 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 393 | { |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 394 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 395 | heap->FlushAllocStack(); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 396 | // TODO: Image spaces only? |
| 397 | // TODO: Add InOrderWalk to heap bitmap. |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 398 | const char* old = self->StartAssertNoThreadSuspension("ImageWriter"); |
Mathieu Chartier | e0f0cb3 | 2012-08-28 11:26:00 -0700 | [diff] [blame] | 399 | DCHECK(heap->GetLargeObjectsSpace()->GetLiveObjects()->IsEmpty()); |
| 400 | for (Spaces::const_iterator it = spaces.begin(); it != spaces.end(); ++it) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 401 | (*it)->GetLiveBitmap()->InOrderWalk(CalculateNewObjectOffsetsCallback, this); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 402 | DCHECK_LT(image_end_, image_->Size()); |
| 403 | } |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 404 | self->EndAssertNoThreadSuspension(old); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 405 | } |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 406 | |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 407 | const byte* oat_file_begin = image_begin_ + RoundUp(image_end_, kPageSize); |
| 408 | const byte* oat_file_end = oat_file_begin + oat_loaded_size; |
| 409 | oat_data_begin_ = oat_file_begin + oat_data_offset; |
| 410 | const byte* oat_data_end = oat_data_begin_ + oat_file_->Size(); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 411 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 412 | // return to write header at start of image with future location of image_roots |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 413 | ImageHeader image_header(reinterpret_cast<uint32_t>(image_begin_), |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 414 | reinterpret_cast<uint32_t>(GetImageAddress(image_roots.get())), |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 415 | oat_file_->GetOatHeader().GetChecksum(), |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 416 | reinterpret_cast<uint32_t>(oat_file_begin), |
| 417 | reinterpret_cast<uint32_t>(oat_data_begin_), |
| 418 | reinterpret_cast<uint32_t>(oat_data_end), |
| 419 | reinterpret_cast<uint32_t>(oat_file_end)); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 420 | memcpy(image_->Begin(), &image_header, sizeof(image_header)); |
Brian Carlstrom | 700c8d3 | 2012-11-05 10:42:02 -0800 | [diff] [blame] | 421 | |
| 422 | // Note that image_end_ is left at end of used space |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 425 | void ImageWriter::CopyAndFixupObjects() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 426 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 427 | Thread* self = Thread::Current(); |
| 428 | const char* old_cause = self->StartAssertNoThreadSuspension("ImageWriter"); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 429 | Heap* heap = Runtime::Current()->GetHeap(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 430 | // TODO: heap validation can't handle this fix up pass |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 431 | heap->DisableObjectValidation(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 432 | // TODO: Image spaces only? |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 433 | WriterMutexLock mu(self, *Locks::heap_bitmap_lock_); |
Mathieu Chartier | 357e9be | 2012-08-01 11:00:14 -0700 | [diff] [blame] | 434 | heap->FlushAllocStack(); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 435 | heap->GetLiveBitmap()->Walk(CopyAndFixupObjectsCallback, this); |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 436 | self->EndAssertNoThreadSuspension(old_cause); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 439 | void ImageWriter::CopyAndFixupObjectsCallback(Object* object, void* arg) { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 440 | DCHECK(object != NULL); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 441 | DCHECK(arg != NULL); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 442 | const Object* obj = object; |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 443 | ImageWriter* image_writer = reinterpret_cast<ImageWriter*>(arg); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 444 | |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 445 | // see GetLocalAddress for similar computation |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 446 | size_t offset = image_writer->GetImageOffset(obj); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 447 | byte* dst = image_writer->image_->Begin() + offset; |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 448 | const byte* src = reinterpret_cast<const byte*>(obj); |
Elliott Hughes | 04b63fd | 2011-08-16 09:40:10 -0700 | [diff] [blame] | 449 | size_t n = obj->SizeOf(); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 450 | DCHECK_LT(offset + n, image_writer->image_->Size()); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 451 | memcpy(dst, src, n); |
| 452 | Object* copy = reinterpret_cast<Object*>(dst); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 453 | copy->SetField32(Object::MonitorOffset(), 0, false); // We may have inflated the lock during compilation. |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 454 | image_writer->FixupObject(obj, copy); |
| 455 | } |
| 456 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 457 | void ImageWriter::FixupObject(const Object* orig, Object* copy) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 458 | DCHECK(orig != NULL); |
| 459 | DCHECK(copy != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 460 | copy->SetClass(down_cast<Class*>(GetImageAddress(orig->GetClass()))); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 461 | // TODO: special case init of pointers to malloc data (or removal of these pointers) |
| 462 | if (orig->IsClass()) { |
| 463 | FixupClass(orig->AsClass(), down_cast<Class*>(copy)); |
| 464 | } else if (orig->IsObjectArray()) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 465 | FixupObjectArray(orig->AsObjectArray<Object>(), down_cast<ObjectArray<Object>*>(copy)); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 466 | } else if (orig->IsMethod()) { |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 467 | FixupMethod(orig->AsMethod(), down_cast<AbstractMethod*>(copy)); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 468 | } else { |
| 469 | FixupInstanceFields(orig, copy); |
| 470 | } |
| 471 | } |
| 472 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 473 | void ImageWriter::FixupClass(const Class* orig, Class* copy) { |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 474 | FixupInstanceFields(orig, copy); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 475 | FixupStaticFields(orig, copy); |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 478 | void ImageWriter::FixupMethod(const AbstractMethod* orig, AbstractMethod* copy) { |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 479 | FixupInstanceFields(orig, copy); |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 480 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 481 | // OatWriter replaces the code_ and invoke_stub_ with offset values. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 482 | // Here we readjust to a pointer relative to oat_begin_ |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 483 | |
| 484 | // Every type of method can have an invoke stub |
| 485 | uint32_t invoke_stub_offset = orig->GetOatInvokeStubOffset(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 486 | const byte* invoke_stub = GetOatAddress(invoke_stub_offset); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 487 | copy->SetInvokeStub(reinterpret_cast<AbstractMethod::InvokeStub*>(const_cast<byte*>(invoke_stub))); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 488 | |
| 489 | if (orig->IsAbstract()) { |
| 490 | // Abstract methods are pointed to a stub that will throw AbstractMethodError if they are called |
| 491 | ByteArray* orig_ame_stub_array_ = Runtime::Current()->GetAbstractMethodErrorStubArray(); |
| 492 | ByteArray* copy_ame_stub_array_ = down_cast<ByteArray*>(GetImageAddress(orig_ame_stub_array_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 493 | copy->SetCode(copy_ame_stub_array_->GetData()); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 494 | return; |
| 495 | } |
| 496 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 497 | if (orig == Runtime::Current()->GetResolutionMethod()) { |
| 498 | // The resolution stub's code points at the unknown resolution trampoline |
| 499 | ByteArray* orig_res_stub_array_ = |
| 500 | Runtime::Current()->GetResolutionStubArray(Runtime::kUnknownMethod); |
| 501 | CHECK(orig->GetCode() == orig_res_stub_array_->GetData()); |
| 502 | ByteArray* copy_res_stub_array_ = down_cast<ByteArray*>(GetImageAddress(orig_res_stub_array_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 503 | copy->SetCode(copy_res_stub_array_->GetData()); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 504 | return; |
| 505 | } |
| 506 | |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 507 | // Non-abstract methods typically have code |
| 508 | uint32_t code_offset = orig->GetOatCodeOffset(); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 509 | const byte* code = NULL; |
| 510 | if (orig->IsStatic()) { |
| 511 | // Static methods may point at the resolution trampoline stub |
| 512 | ByteArray* orig_res_stub_array_ = |
| 513 | Runtime::Current()->GetResolutionStubArray(Runtime::kStaticMethod); |
| 514 | if (reinterpret_cast<int8_t*>(code_offset) == orig_res_stub_array_->GetData()) { |
| 515 | ByteArray* copy_res_stub_array_ = down_cast<ByteArray*>(GetImageAddress(orig_res_stub_array_)); |
| 516 | code = reinterpret_cast<const byte*>(copy_res_stub_array_->GetData()); |
| 517 | } |
| 518 | } |
| 519 | if (code == NULL) { |
| 520 | code = GetOatAddress(code_offset); |
| 521 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 522 | copy->SetCode(code); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 523 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 524 | if (orig->IsNative()) { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 525 | // The native method's pointer is directed to a stub to lookup via dlsym. |
| 526 | // Note this is not the code_ pointer, that is handled above. |
Ian Rogers | 169c9a7 | 2011-11-13 20:13:17 -0800 | [diff] [blame] | 527 | ByteArray* orig_jni_stub_array_ = Runtime::Current()->GetJniDlsymLookupStub(); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 528 | ByteArray* copy_jni_stub_array_ = down_cast<ByteArray*>(GetImageAddress(orig_jni_stub_array_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 529 | copy->SetNativeMethod(copy_jni_stub_array_->GetData()); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 530 | } else { |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 531 | // normal (non-abstract non-native) methods have mapping tables to relocate |
| 532 | uint32_t mapping_table_off = orig->GetOatMappingTableOffset(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 533 | const byte* mapping_table = GetOatAddress(mapping_table_off); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 534 | copy->SetMappingTable(reinterpret_cast<const uint32_t*>(mapping_table)); |
Brian Carlstrom | 3320cf4 | 2011-10-04 14:58:28 -0700 | [diff] [blame] | 535 | |
| 536 | uint32_t vmap_table_offset = orig->GetOatVmapTableOffset(); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 537 | const byte* vmap_table = GetOatAddress(vmap_table_offset); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 538 | copy->SetVmapTable(reinterpret_cast<const uint16_t*>(vmap_table)); |
Brian Carlstrom | e7d856b | 2012-01-11 18:10:55 -0800 | [diff] [blame] | 539 | |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 540 | uint32_t native_gc_map_offset = orig->GetOatNativeGcMapOffset(); |
| 541 | const byte* native_gc_map = GetOatAddress(native_gc_map_offset); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 542 | copy->SetNativeGcMap(reinterpret_cast<const uint8_t*>(native_gc_map)); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 543 | } |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 546 | void ImageWriter::FixupObjectArray(const ObjectArray<Object>* orig, ObjectArray<Object>* copy) { |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 547 | for (int32_t i = 0; i < orig->GetLength(); ++i) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 548 | const Object* element = orig->Get(i); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 549 | copy->SetPtrWithoutChecks(i, GetImageAddress(element)); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 553 | void ImageWriter::FixupInstanceFields(const Object* orig, Object* copy) { |
| 554 | DCHECK(orig != NULL); |
| 555 | DCHECK(copy != NULL); |
| 556 | Class* klass = orig->GetClass(); |
| 557 | DCHECK(klass != NULL); |
| 558 | FixupFields(orig, |
| 559 | copy, |
| 560 | klass->GetReferenceInstanceOffsets(), |
| 561 | false); |
| 562 | } |
| 563 | |
| 564 | void ImageWriter::FixupStaticFields(const Class* orig, Class* copy) { |
| 565 | DCHECK(orig != NULL); |
| 566 | DCHECK(copy != NULL); |
| 567 | FixupFields(orig, |
| 568 | copy, |
| 569 | orig->GetReferenceStaticOffsets(), |
| 570 | true); |
| 571 | } |
| 572 | |
| 573 | void ImageWriter::FixupFields(const Object* orig, |
| 574 | Object* copy, |
| 575 | uint32_t ref_offsets, |
| 576 | bool is_static) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 577 | if (ref_offsets != CLASS_WALK_SUPER) { |
| 578 | // Found a reference offset bitmap. Fixup the specified offsets. |
| 579 | while (ref_offsets != 0) { |
| 580 | size_t right_shift = CLZ(ref_offsets); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 581 | MemberOffset byte_offset = CLASS_OFFSET_FROM_CLZ(right_shift); |
| 582 | const Object* ref = orig->GetFieldObject<const Object*>(byte_offset, false); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 583 | // Use SetFieldPtr to avoid card marking since we are writing to the image. |
| 584 | copy->SetFieldPtr(byte_offset, GetImageAddress(ref), false); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 585 | ref_offsets &= ~(CLASS_HIGH_BIT >> right_shift); |
| 586 | } |
| 587 | } else { |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 588 | // There is no reference offset bitmap. In the non-static case, |
| 589 | // walk up the class inheritance hierarchy and find reference |
| 590 | // offsets the hard way. In the static case, just consider this |
| 591 | // class. |
| 592 | for (const Class *klass = is_static ? orig->AsClass() : orig->GetClass(); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 593 | klass != NULL; |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 594 | klass = is_static ? NULL : klass->GetSuperClass()) { |
| 595 | size_t num_reference_fields = (is_static |
| 596 | ? klass->NumReferenceStaticFields() |
| 597 | : klass->NumReferenceInstanceFields()); |
| 598 | for (size_t i = 0; i < num_reference_fields; ++i) { |
| 599 | Field* field = (is_static |
| 600 | ? klass->GetStaticField(i) |
| 601 | : klass->GetInstanceField(i)); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 602 | MemberOffset field_offset = field->GetOffset(); |
| 603 | const Object* ref = orig->GetFieldObject<const Object*>(field_offset, false); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 604 | // Use SetFieldPtr to avoid card marking since we are writing to the image. |
| 605 | copy->SetFieldPtr(field_offset, GetImageAddress(ref), false); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | } |
Ian Rogers | 64b6d14 | 2012-10-29 16:34:15 -0700 | [diff] [blame] | 609 | if (!is_static && orig->IsReferenceInstance()) { |
| 610 | // Fix-up referent, that isn't marked as an object field, for References. |
| 611 | Field* field = orig->GetClass()->FindInstanceField("referent", "Ljava/lang/Object;"); |
| 612 | MemberOffset field_offset = field->GetOffset(); |
| 613 | const Object* ref = orig->GetFieldObject<const Object*>(field_offset, false); |
| 614 | // Use SetFieldPtr to avoid card marking since we are writing to the image. |
| 615 | copy->SetFieldPtr(field_offset, GetImageAddress(ref), false); |
| 616 | } |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 619 | static AbstractMethod* GetTargetMethod(const CompilerDriver::PatchInformation* patch) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 620 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 621 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 622 | DexCache* dex_cache = class_linker->FindDexCache(patch->GetDexFile()); |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 623 | AbstractMethod* method = class_linker->ResolveMethod(patch->GetDexFile(), |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 624 | patch->GetTargetMethodIdx(), |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 625 | dex_cache, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 626 | NULL, |
jeffhao | c0228b8 | 2012-08-29 18:15:05 -0700 | [diff] [blame] | 627 | NULL, |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 628 | patch->GetTargetInvokeType()); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 629 | CHECK(method != NULL) |
| 630 | << patch->GetDexFile().GetLocation() << " " << patch->GetTargetMethodIdx(); |
Brian Carlstrom | 0637e27 | 2012-03-20 01:07:52 -0700 | [diff] [blame] | 631 | CHECK(!method->IsRuntimeMethod()) |
| 632 | << patch->GetDexFile().GetLocation() << " " << patch->GetTargetMethodIdx(); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 633 | CHECK(dex_cache->GetResolvedMethods()->Get(patch->GetTargetMethodIdx()) == method) |
Brian Carlstrom | 0637e27 | 2012-03-20 01:07:52 -0700 | [diff] [blame] | 634 | << patch->GetDexFile().GetLocation() << " " << patch->GetReferrerMethodIdx() << " " |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 635 | << PrettyMethod(dex_cache->GetResolvedMethods()->Get(patch->GetTargetMethodIdx())) << " " |
Brian Carlstrom | 0637e27 | 2012-03-20 01:07:52 -0700 | [diff] [blame] | 636 | << PrettyMethod(method); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 637 | return method; |
| 638 | } |
| 639 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 640 | void ImageWriter::PatchOatCodeAndMethods(const CompilerDriver& compiler) { |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 641 | Thread* self = Thread::Current(); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 642 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 643 | const char* old_cause = self->StartAssertNoThreadSuspension("ImageWriter"); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 644 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 645 | typedef std::vector<const CompilerDriver::PatchInformation*> Patches; |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 646 | const Patches& code_to_patch = compiler.GetCodeToPatch(); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 647 | for (size_t i = 0; i < code_to_patch.size(); i++) { |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 648 | const CompilerDriver::PatchInformation* patch = code_to_patch[i]; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 649 | AbstractMethod* target = GetTargetMethod(patch); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 650 | uint32_t code = reinterpret_cast<uint32_t>(class_linker->GetOatCodeFor(target)); |
| 651 | uint32_t code_base = reinterpret_cast<uint32_t>(&oat_file_->GetOatHeader()); |
| 652 | uint32_t code_offset = code - code_base; |
| 653 | SetPatchLocation(patch, reinterpret_cast<uint32_t>(GetOatAddress(code_offset))); |
| 654 | } |
| 655 | |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 656 | const Patches& methods_to_patch = compiler.GetMethodsToPatch(); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 657 | for (size_t i = 0; i < methods_to_patch.size(); i++) { |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 658 | const CompilerDriver::PatchInformation* patch = methods_to_patch[i]; |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 659 | AbstractMethod* target = GetTargetMethod(patch); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 660 | SetPatchLocation(patch, reinterpret_cast<uint32_t>(GetImageAddress(target))); |
| 661 | } |
Brian Carlstrom | a85b837 | 2012-10-18 17:00:32 -0700 | [diff] [blame] | 662 | |
| 663 | // Update the image header with the new checksum after patching |
| 664 | ImageHeader* image_header = reinterpret_cast<ImageHeader*>(image_->Begin()); |
| 665 | image_header->SetOatChecksum(oat_file_->GetOatHeader().GetChecksum()); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 666 | self->EndAssertNoThreadSuspension(old_cause); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 669 | void ImageWriter::SetPatchLocation(const CompilerDriver::PatchInformation* patch, uint32_t value) { |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 670 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 671 | const void* oat_code = class_linker->GetOatCodeFor(patch->GetDexFile(), |
| 672 | patch->GetReferrerMethodIdx()); |
Brian Carlstrom | a85b837 | 2012-10-18 17:00:32 -0700 | [diff] [blame] | 673 | OatHeader& oat_header = const_cast<OatHeader&>(oat_file_->GetOatHeader()); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 674 | // TODO: make this Thumb2 specific |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 675 | uint8_t* base = reinterpret_cast<uint8_t*>(reinterpret_cast<uint32_t>(oat_code) & ~0x1); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 676 | uint32_t* patch_location = reinterpret_cast<uint32_t*>(base + patch->GetLiteralOffset()); |
| 677 | #ifndef NDEBUG |
| 678 | const DexFile::MethodId& id = patch->GetDexFile().GetMethodId(patch->GetTargetMethodIdx()); |
| 679 | uint32_t expected = reinterpret_cast<uint32_t>(&id); |
| 680 | uint32_t actual = *patch_location; |
| 681 | CHECK(actual == expected || actual == value) << std::hex |
| 682 | << "actual=" << actual |
| 683 | << "expected=" << expected |
| 684 | << "value=" << value; |
| 685 | #endif |
Elliott Hughes | b25c3f6 | 2012-03-26 16:35:06 -0700 | [diff] [blame] | 686 | *patch_location = value; |
Brian Carlstrom | a85b837 | 2012-10-18 17:00:32 -0700 | [diff] [blame] | 687 | oat_header.UpdateChecksum(patch_location, sizeof(value)); |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 690 | } // namespace art |