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