| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 ASSERT_EQ(interrupt_code->entry(), | 256 ASSERT_EQ(interrupt_code->entry(), |
| 257 Assembler::target_address_at(call_target_address)); | 257 Assembler::target_address_at(call_target_address)); |
| 258 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); | 258 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); |
| 259 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); | 259 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 260 return false; | 260 return false; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 #endif // DEBUG | 263 #endif // DEBUG |
| 264 | 264 |
| 265 | 265 |
| 266 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { | |
| 267 ByteArray* translations = data->TranslationByteArray(); | |
| 268 int length = data->DeoptCount(); | |
| 269 for (int i = 0; i < length; i++) { | |
| 270 if (data->AstId(i) == ast_id) { | |
| 271 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | |
| 272 int value = it.Next(); | |
| 273 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); | |
| 274 // Read the number of frames. | |
| 275 value = it.Next(); | |
| 276 if (value == 1) return i; | |
| 277 } | |
| 278 } | |
| 279 UNREACHABLE(); | |
| 280 return -1; | |
| 281 } | |
| 282 | |
| 283 | |
| 284 void Deoptimizer::DoComputeOsrOutputFrame() { | |
| 285 DeoptimizationInputData* data = DeoptimizationInputData::cast( | |
| 286 compiled_code_->deoptimization_data()); | |
| 287 unsigned ast_id = data->OsrAstId()->value(); | |
| 288 // TODO(kasperl): This should not be the bailout_id_. It should be | |
| 289 // the ast id. Confusing. | |
| 290 ASSERT(bailout_id_ == ast_id); | |
| 291 | |
| 292 int bailout_id = LookupBailoutId(data, BailoutId(ast_id)); | |
| 293 unsigned translation_index = data->TranslationIndex(bailout_id)->value(); | |
| 294 ByteArray* translations = data->TranslationByteArray(); | |
| 295 | |
| 296 TranslationIterator iterator(translations, translation_index); | |
| 297 Translation::Opcode opcode = | |
| 298 static_cast<Translation::Opcode>(iterator.Next()); | |
| 299 ASSERT(Translation::BEGIN == opcode); | |
| 300 USE(opcode); | |
| 301 int count = iterator.Next(); | |
| 302 iterator.Next(); // Drop JS frames count. | |
| 303 ASSERT(count == 1); | |
| 304 USE(count); | |
| 305 | |
| 306 opcode = static_cast<Translation::Opcode>(iterator.Next()); | |
| 307 USE(opcode); | |
| 308 ASSERT(Translation::JS_FRAME == opcode); | |
| 309 unsigned node_id = iterator.Next(); | |
| 310 USE(node_id); | |
| 311 ASSERT(node_id == ast_id); | |
| 312 int closure_id = iterator.Next(); | |
| 313 USE(closure_id); | |
| 314 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); | |
| 315 unsigned height = iterator.Next(); | |
| 316 unsigned height_in_bytes = height * kPointerSize; | |
| 317 USE(height_in_bytes); | |
| 318 | |
| 319 unsigned fixed_size = ComputeFixedSize(function_); | |
| 320 unsigned input_frame_size = input_->GetFrameSize(); | |
| 321 ASSERT(fixed_size + height_in_bytes == input_frame_size); | |
| 322 | |
| 323 unsigned stack_slot_size = compiled_code_->stack_slots() * kPointerSize; | |
| 324 unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value(); | |
| 325 unsigned outgoing_size = outgoing_height * kPointerSize; | |
| 326 unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size; | |
| 327 ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call. | |
| 328 | |
| 329 if (FLAG_trace_osr) { | |
| 330 PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ", | |
| 331 reinterpret_cast<intptr_t>(function_)); | |
| 332 PrintFunctionName(); | |
| 333 PrintF(" => node=%u, frame=%d->%d, ebp:esp=0x%08x:0x%08x]\n", | |
| 334 ast_id, | |
| 335 input_frame_size, | |
| 336 output_frame_size, | |
| 337 input_->GetRegister(ebp.code()), | |
| 338 input_->GetRegister(esp.code())); | |
| 339 } | |
| 340 | |
| 341 // There's only one output frame in the OSR case. | |
| 342 output_count_ = 1; | |
| 343 output_ = new FrameDescription*[1]; | |
| 344 output_[0] = new(output_frame_size) FrameDescription( | |
| 345 output_frame_size, function_); | |
| 346 output_[0]->SetFrameType(StackFrame::JAVA_SCRIPT); | |
| 347 | |
| 348 // Clear the incoming parameters in the optimized frame to avoid | |
| 349 // confusing the garbage collector. | |
| 350 unsigned output_offset = output_frame_size - kPointerSize; | |
| 351 int parameter_count = function_->shared()->formal_parameter_count() + 1; | |
| 352 for (int i = 0; i < parameter_count; ++i) { | |
| 353 output_[0]->SetFrameSlot(output_offset, 0); | |
| 354 output_offset -= kPointerSize; | |
| 355 } | |
| 356 | |
| 357 // Translate the incoming parameters. This may overwrite some of the | |
| 358 // incoming argument slots we've just cleared. | |
| 359 int input_offset = input_frame_size - kPointerSize; | |
| 360 bool ok = true; | |
| 361 int limit = input_offset - (parameter_count * kPointerSize); | |
| 362 while (ok && input_offset > limit) { | |
| 363 ok = DoOsrTranslateCommand(&iterator, &input_offset); | |
| 364 } | |
| 365 | |
| 366 // There are no translation commands for the caller's pc and fp, the | |
| 367 // context, and the function. Set them up explicitly. | |
| 368 for (int i = StandardFrameConstants::kCallerPCOffset; | |
| 369 ok && i >= StandardFrameConstants::kMarkerOffset; | |
| 370 i -= kPointerSize) { | |
| 371 uint32_t input_value = input_->GetFrameSlot(input_offset); | |
| 372 if (FLAG_trace_osr) { | |
| 373 const char* name = "UNKNOWN"; | |
| 374 switch (i) { | |
| 375 case StandardFrameConstants::kCallerPCOffset: | |
| 376 name = "caller's pc"; | |
| 377 break; | |
| 378 case StandardFrameConstants::kCallerFPOffset: | |
| 379 name = "fp"; | |
| 380 break; | |
| 381 case StandardFrameConstants::kContextOffset: | |
| 382 name = "context"; | |
| 383 break; | |
| 384 case StandardFrameConstants::kMarkerOffset: | |
| 385 name = "function"; | |
| 386 break; | |
| 387 } | |
| 388 PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part - %s)\n", | |
| 389 output_offset, | |
| 390 input_value, | |
| 391 input_offset, | |
| 392 name); | |
| 393 } | |
| 394 output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset)); | |
| 395 input_offset -= kPointerSize; | |
| 396 output_offset -= kPointerSize; | |
| 397 } | |
| 398 | |
| 399 // All OSR stack frames are dynamically aligned to an 8-byte boundary. | |
| 400 int frame_pointer = input_->GetRegister(ebp.code()); | |
| 401 if ((frame_pointer & kPointerSize) != 0) { | |
| 402 frame_pointer -= kPointerSize; | |
| 403 has_alignment_padding_ = 1; | |
| 404 } | |
| 405 | |
| 406 int32_t alignment_state = (has_alignment_padding_ == 1) ? | |
| 407 kAlignmentPaddingPushed : | |
| 408 kNoAlignmentPadding; | |
| 409 if (FLAG_trace_osr) { | |
| 410 PrintF(" [sp + %d] <- 0x%08x ; (alignment state)\n", | |
| 411 output_offset, | |
| 412 alignment_state); | |
| 413 } | |
| 414 output_[0]->SetFrameSlot(output_offset, alignment_state); | |
| 415 output_offset -= kPointerSize; | |
| 416 | |
| 417 // Translate the rest of the frame. | |
| 418 while (ok && input_offset >= 0) { | |
| 419 ok = DoOsrTranslateCommand(&iterator, &input_offset); | |
| 420 } | |
| 421 | |
| 422 // If translation of any command failed, continue using the input frame. | |
| 423 if (!ok) { | |
| 424 delete output_[0]; | |
| 425 output_[0] = input_; | |
| 426 output_[0]->SetPc(reinterpret_cast<uint32_t>(from_)); | |
| 427 } else { | |
| 428 // Set up the frame pointer and the context pointer. | |
| 429 output_[0]->SetRegister(ebp.code(), frame_pointer); | |
| 430 output_[0]->SetRegister(esi.code(), input_->GetRegister(esi.code())); | |
| 431 | |
| 432 unsigned pc_offset = data->OsrPcOffset()->value(); | |
| 433 uint32_t pc = reinterpret_cast<uint32_t>( | |
| 434 compiled_code_->entry() + pc_offset); | |
| 435 output_[0]->SetPc(pc); | |
| 436 } | |
| 437 Code* continuation = | |
| 438 function_->GetIsolate()->builtins()->builtin(Builtins::kNotifyOSR); | |
| 439 output_[0]->SetContinuation( | |
| 440 reinterpret_cast<uint32_t>(continuation->entry())); | |
| 441 | |
| 442 if (FLAG_trace_osr) { | |
| 443 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | |
| 444 ok ? "finished" : "aborted", | |
| 445 reinterpret_cast<intptr_t>(function_)); | |
| 446 PrintFunctionName(); | |
| 447 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | |
| 448 } | |
| 449 } | |
| 450 | |
| 451 | |
| 452 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { | 266 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
| 453 // Set the register values. The values are not important as there are no | 267 // Set the register values. The values are not important as there are no |
| 454 // callee saved registers in JavaScript frames, so all registers are | 268 // callee saved registers in JavaScript frames, so all registers are |
| 455 // spilled. Registers ebp and esp are set to the correct values though. | 269 // spilled. Registers ebp and esp are set to the correct values though. |
| 456 | 270 |
| 457 for (int i = 0; i < Register::kNumRegisters; i++) { | 271 for (int i = 0; i < Register::kNumRegisters; i++) { |
| 458 input_->SetRegister(i, i * 4); | 272 input_->SetRegister(i, i * 4); |
| 459 } | 273 } |
| 460 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); | 274 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
| 461 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); | 275 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 __ push(eax); | 423 __ push(eax); |
| 610 __ PrepareCallCFunction(1, ebx); | 424 __ PrepareCallCFunction(1, ebx); |
| 611 __ mov(Operand(esp, 0 * kPointerSize), eax); | 425 __ mov(Operand(esp, 0 * kPointerSize), eax); |
| 612 { | 426 { |
| 613 AllowExternalCallThatCantCauseGC scope(masm()); | 427 AllowExternalCallThatCantCauseGC scope(masm()); |
| 614 __ CallCFunction( | 428 __ CallCFunction( |
| 615 ExternalReference::compute_output_frames_function(isolate()), 1); | 429 ExternalReference::compute_output_frames_function(isolate()), 1); |
| 616 } | 430 } |
| 617 __ pop(eax); | 431 __ pop(eax); |
| 618 | 432 |
| 619 if (type() != OSR) { | 433 // If frame was dynamically aligned, pop padding. |
| 620 // If frame was dynamically aligned, pop padding. | 434 Label no_padding; |
| 621 Label no_padding; | 435 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()), |
| 622 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()), | 436 Immediate(0)); |
| 623 Immediate(0)); | 437 __ j(equal, &no_padding); |
| 624 __ j(equal, &no_padding); | 438 __ pop(ecx); |
| 625 __ pop(ecx); | 439 if (FLAG_debug_code) { |
| 626 if (FLAG_debug_code) { | 440 __ cmp(ecx, Immediate(kAlignmentZapValue)); |
| 627 __ cmp(ecx, Immediate(kAlignmentZapValue)); | 441 __ Assert(equal, "alignment marker expected"); |
| 628 __ Assert(equal, "alignment marker expected"); | |
| 629 } | |
| 630 __ bind(&no_padding); | |
| 631 } else { | |
| 632 // If frame needs dynamic alignment push padding. | |
| 633 Label no_padding; | |
| 634 __ cmp(Operand(eax, Deoptimizer::has_alignment_padding_offset()), | |
| 635 Immediate(0)); | |
| 636 __ j(equal, &no_padding); | |
| 637 __ push(Immediate(kAlignmentZapValue)); | |
| 638 __ bind(&no_padding); | |
| 639 } | 442 } |
| 443 __ bind(&no_padding); |
| 640 | 444 |
| 641 // Replace the current frame with the output frames. | 445 // Replace the current frame with the output frames. |
| 642 Label outer_push_loop, inner_push_loop, | 446 Label outer_push_loop, inner_push_loop, |
| 643 outer_loop_header, inner_loop_header; | 447 outer_loop_header, inner_loop_header; |
| 644 // Outer loop state: eax = current FrameDescription**, edx = one past the | 448 // Outer loop state: eax = current FrameDescription**, edx = one past the |
| 645 // last FrameDescription**. | 449 // last FrameDescription**. |
| 646 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset())); | 450 __ mov(edx, Operand(eax, Deoptimizer::output_count_offset())); |
| 647 __ mov(eax, Operand(eax, Deoptimizer::output_offset())); | 451 __ mov(eax, Operand(eax, Deoptimizer::output_offset())); |
| 648 __ lea(edx, Operand(eax, edx, times_4, 0)); | 452 __ lea(edx, Operand(eax, edx, times_4, 0)); |
| 649 __ jmp(&outer_loop_header); | 453 __ jmp(&outer_loop_header); |
| 650 __ bind(&outer_push_loop); | 454 __ bind(&outer_push_loop); |
| 651 // Inner loop state: ebx = current FrameDescription*, ecx = loop index. | 455 // Inner loop state: ebx = current FrameDescription*, ecx = loop index. |
| 652 __ mov(ebx, Operand(eax, 0)); | 456 __ mov(ebx, Operand(eax, 0)); |
| 653 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); | 457 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); |
| 654 __ jmp(&inner_loop_header); | 458 __ jmp(&inner_loop_header); |
| 655 __ bind(&inner_push_loop); | 459 __ bind(&inner_push_loop); |
| 656 __ sub(ecx, Immediate(sizeof(uint32_t))); | 460 __ sub(ecx, Immediate(sizeof(uint32_t))); |
| 657 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); | 461 __ push(Operand(ebx, ecx, times_1, FrameDescription::frame_content_offset())); |
| 658 __ bind(&inner_loop_header); | 462 __ bind(&inner_loop_header); |
| 659 __ test(ecx, ecx); | 463 __ test(ecx, ecx); |
| 660 __ j(not_zero, &inner_push_loop); | 464 __ j(not_zero, &inner_push_loop); |
| 661 __ add(eax, Immediate(kPointerSize)); | 465 __ add(eax, Immediate(kPointerSize)); |
| 662 __ bind(&outer_loop_header); | 466 __ bind(&outer_loop_header); |
| 663 __ cmp(eax, edx); | 467 __ cmp(eax, edx); |
| 664 __ j(below, &outer_push_loop); | 468 __ j(below, &outer_push_loop); |
| 665 | 469 |
| 666 // In case of OSR or a failed STUB, we have to restore the XMM registers. | 470 // In case of a failed STUB, we have to restore the XMM registers. |
| 667 if (CpuFeatures::IsSupported(SSE2)) { | 471 if (CpuFeatures::IsSupported(SSE2)) { |
| 668 CpuFeatureScope scope(masm(), SSE2); | 472 CpuFeatureScope scope(masm(), SSE2); |
| 669 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 473 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
| 670 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); | 474 XMMRegister xmm_reg = XMMRegister::FromAllocationIndex(i); |
| 671 int src_offset = i * kDoubleSize + double_regs_offset; | 475 int src_offset = i * kDoubleSize + double_regs_offset; |
| 672 __ movdbl(xmm_reg, Operand(ebx, src_offset)); | 476 __ movdbl(xmm_reg, Operand(ebx, src_offset)); |
| 673 } | 477 } |
| 674 } | 478 } |
| 675 | 479 |
| 676 // Push state, pc, and continuation from the last output frame. | 480 // Push state, pc, and continuation from the last output frame. |
| 677 if (type() != OSR) { | 481 __ push(Operand(ebx, FrameDescription::state_offset())); |
| 678 __ push(Operand(ebx, FrameDescription::state_offset())); | |
| 679 } | |
| 680 __ push(Operand(ebx, FrameDescription::pc_offset())); | 482 __ push(Operand(ebx, FrameDescription::pc_offset())); |
| 681 __ push(Operand(ebx, FrameDescription::continuation_offset())); | 483 __ push(Operand(ebx, FrameDescription::continuation_offset())); |
| 682 | 484 |
| 683 | 485 |
| 684 // Push the registers from the last output frame. | 486 // Push the registers from the last output frame. |
| 685 for (int i = 0; i < kNumberOfRegisters; i++) { | 487 for (int i = 0; i < kNumberOfRegisters; i++) { |
| 686 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); | 488 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 687 __ push(Operand(ebx, offset)); | 489 __ push(Operand(ebx, offset)); |
| 688 } | 490 } |
| 689 | 491 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 718 SetFrameSlot(offset, value); | 520 SetFrameSlot(offset, value); |
| 719 } | 521 } |
| 720 | 522 |
| 721 | 523 |
| 722 #undef __ | 524 #undef __ |
| 723 | 525 |
| 724 | 526 |
| 725 } } // namespace v8::internal | 527 } } // namespace v8::internal |
| 726 | 528 |
| 727 #endif // V8_TARGET_ARCH_IA32 | 529 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |