diff options
author | 2023-08-04 10:54:36 +0000 | |
---|---|---|
committer | 2023-08-11 10:53:33 +0000 | |
commit | 5acf9aa40740add96f1132731c47a0c1c2eb44bb (patch) | |
tree | d3a60ebd5a57274473cfd87048a4ae78beb63a43 | |
parent | 303d061d79ffd06aec960a921012712f49df844e (diff) |
Allow disabling app image loading by process name
Test: build, flash, run app with special process name, see logcat + use
showmap to ensure app image is not loaded
Bug: 292210260
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b3abf9807fab5baf44984b255dcd41ce0c76d82d)
Merged-In: If9b277e0d88b8b428afe953fea56f2209cdb990d
Change-Id: If9b277e0d88b8b428afe953fea56f2209cdb990d
-rw-r--r-- | runtime/oat_file_manager.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc index 1413896a1c..fcfda96503 100644 --- a/runtime/oat_file_manager.cc +++ b/runtime/oat_file_manager.cc @@ -16,15 +16,16 @@ #include "oat_file_manager.h" +#include <stdlib.h> +#include <sys/stat.h> + #include <memory> #include <queue> #include <vector> -#include <sys/stat.h> #include "android-base/file.h" #include "android-base/stringprintf.h" #include "android-base/strings.h" - #include "art_field-inl.h" #include "base/bit_vector-inl.h" #include "base/file_utils.h" @@ -69,6 +70,10 @@ static constexpr bool kEnableAppImage = true; // If true, we attempt to load an app image generated by the runtime. static const bool kEnableRuntimeAppImage = true; +#if defined(__ANDROID__) +static const char* kDisableAppImageKeyword = "_disable_art_image_"; +#endif + const OatFile* OatFileManager::RegisterOatFile(std::unique_ptr<const OatFile> oat_file, bool in_memory) { // Use class_linker vlog to match the log for dex file registration. @@ -171,7 +176,20 @@ std::vector<const OatFile*> OatFileManager::RegisterImageOatFiles( bool OatFileManager::ShouldLoadAppImage() const { Runtime* const runtime = Runtime::Current(); - return kEnableAppImage && !runtime->IsJavaDebuggableAtInit(); + if (!kEnableAppImage || runtime->IsJavaDebuggableAtInit()) { + return false; + } + +#if defined(__ANDROID__) + const char* process_name = getprogname(); + // Some processes would rather take the runtime impact in the interest of memory (b/292210260) + if (process_name != nullptr && strstr(process_name, kDisableAppImageKeyword) != nullptr) { + LOG(INFO) << "Skipping app image load for " << process_name; + return false; + } +#endif + + return true; } std::vector<std::unique_ptr<const DexFile>> OatFileManager::OpenDexFilesFromOat( |