Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Unified Diff: base/android/library_loader/library_prefetcher.h

Issue 1001343002: Prefetch the native library from native code by parsing /proc/pid/maps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/android/library_loader/library_prefetcher.h
diff --git a/base/android/library_loader/library_prefetcher.h b/base/android/library_loader/library_prefetcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..317240abc633578f04f774a2484aba65fd212ee2
--- /dev/null
+++ b/base/android/library_loader/library_prefetcher.h
@@ -0,0 +1,62 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_
+#define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_
+
+#include <jni.h>
+
+#include <sys/types.h>
+#include <string>
+
+#include "base/files/file_util.h"
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/strings/string_split.h"
+
+namespace base {
+namespace android {
+
+class NativeLibraryPrefetcher {
+ public:
+ // Finds the ranges matching the native library, forks a low priority
+ // process pre-fetching these ranges and wait()s for it.
+ // Returns false on error.
+ static bool ForkAndPrefetchNativeLibrary();
+
+ private:
+ struct Mapping {
+ uint64_t start;
+ uint64_t end;
+ std::string flags;
+ std::string filename;
+ };
+
+ // Returns true for success.
+ static bool ParseMapping(const std::string& line, Mapping* mapping);
+ // Returns true if the mapping matches native code or data.
+ static bool IsGoodToPrefetch(const Mapping& mapping);
+ // Finds the ranges matching the native library in /proc/self/maps.
+ // Returns true for success.
+ static bool FindRanges(std::vector<std::pair<uint64_t, uint64_t>>* range);
+
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine32Bits);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine64Bits);
+ FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLineNoFile);
+ FRIEND_TEST_ALL_PREFIXES(
pasko 2015/03/31 12:01:43 please to 'git cl format' for this change, it will
Benoit L 2015/03/31 14:00:01 Done.
+ NativeLibraryPrefetcherTest, TestIsGoodToPrefetchNoRange);
+ FRIEND_TEST_ALL_PREFIXES(
+ NativeLibraryPrefetcherTest, TestIsGoodToPrefetchUnreadableRange);
+ FRIEND_TEST_ALL_PREFIXES(
+ NativeLibraryPrefetcherTest, TestIsGoodToPrefetchSkipSharedRange);
+ FRIEND_TEST_ALL_PREFIXES(
+ NativeLibraryPrefetcherTest, TestIsGoodToPrefetchLibchromeRange);
+ FRIEND_TEST_ALL_PREFIXES(
+ NativeLibraryPrefetcherTest, TestIsGoodToPrefetchBaseApkRange);
+};
+
+} // namespace android
+} // namespace base
+
+#endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_

Powered by Google App Engine
This is Rietveld 408576698