summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2024-03-19 14:52:32 +0000
committer Santiago Aboy Solanes <solanes@google.com> 2024-03-26 09:44:04 +0000
commit42646b1ef936d12c4099fbefefdc976f9dc3c976 (patch)
treec6a4bd1feccf4149654afcb4a27dea7fcc4c26db
parent832ebf45a1746c3f39e3ac1dc744582de084e43a (diff)
Move methods used only once from utils.h to jit.cc
Bug: 329379384 Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b Change-Id: I312fa2e8f50896e6658ddc99447416050166f8e5
-rw-r--r--libartbase/base/utils.cc41
-rw-r--r--libartbase/base/utils.h8
-rw-r--r--runtime/jit/jit.cc45
3 files changed, 45 insertions, 49 deletions
diff --git a/libartbase/base/utils.cc b/libartbase/base/utils.cc
index bc359db173..9efc1477cc 100644
--- a/libartbase/base/utils.cc
+++ b/libartbase/base/utils.cc
@@ -366,45 +366,4 @@ std::string GetProcessStatus(const char* key) {
return "<unknown>";
}
-bool IsAddressKnownBackedByFileOrShared(const void* addr) {
- // We use the Linux pagemap interface for knowing if an address is backed
- // by a file or is shared. See:
- // https://www.kernel.org/doc/Documentation/vm/pagemap.txt
- const size_t page_size = MemMap::GetPageSize();
- uintptr_t vmstart = reinterpret_cast<uintptr_t>(AlignDown(addr, page_size));
- off_t index = (vmstart / page_size) * sizeof(uint64_t);
- android::base::unique_fd pagemap(open("/proc/self/pagemap", O_RDONLY | O_CLOEXEC));
- if (pagemap == -1) {
- return false;
- }
- if (lseek(pagemap, index, SEEK_SET) != index) {
- return false;
- }
- uint64_t flags;
- if (read(pagemap, &flags, sizeof(uint64_t)) != sizeof(uint64_t)) {
- return false;
- }
- // From https://www.kernel.org/doc/Documentation/vm/pagemap.txt:
- // * Bit 61 page is file-page or shared-anon (since 3.5)
- 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 92956bc8e9..b21401a589 100644
--- a/libartbase/base/utils.h
+++ b/libartbase/base/utils.h
@@ -145,14 +145,6 @@ inline void ForceRead(const T* pointer) {
// there is an I/O error.
std::string GetProcessStatus(const char* key);
-// Return whether the address is guaranteed to be backed by a file or is shared.
-// This information can be used to know whether MADV_DONTNEED will make
-// 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_
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index 90e909595e..1bab55a93f 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -716,6 +716,32 @@ static std::string GetBootProfileFile(const std::string& profile) {
return ReplaceFileExtension(profile, "bprof");
}
+// Return whether the address is guaranteed to be backed by a file or is shared.
+// This information can be used to know whether MADV_DONTNEED will make
+// following accesses repopulate the memory or return zero.
+static bool IsAddressKnownBackedByFileOrShared(const void* addr) {
+ // We use the Linux pagemap interface for knowing if an address is backed
+ // by a file or is shared. See:
+ // https://www.kernel.org/doc/Documentation/vm/pagemap.txt
+ const size_t page_size = MemMap::GetPageSize();
+ uintptr_t vmstart = reinterpret_cast<uintptr_t>(AlignDown(addr, page_size));
+ off_t index = (vmstart / page_size) * sizeof(uint64_t);
+ android::base::unique_fd pagemap(open("/proc/self/pagemap", O_RDONLY | O_CLOEXEC));
+ if (pagemap == -1) {
+ return false;
+ }
+ if (lseek(pagemap, index, SEEK_SET) != index) {
+ return false;
+ }
+ uint64_t flags;
+ if (read(pagemap, &flags, sizeof(uint64_t)) != sizeof(uint64_t)) {
+ return false;
+ }
+ // From https://www.kernel.org/doc/Documentation/vm/pagemap.txt:
+ // * Bit 61 page is file-page or shared-anon (since 3.5)
+ return (flags & (1LL << 61)) != 0;
+}
+
/**
* A JIT task to run after all profile compilation is done.
*/
@@ -1536,6 +1562,25 @@ void Jit::PreZygoteFork() {
NativeDebugInfoPreFork();
}
+// Returns the number of threads running.
+static 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;
+}
+
void Jit::PostZygoteFork() {
Runtime* runtime = Runtime::Current();
if (thread_pool_ == nullptr) {