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
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 1413896..fcfda96 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 @@
// 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 @@
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(