1 // Copyright 2012 the V8 project authors. All rights reserved. 2 // Redistribution and use in source and binary forms, with or without 3 // modification, are permitted provided that the following conditions are 4 // met: 5 // 6 // * Redistributions of source code must retain the above copyright 7 // notice, this list of conditions and the following disclaimer. 8 // * Redistributions in binary form must reproduce the above 9 // copyright notice, this list of conditions and the following 10 // disclaimer in the documentation and/or other materials provided 11 // with the distribution. 12 // * Neither the name of Google Inc. nor the names of its 13 // contributors may be used to endorse or promote products derived 14 // from this software without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 #include "v8.h" 29 30 #include "codegen.h" 31 #include "deoptimizer.h" 32 #include "full-codegen.h" 33 #include "safepoint-table.h" 34 35 namespace v8 { 36 namespace internal { 37 38 const int Deoptimizer::table_entry_size_ = 12; 39 40 41 int Deoptimizer::patch_size() { 42 const int kCallInstructionSizeInWords = 3; 43 return kCallInstructionSizeInWords * Assembler::kInstrSize; 44 } 45 46 47 void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { 48 Address code_start_address = code->instruction_start(); 49 // Invalidate the relocation information, as it will become invalid by the 50 // code patching below, and is not needed any more. 51 code->InvalidateRelocation(); 52 53 // For each LLazyBailout instruction insert a call to the corresponding 54 // deoptimization entry. 55 DeoptimizationInputData* deopt_data = 56 DeoptimizationInputData::cast(code->deoptimization_data()); 57 #ifdef DEBUG 58 Address prev_call_address = NULL; 59 #endif 60 for (int i = 0; i < deopt_data->DeoptCount(); i++) { 61 if (deopt_data->Pc(i)->value() == -1) continue; 62 Address call_address = code_start_address + deopt_data->Pc(i)->value(); 63 Address deopt_entry = GetDeoptimizationEntry(isolate, i, LAZY); 64 // We need calls to have a predictable size in the unoptimized code, but 65 // this is optimized code, so we don't have to have a predictable size. 66 int call_size_in_bytes = 67 MacroAssembler::CallSizeNotPredictableCodeSize(deopt_entry, 68 RelocInfo::NONE32); 69 int call_size_in_words = call_size_in_bytes / Assembler::kInstrSize; 70 ASSERT(call_size_in_bytes % Assembler::kInstrSize == 0); 71 ASSERT(call_size_in_bytes <= patch_size()); 72 CodePatcher patcher(call_address, call_size_in_words); 73 patcher.masm()->Call(deopt_entry, RelocInfo::NONE32); 74 ASSERT(prev_call_address == NULL || 75 call_address >= prev_call_address + patch_size()); 76 ASSERT(call_address + patch_size() <= code->instruction_end()); 77 #ifdef DEBUG 78 prev_call_address = call_address; 79 #endif 80 } 81 } 82 83 84 static const int32_t kBranchBeforeInterrupt = 0x5a000004; 85 86 // The back edge bookkeeping code matches the pattern: 87 // 88 // <decrement profiling counter> 89 // 2a 00 00 01 bpl ok 90 // e5 9f c? ?? ldr ip, [pc, <interrupt stub address>] 91 // e1 2f ff 3c blx ip 92 // ok-label 93 // 94 // We patch the code to the following form: 95 // 96 // <decrement profiling counter> 97 // e1 a0 00 00 mov r0, r0 (NOP) 98 // e5 9f c? ?? ldr ip, [pc, <on-stack replacement address>] 99 // e1 2f ff 3c blx ip 100 // ok-label 101 102 void Deoptimizer::PatchInterruptCodeAt(Code* unoptimized_code, 103 Address pc_after, 104 Code* interrupt_code, 105 Code* replacement_code) { 106 ASSERT(!InterruptCodeIsPatched(unoptimized_code, 107 pc_after, 108 interrupt_code, 109 replacement_code)); 110 static const int kInstrSize = Assembler::kInstrSize; 111 // Turn the jump into nops. 112 CodePatcher patcher(pc_after - 3 * kInstrSize, 1); 113 patcher.masm()->nop(); 114 // Replace the call address. 115 uint32_t interrupt_address_offset = Memory::uint16_at(pc_after - 116 2 * kInstrSize) & 0xfff; 117 Address interrupt_address_pointer = pc_after + interrupt_address_offset; 118 Memory::uint32_at(interrupt_address_pointer) = 119 reinterpret_cast<uint32_t>(replacement_code->entry()); 120 121 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( 122 unoptimized_code, pc_after - 2 * kInstrSize, replacement_code); 123 } 124 125 126 void Deoptimizer::RevertInterruptCodeAt(Code* unoptimized_code, 127 Address pc_after, 128 Code* interrupt_code, 129 Code* replacement_code) { 130 ASSERT(InterruptCodeIsPatched(unoptimized_code, 131 pc_after, 132 interrupt_code, 133 replacement_code)); 134 static const int kInstrSize = Assembler::kInstrSize; 135 // Restore the original jump. 136 CodePatcher patcher(pc_after - 3 * kInstrSize, 1); 137 patcher.masm()->b(4 * kInstrSize, pl); // ok-label is 4 instructions later. 138 ASSERT_EQ(kBranchBeforeInterrupt, 139 Memory::int32_at(pc_after - 3 * kInstrSize)); 140 // Restore the original call address. 141 uint32_t interrupt_address_offset = Memory::uint16_at(pc_after - 142 2 * kInstrSize) & 0xfff; 143 Address interrupt_address_pointer = pc_after + interrupt_address_offset; 144 Memory::uint32_at(interrupt_address_pointer) = 145 reinterpret_cast<uint32_t>(interrupt_code->entry()); 146 147 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( 148 unoptimized_code, pc_after - 2 * kInstrSize, interrupt_code); 149 } 150 151 152 #ifdef DEBUG 153 bool Deoptimizer::InterruptCodeIsPatched(Code* unoptimized_code, 154 Address pc_after, 155 Code* interrupt_code, 156 Code* replacement_code) { 157 static const int kInstrSize = Assembler::kInstrSize; 158 ASSERT(Memory::int32_at(pc_after - kInstrSize) == kBlxIp); 159 160 uint32_t interrupt_address_offset = 161 Memory::uint16_at(pc_after - 2 * kInstrSize) & 0xfff; 162 Address interrupt_address_pointer = pc_after + interrupt_address_offset; 163 164 if (Assembler::IsNop(Assembler::instr_at(pc_after - 3 * kInstrSize))) { 165 ASSERT(Assembler::IsLdrPcImmediateOffset( 166 Assembler::instr_at(pc_after - 2 * kInstrSize))); 167 ASSERT(reinterpret_cast<uint32_t>(replacement_code->entry()) == 168 Memory::uint32_at(interrupt_address_pointer)); 169 return true; 170 } else { 171 ASSERT(Assembler::IsLdrPcImmediateOffset( 172 Assembler::instr_at(pc_after - 2 * kInstrSize))); 173 ASSERT_EQ(kBranchBeforeInterrupt, 174 Memory::int32_at(pc_after - 3 * kInstrSize)); 175 ASSERT(reinterpret_cast<uint32_t>(interrupt_code->entry()) == 176 Memory::uint32_at(interrupt_address_pointer)); 177 return false; 178 } 179 } 180 #endif // DEBUG 181 182 183 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { 184 ByteArray* translations = data->TranslationByteArray(); 185 int length = data->DeoptCount(); 186 for (int i = 0; i < length; i++) { 187 if (data->AstId(i) == ast_id) { 188 TranslationIterator it(translations, data->TranslationIndex(i)->value()); 189 int value = it.Next(); 190 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); 191 // Read the number of frames. 192 value = it.Next(); 193 if (value == 1) return i; 194 } 195 } 196 UNREACHABLE(); 197 return -1; 198 } 199 200 201 void Deoptimizer::DoComputeOsrOutputFrame() { 202 DeoptimizationInputData* data = DeoptimizationInputData::cast( 203 compiled_code_->deoptimization_data()); 204 unsigned ast_id = data->OsrAstId()->value(); 205 206 int bailout_id = LookupBailoutId(data, BailoutId(ast_id)); 207 unsigned translation_index = data->TranslationIndex(bailout_id)->value(); 208 ByteArray* translations = data->TranslationByteArray(); 209 210 TranslationIterator iterator(translations, translation_index); 211 Translation::Opcode opcode = 212 static_cast<Translation::Opcode>(iterator.Next()); 213 ASSERT(Translation::BEGIN == opcode); 214 USE(opcode); 215 int count = iterator.Next(); 216 iterator.Skip(1); // Drop JS frame count. 217 ASSERT(count == 1); 218 USE(count); 219 220 opcode = static_cast<Translation::Opcode>(iterator.Next()); 221 USE(opcode); 222 ASSERT(Translation::JS_FRAME == opcode); 223 unsigned node_id = iterator.Next(); 224 USE(node_id); 225 ASSERT(node_id == ast_id); 226 int closure_id = iterator.Next(); 227 USE(closure_id); 228 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); 229 unsigned height = iterator.Next(); 230 unsigned height_in_bytes = height * kPointerSize; 231 USE(height_in_bytes); 232 233 unsigned fixed_size = ComputeFixedSize(function_); 234 unsigned input_frame_size = input_->GetFrameSize(); 235 ASSERT(fixed_size + height_in_bytes == input_frame_size); 236 237 unsigned stack_slot_size = compiled_code_->stack_slots() * kPointerSize; 238 unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value(); 239 unsigned outgoing_size = outgoing_height * kPointerSize; 240 unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size; 241 ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call. 242 243 if (FLAG_trace_osr) { 244 PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ", 245 reinterpret_cast<intptr_t>(function_)); 246 PrintFunctionName(); 247 PrintF(" => node=%u, frame=%d->%d]\n", 248 ast_id, 249 input_frame_size, 250 output_frame_size); 251 } 252 253 // There's only one output frame in the OSR case. 254 output_count_ = 1; 255 output_ = new FrameDescription*[1]; 256 output_[0] = new(output_frame_size) FrameDescription( 257 output_frame_size, function_); 258 output_[0]->SetFrameType(StackFrame::JAVA_SCRIPT); 259 260 // Clear the incoming parameters in the optimized frame to avoid 261 // confusing the garbage collector. 262 unsigned output_offset = output_frame_size - kPointerSize; 263 int parameter_count = function_->shared()->formal_parameter_count() + 1; 264 for (int i = 0; i < parameter_count; ++i) { 265 output_[0]->SetFrameSlot(output_offset, 0); 266 output_offset -= kPointerSize; 267 } 268 269 // Translate the incoming parameters. This may overwrite some of the 270 // incoming argument slots we've just cleared. 271 int input_offset = input_frame_size - kPointerSize; 272 bool ok = true; 273 int limit = input_offset - (parameter_count * kPointerSize); 274 while (ok && input_offset > limit) { 275 ok = DoOsrTranslateCommand(&iterator, &input_offset); 276 } 277 278 // There are no translation commands for the caller's pc and fp, the 279 // context, and the function. Set them up explicitly. 280 for (int i = StandardFrameConstants::kCallerPCOffset; 281 ok && i >= StandardFrameConstants::kMarkerOffset; 282 i -= kPointerSize) { 283 uint32_t input_value = input_->GetFrameSlot(input_offset); 284 if (FLAG_trace_osr) { 285 const char* name = "UNKNOWN"; 286 switch (i) { 287 case StandardFrameConstants::kCallerPCOffset: 288 name = "caller's pc"; 289 break; 290 case StandardFrameConstants::kCallerFPOffset: 291 name = "fp"; 292 break; 293 case StandardFrameConstants::kContextOffset: 294 name = "context"; 295 break; 296 case StandardFrameConstants::kMarkerOffset: 297 name = "function"; 298 break; 299 } 300 PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part - %s)\n", 301 output_offset, 302 input_value, 303 input_offset, 304 name); 305 } 306 307 output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset)); 308 input_offset -= kPointerSize; 309 output_offset -= kPointerSize; 310 } 311 312 // Translate the rest of the frame. 313 while (ok && input_offset >= 0) { 314 ok = DoOsrTranslateCommand(&iterator, &input_offset); 315 } 316 317 // If translation of any command failed, continue using the input frame. 318 if (!ok) { 319 delete output_[0]; 320 output_[0] = input_; 321 output_[0]->SetPc(reinterpret_cast<uint32_t>(from_)); 322 } else { 323 // Set up the frame pointer and the context pointer. 324 output_[0]->SetRegister(fp.code(), input_->GetRegister(fp.code())); 325 output_[0]->SetRegister(cp.code(), input_->GetRegister(cp.code())); 326 327 unsigned pc_offset = data->OsrPcOffset()->value(); 328 uint32_t pc = reinterpret_cast<uint32_t>( 329 compiled_code_->entry() + pc_offset); 330 output_[0]->SetPc(pc); 331 } 332 Code* continuation = isolate_->builtins()->builtin(Builtins::kNotifyOSR); 333 output_[0]->SetContinuation( 334 reinterpret_cast<uint32_t>(continuation->entry())); 335 336 if (FLAG_trace_osr) { 337 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", 338 ok ? "finished" : "aborted", 339 reinterpret_cast<intptr_t>(function_)); 340 PrintFunctionName(); 341 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); 342 } 343 } 344 345 346 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { 347 // Set the register values. The values are not important as there are no 348 // callee saved registers in JavaScript frames, so all registers are 349 // spilled. Registers fp and sp are set to the correct values though. 350 351 for (int i = 0; i < Register::kNumRegisters; i++) { 352 input_->SetRegister(i, i * 4); 353 } 354 input_->SetRegister(sp.code(), reinterpret_cast<intptr_t>(frame->sp())); 355 input_->SetRegister(fp.code(), reinterpret_cast<intptr_t>(frame->fp())); 356 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { 357 input_->SetDoubleRegister(i, 0.0); 358 } 359 360 // Fill the frame content from the actual data on the frame. 361 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { 362 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); 363 } 364 } 365 366 367 void Deoptimizer::SetPlatformCompiledStubRegisters( 368 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { 369 ApiFunction function(descriptor->deoptimization_handler_); 370 ExternalReference xref(&function, ExternalReference::BUILTIN_CALL, isolate_); 371 intptr_t handler = reinterpret_cast<intptr_t>(xref.address()); 372 int params = descriptor->register_param_count_; 373 if (descriptor->stack_parameter_count_ != NULL) { 374 params++; 375 } 376 output_frame->SetRegister(r0.code(), params); 377 output_frame->SetRegister(r1.code(), handler); 378 } 379 380 381 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { 382 for (int i = 0; i < DwVfpRegister::kMaxNumRegisters; ++i) { 383 double double_value = input_->GetDoubleRegister(i); 384 output_frame->SetDoubleRegister(i, double_value); 385 } 386 } 387 388 389 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { 390 // There is no dynamic alignment padding on ARM in the input frame. 391 return false; 392 } 393 394 395 #define __ masm()-> 396 397 // This code tries to be close to ia32 code so that any changes can be 398 // easily ported. 399 void Deoptimizer::EntryGenerator::Generate() { 400 GeneratePrologue(); 401 402 // Save all general purpose registers before messing with them. 403 const int kNumberOfRegisters = Register::kNumRegisters; 404 405 // Everything but pc, lr and ip which will be saved but not restored. 406 RegList restored_regs = kJSCallerSaved | kCalleeSaved | ip.bit(); 407 408 const int kDoubleRegsSize = 409 kDoubleSize * DwVfpRegister::kMaxNumAllocatableRegisters; 410 411 // Save all allocatable VFP registers before messing with them. 412 ASSERT(kDoubleRegZero.code() == 14); 413 ASSERT(kScratchDoubleReg.code() == 15); 414 415 // Check CPU flags for number of registers, setting the Z condition flag. 416 __ CheckFor32DRegs(ip); 417 418 // Push registers d0-d13, and possibly d16-d31, on the stack. 419 // If d16-d31 are not pushed, decrease the stack pointer instead. 420 __ vstm(db_w, sp, d16, d31, ne); 421 __ sub(sp, sp, Operand(16 * kDoubleSize), LeaveCC, eq); 422 __ vstm(db_w, sp, d0, d13); 423 424 // Push all 16 registers (needed to populate FrameDescription::registers_). 425 // TODO(1588) Note that using pc with stm is deprecated, so we should perhaps 426 // handle this a bit differently. 427 __ stm(db_w, sp, restored_regs | sp.bit() | lr.bit() | pc.bit()); 428 429 const int kSavedRegistersAreaSize = 430 (kNumberOfRegisters * kPointerSize) + kDoubleRegsSize; 431 432 // Get the bailout id from the stack. 433 __ ldr(r2, MemOperand(sp, kSavedRegistersAreaSize)); 434 435 // Get the address of the location in the code object (r3) (return 436 // address for lazy deoptimization) and compute the fp-to-sp delta in 437 // register r4. 438 __ mov(r3, lr); 439 // Correct one word for bailout id. 440 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); 441 __ sub(r4, fp, r4); 442 443 // Allocate a new deoptimizer object. 444 // Pass four arguments in r0 to r3 and fifth argument on stack. 445 __ PrepareCallCFunction(6, r5); 446 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); 447 __ mov(r1, Operand(type())); // bailout type, 448 // r2: bailout id already loaded. 449 // r3: code address or 0 already loaded. 450 __ str(r4, MemOperand(sp, 0 * kPointerSize)); // Fp-to-sp delta. 451 __ mov(r5, Operand(ExternalReference::isolate_address(isolate()))); 452 __ str(r5, MemOperand(sp, 1 * kPointerSize)); // Isolate. 453 // Call Deoptimizer::New(). 454 { 455 AllowExternalCallThatCantCauseGC scope(masm()); 456 __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6); 457 } 458 459 // Preserve "deoptimizer" object in register r0 and get the input 460 // frame descriptor pointer to r1 (deoptimizer->input_); 461 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset())); 462 463 // Copy core registers into FrameDescription::registers_[kNumRegisters]. 464 ASSERT(Register::kNumRegisters == kNumberOfRegisters); 465 for (int i = 0; i < kNumberOfRegisters; i++) { 466 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); 467 __ ldr(r2, MemOperand(sp, i * kPointerSize)); 468 __ str(r2, MemOperand(r1, offset)); 469 } 470 471 // Copy VFP registers to 472 // double_registers_[DoubleRegister::kMaxNumAllocatableRegisters] 473 int double_regs_offset = FrameDescription::double_registers_offset(); 474 for (int i = 0; i < DwVfpRegister::kMaxNumAllocatableRegisters; ++i) { 475 int dst_offset = i * kDoubleSize + double_regs_offset; 476 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; 477 __ vldr(d0, sp, src_offset); 478 __ vstr(d0, r1, dst_offset); 479 } 480 481 // Remove the bailout id and the saved registers from the stack. 482 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); 483 484 // Compute a pointer to the unwinding limit in register r2; that is 485 // the first stack slot not part of the input frame. 486 __ ldr(r2, MemOperand(r1, FrameDescription::frame_size_offset())); 487 __ add(r2, r2, sp); 488 489 // Unwind the stack down to - but not including - the unwinding 490 // limit and copy the contents of the activation frame to the input 491 // frame description. 492 __ add(r3, r1, Operand(FrameDescription::frame_content_offset())); 493 Label pop_loop; 494 Label pop_loop_header; 495 __ b(&pop_loop_header); 496 __ bind(&pop_loop); 497 __ pop(r4); 498 __ str(r4, MemOperand(r3, 0)); 499 __ add(r3, r3, Operand(sizeof(uint32_t))); 500 __ bind(&pop_loop_header); 501 __ cmp(r2, sp); 502 __ b(ne, &pop_loop); 503 504 // Compute the output frame in the deoptimizer. 505 __ push(r0); // Preserve deoptimizer object across call. 506 // r0: deoptimizer object; r1: scratch. 507 __ PrepareCallCFunction(1, r1); 508 // Call Deoptimizer::ComputeOutputFrames(). 509 { 510 AllowExternalCallThatCantCauseGC scope(masm()); 511 __ CallCFunction( 512 ExternalReference::compute_output_frames_function(isolate()), 1); 513 } 514 __ pop(r0); // Restore deoptimizer object (class Deoptimizer). 515 516 // Replace the current (input) frame with the output frames. 517 Label outer_push_loop, inner_push_loop, 518 outer_loop_header, inner_loop_header; 519 // Outer loop state: r4 = current "FrameDescription** output_", 520 // r1 = one past the last FrameDescription**. 521 __ ldr(r1, MemOperand(r0, Deoptimizer::output_count_offset())); 522 __ ldr(r4, MemOperand(r0, Deoptimizer::output_offset())); // r4 is output_. 523 __ add(r1, r4, Operand(r1, LSL, 2)); 524 __ jmp(&outer_loop_header); 525 __ bind(&outer_push_loop); 526 // Inner loop state: r2 = current FrameDescription*, r3 = loop index. 527 __ ldr(r2, MemOperand(r4, 0)); // output_[ix] 528 __ ldr(r3, MemOperand(r2, FrameDescription::frame_size_offset())); 529 __ jmp(&inner_loop_header); 530 __ bind(&inner_push_loop); 531 __ sub(r3, r3, Operand(sizeof(uint32_t))); 532 __ add(r6, r2, Operand(r3)); 533 __ ldr(r7, MemOperand(r6, FrameDescription::frame_content_offset())); 534 __ push(r7); 535 __ bind(&inner_loop_header); 536 __ cmp(r3, Operand::Zero()); 537 __ b(ne, &inner_push_loop); // test for gt? 538 __ add(r4, r4, Operand(kPointerSize)); 539 __ bind(&outer_loop_header); 540 __ cmp(r4, r1); 541 __ b(lt, &outer_push_loop); 542 543 // Check CPU flags for number of registers, setting the Z condition flag. 544 __ CheckFor32DRegs(ip); 545 546 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset())); 547 int src_offset = FrameDescription::double_registers_offset(); 548 for (int i = 0; i < DwVfpRegister::kMaxNumRegisters; ++i) { 549 if (i == kDoubleRegZero.code()) continue; 550 if (i == kScratchDoubleReg.code()) continue; 551 552 const DwVfpRegister reg = DwVfpRegister::from_code(i); 553 __ vldr(reg, r1, src_offset, i < 16 ? al : ne); 554 src_offset += kDoubleSize; 555 } 556 557 // Push state, pc, and continuation from the last output frame. 558 if (type() != OSR) { 559 __ ldr(r6, MemOperand(r2, FrameDescription::state_offset())); 560 __ push(r6); 561 } 562 563 __ ldr(r6, MemOperand(r2, FrameDescription::pc_offset())); 564 __ push(r6); 565 __ ldr(r6, MemOperand(r2, FrameDescription::continuation_offset())); 566 __ push(r6); 567 568 // Push the registers from the last output frame. 569 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { 570 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); 571 __ ldr(r6, MemOperand(r2, offset)); 572 __ push(r6); 573 } 574 575 // Restore the registers from the stack. 576 __ ldm(ia_w, sp, restored_regs); // all but pc registers. 577 __ pop(ip); // remove sp 578 __ pop(ip); // remove lr 579 580 __ InitializeRootRegister(); 581 582 __ pop(ip); // remove pc 583 __ pop(r7); // get continuation, leave pc on stack 584 __ pop(lr); 585 __ Jump(r7); 586 __ stop("Unreachable."); 587 } 588 589 590 void Deoptimizer::TableEntryGenerator::GeneratePrologue() { 591 // Create a sequence of deoptimization entries. 592 // Note that registers are still live when jumping to an entry. 593 Label done; 594 for (int i = 0; i < count(); i++) { 595 int start = masm()->pc_offset(); 596 USE(start); 597 __ mov(ip, Operand(i)); 598 __ push(ip); 599 __ b(&done); 600 ASSERT(masm()->pc_offset() - start == table_entry_size_); 601 } 602 __ bind(&done); 603 } 604 605 606 void FrameDescription::SetCallerPc(unsigned offset, intptr_t value) { 607 SetFrameSlot(offset, value); 608 } 609 610 611 void FrameDescription::SetCallerFp(unsigned offset, intptr_t value) { 612 SetFrameSlot(offset, value); 613 } 614 615 616 #undef __ 617 618 } } // namespace v8::internal 619