Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: src/ia32/deoptimizer-ia32.cc

Issue 14843020: Unify deoptimizer for JavaScript frames. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/frames.h ('k') | src/ia32/frames-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (FLAG_trace_osr) { 475 if (FLAG_trace_osr) {
476 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", 476 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ",
477 ok ? "finished" : "aborted", 477 ok ? "finished" : "aborted",
478 reinterpret_cast<intptr_t>(function_)); 478 reinterpret_cast<intptr_t>(function_));
479 function_->PrintName(); 479 function_->PrintName();
480 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); 480 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc());
481 } 481 }
482 } 482 }
483 483
484 484
485 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator,
486 int frame_index) {
487 BailoutId node_id = BailoutId(iterator->Next());
488 JSFunction* function;
489 if (frame_index != 0) {
490 function = JSFunction::cast(ComputeLiteral(iterator->Next()));
491 } else {
492 int closure_id = iterator->Next();
493 USE(closure_id);
494 ASSERT_EQ(Translation::kSelfLiteralId, closure_id);
495 function = function_;
496 }
497 unsigned height = iterator->Next();
498 unsigned height_in_bytes = height * kPointerSize;
499 if (trace_) {
500 PrintF(" translating ");
501 function->PrintName();
502 PrintF(" => node=%d, height=%d\n", node_id.ToInt(), height_in_bytes);
503 }
504
505 // The 'fixed' part of the frame consists of the incoming parameters and
506 // the part described by JavaScriptFrameConstants.
507 unsigned fixed_frame_size = ComputeFixedSize(function);
508 unsigned input_frame_size = input_->GetFrameSize();
509 unsigned output_frame_size = height_in_bytes + fixed_frame_size;
510
511 // Allocate and store the output frame description.
512 FrameDescription* output_frame =
513 new(output_frame_size) FrameDescription(output_frame_size, function);
514 output_frame->SetFrameType(StackFrame::JAVA_SCRIPT);
515
516 bool is_bottommost = (0 == frame_index);
517 bool is_topmost = (output_count_ - 1 == frame_index);
518 ASSERT(frame_index >= 0 && frame_index < output_count_);
519 ASSERT(output_[frame_index] == NULL);
520 output_[frame_index] = output_frame;
521
522 // Compute the incoming parameter translation.
523 int parameter_count = function->shared()->formal_parameter_count() + 1;
524 unsigned output_offset = output_frame_size;
525 unsigned input_offset = input_frame_size;
526
527 unsigned alignment_state_offset =
528 input_offset - parameter_count * kPointerSize -
529 StandardFrameConstants::kFixedFrameSize -
530 kPointerSize;
531 ASSERT(JavaScriptFrameConstants::kDynamicAlignmentStateOffset ==
532 JavaScriptFrameConstants::kLocal0Offset);
533
534 // The top address for the bottommost output frame can be computed from
535 // the input frame pointer and the output frame's height. For all
536 // subsequent output frames, it can be computed from the previous one's
537 // top address and the current frame's size.
538 uint32_t top_address;
539 if (is_bottommost) {
540 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset);
541 has_alignment_padding_ =
542 (alignment_state == kAlignmentPaddingPushed) ? 1 : 0;
543 // 2 = context and function in the frame.
544 // If the optimized frame had alignment padding, adjust the frame pointer
545 // to point to the new position of the old frame pointer after padding
546 // is removed. Subtract 2 * kPointerSize for the context and function slots.
547 top_address = input_->GetRegister(ebp.code()) - (2 * kPointerSize) -
548 height_in_bytes + has_alignment_padding_ * kPointerSize;
549 } else {
550 top_address = output_[frame_index - 1]->GetTop() - output_frame_size;
551 }
552 output_frame->SetTop(top_address);
553
554 for (int i = 0; i < parameter_count; ++i) {
555 output_offset -= kPointerSize;
556 DoTranslateCommand(iterator, frame_index, output_offset);
557 }
558 input_offset -= (parameter_count * kPointerSize);
559
560 // There are no translation commands for the caller's pc and fp, the
561 // context, and the function. Synthesize their values and set them up
562 // explicitly.
563 //
564 // The caller's pc for the bottommost output frame is the same as in the
565 // input frame. For all subsequent output frames, it can be read from the
566 // previous one. This frame's pc can be computed from the non-optimized
567 // function code and AST id of the bailout.
568 output_offset -= kPointerSize;
569 input_offset -= kPointerSize;
570 intptr_t value;
571 if (is_bottommost) {
572 value = input_->GetFrameSlot(input_offset);
573 } else {
574 value = output_[frame_index - 1]->GetPc();
575 }
576 output_frame->SetFrameSlot(output_offset, value);
577 if (trace_) {
578 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n",
579 top_address + output_offset, output_offset, value);
580 }
581
582 // The caller's frame pointer for the bottommost output frame is the same
583 // as in the input frame. For all subsequent output frames, it can be
584 // read from the previous one. Also compute and set this frame's frame
585 // pointer.
586 output_offset -= kPointerSize;
587 input_offset -= kPointerSize;
588 if (is_bottommost) {
589 value = input_->GetFrameSlot(input_offset);
590 } else {
591 value = output_[frame_index - 1]->GetFp();
592 }
593 output_frame->SetFrameSlot(output_offset, value);
594 intptr_t fp_value = top_address + output_offset;
595 ASSERT(!is_bottommost ||
596 (input_->GetRegister(ebp.code()) + has_alignment_padding_ * kPointerSize) ==
597 fp_value);
598 output_frame->SetFp(fp_value);
599 if (is_topmost) output_frame->SetRegister(ebp.code(), fp_value);
600 if (trace_) {
601 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n",
602 fp_value, output_offset, value);
603 }
604 ASSERT(!is_bottommost || !has_alignment_padding_ ||
605 (fp_value & kPointerSize) != 0);
606
607 // For the bottommost output frame the context can be gotten from the input
608 // frame. For all subsequent output frames it can be gotten from the function
609 // so long as we don't inline functions that need local contexts.
610 output_offset -= kPointerSize;
611 input_offset -= kPointerSize;
612 if (is_bottommost) {
613 value = input_->GetFrameSlot(input_offset);
614 } else {
615 value = reinterpret_cast<uint32_t>(function->context());
616 }
617 output_frame->SetFrameSlot(output_offset, value);
618 output_frame->SetContext(value);
619 if (is_topmost) output_frame->SetRegister(esi.code(), value);
620 if (trace_) {
621 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n",
622 top_address + output_offset, output_offset, value);
623 }
624
625 // The function was mentioned explicitly in the BEGIN_FRAME.
626 output_offset -= kPointerSize;
627 input_offset -= kPointerSize;
628 value = reinterpret_cast<uint32_t>(function);
629 // The function for the bottommost output frame should also agree with the
630 // input frame.
631 ASSERT(!is_bottommost || input_->GetFrameSlot(input_offset) == value);
632 output_frame->SetFrameSlot(output_offset, value);
633 if (trace_) {
634 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function\n",
635 top_address + output_offset, output_offset, value);
636 }
637
638 // Translate the rest of the frame.
639 for (unsigned i = 0; i < height; ++i) {
640 output_offset -= kPointerSize;
641 DoTranslateCommand(iterator, frame_index, output_offset);
642 }
643 ASSERT(0 == output_offset);
644
645 // Compute this frame's PC, state, and continuation.
646 Code* non_optimized_code = function->shared()->code();
647 FixedArray* raw_data = non_optimized_code->deoptimization_data();
648 DeoptimizationOutputData* data = DeoptimizationOutputData::cast(raw_data);
649 Address start = non_optimized_code->instruction_start();
650 unsigned pc_and_state = GetOutputInfo(data, node_id, function->shared());
651 unsigned pc_offset = FullCodeGenerator::PcField::decode(pc_and_state);
652 uint32_t pc_value = reinterpret_cast<uint32_t>(start + pc_offset);
653 output_frame->SetPc(pc_value);
654
655 FullCodeGenerator::State state =
656 FullCodeGenerator::StateField::decode(pc_and_state);
657 output_frame->SetState(Smi::FromInt(state));
658
659 // Set the continuation for the topmost frame.
660 if (is_topmost && bailout_type_ != DEBUGGER) {
661 Builtins* builtins = isolate_->builtins();
662 Code* continuation = builtins->builtin(Builtins::kNotifyDeoptimized);
663 if (bailout_type_ == LAZY) {
664 continuation = builtins->builtin(Builtins::kNotifyLazyDeoptimized);
665 } else if (bailout_type_ == SOFT) {
666 continuation = builtins->builtin(Builtins::kNotifySoftDeoptimized);
667 } else {
668 ASSERT(bailout_type_ == EAGER);
669 }
670 output_frame->SetContinuation(
671 reinterpret_cast<uint32_t>(continuation->entry()));
672 }
673 }
674
675
676 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { 485 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) {
677 // Set the register values. The values are not important as there are no 486 // Set the register values. The values are not important as there are no
678 // callee saved registers in JavaScript frames, so all registers are 487 // callee saved registers in JavaScript frames, so all registers are
679 // spilled. Registers ebp and esp are set to the correct values though. 488 // spilled. Registers ebp and esp are set to the correct values though.
680 489
681 for (int i = 0; i < Register::kNumRegisters; i++) { 490 for (int i = 0; i < Register::kNumRegisters; i++) {
682 input_->SetRegister(i, i * 4); 491 input_->SetRegister(i, i * 4);
683 } 492 }
684 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp())); 493 input_->SetRegister(esp.code(), reinterpret_cast<intptr_t>(frame->sp()));
685 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp())); 494 input_->SetRegister(ebp.code(), reinterpret_cast<intptr_t>(frame->fp()));
(...skipping 22 matching lines...) Expand all
708 517
709 518
710 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { 519 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) {
711 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { 520 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) {
712 double double_value = input_->GetDoubleRegister(i); 521 double double_value = input_->GetDoubleRegister(i);
713 output_frame->SetDoubleRegister(i, double_value); 522 output_frame->SetDoubleRegister(i, double_value);
714 } 523 }
715 } 524 }
716 525
717 526
527 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) {
528 int parameter_count = function->shared()->formal_parameter_count() + 1;
529 unsigned input_frame_size = input_->GetFrameSize();
530 unsigned alignment_state_offset =
531 input_frame_size - parameter_count * kPointerSize -
532 StandardFrameConstants::kFixedFrameSize -
533 kPointerSize;
534 ASSERT(JavaScriptFrameConstants::kDynamicAlignmentStateOffset ==
535 JavaScriptFrameConstants::kLocal0Offset);
536 int32_t alignment_state = input_->GetFrameSlot(alignment_state_offset);
537 return (alignment_state == kAlignmentPaddingPushed);
538 }
539
540
718 #define __ masm()-> 541 #define __ masm()->
719 542
720 void Deoptimizer::EntryGenerator::Generate() { 543 void Deoptimizer::EntryGenerator::Generate() {
721 GeneratePrologue(); 544 GeneratePrologue();
722 545
723 // Save all general purpose registers before messing with them. 546 // Save all general purpose registers before messing with them.
724 const int kNumberOfRegisters = Register::kNumRegisters; 547 const int kNumberOfRegisters = Register::kNumRegisters;
725 548
726 const int kDoubleRegsSize = kDoubleSize * 549 const int kDoubleRegsSize = kDoubleSize *
727 XMMRegister::kNumAllocatableRegisters; 550 XMMRegister::kNumAllocatableRegisters;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 } 748 }
926 __ bind(&done); 749 __ bind(&done);
927 } 750 }
928 751
929 #undef __ 752 #undef __
930 753
931 754
932 } } // namespace v8::internal 755 } } // namespace v8::internal
933 756
934 #endif // V8_TARGET_ARCH_IA32 757 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/frames.h ('k') | src/ia32/frames-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698