@@ -8162,6 +8162,18 @@ void GenerateTypedArrayLoadFromDataPointer(MaglevAssembler* masm,
81628162 }
81638163}
81648164
8165+ void RetainConstantTypedArrayBuffer (MaglevAssembler* masm,
8166+ compiler::JSTypedArrayRef typed_array) {
8167+ // The constant typed array comes from a constant-folded source (property
8168+ // cell, const field, ...) which holds it strongly, and the code depends on
8169+ // that source not changing. So the buffer behind the embedded data pointer
8170+ // cannot die while this code is valid. Embed the buffer anyway as defense in
8171+ // depth: with this weak reference, the code is deoptimized when the buffer
8172+ // dies.
8173+ masm->code_gen_state ()->Retain (
8174+ typed_array.buffer (masm->compilation_info ()->broker ()).object ());
8175+ }
8176+
81658177template <typename ResultReg>
81668178void GenerateTypedArrayLoad (MaglevAssembler* masm, Register object,
81678179 Register index, ResultReg result_reg,
@@ -8189,6 +8201,8 @@ void GenerateConstantTypedArrayLoad(MaglevAssembler* masm,
81898201 compiler::JSTypedArrayRef typed_array,
81908202 Register index, ResultReg result_reg,
81918203 ElementsKind kind) {
8204+ RetainConstantTypedArrayBuffer (masm, typed_array);
8205+
81928206 MaglevAssembler::TemporaryRegisterScope temps (masm);
81938207 Register data_pointer = temps.Acquire ();
81948208 __ Move (data_pointer, reinterpret_cast <intptr_t >(typed_array.data_ptr ()));
@@ -8250,6 +8264,8 @@ void GenerateConstantTypedArrayStore(MaglevAssembler* masm,
82508264 compiler::JSTypedArrayRef typed_array,
82518265 Register index, ValueReg value,
82528266 ElementsKind elements_kind) {
8267+ RetainConstantTypedArrayBuffer (masm, typed_array);
8268+
82538269 MaglevAssembler::TemporaryRegisterScope temps (masm);
82548270 Register data_pointer = temps.Acquire ();
82558271
0 commit comments