Chromium Code Reviews
Help | Chromium Project | Gerrit Changes | Sign in
(8)

Issue 1719433002: Introduce allocator shim for Android (Closed)

Created:
3 years, 8 months ago by Primiano Tucci (use gerrit)
Modified:
3 years, 3 months ago
Reviewers:
Nico
CC:
chromium-reviews, wfh+watch_chromium.org, Dai Mikurube (NOT FULLTIME), vmpstr+watch_chromium.org, Will Harris, kraynov, ssid, DmitrySkiba
Base URL:
https://chromium.googlesource.com/chromium/src.git@shim_traceintegration
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Introduce allocator shim for Android This is a follow-up to the work of crrev.com/1675143004 and ports the shim layer to Android. Conversely to Linux, on Android symbol interposition is not possible. This is because Android processes are fork-ed from the Android zygote, which pre-loads libc.so, and later native code gets dlopen-ed. Therefore a different approach is used on Android, that is: - All linker units that depend on //base:allocator (via //base) get the --Wl,-wrap,malloc (& friends) linker flag. - Such linker flags causes all symbol references to malloc to be rewritten as references to __wrap_malloc. - The __wrap_malloc & friends symbols are defined by allocator_shim_override_linker_wrapped_symbols.h. These symbols route the malloc calls inside the shim layer. - The shim layer ultimately dispatches the calls to the __real_malloc symbol. - The special __real_malloc symbols are resolved by the linker (as a result of -wrap) against what would have been the original "malloc" symbol. In summary, this entire trickery is transparent to the dynamic loader, which still sees undefined symbol references to malloc & friend symbols. Those symbols will be resolved against libc.so (or whatever other weird choice the Android OEM made) as usual. An alternative approach would have been just redefining the malloc symbols and use dlsym() to do the routing to bionic. This has the following disadvantages: - More risky, as Chrome for Android has insane layers of complexity around loading (crazylinker pre M, relies on a special flavour of dlopen on M+). - Won't be possible to support component builds, as all components % libbase.so would resolve malloc against libc.so (unless violating ODR and redefining malloc & friends in every component, which smells bad++). All this trickery is a noop when use_experimental_allocator_shim=false. This CL does NOT enable the shim by default on Android. This will happen separately in crrev.com/1875043003 Motivations of this work ------------------------ - This allows the memory-infra heap-profiler to work on Android (design doc: https://goo.gl/UPfbF4). - This enables security checks (suicide on malloc()==null via the std::new_handler) on Android. - This fixes by accident crbug.com/598075 (Some Android device vendor forgot to implement posix_memalign on J, as mandated by the NDK, causing chrome to crash on startup). Performance considerations ------------------------ Binary size diff (GN, arm, static, official build): 24k I did a mixture of local and trybots run to estimate the perf impact of this change. Didn't get any conclusive data, everything I tried seems in the same ballpark, below noise levels. More in details: cc_perftests.PrepareTiles on a Nexus 4. Rationale of the choice: in a previous CL (crbug.com/593344), this benchmark revealed the presence of two mfences in the malloc path. Results: https://goo.gl/8VC3Jp in the same ballpark. page-cycler on Nexus 9 via trybots: Results: http://goo.gl/J3i50a seems to suggest that this CL improves both warm and cold times in most cases. I doubt it, more likely it's noise. All the other perf trybots failed. The perf waterfall seems to be in a bad state in these days. BUG=550886, 598075 TEST=base_unittests --gtest_filter=AllocatorShimTest.* Committed: https://crrev.com/40b65c66b855b58cb2fda9228b7626f2904581a5 Cr-Commit-Position: refs/heads/master@{#386382}

Patch Set 1 #

Patch Set 2 : android host toolchain #

Total comments: 6

Patch Set 3 : Add readme changes, do NOT enabled by default in this cl #

Unified diffs Side-by-side diffs Delta from patch set Stats (+253 lines, -5 lines) Patch
M base/allocator/BUILD.gn View 1 2 chunks +21 lines, -1 line 0 comments Download
M base/allocator/README.md View 1 2 2 chunks +91 lines, -1 line 0 comments Download
M base/allocator/allocator.gyp View 1 2 1 chunk +22 lines, -1 line 0 comments Download
M base/allocator/allocator_shim.cc View 1 1 chunk +6 lines, -0 lines 0 comments Download
A base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc View 1 2 1 chunk +57 lines, -0 lines 0 comments Download
A base/allocator/allocator_shim_override_linker_wrapped_symbols.h View 1 1 chunk +44 lines, -0 lines 0 comments Download
M base/allocator/allocator_shim_unittest.cc View 1 2 1 chunk +9 lines, -0 lines 0 comments Download
M build/config/allocator.gni View 1 2 1 chunk +3 lines, -2 lines 0 comments Download

Dependent Patchsets:

Messages

Total messages: 27 (19 generated)
Primiano Tucci (use gerrit)
Hi, I'm back! Nico, I still have to look to perf numbers and fix build ...
3 years, 7 months ago (2016-04-06 17:13:11 UTC) #5
Primiano Tucci (use gerrit)
On 2016/04/06 17:13:11, Primiano Tucci wrote: > Hi, I'm back! > Nico, I still have ...
3 years, 7 months ago (2016-04-06 17:16:23 UTC) #6
Primiano Tucci (use gerrit)
Ok I fixed build issues and did perf investigations. This is ready from my side. ...
3 years, 7 months ago (2016-04-08 18:41:18 UTC) #17
Nico
lgtm as far as i can tell. consider landing the part that toggles the flag ...
3 years, 7 months ago (2016-04-08 20:23:07 UTC) #18
Primiano Tucci (use gerrit)
Thanks for the review Nico. Splitting out the enabling in crrev.com/1875043003 Also I realized that ...
3 years, 7 months ago (2016-04-11 13:49:14 UTC) #20
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1719433002/160001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1719433002/160001
3 years, 7 months ago (2016-04-11 13:49:35 UTC) #23
commit-bot: I haz the power
Committed patchset #3 (id:160001)
3 years, 7 months ago (2016-04-11 14:47:37 UTC) #25
commit-bot: I haz the power
3 years, 7 months ago (2016-04-11 14:49:20 UTC) #27
Message was sent while issue was closed.
Patchset 3 (id:??) landed as
https://crrev.com/40b65c66b855b58cb2fda9228b7626f2904581a5
Cr-Commit-Position: refs/heads/master@{#386382}

Powered by Google App Engine
This is Rietveld 408576698