Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ | |
| 6 #define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include <sys/types.h> | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/files/file_util.h" | |
| 14 #include "base/gtest_prod_util.h" | |
| 15 #include "base/macros.h" | |
| 16 #include "base/strings/string_split.h" | |
| 17 | |
| 18 namespace base { | |
| 19 namespace android { | |
| 20 | |
| 21 class NativeLibraryPrefetcher { | |
| 22 public: | |
| 23 // Finds the ranges matching the native library, forks a low priority | |
| 24 // process pre-fetching these ranges and wait()s for it. | |
| 25 // Returns false on error. | |
| 26 static bool ForkAndPrefetchNativeLibrary(); | |
| 27 | |
| 28 private: | |
| 29 struct Mapping { | |
| 30 uint64_t start; | |
| 31 uint64_t end; | |
| 32 std::string flags; | |
| 33 std::string filename; | |
| 34 }; | |
| 35 | |
| 36 // Returns true for success. | |
| 37 static bool ParseMapping(const std::string& line, Mapping* mapping); | |
| 38 // Returns true if the mapping matches native code or data. | |
| 39 static bool IsGoodToPrefetch(const Mapping& mapping); | |
| 40 // Finds the ranges matching the native library in /proc/self/maps. | |
| 41 // Returns true for success. | |
| 42 static bool FindRanges(std::vector<std::pair<uint64_t, uint64_t>>* range); | |
| 43 | |
| 44 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine32Bits); | |
| 45 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLine64Bits); | |
| 46 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, TestParseLineNoFile); | |
| 47 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.
| |
| 48 NativeLibraryPrefetcherTest, TestIsGoodToPrefetchNoRange); | |
| 49 FRIEND_TEST_ALL_PREFIXES( | |
| 50 NativeLibraryPrefetcherTest, TestIsGoodToPrefetchUnreadableRange); | |
| 51 FRIEND_TEST_ALL_PREFIXES( | |
| 52 NativeLibraryPrefetcherTest, TestIsGoodToPrefetchSkipSharedRange); | |
| 53 FRIEND_TEST_ALL_PREFIXES( | |
| 54 NativeLibraryPrefetcherTest, TestIsGoodToPrefetchLibchromeRange); | |
| 55 FRIEND_TEST_ALL_PREFIXES( | |
| 56 NativeLibraryPrefetcherTest, TestIsGoodToPrefetchBaseApkRange); | |
| 57 }; | |
| 58 | |
| 59 } // namespace android | |
| 60 } // namespace base | |
| 61 | |
| 62 #endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ | |
| OLD | NEW |