Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -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 | |
| 17 | #include "image_space.h" |
| 18 | |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 19 | #include <dirent.h> |
Andreas Gampe | 70be1fb | 2014-10-31 16:45:19 -0700 | [diff] [blame] | 20 | #include <sys/statvfs.h> |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 22 | #include <unistd.h> |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 23 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 24 | #include <random> |
| 25 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 26 | #include "art_method.h" |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 27 | #include "base/macros.h" |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 28 | #include "base/stl_util.h" |
Narayan Kamath | d1c606f | 2014-06-09 16:50:19 +0100 | [diff] [blame] | 29 | #include "base/scoped_flock.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 30 | #include "base/time_utils.h" |
| 31 | #include "base/unix_file/fd_file.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 32 | #include "gc/accounting/space_bitmap-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 33 | #include "mirror/class-inl.h" |
| 34 | #include "mirror/object-inl.h" |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 35 | #include "oat_file.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 36 | #include "os.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 37 | #include "space-inl.h" |
| 38 | #include "utils.h" |
| 39 | |
| 40 | namespace art { |
| 41 | namespace gc { |
| 42 | namespace space { |
| 43 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 44 | Atomic<uint32_t> ImageSpace::bitmap_index_(0); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 45 | |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 46 | ImageSpace::ImageSpace(const std::string& image_filename, const char* image_location, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 47 | MemMap* mem_map, accounting::ContinuousSpaceBitmap* live_bitmap, |
| 48 | uint8_t* end) |
| 49 | : MemMapSpace(image_filename, mem_map, mem_map->Begin(), end, end, |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 50 | kGcRetentionPolicyNeverCollect), |
| 51 | image_location_(image_location) { |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 52 | DCHECK(live_bitmap != nullptr); |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 53 | live_bitmap_.reset(live_bitmap); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Alex Light | cf4bf38 | 2014-07-24 11:29:14 -0700 | [diff] [blame] | 56 | static int32_t ChooseRelocationOffsetDelta(int32_t min_delta, int32_t max_delta) { |
| 57 | CHECK_ALIGNED(min_delta, kPageSize); |
| 58 | CHECK_ALIGNED(max_delta, kPageSize); |
| 59 | CHECK_LT(min_delta, max_delta); |
| 60 | |
Alex Light | 1532476 | 2015-11-19 11:03:10 -0800 | [diff] [blame^] | 61 | int32_t r = GetRandomNumber<int32_t>(min_delta, max_delta); |
Alex Light | cf4bf38 | 2014-07-24 11:29:14 -0700 | [diff] [blame] | 62 | if (r % 2 == 0) { |
| 63 | r = RoundUp(r, kPageSize); |
| 64 | } else { |
| 65 | r = RoundDown(r, kPageSize); |
| 66 | } |
| 67 | CHECK_LE(min_delta, r); |
| 68 | CHECK_GE(max_delta, r); |
| 69 | CHECK_ALIGNED(r, kPageSize); |
| 70 | return r; |
| 71 | } |
| 72 | |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 73 | // We are relocating or generating the core image. We should get rid of everything. It is all |
Andreas Gampe | 8db9dcd | 2014-11-09 18:14:30 -0800 | [diff] [blame] | 74 | // out-of-date. We also don't really care if this fails since it is just a convenience. |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 75 | // Adapted from prune_dex_cache(const char* subdir) in frameworks/native/cmds/installd/commands.c |
| 76 | // Note this should only be used during first boot. |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 77 | static void RealPruneDalvikCache(const std::string& cache_dir_path); |
Andreas Gampe | 8db9dcd | 2014-11-09 18:14:30 -0800 | [diff] [blame] | 78 | |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 79 | static void PruneDalvikCache(InstructionSet isa) { |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 80 | CHECK_NE(isa, kNone); |
Andreas Gampe | 8db9dcd | 2014-11-09 18:14:30 -0800 | [diff] [blame] | 81 | // Prune the base /data/dalvik-cache. |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 82 | RealPruneDalvikCache(GetDalvikCacheOrDie(".", false)); |
Andreas Gampe | 8db9dcd | 2014-11-09 18:14:30 -0800 | [diff] [blame] | 83 | // Prune /data/dalvik-cache/<isa>. |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 84 | RealPruneDalvikCache(GetDalvikCacheOrDie(GetInstructionSetString(isa), false)); |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 85 | } |
Andreas Gampe | 8db9dcd | 2014-11-09 18:14:30 -0800 | [diff] [blame] | 86 | |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 87 | static void RealPruneDalvikCache(const std::string& cache_dir_path) { |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 88 | if (!OS::DirectoryExists(cache_dir_path.c_str())) { |
| 89 | return; |
| 90 | } |
| 91 | DIR* cache_dir = opendir(cache_dir_path.c_str()); |
| 92 | if (cache_dir == nullptr) { |
| 93 | PLOG(WARNING) << "Unable to open " << cache_dir_path << " to delete it's contents"; |
| 94 | return; |
| 95 | } |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 96 | |
| 97 | for (struct dirent* de = readdir(cache_dir); de != nullptr; de = readdir(cache_dir)) { |
| 98 | const char* name = de->d_name; |
| 99 | if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { |
| 100 | continue; |
| 101 | } |
Andreas Gampe | 8db9dcd | 2014-11-09 18:14:30 -0800 | [diff] [blame] | 102 | // We only want to delete regular files and symbolic links. |
| 103 | if (de->d_type != DT_REG && de->d_type != DT_LNK) { |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 104 | if (de->d_type != DT_DIR) { |
| 105 | // We do expect some directories (namely the <isa> for pruning the base dalvik-cache). |
| 106 | LOG(WARNING) << "Unexpected file type of " << std::hex << de->d_type << " encountered."; |
| 107 | } |
| 108 | continue; |
| 109 | } |
Brian Carlstrom | debdda0 | 2014-08-28 22:17:13 -0700 | [diff] [blame] | 110 | std::string cache_file(cache_dir_path); |
| 111 | cache_file += '/'; |
| 112 | cache_file += name; |
| 113 | if (TEMP_FAILURE_RETRY(unlink(cache_file.c_str())) != 0) { |
| 114 | PLOG(ERROR) << "Unable to unlink " << cache_file; |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 115 | continue; |
| 116 | } |
| 117 | } |
| 118 | CHECK_EQ(0, TEMP_FAILURE_RETRY(closedir(cache_dir))) << "Unable to close directory."; |
| 119 | } |
| 120 | |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 121 | // We write out an empty file to the zygote's ISA specific cache dir at the start of |
| 122 | // every zygote boot and delete it when the boot completes. If we find a file already |
| 123 | // present, it usually means the boot didn't complete. We wipe the entire dalvik |
| 124 | // cache if that's the case. |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 125 | static void MarkZygoteStart(const InstructionSet isa, const uint32_t max_failed_boots) { |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 126 | const std::string isa_subdir = GetDalvikCacheOrDie(GetInstructionSetString(isa), false); |
| 127 | const std::string boot_marker = isa_subdir + "/.booting"; |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 128 | const char* file_name = boot_marker.c_str(); |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 129 | |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 130 | uint32_t num_failed_boots = 0; |
| 131 | std::unique_ptr<File> file(OS::OpenFileReadWrite(file_name)); |
| 132 | if (file.get() == nullptr) { |
| 133 | file.reset(OS::CreateEmptyFile(file_name)); |
| 134 | |
| 135 | if (file.get() == nullptr) { |
| 136 | PLOG(WARNING) << "Failed to create boot marker."; |
| 137 | return; |
| 138 | } |
| 139 | } else { |
| 140 | if (!file->ReadFully(&num_failed_boots, sizeof(num_failed_boots))) { |
| 141 | PLOG(WARNING) << "Failed to read boot marker."; |
| 142 | file->Erase(); |
| 143 | return; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | if (max_failed_boots != 0 && num_failed_boots > max_failed_boots) { |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 148 | LOG(WARNING) << "Incomplete boot detected. Pruning dalvik cache"; |
| 149 | RealPruneDalvikCache(isa_subdir); |
| 150 | } |
| 151 | |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 152 | ++num_failed_boots; |
| 153 | VLOG(startup) << "Number of failed boots on : " << boot_marker << " = " << num_failed_boots; |
| 154 | |
| 155 | if (lseek(file->Fd(), 0, SEEK_SET) == -1) { |
| 156 | PLOG(WARNING) << "Failed to write boot marker."; |
| 157 | file->Erase(); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | if (!file->WriteFully(&num_failed_boots, sizeof(num_failed_boots))) { |
| 162 | PLOG(WARNING) << "Failed to write boot marker."; |
| 163 | file->Erase(); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | if (file->FlushCloseOrErase() != 0) { |
| 168 | PLOG(WARNING) << "Failed to flush boot marker."; |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 172 | static bool GenerateImage(const std::string& image_filename, InstructionSet image_isa, |
| 173 | std::string* error_msg) { |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 174 | const std::string boot_class_path_string(Runtime::Current()->GetBootClassPathString()); |
| 175 | std::vector<std::string> boot_class_path; |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 176 | Split(boot_class_path_string, ':', &boot_class_path); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 177 | if (boot_class_path.empty()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 178 | *error_msg = "Failed to generate image because no boot class path specified"; |
| 179 | return false; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 180 | } |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 181 | // We should clean up so we are more likely to have room for the image. |
| 182 | if (Runtime::Current()->IsZygote()) { |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 183 | LOG(INFO) << "Pruning dalvik-cache since we are generating an image and will need to recompile"; |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 184 | PruneDalvikCache(image_isa); |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 185 | } |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 186 | |
Mathieu Chartier | 8bbc8c0 | 2013-07-31 16:27:01 -0700 | [diff] [blame] | 187 | std::vector<std::string> arg_vector; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 188 | |
Tsu Chiang Chuang | 12e6d74 | 2014-05-22 10:22:25 -0700 | [diff] [blame] | 189 | std::string dex2oat(Runtime::Current()->GetCompilerExecutable()); |
Mathieu Chartier | 08d7d44 | 2013-07-31 18:08:51 -0700 | [diff] [blame] | 190 | arg_vector.push_back(dex2oat); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 191 | |
| 192 | std::string image_option_string("--image="); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 193 | image_option_string += image_filename; |
Mathieu Chartier | 8bbc8c0 | 2013-07-31 16:27:01 -0700 | [diff] [blame] | 194 | arg_vector.push_back(image_option_string); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 195 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 196 | for (size_t i = 0; i < boot_class_path.size(); i++) { |
Mathieu Chartier | 8bbc8c0 | 2013-07-31 16:27:01 -0700 | [diff] [blame] | 197 | arg_vector.push_back(std::string("--dex-file=") + boot_class_path[i]); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | std::string oat_file_option_string("--oat-file="); |
Brian Carlstrom | 2f1e15c | 2014-10-27 16:27:06 -0700 | [diff] [blame] | 201 | oat_file_option_string += ImageHeader::GetOatLocationFromImageLocation(image_filename); |
Mathieu Chartier | 8bbc8c0 | 2013-07-31 16:27:01 -0700 | [diff] [blame] | 202 | arg_vector.push_back(oat_file_option_string); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 203 | |
Sebastien Hertz | 0de1133 | 2015-05-13 12:14:05 +0200 | [diff] [blame] | 204 | // Note: we do not generate a fully debuggable boot image so we do not pass the |
| 205 | // compiler flag --debuggable here. |
| 206 | |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 207 | Runtime::Current()->AddCurrentRuntimeFeaturesAsDex2OatArguments(&arg_vector); |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 208 | CHECK_EQ(image_isa, kRuntimeISA) |
| 209 | << "We should always be generating an image for the current isa."; |
Ian Rogers | 8afeb85 | 2014-04-02 14:55:49 -0700 | [diff] [blame] | 210 | |
Alex Light | cf4bf38 | 2014-07-24 11:29:14 -0700 | [diff] [blame] | 211 | int32_t base_offset = ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA, |
| 212 | ART_BASE_ADDRESS_MAX_DELTA); |
| 213 | LOG(INFO) << "Using an offset of 0x" << std::hex << base_offset << " from default " |
| 214 | << "art base address of 0x" << std::hex << ART_BASE_ADDRESS; |
| 215 | arg_vector.push_back(StringPrintf("--base=0x%x", ART_BASE_ADDRESS + base_offset)); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 216 | |
Brian Carlstrom | 57309db | 2014-07-30 15:13:25 -0700 | [diff] [blame] | 217 | if (!kIsTargetBuild) { |
Mathieu Chartier | 8bbc8c0 | 2013-07-31 16:27:01 -0700 | [diff] [blame] | 218 | arg_vector.push_back("--host"); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 221 | const std::vector<std::string>& compiler_options = Runtime::Current()->GetImageCompilerOptions(); |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 222 | for (size_t i = 0; i < compiler_options.size(); ++i) { |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 223 | arg_vector.push_back(compiler_options[i].c_str()); |
| 224 | } |
| 225 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 226 | std::string command_line(Join(arg_vector, ' ')); |
| 227 | LOG(INFO) << "GenerateImage: " << command_line; |
Brian Carlstrom | 6449c62 | 2014-02-10 23:48:36 -0800 | [diff] [blame] | 228 | return Exec(arg_vector, error_msg); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 231 | bool ImageSpace::FindImageFilename(const char* image_location, |
| 232 | const InstructionSet image_isa, |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 233 | std::string* system_filename, |
| 234 | bool* has_system, |
| 235 | std::string* cache_filename, |
| 236 | bool* dalvik_cache_exists, |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 237 | bool* has_cache, |
| 238 | bool* is_global_cache) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 239 | *has_system = false; |
| 240 | *has_cache = false; |
Brian Carlstrom | 0e12bdc | 2014-05-14 17:44:28 -0700 | [diff] [blame] | 241 | // image_location = /system/framework/boot.art |
| 242 | // system_image_location = /system/framework/<image_isa>/boot.art |
| 243 | std::string system_image_filename(GetSystemImageFilename(image_location, image_isa)); |
| 244 | if (OS::FileExists(system_image_filename.c_str())) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 245 | *system_filename = system_image_filename; |
| 246 | *has_system = true; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 247 | } |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 248 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 249 | bool have_android_data = false; |
| 250 | *dalvik_cache_exists = false; |
| 251 | std::string dalvik_cache; |
| 252 | GetDalvikCache(GetInstructionSetString(image_isa), true, &dalvik_cache, |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 253 | &have_android_data, dalvik_cache_exists, is_global_cache); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 254 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 255 | if (have_android_data && *dalvik_cache_exists) { |
| 256 | // Always set output location even if it does not exist, |
| 257 | // so that the caller knows where to create the image. |
| 258 | // |
| 259 | // image_location = /system/framework/boot.art |
| 260 | // *image_filename = /data/dalvik-cache/<image_isa>/boot.art |
| 261 | std::string error_msg; |
| 262 | if (!GetDalvikCacheFilename(image_location, dalvik_cache.c_str(), cache_filename, &error_msg)) { |
| 263 | LOG(WARNING) << error_msg; |
| 264 | return *has_system; |
| 265 | } |
| 266 | *has_cache = OS::FileExists(cache_filename->c_str()); |
| 267 | } |
| 268 | return *has_system || *has_cache; |
| 269 | } |
| 270 | |
| 271 | static bool ReadSpecificImageHeader(const char* filename, ImageHeader* image_header) { |
| 272 | std::unique_ptr<File> image_file(OS::OpenFileForReading(filename)); |
| 273 | if (image_file.get() == nullptr) { |
| 274 | return false; |
| 275 | } |
| 276 | const bool success = image_file->ReadFully(image_header, sizeof(ImageHeader)); |
| 277 | if (!success || !image_header->IsValid()) { |
| 278 | return false; |
| 279 | } |
| 280 | return true; |
| 281 | } |
| 282 | |
Alex Light | 6e183f2 | 2014-07-18 14:57:04 -0700 | [diff] [blame] | 283 | // Relocate the image at image_location to dest_filename and relocate it by a random amount. |
| 284 | static bool RelocateImage(const char* image_location, const char* dest_filename, |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 285 | InstructionSet isa, std::string* error_msg) { |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 286 | // We should clean up so we are more likely to have room for the image. |
| 287 | if (Runtime::Current()->IsZygote()) { |
| 288 | LOG(INFO) << "Pruning dalvik-cache since we are relocating an image and will need to recompile"; |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 289 | PruneDalvikCache(isa); |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 292 | std::string patchoat(Runtime::Current()->GetPatchoatExecutable()); |
| 293 | |
| 294 | std::string input_image_location_arg("--input-image-location="); |
| 295 | input_image_location_arg += image_location; |
| 296 | |
| 297 | std::string output_image_filename_arg("--output-image-file="); |
| 298 | output_image_filename_arg += dest_filename; |
| 299 | |
| 300 | std::string input_oat_location_arg("--input-oat-location="); |
| 301 | input_oat_location_arg += ImageHeader::GetOatLocationFromImageLocation(image_location); |
| 302 | |
| 303 | std::string output_oat_filename_arg("--output-oat-file="); |
| 304 | output_oat_filename_arg += ImageHeader::GetOatLocationFromImageLocation(dest_filename); |
| 305 | |
| 306 | std::string instruction_set_arg("--instruction-set="); |
| 307 | instruction_set_arg += GetInstructionSetString(isa); |
| 308 | |
| 309 | std::string base_offset_arg("--base-offset-delta="); |
| 310 | StringAppendF(&base_offset_arg, "%d", ChooseRelocationOffsetDelta(ART_BASE_ADDRESS_MIN_DELTA, |
| 311 | ART_BASE_ADDRESS_MAX_DELTA)); |
| 312 | |
| 313 | std::vector<std::string> argv; |
| 314 | argv.push_back(patchoat); |
| 315 | |
| 316 | argv.push_back(input_image_location_arg); |
| 317 | argv.push_back(output_image_filename_arg); |
| 318 | |
| 319 | argv.push_back(input_oat_location_arg); |
| 320 | argv.push_back(output_oat_filename_arg); |
| 321 | |
| 322 | argv.push_back(instruction_set_arg); |
| 323 | argv.push_back(base_offset_arg); |
| 324 | |
| 325 | std::string command_line(Join(argv, ' ')); |
| 326 | LOG(INFO) << "RelocateImage: " << command_line; |
| 327 | return Exec(argv, error_msg); |
| 328 | } |
| 329 | |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 330 | static ImageHeader* ReadSpecificImageHeader(const char* filename, std::string* error_msg) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 331 | std::unique_ptr<ImageHeader> hdr(new ImageHeader); |
| 332 | if (!ReadSpecificImageHeader(filename, hdr.get())) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 333 | *error_msg = StringPrintf("Unable to read image header for %s", filename); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 334 | return nullptr; |
| 335 | } |
| 336 | return hdr.release(); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | ImageHeader* ImageSpace::ReadImageHeaderOrDie(const char* image_location, |
| 340 | const InstructionSet image_isa) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 341 | std::string error_msg; |
| 342 | ImageHeader* image_header = ReadImageHeader(image_location, image_isa, &error_msg); |
| 343 | if (image_header == nullptr) { |
| 344 | LOG(FATAL) << error_msg; |
| 345 | } |
| 346 | return image_header; |
| 347 | } |
| 348 | |
| 349 | ImageHeader* ImageSpace::ReadImageHeader(const char* image_location, |
| 350 | const InstructionSet image_isa, |
| 351 | std::string* error_msg) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 352 | std::string system_filename; |
| 353 | bool has_system = false; |
| 354 | std::string cache_filename; |
| 355 | bool has_cache = false; |
| 356 | bool dalvik_cache_exists = false; |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 357 | bool is_global_cache = false; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 358 | if (FindImageFilename(image_location, image_isa, &system_filename, &has_system, |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 359 | &cache_filename, &dalvik_cache_exists, &has_cache, &is_global_cache)) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 360 | if (Runtime::Current()->ShouldRelocate()) { |
| 361 | if (has_system && has_cache) { |
| 362 | std::unique_ptr<ImageHeader> sys_hdr(new ImageHeader); |
| 363 | std::unique_ptr<ImageHeader> cache_hdr(new ImageHeader); |
| 364 | if (!ReadSpecificImageHeader(system_filename.c_str(), sys_hdr.get())) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 365 | *error_msg = StringPrintf("Unable to read image header for %s at %s", |
| 366 | image_location, system_filename.c_str()); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 367 | return nullptr; |
| 368 | } |
| 369 | if (!ReadSpecificImageHeader(cache_filename.c_str(), cache_hdr.get())) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 370 | *error_msg = StringPrintf("Unable to read image header for %s at %s", |
| 371 | image_location, cache_filename.c_str()); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 372 | return nullptr; |
| 373 | } |
| 374 | if (sys_hdr->GetOatChecksum() != cache_hdr->GetOatChecksum()) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 375 | *error_msg = StringPrintf("Unable to find a relocated version of image file %s", |
| 376 | image_location); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 377 | return nullptr; |
| 378 | } |
| 379 | return cache_hdr.release(); |
| 380 | } else if (!has_cache) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 381 | *error_msg = StringPrintf("Unable to find a relocated version of image file %s", |
| 382 | image_location); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 383 | return nullptr; |
| 384 | } else if (!has_system && has_cache) { |
| 385 | // This can probably just use the cache one. |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 386 | return ReadSpecificImageHeader(cache_filename.c_str(), error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 387 | } |
| 388 | } else { |
| 389 | // We don't want to relocate, Just pick the appropriate one if we have it and return. |
| 390 | if (has_system && has_cache) { |
| 391 | // We want the cache if the checksum matches, otherwise the system. |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 392 | std::unique_ptr<ImageHeader> system(ReadSpecificImageHeader(system_filename.c_str(), |
| 393 | error_msg)); |
| 394 | std::unique_ptr<ImageHeader> cache(ReadSpecificImageHeader(cache_filename.c_str(), |
| 395 | error_msg)); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 396 | if (system.get() == nullptr || |
| 397 | (cache.get() != nullptr && cache->GetOatChecksum() == system->GetOatChecksum())) { |
| 398 | return cache.release(); |
| 399 | } else { |
| 400 | return system.release(); |
| 401 | } |
| 402 | } else if (has_system) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 403 | return ReadSpecificImageHeader(system_filename.c_str(), error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 404 | } else if (has_cache) { |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 405 | return ReadSpecificImageHeader(cache_filename.c_str(), error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 406 | } |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 407 | } |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Brian Carlstrom | 31d8f52 | 2014-09-29 11:22:54 -0700 | [diff] [blame] | 410 | *error_msg = StringPrintf("Unable to find image file for %s", image_location); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 411 | return nullptr; |
| 412 | } |
| 413 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 414 | static bool ChecksumsMatch(const char* image_a, const char* image_b) { |
| 415 | ImageHeader hdr_a; |
| 416 | ImageHeader hdr_b; |
| 417 | return ReadSpecificImageHeader(image_a, &hdr_a) && ReadSpecificImageHeader(image_b, &hdr_b) |
| 418 | && hdr_a.GetOatChecksum() == hdr_b.GetOatChecksum(); |
| 419 | } |
| 420 | |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 421 | static bool ImageCreationAllowed(bool is_global_cache, std::string* error_msg) { |
| 422 | // Anyone can write into a "local" cache. |
| 423 | if (!is_global_cache) { |
| 424 | return true; |
| 425 | } |
| 426 | |
| 427 | // Only the zygote is allowed to create the global boot image. |
| 428 | if (Runtime::Current()->IsZygote()) { |
| 429 | return true; |
| 430 | } |
| 431 | |
| 432 | *error_msg = "Only the zygote can create the global boot image."; |
| 433 | return false; |
| 434 | } |
| 435 | |
Andreas Gampe | 70be1fb | 2014-10-31 16:45:19 -0700 | [diff] [blame] | 436 | static constexpr uint64_t kLowSpaceValue = 50 * MB; |
| 437 | static constexpr uint64_t kTmpFsSentinelValue = 384 * MB; |
| 438 | |
| 439 | // Read the free space of the cache partition and make a decision whether to keep the generated |
| 440 | // image. This is to try to mitigate situations where the system might run out of space later. |
| 441 | static bool CheckSpace(const std::string& cache_filename, std::string* error_msg) { |
| 442 | // Using statvfs vs statvfs64 because of b/18207376, and it is enough for all practical purposes. |
| 443 | struct statvfs buf; |
| 444 | |
| 445 | int res = TEMP_FAILURE_RETRY(statvfs(cache_filename.c_str(), &buf)); |
| 446 | if (res != 0) { |
| 447 | // Could not stat. Conservatively tell the system to delete the image. |
| 448 | *error_msg = "Could not stat the filesystem, assuming low-memory situation."; |
| 449 | return false; |
| 450 | } |
| 451 | |
| 452 | uint64_t fs_overall_size = buf.f_bsize * static_cast<uint64_t>(buf.f_blocks); |
| 453 | // Zygote is privileged, but other things are not. Use bavail. |
| 454 | uint64_t fs_free_size = buf.f_bsize * static_cast<uint64_t>(buf.f_bavail); |
| 455 | |
| 456 | // Take the overall size as an indicator for a tmpfs, which is being used for the decryption |
| 457 | // environment. We do not want to fail quickening the boot image there, as it is beneficial |
| 458 | // for time-to-UI. |
| 459 | if (fs_overall_size > kTmpFsSentinelValue) { |
| 460 | if (fs_free_size < kLowSpaceValue) { |
| 461 | *error_msg = StringPrintf("Low-memory situation: only %4.2f megabytes available after image" |
| 462 | " generation, need at least %" PRIu64 ".", |
| 463 | static_cast<double>(fs_free_size) / MB, |
| 464 | kLowSpaceValue / MB); |
| 465 | return false; |
| 466 | } |
| 467 | } |
| 468 | return true; |
| 469 | } |
| 470 | |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 471 | ImageSpace* ImageSpace::Create(const char* image_location, |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 472 | const InstructionSet image_isa, |
| 473 | std::string* error_msg) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 474 | std::string system_filename; |
| 475 | bool has_system = false; |
| 476 | std::string cache_filename; |
| 477 | bool has_cache = false; |
| 478 | bool dalvik_cache_exists = false; |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 479 | bool is_global_cache = true; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 480 | const bool found_image = FindImageFilename(image_location, image_isa, &system_filename, |
| 481 | &has_system, &cache_filename, &dalvik_cache_exists, |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 482 | &has_cache, &is_global_cache); |
Narayan Kamath | d1c606f | 2014-06-09 16:50:19 +0100 | [diff] [blame] | 483 | |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 484 | if (Runtime::Current()->IsZygote()) { |
Narayan Kamath | 5a2be3f | 2015-02-16 13:51:51 +0000 | [diff] [blame] | 485 | MarkZygoteStart(image_isa, Runtime::Current()->GetZygoteMaxFailedBoots()); |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 488 | ImageSpace* space; |
| 489 | bool relocate = Runtime::Current()->ShouldRelocate(); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 490 | bool can_compile = Runtime::Current()->IsImageDex2OatEnabled(); |
Narayan Kamath | d1c606f | 2014-06-09 16:50:19 +0100 | [diff] [blame] | 491 | if (found_image) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 492 | const std::string* image_filename; |
| 493 | bool is_system = false; |
| 494 | bool relocated_version_used = false; |
| 495 | if (relocate) { |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 496 | if (!dalvik_cache_exists) { |
| 497 | *error_msg = StringPrintf("Requiring relocation for image '%s' at '%s' but we do not have " |
| 498 | "any dalvik_cache to find/place it in.", |
| 499 | image_location, system_filename.c_str()); |
| 500 | return nullptr; |
| 501 | } |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 502 | if (has_system) { |
| 503 | if (has_cache && ChecksumsMatch(system_filename.c_str(), cache_filename.c_str())) { |
| 504 | // We already have a relocated version |
| 505 | image_filename = &cache_filename; |
| 506 | relocated_version_used = true; |
| 507 | } else { |
| 508 | // We cannot have a relocated version, Relocate the system one and use it. |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 509 | |
| 510 | std::string reason; |
| 511 | bool success; |
| 512 | |
| 513 | // Check whether we are allowed to relocate. |
| 514 | if (!can_compile) { |
| 515 | reason = "Image dex2oat disabled by -Xnoimage-dex2oat."; |
| 516 | success = false; |
| 517 | } else if (!ImageCreationAllowed(is_global_cache, &reason)) { |
| 518 | // Whether we can write to the cache. |
| 519 | success = false; |
| 520 | } else { |
| 521 | // Try to relocate. |
| 522 | success = RelocateImage(image_location, cache_filename.c_str(), image_isa, &reason); |
| 523 | } |
| 524 | |
| 525 | if (success) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 526 | relocated_version_used = true; |
| 527 | image_filename = &cache_filename; |
| 528 | } else { |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 529 | *error_msg = StringPrintf("Unable to relocate image '%s' from '%s' to '%s': %s", |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 530 | image_location, system_filename.c_str(), |
| 531 | cache_filename.c_str(), reason.c_str()); |
Brian Carlstrom | e9105f7 | 2014-10-28 15:53:43 -0700 | [diff] [blame] | 532 | // We failed to create files, remove any possibly garbage output. |
| 533 | // Since ImageCreationAllowed was true above, we are the zygote |
| 534 | // and therefore the only process expected to generate these for |
| 535 | // the device. |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 536 | PruneDalvikCache(image_isa); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 537 | return nullptr; |
| 538 | } |
| 539 | } |
| 540 | } else { |
| 541 | CHECK(has_cache); |
| 542 | // We can just use cache's since it should be fine. This might or might not be relocated. |
| 543 | image_filename = &cache_filename; |
| 544 | } |
| 545 | } else { |
| 546 | if (has_system && has_cache) { |
| 547 | // Check they have the same cksum. If they do use the cache. Otherwise system. |
| 548 | if (ChecksumsMatch(system_filename.c_str(), cache_filename.c_str())) { |
| 549 | image_filename = &cache_filename; |
| 550 | relocated_version_used = true; |
| 551 | } else { |
| 552 | image_filename = &system_filename; |
Alex Light | 1a76213 | 2014-07-31 09:32:13 -0700 | [diff] [blame] | 553 | is_system = true; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 554 | } |
| 555 | } else if (has_system) { |
| 556 | image_filename = &system_filename; |
Alex Light | 1a76213 | 2014-07-31 09:32:13 -0700 | [diff] [blame] | 557 | is_system = true; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 558 | } else { |
| 559 | CHECK(has_cache); |
| 560 | image_filename = &cache_filename; |
| 561 | } |
| 562 | } |
| 563 | { |
| 564 | // Note that we must not use the file descriptor associated with |
| 565 | // ScopedFlock::GetFile to Init the image file. We want the file |
| 566 | // descriptor (and the associated exclusive lock) to be released when |
| 567 | // we leave Create. |
| 568 | ScopedFlock image_lock; |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 569 | image_lock.Init(image_filename->c_str(), error_msg); |
Alex Light | b6cabc1 | 2014-08-21 09:45:00 -0700 | [diff] [blame] | 570 | VLOG(startup) << "Using image file " << image_filename->c_str() << " for image location " |
| 571 | << image_location; |
Alex Light | b93637a | 2014-07-31 10:48:46 -0700 | [diff] [blame] | 572 | // If we are in /system we can assume the image is good. We can also |
| 573 | // assume this if we are using a relocated image (i.e. image checksum |
| 574 | // matches) since this is only different by the offset. We need this to |
| 575 | // make sure that host tests continue to work. |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 576 | space = ImageSpace::Init(image_filename->c_str(), image_location, |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 577 | !(is_system || relocated_version_used), error_msg); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 578 | } |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 579 | if (space != nullptr) { |
| 580 | return space; |
| 581 | } |
| 582 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 583 | if (relocated_version_used) { |
Brian Carlstrom | e9105f7 | 2014-10-28 15:53:43 -0700 | [diff] [blame] | 584 | // Something is wrong with the relocated copy (even though checksums match). Cleanup. |
| 585 | // This can happen if the .oat is corrupt, since the above only checks the .art checksums. |
| 586 | // TODO: Check the oat file validity earlier. |
| 587 | *error_msg = StringPrintf("Attempted to use relocated version of %s at %s generated from %s " |
| 588 | "but image failed to load: %s", |
| 589 | image_location, cache_filename.c_str(), system_filename.c_str(), |
| 590 | error_msg->c_str()); |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 591 | PruneDalvikCache(image_isa); |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 592 | return nullptr; |
| 593 | } else if (is_system) { |
Brian Carlstrom | e9105f7 | 2014-10-28 15:53:43 -0700 | [diff] [blame] | 594 | // If the /system file exists, it should be up-to-date, don't try to generate it. |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 595 | *error_msg = StringPrintf("Failed to load /system image '%s': %s", |
| 596 | image_filename->c_str(), error_msg->c_str()); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 597 | return nullptr; |
Mathieu Chartier | c7cb190 | 2014-03-05 14:41:03 -0800 | [diff] [blame] | 598 | } else { |
Brian Carlstrom | e9105f7 | 2014-10-28 15:53:43 -0700 | [diff] [blame] | 599 | // Otherwise, log a warning and fall through to GenerateImage. |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 600 | LOG(WARNING) << *error_msg; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 601 | } |
| 602 | } |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 603 | |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 604 | if (!can_compile) { |
| 605 | *error_msg = "Not attempting to compile image because -Xnoimage-dex2oat"; |
| 606 | return nullptr; |
| 607 | } else if (!dalvik_cache_exists) { |
| 608 | *error_msg = StringPrintf("No place to put generated image."); |
| 609 | return nullptr; |
Andreas Gampe | 3c13a79 | 2014-09-18 20:56:04 -0700 | [diff] [blame] | 610 | } else if (!ImageCreationAllowed(is_global_cache, error_msg)) { |
| 611 | return nullptr; |
Alex Light | 2539613 | 2014-08-27 15:37:23 -0700 | [diff] [blame] | 612 | } else if (!GenerateImage(cache_filename, image_isa, error_msg)) { |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 613 | *error_msg = StringPrintf("Failed to generate image '%s': %s", |
| 614 | cache_filename.c_str(), error_msg->c_str()); |
Brian Carlstrom | e9105f7 | 2014-10-28 15:53:43 -0700 | [diff] [blame] | 615 | // We failed to create files, remove any possibly garbage output. |
| 616 | // Since ImageCreationAllowed was true above, we are the zygote |
| 617 | // and therefore the only process expected to generate these for |
| 618 | // the device. |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 619 | PruneDalvikCache(image_isa); |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 620 | return nullptr; |
| 621 | } else { |
Andreas Gampe | 70be1fb | 2014-10-31 16:45:19 -0700 | [diff] [blame] | 622 | // Check whether there is enough space left over after we have generated the image. |
| 623 | if (!CheckSpace(cache_filename, error_msg)) { |
| 624 | // No. Delete the generated image and try to run out of the dex files. |
Narayan Kamath | 28bc987 | 2014-11-07 17:46:28 +0000 | [diff] [blame] | 625 | PruneDalvikCache(image_isa); |
Andreas Gampe | 70be1fb | 2014-10-31 16:45:19 -0700 | [diff] [blame] | 626 | return nullptr; |
| 627 | } |
| 628 | |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 629 | // Note that we must not use the file descriptor associated with |
| 630 | // ScopedFlock::GetFile to Init the image file. We want the file |
| 631 | // descriptor (and the associated exclusive lock) to be released when |
| 632 | // we leave Create. |
| 633 | ScopedFlock image_lock; |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 634 | image_lock.Init(cache_filename.c_str(), error_msg); |
| 635 | space = ImageSpace::Init(cache_filename.c_str(), image_location, true, error_msg); |
| 636 | if (space == nullptr) { |
| 637 | *error_msg = StringPrintf("Failed to load generated image '%s': %s", |
| 638 | cache_filename.c_str(), error_msg->c_str()); |
| 639 | } |
| 640 | return space; |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 641 | } |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 644 | void ImageSpace::VerifyImageAllocations() { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 645 | uint8_t* current = Begin() + RoundUp(sizeof(ImageHeader), kObjectAlignment); |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 646 | while (current < End()) { |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 647 | CHECK_ALIGNED(current, kObjectAlignment); |
| 648 | auto* obj = reinterpret_cast<mirror::Object*>(current); |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 649 | CHECK(obj->GetClass() != nullptr) << "Image object at address " << obj << " has null class"; |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 650 | CHECK(live_bitmap_->Test(obj)) << PrettyTypeOf(obj); |
Hiroshi Yamauchi | 624468c | 2014-03-31 15:14:47 -0700 | [diff] [blame] | 651 | if (kUseBakerOrBrooksReadBarrier) { |
| 652 | obj->AssertReadBarrierPointer(); |
Hiroshi Yamauchi | 9d04a20 | 2014-01-31 13:35:49 -0800 | [diff] [blame] | 653 | } |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 654 | current += RoundUp(obj->SizeOf(), kObjectAlignment); |
| 655 | } |
| 656 | } |
| 657 | |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 658 | ImageSpace* ImageSpace::Init(const char* image_filename, const char* image_location, |
| 659 | bool validate_oat_file, std::string* error_msg) { |
| 660 | CHECK(image_filename != nullptr); |
| 661 | CHECK(image_location != nullptr); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 662 | |
| 663 | uint64_t start_time = 0; |
| 664 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 665 | start_time = NanoTime(); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 666 | LOG(INFO) << "ImageSpace::Init entering image_filename=" << image_filename; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 669 | std::unique_ptr<File> file(OS::OpenFileForReading(image_filename)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 670 | if (file.get() == nullptr) { |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 671 | *error_msg = StringPrintf("Failed to open '%s'", image_filename); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 672 | return nullptr; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 673 | } |
| 674 | ImageHeader image_header; |
| 675 | bool success = file->ReadFully(&image_header, sizeof(image_header)); |
| 676 | if (!success || !image_header.IsValid()) { |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 677 | *error_msg = StringPrintf("Invalid image header in '%s'", image_filename); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 678 | return nullptr; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 679 | } |
Andreas Gampe | 6c8b49f | 2015-02-19 11:42:36 -0800 | [diff] [blame] | 680 | // Check that the file is large enough. |
| 681 | uint64_t image_file_size = static_cast<uint64_t>(file->GetLength()); |
| 682 | if (image_header.GetImageSize() > image_file_size) { |
| 683 | *error_msg = StringPrintf("Image file too small for image heap: %" PRIu64 " vs. %zu.", |
| 684 | image_file_size, image_header.GetImageSize()); |
| 685 | return nullptr; |
| 686 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 687 | |
| 688 | if (kIsDebugBuild) { |
| 689 | LOG(INFO) << "Dumping image sections"; |
| 690 | for (size_t i = 0; i < ImageHeader::kSectionCount; ++i) { |
| 691 | const auto section_idx = static_cast<ImageHeader::ImageSections>(i); |
| 692 | auto& section = image_header.GetImageSection(section_idx); |
| 693 | LOG(INFO) << section_idx << " start=" |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 694 | << reinterpret_cast<void*>(image_header.GetImageBegin() + section.Offset()) << " " |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 695 | << section; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | const auto& bitmap_section = image_header.GetImageSection(ImageHeader::kSectionImageBitmap); |
| 700 | auto end_of_bitmap = static_cast<size_t>(bitmap_section.End()); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 701 | if (end_of_bitmap != image_file_size) { |
| 702 | *error_msg = StringPrintf( |
| 703 | "Image file size does not equal end of bitmap: size=%" PRIu64 " vs. %zu.", image_file_size, |
| 704 | end_of_bitmap); |
Andreas Gampe | 6c8b49f | 2015-02-19 11:42:36 -0800 | [diff] [blame] | 705 | return nullptr; |
| 706 | } |
| 707 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 708 | // Note: The image header is part of the image due to mmap page alignment required of offset. |
Mathieu Chartier | 42bddce | 2015-11-09 15:16:56 -0800 | [diff] [blame] | 709 | std::unique_ptr<MemMap> map(MemMap::MapFileAtAddress(image_header.GetImageBegin(), |
| 710 | image_header.GetImageSize(), |
| 711 | PROT_READ | PROT_WRITE, |
| 712 | MAP_PRIVATE, |
| 713 | file->Fd(), |
| 714 | 0, |
| 715 | /*low_4gb*/false, |
| 716 | /*reuse*/false, |
| 717 | image_filename, |
| 718 | error_msg)); |
| 719 | if (map == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 720 | DCHECK(!error_msg->empty()); |
| 721 | return nullptr; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 722 | } |
| 723 | CHECK_EQ(image_header.GetImageBegin(), map->Begin()); |
| 724 | DCHECK_EQ(0, memcmp(&image_header, map->Begin(), sizeof(ImageHeader))); |
| 725 | |
Mathieu Chartier | 42bddce | 2015-11-09 15:16:56 -0800 | [diff] [blame] | 726 | std::unique_ptr<MemMap> image_map(MemMap::MapFileAtAddress(nullptr, |
| 727 | bitmap_section.Size(), |
| 728 | PROT_READ, MAP_PRIVATE, |
| 729 | file->Fd(), |
| 730 | bitmap_section.Offset(), |
| 731 | /*low_4gb*/false, |
| 732 | /*reuse*/false, |
| 733 | image_filename, |
| 734 | error_msg)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 735 | if (image_map.get() == nullptr) { |
| 736 | *error_msg = StringPrintf("Failed to map image bitmap: %s", error_msg->c_str()); |
| 737 | return nullptr; |
| 738 | } |
Ian Rogers | 3e5cf30 | 2014-05-20 16:40:37 -0700 | [diff] [blame] | 739 | uint32_t bitmap_index = bitmap_index_.FetchAndAddSequentiallyConsistent(1); |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 740 | std::string bitmap_name(StringPrintf("imagespace %s live-bitmap %u", image_filename, |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 741 | bitmap_index)); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 742 | std::unique_ptr<accounting::ContinuousSpaceBitmap> bitmap( |
Mathieu Chartier | d39645e | 2015-06-09 17:50:29 -0700 | [diff] [blame] | 743 | accounting::ContinuousSpaceBitmap::CreateFromMemMap( |
| 744 | bitmap_name, image_map.release(), reinterpret_cast<uint8_t*>(map->Begin()), |
| 745 | accounting::ContinuousSpaceBitmap::ComputeHeapSize(bitmap_section.Size()))); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 746 | if (bitmap.get() == nullptr) { |
| 747 | *error_msg = StringPrintf("Could not create bitmap '%s'", bitmap_name.c_str()); |
| 748 | return nullptr; |
| 749 | } |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 750 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 751 | // We only want the mirror object, not the ArtFields and ArtMethods. |
| 752 | uint8_t* const image_end = |
| 753 | map->Begin() + image_header.GetImageSection(ImageHeader::kSectionObjects).End(); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 754 | std::unique_ptr<ImageSpace> space(new ImageSpace(image_filename, image_location, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 755 | map.release(), bitmap.release(), image_end)); |
Hiroshi Yamauchi | bd0fb61 | 2014-05-20 13:46:00 -0700 | [diff] [blame] | 756 | |
| 757 | // VerifyImageAllocations() will be called later in Runtime::Init() |
| 758 | // as some class roots like ArtMethod::java_lang_reflect_ArtMethod_ |
| 759 | // and ArtField::java_lang_reflect_ArtField_, which are used from |
| 760 | // Object::SizeOf() which VerifyImageAllocations() calls, are not |
| 761 | // set yet at this point. |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 762 | |
Narayan Kamath | 52f8488 | 2014-05-02 10:10:39 +0100 | [diff] [blame] | 763 | space->oat_file_.reset(space->OpenOatFile(image_filename, error_msg)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 764 | if (space->oat_file_.get() == nullptr) { |
| 765 | DCHECK(!error_msg->empty()); |
| 766 | return nullptr; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 767 | } |
Andreas Gampe | 88da3b0 | 2015-06-12 20:38:49 -0700 | [diff] [blame] | 768 | space->oat_file_non_owned_ = space->oat_file_.get(); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 769 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 770 | if (validate_oat_file && !space->ValidateOatFile(error_msg)) { |
| 771 | DCHECK(!error_msg->empty()); |
| 772 | return nullptr; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 775 | Runtime* runtime = Runtime::Current(); |
| 776 | runtime->SetInstructionSet(space->oat_file_->GetOatHeader().GetInstructionSet()); |
| 777 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 778 | runtime->SetResolutionMethod(image_header.GetImageMethod(ImageHeader::kResolutionMethod)); |
| 779 | runtime->SetImtConflictMethod(image_header.GetImageMethod(ImageHeader::kImtConflictMethod)); |
| 780 | runtime->SetImtUnimplementedMethod( |
| 781 | image_header.GetImageMethod(ImageHeader::kImtUnimplementedMethod)); |
| 782 | runtime->SetCalleeSaveMethod( |
| 783 | image_header.GetImageMethod(ImageHeader::kCalleeSaveMethod), Runtime::kSaveAll); |
| 784 | runtime->SetCalleeSaveMethod( |
| 785 | image_header.GetImageMethod(ImageHeader::kRefsOnlySaveMethod), Runtime::kRefsOnly); |
| 786 | runtime->SetCalleeSaveMethod( |
| 787 | image_header.GetImageMethod(ImageHeader::kRefsAndArgsSaveMethod), Runtime::kRefsAndArgs); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 788 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 789 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
| 790 | LOG(INFO) << "ImageSpace::Init exiting (" << PrettyDuration(NanoTime() - start_time) |
| 791 | << ") " << *space.get(); |
| 792 | } |
| 793 | return space.release(); |
| 794 | } |
| 795 | |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 796 | OatFile* ImageSpace::OpenOatFile(const char* image_path, std::string* error_msg) const { |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 797 | const ImageHeader& image_header = GetImageHeader(); |
Nicolas Geoffray | 9583fbc | 2014-02-28 15:21:07 +0000 | [diff] [blame] | 798 | std::string oat_filename = ImageHeader::GetOatLocationFromImageLocation(image_path); |
| 799 | |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 800 | CHECK(image_header.GetOatDataBegin() != nullptr); |
| 801 | |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 802 | OatFile* oat_file = OatFile::Open(oat_filename, |
| 803 | oat_filename, |
| 804 | image_header.GetOatDataBegin(), |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 805 | image_header.GetOatFileBegin(), |
Richard Uhler | e5fed03 | 2015-03-18 08:21:11 -0700 | [diff] [blame] | 806 | !Runtime::Current()->IsAotCompiler(), |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 807 | nullptr, |
| 808 | error_msg); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 809 | if (oat_file == nullptr) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 810 | *error_msg = StringPrintf("Failed to open oat file '%s' referenced from image %s: %s", |
| 811 | oat_filename.c_str(), GetName(), error_msg->c_str()); |
| 812 | return nullptr; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 813 | } |
| 814 | uint32_t oat_checksum = oat_file->GetOatHeader().GetChecksum(); |
| 815 | uint32_t image_oat_checksum = image_header.GetOatChecksum(); |
| 816 | if (oat_checksum != image_oat_checksum) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 817 | *error_msg = StringPrintf("Failed to match oat file checksum 0x%x to expected oat checksum 0x%x" |
| 818 | " in image %s", oat_checksum, image_oat_checksum, GetName()); |
| 819 | return nullptr; |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 820 | } |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 821 | int32_t image_patch_delta = image_header.GetPatchDelta(); |
| 822 | int32_t oat_patch_delta = oat_file->GetOatHeader().GetImagePatchDelta(); |
Igor Murashkin | 4677476 | 2014-10-22 11:37:02 -0700 | [diff] [blame] | 823 | if (oat_patch_delta != image_patch_delta && !image_header.CompilePic()) { |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 824 | // We should have already relocated by this point. Bail out. |
| 825 | *error_msg = StringPrintf("Failed to match oat file patch delta %d to expected patch delta %d " |
| 826 | "in image %s", oat_patch_delta, image_patch_delta, GetName()); |
| 827 | return nullptr; |
| 828 | } |
| 829 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 830 | return oat_file; |
| 831 | } |
| 832 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 833 | bool ImageSpace::ValidateOatFile(std::string* error_msg) const { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 834 | CHECK(oat_file_.get() != nullptr); |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 835 | for (const OatFile::OatDexFile* oat_dex_file : oat_file_->GetOatDexFiles()) { |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 836 | const std::string& dex_file_location = oat_dex_file->GetDexFileLocation(); |
| 837 | uint32_t dex_file_location_checksum; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 838 | if (!DexFile::GetChecksum(dex_file_location.c_str(), &dex_file_location_checksum, error_msg)) { |
| 839 | *error_msg = StringPrintf("Failed to get checksum of dex file '%s' referenced by image %s: " |
| 840 | "%s", dex_file_location.c_str(), GetName(), error_msg->c_str()); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 841 | return false; |
| 842 | } |
| 843 | if (dex_file_location_checksum != oat_dex_file->GetDexFileLocationChecksum()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 844 | *error_msg = StringPrintf("ValidateOatFile found checksum mismatch between oat file '%s' and " |
| 845 | "dex file '%s' (0x%x != 0x%x)", |
| 846 | oat_file_->GetLocation().c_str(), dex_file_location.c_str(), |
| 847 | oat_dex_file->GetDexFileLocationChecksum(), |
| 848 | dex_file_location_checksum); |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 849 | return false; |
| 850 | } |
| 851 | } |
| 852 | return true; |
| 853 | } |
| 854 | |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 855 | const OatFile* ImageSpace::GetOatFile() const { |
Andreas Gampe | 88da3b0 | 2015-06-12 20:38:49 -0700 | [diff] [blame] | 856 | return oat_file_non_owned_; |
Andreas Gampe | 22f8e5c | 2014-07-09 11:38:21 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 859 | std::unique_ptr<const OatFile> ImageSpace::ReleaseOatFile() { |
| 860 | CHECK(oat_file_ != nullptr); |
| 861 | return std::move(oat_file_); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 864 | void ImageSpace::Dump(std::ostream& os) const { |
| 865 | os << GetType() |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 866 | << " begin=" << reinterpret_cast<void*>(Begin()) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 867 | << ",end=" << reinterpret_cast<void*>(End()) |
| 868 | << ",size=" << PrettySize(Size()) |
| 869 | << ",name=\"" << GetName() << "\"]"; |
| 870 | } |
| 871 | |
| 872 | } // namespace space |
| 873 | } // namespace gc |
| 874 | } // namespace art |