[jitzygote] Remap boot boot image methods in zygote when single-threaded.
This avoids concurrent updates made by other threads while copying the
data.
Bug: 143569713
Bug: 119800099
Test: boots
Change-Id: Ife0141a45b8d8671ab0c5868ccf90b4799a9f5db
diff --git a/libartbase/base/utils.cc b/libartbase/base/utils.cc
index a088434..7d4dd59 100644
--- a/libartbase/base/utils.cc
+++ b/libartbase/base/utils.cc
@@ -16,6 +16,7 @@
#include "utils.h"
+#include <dirent.h>
#include <inttypes.h>
#include <pthread.h>
#include <sys/stat.h>
@@ -355,4 +356,22 @@
return (flags & (1LL << 61)) != 0;
}
+int GetTaskCount() {
+ DIR* directory = opendir("/proc/self/task");
+ if (directory == nullptr) {
+ return -1;
+ }
+
+ uint32_t count = 0;
+ struct dirent* entry = nullptr;
+ while ((entry = readdir(directory)) != nullptr) {
+ if ((strcmp(entry->d_name, ".") == 0) || (strcmp(entry->d_name, "..") == 0)) {
+ continue;
+ }
+ ++count;
+ }
+ closedir(directory);
+ return count;
+}
+
} // namespace art
diff --git a/libartbase/base/utils.h b/libartbase/base/utils.h
index 6fc537a..4bcb915 100644
--- a/libartbase/base/utils.h
+++ b/libartbase/base/utils.h
@@ -159,6 +159,9 @@
// following accesses repopulate the memory or return zero.
bool IsAddressKnownBackedByFileOrShared(const void* addr);
+// Returns the number of threads running.
+int GetTaskCount();
+
} // namespace art
#endif // ART_LIBARTBASE_BASE_UTILS_H_