5 #include "src/assembler-inl.h" 6 #include "src/deoptimizer.h" 7 #include "src/objects-inl.h" 8 #include "src/register-configuration.h" 9 #include "src/safepoint-table.h" 14 const int Deoptimizer::table_entry_size_ = 8;
20 void Deoptimizer::TableEntryGenerator::Generate() {
24 const int kNumberOfRegisters = Register::kNumRegisters;
27 RegList restored_regs = kJSCallerSaved | kCalleeSaved | ip.bit();
29 const int kDoubleRegsSize = kDoubleSize * DwVfpRegister::kNumRegisters;
30 const int kFloatRegsSize = kFloatSize * SwVfpRegister::kNumRegisters;
35 CpuFeatureScope scope(masm(), VFP32DREGS,
36 CpuFeatureScope::kDontCheckSupported);
37 UseScratchRegisterScope temps(masm());
38 Register scratch = temps.Acquire();
41 __ CheckFor32DRegs(scratch);
45 __ vstm(db_w, sp, d16, d31, ne);
46 __ sub(sp, sp, Operand(16 * kDoubleSize), LeaveCC, eq);
47 __ vstm(db_w, sp, d0, d15);
50 __ vstm(db_w, sp, s0, s31);
56 __ stm(db_w, sp, restored_regs | sp.bit() | lr.bit() | pc.bit());
59 UseScratchRegisterScope temps(masm());
60 Register scratch = temps.Acquire();
61 __ mov(scratch, Operand(ExternalReference::Create(
62 IsolateAddressId::kCEntryFPAddress, isolate())));
63 __ str(fp, MemOperand(scratch));
66 const int kSavedRegistersAreaSize =
67 (kNumberOfRegisters * kPointerSize) + kDoubleRegsSize + kFloatRegsSize;
70 __ ldr(r2, MemOperand(sp, kSavedRegistersAreaSize));
77 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize)));
82 __ PrepareCallCFunction(6);
83 __ mov(r0, Operand(0));
85 __ ldr(r1, MemOperand(fp, CommonFrameConstants::kContextOrFrameTypeOffset));
86 __ JumpIfSmi(r1, &context_check);
87 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
88 __ bind(&context_check);
89 __ mov(r1, Operand(static_cast<int>(deopt_kind())));
92 __ str(r4, MemOperand(sp, 0 * kPointerSize));
93 __ mov(r5, Operand(ExternalReference::isolate_address(isolate())));
94 __ str(r5, MemOperand(sp, 1 * kPointerSize));
97 AllowExternalCallThatCantCauseGC scope(masm());
98 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 6);
103 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset()));
106 DCHECK_EQ(Register::kNumRegisters, kNumberOfRegisters);
107 for (
int i = 0;
i < kNumberOfRegisters;
i++) {
108 int offset = (
i * kPointerSize) + FrameDescription::registers_offset();
109 __ ldr(r2, MemOperand(sp,
i * kPointerSize));
110 __ str(r2, MemOperand(r1, offset));
115 int double_regs_offset = FrameDescription::double_registers_offset();
116 const RegisterConfiguration* config = RegisterConfiguration::Default();
117 for (
int i = 0;
i < config->num_allocatable_double_registers(); ++
i) {
118 int code = config->GetAllocatableDoubleCode(
i);
119 int dst_offset = code * kDoubleSize + double_regs_offset;
121 code * kDoubleSize + kNumberOfRegisters * kPointerSize + kFloatRegsSize;
122 __ vldr(d0, sp, src_offset);
123 __ vstr(d0, r1, dst_offset);
128 int float_regs_offset = FrameDescription::float_registers_offset();
129 for (
int i = 0;
i < config->num_allocatable_float_registers(); ++
i) {
130 int code = config->GetAllocatableFloatCode(
i);
131 int dst_offset = code * kFloatSize + float_regs_offset;
132 int src_offset = code * kFloatSize + kNumberOfRegisters * kPointerSize;
133 __ ldr(r2, MemOperand(sp, src_offset));
134 __ str(r2, MemOperand(r1, dst_offset));
138 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize)));
142 __ ldr(r2, MemOperand(r1, FrameDescription::frame_size_offset()));
148 __ add(r3, r1, Operand(FrameDescription::frame_content_offset()));
150 Label pop_loop_header;
151 __ b(&pop_loop_header);
154 __ str(r4, MemOperand(r3, 0));
155 __ add(r3, r3, Operand(
sizeof(
uint32_t)));
156 __ bind(&pop_loop_header);
163 __ PrepareCallCFunction(1);
166 AllowExternalCallThatCantCauseGC scope(masm());
167 __ CallCFunction(ExternalReference::compute_output_frames_function(), 1);
171 __ ldr(sp, MemOperand(r0, Deoptimizer::caller_frame_top_offset()));
174 Label outer_push_loop, inner_push_loop,
175 outer_loop_header, inner_loop_header;
178 __ ldr(r1, MemOperand(r0, Deoptimizer::output_count_offset()));
179 __ ldr(r4, MemOperand(r0, Deoptimizer::output_offset()));
180 __ add(r1, r4, Operand(r1, LSL, 2));
181 __ jmp(&outer_loop_header);
182 __ bind(&outer_push_loop);
184 __ ldr(r2, MemOperand(r4, 0));
185 __ ldr(r3, MemOperand(r2, FrameDescription::frame_size_offset()));
186 __ jmp(&inner_loop_header);
187 __ bind(&inner_push_loop);
188 __ sub(r3, r3, Operand(
sizeof(
uint32_t)));
189 __ add(r6, r2, Operand(r3));
190 __ ldr(r6, MemOperand(r6, FrameDescription::frame_content_offset()));
192 __ bind(&inner_loop_header);
193 __ cmp(r3, Operand::Zero());
194 __ b(ne, &inner_push_loop);
195 __ add(r4, r4, Operand(kPointerSize));
196 __ bind(&outer_loop_header);
198 __ b(lt, &outer_push_loop);
200 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset()));
201 for (
int i = 0;
i < config->num_allocatable_double_registers(); ++
i) {
202 int code = config->GetAllocatableDoubleCode(
i);
203 DwVfpRegister reg = DwVfpRegister::from_code(code);
204 int src_offset = code * kDoubleSize + double_regs_offset;
205 __ vldr(reg, r1, src_offset);
209 __ ldr(r6, MemOperand(r2, FrameDescription::pc_offset()));
211 __ ldr(r6, MemOperand(r2, FrameDescription::continuation_offset()));
215 for (
int i = kNumberOfRegisters - 1;
i >= 0;
i--) {
216 int offset = (
i * kPointerSize) + FrameDescription::registers_offset();
217 __ ldr(r6, MemOperand(r2, offset));
222 __ ldm(ia_w, sp, restored_regs);
227 UseScratchRegisterScope temps(masm());
228 Register scratch = temps.Acquire();
233 __ stop(
"Unreachable.");
237 void Deoptimizer::TableEntryGenerator::GeneratePrologue() {
244 STATIC_ASSERT((kMaxNumberOfEntries - 1) <= 0xFFFF);
245 UseScratchRegisterScope temps(masm());
246 Register scratch = temps.Acquire();
247 if (CpuFeatures::IsSupported(ARMv7)) {
248 CpuFeatureScope scope(masm(), ARMv7);
250 for (
int i = 0;
i < count();
i++) {
251 int start = masm()->pc_offset();
255 DCHECK_EQ(table_entry_size_, masm()->pc_offset() - start);
263 Label high_fixes[256];
264 int high_fix_max = (count() - 1) >> 8;
265 DCHECK_GT(arraysize(high_fixes), static_cast<size_t>(high_fix_max));
266 for (
int i = 0;
i < count();
i++) {
267 int start = masm()->pc_offset();
269 __ mov(scratch, Operand(
i & 0xFF));
270 __ b(&high_fixes[
i >> 8]);
271 DCHECK_EQ(table_entry_size_, masm()->pc_offset() - start);
274 for (
int high = 1; high <= high_fix_max; high++) {
275 __ bind(&high_fixes[high]);
276 __ orr(scratch, scratch, Operand(high << 8));
279 if (high < high_fix_max) __ b(&high_fixes[0]);
284 __ bind(&high_fixes[0]);
289 bool Deoptimizer::PadTopOfStackRegister() {
return false; }
291 void FrameDescription::SetCallerPc(
unsigned offset, intptr_t value) {
292 SetFrameSlot(offset, value);
296 void FrameDescription::SetCallerFp(
unsigned offset, intptr_t value) {
297 SetFrameSlot(offset, value);
301 void FrameDescription::SetCallerConstantPool(
unsigned offset, intptr_t value) {