diff --git a/src/codegen/ia32/assembler-ia32-inl.h b/src/codegen/ia32/assembler-ia32-inl.h index 1585f970e8..1d84be7b4a 100644 --- a/src/codegen/ia32/assembler-ia32-inl.h +++ b/src/codegen/ia32/assembler-ia32-inl.h @@ -185,6 +185,13 @@ void Assembler::emit(Handle handle) { void Assembler::emit(uint32_t x, RelocInfo::Mode rmode) { if (!RelocInfo::IsNone(rmode)) { RecordRelocInfo(rmode); + if (rmode == RelocInfo::FULL_EMBEDDED_OBJECT && IsOnHeap()) { + Handle object(reinterpret_cast(x)); + saved_handles_for_raw_object_ptr_.push_back( + std::make_pair(pc_offset(), x)); + emit(object->ptr()); + return; + } } emit(x); } @@ -203,9 +210,15 @@ void Assembler::emit(const Immediate& x) { if (x.is_heap_object_request()) { RequestHeapObject(x.heap_object_request()); emit(0); - } else { - emit(x.immediate()); + return; } + if (x.is_embedded_object() && IsOnHeap()) { + saved_handles_for_raw_object_ptr_.push_back( + std::make_pair(pc_offset(), x.immediate())); + emit(x.embedded_object()->ptr()); + return; + } + emit(x.immediate()); } void Assembler::emit_code_relative_offset(Label* label) { diff --git a/src/codegen/ia32/assembler-ia32.cc b/src/codegen/ia32/assembler-ia32.cc index 24e926f80d..1880ee1ad7 100644 --- a/src/codegen/ia32/assembler-ia32.cc +++ b/src/codegen/ia32/assembler-ia32.cc @@ -3345,6 +3345,8 @@ void Assembler::GrowBuffer() { DCHECK(buffer_overflow()); DCHECK_EQ(buffer_start_, buffer_->start()); + bool previously_on_heap = buffer_->IsOnHeap(); + // Compute new buffer size. int old_size = buffer_->size(); int new_size = 2 * old_size; @@ -3392,6 +3394,14 @@ void Assembler::GrowBuffer() { it.rinfo()->apply(pc_delta); } + // Patch on-heap references to handles. + if (previously_on_heap && !buffer_->IsOnHeap()) { + Address base = reinterpret_cast
(buffer_->start()); + for (auto p : saved_handles_for_raw_object_ptr_) { + WriteUnalignedValue(base + p.first, p.second); + } + } + DCHECK(!buffer_overflow()); }