Commit b03be84e authored by Benoit Lize's avatar Benoit Lize Committed by Commit Bot

base/android: Fix the orderfile build.

The orderfile build doesn't prefetch the native library, creating
unreached code, which is a compile time error with the flags we
use. Move the unreached code out of the build in this case. See the
linked bug for the detailed error message.

Bug: 1065182
Change-Id: Ic8c5b17e6077c4639a82b9caf574a7ae4018e64f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2124258Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754012}
parent c128a19b
...@@ -40,35 +40,9 @@ namespace android { ...@@ -40,35 +40,9 @@ namespace android {
namespace { namespace {
// Android defines the background priority to this value since at least 2009
// (see Process.java).
constexpr int kBackgroundPriority = 10;
// Valid for all Android architectures. // Valid for all Android architectures.
constexpr size_t kPageSize = 4096; constexpr size_t kPageSize = 4096;
// Reads a byte per page between |start| and |end| to force it into the page
// cache.
// Heap allocations, syscalls and library functions are not allowed in this
// function.
// Returns true for success.
#if defined(ADDRESS_SANITIZER)
// Disable AddressSanitizer instrumentation for this function. It is touching
// memory that hasn't been allocated by the app, though the addresses are
// valid. Furthermore, this takes place in a child process. See crbug.com/653372
// for the context.
__attribute__((no_sanitize_address))
#endif
void Prefetch(size_t start, size_t end) {
unsigned char* start_ptr = reinterpret_cast<unsigned char*>(start);
unsigned char* end_ptr = reinterpret_cast<unsigned char*>(end);
unsigned char dummy = 0;
for (unsigned char* ptr = start_ptr; ptr < end_ptr; ptr += kPageSize) {
// Volatile is required to prevent the compiler from eliminating this
// loop.
dummy ^= *static_cast<volatile unsigned char*>(ptr);
}
}
// Populates the per-page residency between |start| and |end| in |residency|. If // Populates the per-page residency between |start| and |end| in |residency|. If
// successful, |residency| has the size of |end| - |start| in pages. // successful, |residency| has the size of |end| - |start| in pages.
// Returns true for success. // Returns true for success.
...@@ -188,6 +162,30 @@ void DumpResidency(size_t start, ...@@ -188,6 +162,30 @@ void DumpResidency(size_t start,
} }
} }
#if !BUILDFLAG(ORDERFILE_INSTRUMENTATION)
// Reads a byte per page between |start| and |end| to force it into the page
// cache.
// Heap allocations, syscalls and library functions are not allowed in this
// function.
// Returns true for success.
#if defined(ADDRESS_SANITIZER)
// Disable AddressSanitizer instrumentation for this function. It is touching
// memory that hasn't been allocated by the app, though the addresses are
// valid. Furthermore, this takes place in a child process. See crbug.com/653372
// for the context.
__attribute__((no_sanitize_address))
#endif
void Prefetch(size_t start, size_t end) {
unsigned char* start_ptr = reinterpret_cast<unsigned char*>(start);
unsigned char* end_ptr = reinterpret_cast<unsigned char*>(end);
unsigned char dummy = 0;
for (unsigned char* ptr = start_ptr; ptr < end_ptr; ptr += kPageSize) {
// Volatile is required to prevent the compiler from eliminating this
// loop.
dummy ^= *static_cast<volatile unsigned char*>(ptr);
}
}
// These values were used in the past for recording // These values were used in the past for recording
// "LibraryLoader.PrefetchDetailedStatus". // "LibraryLoader.PrefetchDetailedStatus".
enum class PrefetchStatus { enum class PrefetchStatus {
...@@ -219,6 +217,9 @@ PrefetchStatus ForkAndPrefetch(bool ordered_only) { ...@@ -219,6 +217,9 @@ PrefetchStatus ForkAndPrefetch(bool ordered_only) {
pid_t pid = fork(); pid_t pid = fork();
if (pid == 0) { if (pid == 0) {
// Android defines the background priority to this value since at least 2009
// (see Process.java).
constexpr int kBackgroundPriority = 10;
setpriority(PRIO_PROCESS, 0, kBackgroundPriority); setpriority(PRIO_PROCESS, 0, kBackgroundPriority);
// _exit() doesn't call the atexit() handlers. // _exit() doesn't call the atexit() handlers.
for (const auto& range : ranges) { for (const auto& range : ranges) {
...@@ -255,6 +256,7 @@ PrefetchStatus ForkAndPrefetch(bool ordered_only) { ...@@ -255,6 +256,7 @@ PrefetchStatus ForkAndPrefetch(bool ordered_only) {
return PrefetchStatus::kChildProcessKilled; return PrefetchStatus::kChildProcessKilled;
} }
} }
#endif // !BUILDFLAG(ORDERFILE_INSTRUMENTATION)
} // namespace } // namespace
...@@ -264,13 +266,13 @@ void NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary(bool ordered_only) { ...@@ -264,13 +266,13 @@ void NativeLibraryPrefetcher::ForkAndPrefetchNativeLibrary(bool ordered_only) {
// Avoid forking with orderfile instrumentation because the child process // Avoid forking with orderfile instrumentation because the child process
// would create a dump as well. // would create a dump as well.
return; return;
#endif #else
PrefetchStatus status = ForkAndPrefetch(ordered_only); PrefetchStatus status = ForkAndPrefetch(ordered_only);
if (status != PrefetchStatus::kSuccess) { if (status != PrefetchStatus::kSuccess) {
LOG(WARNING) << "Cannot prefetch the library. status = " LOG(WARNING) << "Cannot prefetch the library. status = "
<< static_cast<int>(status); << static_cast<int>(status);
} }
#endif // BUILDFLAG(ORDERFILE_INSTRUMENTATION)
} }
// static // static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment