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 <stdint.h> | |
11 #include <string> | |
12 | |
13 #include "base/debug/proc_maps_linux.h" | |
14 #include "base/gtest_prod_util.h" | |
15 | |
16 namespace base { | |
17 namespace android { | |
18 | |
19 class NativeLibraryPrefetcher { | |
20 public: | |
21 // Finds the ranges matching the native library, forks a low priority | |
22 // process pre-fetching these ranges and wait()s for it. | |
23 // Returns false on error. | |
24 static bool ForkAndPrefetchNativeLibrary(); | |
25 | |
26 private: | |
27 using AddressRange = std::pair<uintptr_t, uintptr_t>; | |
28 // Returns true if the region matches native code or data. | |
29 static bool IsGoodToPrefetch(const base::debug::MappedMemoryRegion& region); | |
30 // Filters the regions to keep only libchrome ranges if possible. | |
31 static void TakeOnlyLibchromeRangesIfPossible( | |
32 const std::vector<base::debug::MappedMemoryRegion>& regions, | |
33 std::vector<AddressRange>* ranges); | |
34 // Finds the ranges matching the native library in /proc/self/maps. | |
35 // Returns true for success. | |
36 static bool FindRanges(std::vector<AddressRange>* ranges); | |
37 | |
38 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
39 TestIsGoodToPrefetchNoRange); | |
40 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
41 TestIsGoodToPrefetchUnreadableRange); | |
42 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
43 TestIsGoodToPrefetchSkipSharedRange); | |
44 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
45 TestIsGoodToPrefetchLibchromeRange); | |
46 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
47 TestIsGoodToPrefetchBaseApkRange); | |
48 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
49 TestTakeOnlyLibchromeRangesIfPossibleNoLibchrome); | |
50 FRIEND_TEST_ALL_PREFIXES(NativeLibraryPrefetcherTest, | |
51 TestTakeOnlyLibchromeRangesIfPossibleHasLibchrome); | |
52 }; | |
Robert Sesek
2015/04/02 19:46:48
DISALLOW_IMPLICIT_CONSTRUCTORS() to prevent instan
Benoit L
2015/04/03 09:47:16
Done.
| |
53 | |
54 } // namespace android | |
55 } // namespace base | |
56 | |
57 #endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_PREFETCHER_H_ | |
OLD | NEW |