Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 "profile_saver.h" |
| 18 | |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 19 | #include <sys/types.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <fcntl.h> |
| 22 | |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 23 | #include "art_method-inl.h" |
Mathieu Chartier | dabdc0f | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 24 | #include "base/systrace.h" |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 25 | #include "scoped_thread_state_change.h" |
| 26 | #include "oat_file_manager.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
Calin Juravle | 932a051 | 2016-01-19 14:32:26 -0800 | [diff] [blame] | 30 | // An arbitrary value to throttle save requests. Set to 2s for now. |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 31 | static constexpr const uint64_t kMilisecondsToNano = 1000000; |
Calin Juravle | 932a051 | 2016-01-19 14:32:26 -0800 | [diff] [blame] | 32 | static constexpr const uint64_t kMinimumTimeBetweenCodeCacheUpdatesNs = 2000 * kMilisecondsToNano; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 33 | |
| 34 | // TODO: read the constants from ProfileOptions, |
| 35 | // Add a random delay each time we go to sleep so that we don't hammer the CPU |
| 36 | // with all profile savers running at the same time. |
Calin Juravle | 932a051 | 2016-01-19 14:32:26 -0800 | [diff] [blame] | 37 | static constexpr const uint64_t kRandomDelayMaxMs = 20 * 1000; // 20 seconds |
| 38 | static constexpr const uint64_t kMaxBackoffMs = 5 * 60 * 1000; // 5 minutes |
| 39 | static constexpr const uint64_t kSavePeriodMs = 10 * 1000; // 10 seconds |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 40 | static constexpr const uint64_t kInitialDelayMs = 2 * 1000; // 2 seconds |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 41 | static constexpr const double kBackoffCoef = 1.5; |
| 42 | |
| 43 | static constexpr const uint32_t kMinimumNrOrMethodsToSave = 10; |
| 44 | |
| 45 | ProfileSaver* ProfileSaver::instance_ = nullptr; |
| 46 | pthread_t ProfileSaver::profiler_pthread_ = 0U; |
| 47 | |
| 48 | ProfileSaver::ProfileSaver(const std::string& output_filename, |
| 49 | jit::JitCodeCache* jit_code_cache, |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 50 | const std::vector<std::string>& code_paths, |
| 51 | const std::string& foreign_dex_profile_path, |
| 52 | const std::string& app_data_dir) |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 53 | : jit_code_cache_(jit_code_cache), |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 54 | foreign_dex_profile_path_(foreign_dex_profile_path), |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 55 | code_cache_last_update_time_ns_(0), |
| 56 | shutting_down_(false), |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 57 | first_profile_(true), |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 58 | wait_lock_("ProfileSaver wait lock"), |
| 59 | period_condition_("ProfileSaver period condition", wait_lock_) { |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 60 | AddTrackedLocations(output_filename, code_paths); |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 61 | app_data_dir_ = ""; |
| 62 | if (!app_data_dir.empty()) { |
| 63 | // The application directory is used to determine which dex files are owned by app. |
| 64 | // Since it could be a symlink (e.g. /data/data instead of /data/user/0), and we |
| 65 | // don't have control over how the dex files are actually loaded (symlink or canonical path), |
| 66 | // store it's canonical form to be sure we use the same base when comparing. |
| 67 | UniqueCPtr<const char[]> app_data_dir_real_path(realpath(app_data_dir.c_str(), nullptr)); |
| 68 | if (app_data_dir_real_path != nullptr) { |
| 69 | app_data_dir_.assign(app_data_dir_real_path.get()); |
| 70 | } else { |
| 71 | LOG(WARNING) << "Failed to get the real path for app dir: " << app_data_dir_ |
| 72 | << ". The app dir will not be used to determine which dex files belong to the app"; |
| 73 | } |
| 74 | } |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void ProfileSaver::Run() { |
| 78 | srand(MicroTime() * getpid()); |
| 79 | Thread* self = Thread::Current(); |
| 80 | |
| 81 | uint64_t save_period_ms = kSavePeriodMs; |
| 82 | VLOG(profiler) << "Save profiling information every " << save_period_ms << " ms"; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 83 | |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 84 | bool first_iteration = true; |
| 85 | while (!ShuttingDown(self)) { |
| 86 | uint64_t sleep_time_ms; |
| 87 | if (first_iteration) { |
| 88 | // Sleep less long for the first iteration since we want to record loaded classes shortly |
| 89 | // after app launch. |
| 90 | sleep_time_ms = kInitialDelayMs; |
| 91 | } else { |
| 92 | const uint64_t random_sleep_delay_ms = rand() % kRandomDelayMaxMs; |
| 93 | sleep_time_ms = save_period_ms + random_sleep_delay_ms; |
| 94 | } |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 95 | { |
| 96 | MutexLock mu(self, wait_lock_); |
| 97 | period_condition_.TimedWait(self, sleep_time_ms, 0); |
| 98 | } |
| 99 | |
| 100 | if (ShuttingDown(self)) { |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | if (!ProcessProfilingInfo() && save_period_ms < kMaxBackoffMs) { |
| 105 | // If we don't need to save now it is less likely that we will need to do |
| 106 | // so in the future. Increase the time between saves according to the |
| 107 | // kBackoffCoef, but make it no larger than kMaxBackoffMs. |
| 108 | save_period_ms = static_cast<uint64_t>(kBackoffCoef * save_period_ms); |
| 109 | } else { |
| 110 | // Reset the period to the initial value as it's highly likely to JIT again. |
| 111 | save_period_ms = kSavePeriodMs; |
| 112 | } |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 113 | first_iteration = false; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | bool ProfileSaver::ProcessProfilingInfo() { |
Mathieu Chartier | dabdc0f | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 118 | ScopedTrace trace(__PRETTY_FUNCTION__); |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 119 | uint64_t last_update_time_ns = jit_code_cache_->GetLastUpdateTimeNs(); |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 120 | if (!first_profile_ && last_update_time_ns - code_cache_last_update_time_ns_ |
| 121 | < kMinimumTimeBetweenCodeCacheUpdatesNs) { |
Calin Juravle | 877fd96 | 2016-01-05 14:29:29 +0000 | [diff] [blame] | 122 | VLOG(profiler) << "Not enough time has passed since the last code cache update." |
| 123 | << "Last update: " << last_update_time_ns |
| 124 | << " Last save: " << code_cache_last_update_time_ns_; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 125 | return false; |
| 126 | } |
| 127 | |
| 128 | uint64_t start = NanoTime(); |
| 129 | code_cache_last_update_time_ns_ = last_update_time_ns; |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 130 | SafeMap<std::string, std::set<std::string>> tracked_locations; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 131 | { |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 132 | // Make a copy so that we don't hold the lock while doing I/O. |
| 133 | MutexLock mu(Thread::Current(), *Locks::profiler_lock_); |
| 134 | tracked_locations = tracked_dex_base_locations_; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 135 | } |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 136 | for (const auto& it : tracked_locations) { |
| 137 | if (ShuttingDown(Thread::Current())) { |
| 138 | return true; |
| 139 | } |
| 140 | const std::string& filename = it.first; |
| 141 | const std::set<std::string>& locations = it.second; |
| 142 | std::vector<ArtMethod*> methods; |
| 143 | { |
| 144 | ScopedObjectAccess soa(Thread::Current()); |
| 145 | jit_code_cache_->GetCompiledArtMethods(locations, methods); |
| 146 | } |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 147 | // Always save for the first one for loaded classes profile. |
| 148 | if (methods.size() < kMinimumNrOrMethodsToSave && !first_profile_) { |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 149 | VLOG(profiler) << "Not enough information to save to: " << filename |
| 150 | <<" Nr of methods: " << methods.size(); |
| 151 | return false; |
| 152 | } |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 153 | |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 154 | std::set<DexCacheResolvedClasses> resolved_classes; |
| 155 | if (first_profile_) { |
| 156 | ClassLinker* const class_linker = Runtime::Current()->GetClassLinker(); |
| 157 | resolved_classes = class_linker->GetResolvedClasses(/*ignore boot classes*/true); |
| 158 | } |
| 159 | |
| 160 | if (!ProfileCompilationInfo::SaveProfilingInfo(filename, methods, resolved_classes)) { |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 161 | LOG(WARNING) << "Could not save profiling info to " << filename; |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | VLOG(profiler) << "Profile process time: " << PrettyDuration(NanoTime() - start); |
| 166 | } |
Mathieu Chartier | 8913fc1 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 167 | first_profile_ = false; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 168 | return true; |
| 169 | } |
| 170 | |
| 171 | void* ProfileSaver::RunProfileSaverThread(void* arg) { |
| 172 | Runtime* runtime = Runtime::Current(); |
| 173 | ProfileSaver* profile_saver = reinterpret_cast<ProfileSaver*>(arg); |
| 174 | |
| 175 | CHECK(runtime->AttachCurrentThread("Profile Saver", |
| 176 | /*as_daemon*/true, |
| 177 | runtime->GetSystemThreadGroup(), |
| 178 | /*create_peer*/true)); |
| 179 | profile_saver->Run(); |
| 180 | |
| 181 | runtime->DetachCurrentThread(); |
| 182 | VLOG(profiler) << "Profile saver shutdown"; |
| 183 | return nullptr; |
| 184 | } |
| 185 | |
| 186 | void ProfileSaver::Start(const std::string& output_filename, |
| 187 | jit::JitCodeCache* jit_code_cache, |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 188 | const std::vector<std::string>& code_paths, |
| 189 | const std::string& foreign_dex_profile_path, |
| 190 | const std::string& app_data_dir) { |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 191 | DCHECK(Runtime::Current()->UseJit()); |
| 192 | DCHECK(!output_filename.empty()); |
| 193 | DCHECK(jit_code_cache != nullptr); |
| 194 | |
| 195 | MutexLock mu(Thread::Current(), *Locks::profiler_lock_); |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 196 | if (instance_ != nullptr) { |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 197 | // If we already have an instance, make sure it uses the same jit_code_cache. |
| 198 | // This may be called multiple times via Runtime::registerAppInfo (e.g. for |
| 199 | // apps which share the same runtime). |
| 200 | DCHECK_EQ(instance_->jit_code_cache_, jit_code_cache); |
| 201 | // Add the code_paths to the tracked locations. |
| 202 | instance_->AddTrackedLocations(output_filename, code_paths); |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 203 | return; |
| 204 | } |
| 205 | |
| 206 | VLOG(profiler) << "Starting profile saver using output file: " << output_filename |
| 207 | << ". Tracking: " << Join(code_paths, ':'); |
| 208 | |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 209 | instance_ = new ProfileSaver(output_filename, |
| 210 | jit_code_cache, |
| 211 | code_paths, |
| 212 | foreign_dex_profile_path, |
| 213 | app_data_dir); |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 214 | |
| 215 | // Create a new thread which does the saving. |
| 216 | CHECK_PTHREAD_CALL( |
| 217 | pthread_create, |
| 218 | (&profiler_pthread_, nullptr, &RunProfileSaverThread, reinterpret_cast<void*>(instance_)), |
| 219 | "Profile saver thread"); |
| 220 | } |
| 221 | |
| 222 | void ProfileSaver::Stop() { |
| 223 | ProfileSaver* profile_saver = nullptr; |
| 224 | pthread_t profiler_pthread = 0U; |
| 225 | |
| 226 | { |
| 227 | MutexLock profiler_mutex(Thread::Current(), *Locks::profiler_lock_); |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 228 | VLOG(profiler) << "Stopping profile saver thread"; |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 229 | profile_saver = instance_; |
| 230 | profiler_pthread = profiler_pthread_; |
| 231 | if (instance_ == nullptr) { |
| 232 | DCHECK(false) << "Tried to stop a profile saver which was not started"; |
| 233 | return; |
| 234 | } |
| 235 | if (instance_->shutting_down_) { |
| 236 | DCHECK(false) << "Tried to stop the profile saver twice"; |
| 237 | return; |
| 238 | } |
| 239 | instance_->shutting_down_ = true; |
| 240 | } |
| 241 | |
| 242 | { |
| 243 | // Wake up the saver thread if it is sleeping to allow for a clean exit. |
| 244 | MutexLock wait_mutex(Thread::Current(), profile_saver->wait_lock_); |
| 245 | profile_saver->period_condition_.Signal(Thread::Current()); |
| 246 | } |
| 247 | |
| 248 | // Wait for the saver thread to stop. |
| 249 | CHECK_PTHREAD_CALL(pthread_join, (profiler_pthread, nullptr), "profile saver thread shutdown"); |
| 250 | |
| 251 | { |
| 252 | MutexLock profiler_mutex(Thread::Current(), *Locks::profiler_lock_); |
| 253 | instance_ = nullptr; |
| 254 | profiler_pthread_ = 0U; |
| 255 | } |
| 256 | delete profile_saver; |
| 257 | } |
| 258 | |
| 259 | bool ProfileSaver::ShuttingDown(Thread* self) { |
| 260 | MutexLock mu(self, *Locks::profiler_lock_); |
| 261 | return shutting_down_; |
| 262 | } |
| 263 | |
| 264 | bool ProfileSaver::IsStarted() { |
| 265 | MutexLock mu(Thread::Current(), *Locks::profiler_lock_); |
| 266 | return instance_ != nullptr; |
| 267 | } |
| 268 | |
Calin Juravle | b4eddd2 | 2016-01-13 15:52:33 -0800 | [diff] [blame] | 269 | void ProfileSaver::AddTrackedLocations(const std::string& output_filename, |
| 270 | const std::vector<std::string>& code_paths) { |
| 271 | auto it = tracked_dex_base_locations_.find(output_filename); |
| 272 | if (it == tracked_dex_base_locations_.end()) { |
| 273 | tracked_dex_base_locations_.Put(output_filename, |
| 274 | std::set<std::string>(code_paths.begin(), code_paths.end())); |
| 275 | } else { |
| 276 | it->second.insert(code_paths.begin(), code_paths.end()); |
| 277 | } |
| 278 | } |
| 279 | |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 280 | void ProfileSaver::NotifyDexUse(const std::string& dex_location) { |
| 281 | std::set<std::string> app_code_paths; |
| 282 | std::string foreign_dex_profile_path; |
| 283 | std::string app_data_dir; |
| 284 | { |
| 285 | MutexLock mu(Thread::Current(), *Locks::profiler_lock_); |
| 286 | DCHECK(instance_ != nullptr); |
| 287 | // Make a copy so that we don't hold the lock while doing I/O. |
| 288 | for (const auto& it : instance_->tracked_dex_base_locations_) { |
| 289 | app_code_paths.insert(it.second.begin(), it.second.end()); |
| 290 | } |
| 291 | foreign_dex_profile_path = instance_->foreign_dex_profile_path_; |
| 292 | app_data_dir = instance_->app_data_dir_; |
| 293 | } |
| 294 | |
| 295 | MaybeRecordDexUseInternal(dex_location, |
| 296 | app_code_paths, |
| 297 | foreign_dex_profile_path, |
| 298 | app_data_dir); |
| 299 | } |
| 300 | |
| 301 | void ProfileSaver::MaybeRecordDexUseInternal( |
| 302 | const std::string& dex_location, |
| 303 | const std::set<std::string>& app_code_paths, |
| 304 | const std::string& foreign_dex_profile_path, |
| 305 | const std::string& app_data_dir) { |
Calin Juravle | 1fae45f | 2016-03-08 12:52:52 +0000 | [diff] [blame^] | 306 | if (dex_location.empty()) { |
| 307 | LOG(WARNING) << "Asked to record foreign dex use with an empty dex location."; |
| 308 | return; |
| 309 | } |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 310 | if (foreign_dex_profile_path.empty()) { |
| 311 | LOG(WARNING) << "Asked to record foreign dex use without a valid profile path "; |
| 312 | return; |
| 313 | } |
| 314 | |
| 315 | UniqueCPtr<const char[]> dex_location_real_path(realpath(dex_location.c_str(), nullptr)); |
Calin Juravle | 1fae45f | 2016-03-08 12:52:52 +0000 | [diff] [blame^] | 316 | if (dex_location_real_path == nullptr) { |
| 317 | PLOG(WARNING) << "Could not get realpath for " << dex_location; |
| 318 | } |
| 319 | std::string dex_location_real_path_str((dex_location_real_path == nullptr) |
| 320 | ? dex_location.c_str() |
| 321 | : dex_location_real_path.get()); |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 322 | |
| 323 | if (dex_location_real_path_str.compare(0, app_data_dir.length(), app_data_dir) == 0) { |
| 324 | // The dex location is under the application folder. Nothing to record. |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | if (app_code_paths.find(dex_location) != app_code_paths.end()) { |
| 329 | // The dex location belongs to the application code paths. Nothing to record. |
| 330 | return; |
| 331 | } |
| 332 | // Do another round of checks with the real paths. |
| 333 | // Note that we could cache all the real locations in the saver (since it's an expensive |
| 334 | // operation). However we expect that app_code_paths is small (usually 1 element), and |
| 335 | // NotifyDexUse is called just a few times in the app lifetime. So we make the compromise |
| 336 | // to save some bytes of memory usage. |
| 337 | for (const auto& app_code_location : app_code_paths) { |
| 338 | UniqueCPtr<const char[]> real_app_code_location(realpath(app_code_location.c_str(), nullptr)); |
Calin Juravle | 1fae45f | 2016-03-08 12:52:52 +0000 | [diff] [blame^] | 339 | if (real_app_code_location == nullptr) { |
| 340 | PLOG(WARNING) << "Could not get realpath for " << app_code_location; |
| 341 | } |
| 342 | std::string real_app_code_location_str((real_app_code_location == nullptr) |
| 343 | ? app_code_location.c_str() |
| 344 | : real_app_code_location.get()); |
Calin Juravle | 86a9ebe | 2016-02-24 10:13:09 +0000 | [diff] [blame] | 345 | if (real_app_code_location_str == dex_location_real_path_str) { |
| 346 | // The dex location belongs to the application code paths. Nothing to record. |
| 347 | return; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | // For foreign dex files we record a flag on disk. PackageManager will (potentially) take this |
| 352 | // into account when deciding how to optimize the loaded dex file. |
| 353 | // The expected flag name is the canonical path of the apk where '/' is substituted to '@'. |
| 354 | // (it needs to be kept in sync with |
| 355 | // frameworks/base/services/core/java/com/android/server/pm/PackageDexOptimizer.java) |
| 356 | std::replace(dex_location_real_path_str.begin(), dex_location_real_path_str.end(), '/', '@'); |
| 357 | std::string flag_path = foreign_dex_profile_path + "/" + dex_location_real_path_str; |
| 358 | // No need to give any sort of access to flag_path. The system has enough permissions |
| 359 | // to test for its existence. |
| 360 | int fd = TEMP_FAILURE_RETRY(open(flag_path.c_str(), O_CREAT | O_EXCL, 0)); |
| 361 | if (fd != -1) { |
| 362 | if (close(fd) != 0) { |
| 363 | PLOG(WARNING) << "Could not close file after flagging foreign dex use " << flag_path; |
| 364 | } |
| 365 | } else { |
| 366 | if (errno != EEXIST) { |
| 367 | // Another app could have already created the file. |
| 368 | PLOG(WARNING) << "Could not create foreign dex use mark " << flag_path; |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
Calin Juravle | 4d77b6a | 2015-12-01 18:38:09 +0000 | [diff] [blame] | 373 | } // namespace art |