Commit 9d0b15af authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

Enables the allocator shim by default on iOS.

Compiles the SamplingHeapProfiler, with associated tests, and adds iOS
to the list of platforms which use the allocator shim.

BUG=1075702

Change-Id: I4e20027633f0e4ca9b49c37b110f6548ae8ace46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2168810
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763472}
parent c21b46e5
......@@ -1186,6 +1186,10 @@ jumbo_component("base") {
if (is_ios) {
sources += [
"allocator/allocator_interception_mac.h",
"allocator/allocator_interception_mac.mm",
"allocator/malloc_zone_functions_mac.cc",
"allocator/malloc_zone_functions_mac.h",
"critical_closure_internal_ios.mm",
"ios/block_types.h",
"ios/crb_protocol_observers.h",
......@@ -1362,7 +1366,7 @@ jumbo_component("base") {
"allocator/allocator_shim_override_linker_wrapped_symbols.h",
]
all_dependent_configs += [ "//base/allocator:wrap_malloc_symbols" ]
} else if (is_mac) {
} else if (is_mac || is_ios) {
sources += [
"allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc",
"allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.h",
......@@ -1969,10 +1973,6 @@ jumbo_component("base") {
"process/process_iterator.h",
"process/process_metrics_posix.cc",
"process/process_posix.cc",
"sampling_heap_profiler/poisson_allocation_sampler.cc",
"sampling_heap_profiler/poisson_allocation_sampler.h",
"sampling_heap_profiler/sampling_heap_profiler.cc",
"sampling_heap_profiler/sampling_heap_profiler.h",
"sync_socket.h",
"sync_socket_posix.cc",
"synchronization/waitable_event_watcher.h",
......@@ -2984,6 +2984,8 @@ test("base_unittests") {
if (is_ios) {
sources += [
"allocator/allocator_interception_mac_unittest.mm",
"allocator/malloc_zone_functions_mac_unittest.cc",
"ios/crb_protocol_observers_unittest.mm",
"ios/device_util_unittest.mm",
"ios/weak_nsobject_unittest.mm",
......
......@@ -17,7 +17,7 @@ if (is_android || is_mac || is_ios || is_asan || is_lsan || is_tsan ||
# The debug CRT on Windows has some debug features that are incompatible with
# the shim. NaCl in particular does seem to link some binaries statically
# against the debug CRT with "is_nacl=false".
if ((is_linux || is_android || is_mac ||
if ((is_linux || is_android || is_mac || is_ios ||
(is_win && !is_component_build && !is_debug)) && !is_asan && !is_hwasan &&
!is_lsan && !is_tsan && !is_msan) {
_default_use_allocator_shim = true
......@@ -37,9 +37,11 @@ assert(use_allocator == "none" || use_allocator == "tcmalloc")
assert(!is_win || use_allocator == "none", "Tcmalloc doesn't work on Windows.")
assert(!is_mac || use_allocator == "none", "Tcmalloc doesn't work on macOS.")
assert(!is_ios || use_allocator == "none", "Tcmalloc doesn't work on iOS.")
assert(!use_allocator_shim || is_linux || is_android || is_win || is_mac,
"use_allocator_shim works only on Android, Linux, macOS, and Windows.")
assert(
!use_allocator_shim || is_linux || is_android || is_win || is_mac || is_ios,
"use_allocator_shim works only on Android, Linux, macOS, iOS, and Windows.")
if (is_win && use_allocator_shim) {
assert(!is_component_build,
......
......@@ -31,13 +31,18 @@
#include "base/bind.h"
#include "base/bits.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/mac/mach_logging.h"
#include "base/process/memory.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h"
#include "third_party/apple_apsl/CFBase.h"
#if defined(OS_IOS)
#include "base/ios/ios_util.h"
#else
#include "base/mac/mac_util.h"
#endif
namespace base {
namespace allocator {
......@@ -208,7 +213,11 @@ void* oom_killer_memalign_purgeable(struct _malloc_zone_t* zone,
// === Core Foundation CFAllocators ===
bool CanGetContextForCFAllocator() {
#if defined(OS_IOS)
return !base::ios::IsRunningOnOrLater(14, 0, 0);
#else
return !base::mac::IsOSLaterThan10_15_DontCallThis();
#endif
}
CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) {
......
......@@ -116,7 +116,13 @@ TEST_F(SamplingHeapProfilerTest, IntervalRandomizationSanity) {
EXPECT_NEAR(1000, mean_samples, 100); // 10% tolerance.
}
#if defined(OS_IOS)
// iOS devices generally have ~4GB of RAM with no swap and therefore need a
// lower allocation limit here.
const int kNumberOfAllocations = 1000;
#else
const int kNumberOfAllocations = 10000;
#endif
NOINLINE void Allocate1() {
void* p = malloc(400);
......
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