Skip to content

Commit 2a56cd6

Browse files
committed
fix(ios): disable the cppgc caged heap
cppgc_enable_caged_heap defaults to true on arm64 and does not track v8_enable_pointer_compression, so it stayed on despite that being off. Enabling it forces cppgc pointer compression, whose reservation asks for twice the cage to satisfy alignment, and V8::Initialize() calls cppgc::InitializeProcess unconditionally -- so every iOS app reserved 8 GiB of 4 GiB-aligned address space at startup without using cppgc. iOS budgets virtual address space per process by device RAM. On smaller devices no such hole exists, the four reservation attempts all fail, and Oilpan's fatal OOM handler aborts before any JS runs: an iPad Air crashed on launch where an iPad Pro was fine. Costs cppgc pointer compression, its young generation and a write-barrier fast path. Nothing in the cppgc API changes and CppHeap is unaffected. Android keeps the cage; 64-bit has the address space and 32-bit cannot enable it anyway.
1 parent 1650a17 commit 2a56cd6

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,22 @@ platform), dispatch the workflow with `platforms: android` or `platforms: ios`.
133133
## The gn args are load-bearing
134134

135135
They are commented at their definition in `scripts/matrix/build-android.sh` and
136-
`scripts/matrix/build-ios.sh`. Two worth knowing:
136+
`scripts/matrix/build-ios.sh`. Three worth knowing:
137+
138+
- `cppgc_enable_caged_heap=false` (iOS only) — it defaults to **true on arm64**
139+
and, contrary to how the flags read, does *not* track
140+
`v8_enable_pointer_compression`; enabling it forces cppgc's own pointer
141+
compression on, whose reservation asks for twice the cage to satisfy
142+
alignment. Since `V8::Initialize()` calls `cppgc::InitializeProcess`
143+
unconditionally, every app reserved **8 GiB of 4 GiB-aligned address space** at
144+
startup regardless of whether it used cppgc. iOS budgets virtual address space
145+
per process by device RAM, so on smaller devices that reservation simply fails
146+
and Oilpan's fatal OOM handler aborts the process before any JS runs — an iPad
147+
Air crashed on launch while an iPad Pro was fine. Turning it off costs cppgc
148+
pointer compression (`Member<T>` becomes 8 bytes), the cppgc young generation,
149+
and a write-barrier fast path; it costs nothing in API, and `CppHeap` and
150+
unified heap tracing are unaffected. Android keeps the cage: 64-bit ABIs have
151+
the address space for it, and it is unavailable on the 32-bit ones anyway.
137152

138153
- `v8_array_buffer_internal_field_count=2` — defaulted to 2 in 10.3 and defaults
139154
to 0 in 14.9. The Android runtime links a `JSInstanceInfo` into internal field

scripts/matrix/build-ios.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ MODULES=(
7070
# iOS proper cannot JIT, so it is built in lite mode. Catalyst runs on macOS,
7171
# where JIT is permitted, and is deliberately not lite -- keeping the two arg
7272
# sets distinct preserves what each currently ships.
73+
#
74+
# cppgc_enable_caged_heap=false is load-bearing and not implied by anything
75+
# else here. It defaults to true on arm64 ("Enable heap reservation of size
76+
# 4GB") independently of v8_enable_pointer_compression, and enabling it forces
77+
# cppgc_enable_pointer_compression on, whose reservation path asks for twice
78+
# the cage to satisfy alignment. V8::Initialize() calls cppgc::InitializeProcess
79+
# unconditionally, so every app reserved 8 GiB of 4 GiB-aligned address space at
80+
# startup whether or not it used cppgc. iOS budgets virtual address space per
81+
# process by device RAM, so that reservation fails outright on smaller devices
82+
# -- four tries, then Oilpan's fatal OOM handler, before any JS runs. It crashed
83+
# on an iPad Air while an iPad Pro was fine.
7384
GN_ARGS="
7485
target_os=\"ios\"
7586
treat_warnings_as_errors=false
@@ -89,6 +100,7 @@ GN_ARGS="
89100
v8_enable_pointer_compression=false
90101
v8_enable_v8_checks=false
91102
v8_enable_webassembly=false
103+
cppgc_enable_caged_heap=false
92104
symbol_level=0
93105
"
94106

0 commit comments

Comments
 (0)