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

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

Issue 12379045: Unify deoptimizer for stub failure trampoline frames. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Daniel Clifford. Created 7 years, 9 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/mips/frames-mips.h ('k') | src/x64/frames-x64.h » ('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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 if (FLAG_trace_osr) { 341 if (FLAG_trace_osr) {
342 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", 342 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ",
343 ok ? "finished" : "aborted", 343 ok ? "finished" : "aborted",
344 reinterpret_cast<intptr_t>(function_)); 344 reinterpret_cast<intptr_t>(function_));
345 function_->PrintName(); 345 function_->PrintName();
346 PrintF(" => pc=0x%0" V8PRIxPTR "]\n", output_[0]->GetPc()); 346 PrintF(" => pc=0x%0" V8PRIxPTR "]\n", output_[0]->GetPc());
347 } 347 }
348 } 348 }
349 349
350 350
351 void Deoptimizer::DoComputeCompiledStubFrame(TranslationIterator* iterator,
352 int frame_index) {
353 //
354 // FROM TO
355 // | .... | | .... |
356 // +-------------------------+ +-------------------------+
357 // | JSFunction continuation | | JSFunction continuation |
358 // +-------------------------+ +-------------------------+
359 // | | saved frame (rbp) | | saved frame (rbp) |
360 // | +=========================+<-rbp +=========================+<-rbp
361 // | | JSFunction context | | JSFunction context |
362 // v +-------------------------+ +-------------------------|
363 // | COMPILED_STUB marker | | STUB_FAILURE marker |
364 // +-------------------------+ +-------------------------+
365 // | | | caller args.arguments_ |
366 // | ... | +-------------------------+
367 // | | | caller args.length_ |
368 // |-------------------------|<-rsp +-------------------------+
369 // | caller args pointer |
370 // +-------------------------+
371 // | caller stack param 1 |
372 // parameters in registers +-------------------------+
373 // and spilled to stack | .... |
374 // +-------------------------+
375 // | caller stack param n |
376 // +-------------------------+<-rsp
377 // rax = number of parameters
378 // rbx = failure handler address
379 // rbp = saved frame
380 // rsi = JSFunction context
381 //
382
383 ASSERT(compiled_code_->kind() == Code::COMPILED_STUB);
384 int major_key = compiled_code_->major_key();
385 CodeStubInterfaceDescriptor* descriptor =
386 isolate_->code_stub_interface_descriptor(major_key);
387
388 // The output frame must have room for all pushed register parameters
389 // and the standard stack frame slots. Include space for an argument
390 // object to the callee and optionally the space to pass the argument
391 // object to the stub failure handler.
392 int height_in_bytes = kPointerSize * descriptor->register_param_count_ +
393 sizeof(Arguments) + kPointerSize;
394 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize;
395 int input_frame_size = input_->GetFrameSize();
396 int output_frame_size = height_in_bytes + fixed_frame_size;
397 if (trace_) {
398 PrintF(" translating %s => StubFailureTrampolineStub, height=%d\n",
399 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false),
400 height_in_bytes);
401 }
402
403 // The stub failure trampoline is a single frame.
404 FrameDescription* output_frame =
405 new(output_frame_size) FrameDescription(output_frame_size, NULL);
406 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE);
407 ASSERT(frame_index == 0);
408 output_[frame_index] = output_frame;
409
410 // The top address for the output frame can be computed from the input
411 // frame pointer and the output frame's height. Subtract space for the
412 // context and function slots.
413 intptr_t top_address = input_->GetRegister(rbp.code()) - (2 * kPointerSize) -
414 height_in_bytes;
415 output_frame->SetTop(top_address);
416
417 // Read caller's PC (JSFunction continuation) from the input frame.
418 unsigned input_frame_offset = input_frame_size - kPointerSize;
419 unsigned output_frame_offset = output_frame_size - kPointerSize;
420 intptr_t value = input_->GetFrameSlot(input_frame_offset);
421 output_frame->SetFrameSlot(output_frame_offset, value);
422 if (trace_) {
423 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
424 V8PRIxPTR " ; caller's pc\n",
425 top_address + output_frame_offset, output_frame_offset, value);
426 }
427
428 // Read caller's FP from the input frame, and set this frame's FP.
429 input_frame_offset -= kPointerSize;
430 value = input_->GetFrameSlot(input_frame_offset);
431 output_frame_offset -= kPointerSize;
432 output_frame->SetFrameSlot(output_frame_offset, value);
433 intptr_t frame_ptr = input_->GetRegister(rbp.code());
434 output_frame->SetRegister(rbp.code(), frame_ptr);
435 output_frame->SetFp(frame_ptr);
436 if (trace_) {
437 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
438 V8PRIxPTR " ; caller's fp\n",
439 top_address + output_frame_offset, output_frame_offset, value);
440 }
441
442 // The context can be gotten from the input frame.
443 input_frame_offset -= kPointerSize;
444 value = input_->GetFrameSlot(input_frame_offset);
445 output_frame->SetRegister(rsi.code(), value);
446 output_frame_offset -= kPointerSize;
447 output_frame->SetFrameSlot(output_frame_offset, value);
448 if (trace_) {
449 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
450 V8PRIxPTR " ; context\n",
451 top_address + output_frame_offset, output_frame_offset, value);
452 }
453
454 // A marker value is used in place of the function.
455 output_frame_offset -= kPointerSize;
456 value = reinterpret_cast<intptr_t>(
457 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE));
458 output_frame->SetFrameSlot(output_frame_offset, value);
459 if (trace_) {
460 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
461 V8PRIxPTR " ; function (stub failure sentinel)\n",
462 top_address + output_frame_offset, output_frame_offset, value);
463 }
464
465 intptr_t caller_arg_count = 0;
466 if (descriptor->stack_parameter_count_ != NULL) {
467 caller_arg_count =
468 input_->GetRegister(descriptor->stack_parameter_count_->code());
469 }
470
471 // Build the Arguments object for the caller's parameters and a pointer to it.
472 output_frame_offset -= kPointerSize;
473 value = frame_ptr + StandardFrameConstants::kCallerSPOffset +
474 (caller_arg_count - 1) * kPointerSize;
475 output_frame->SetFrameSlot(output_frame_offset, value);
476 if (trace_) {
477 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
478 V8PRIxPTR " ; args.arguments\n",
479 top_address + output_frame_offset, output_frame_offset, value);
480 }
481
482 output_frame_offset -= kPointerSize;
483 value = caller_arg_count;
484 output_frame->SetFrameSlot(output_frame_offset, value);
485 if (trace_) {
486 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
487 V8PRIxPTR " ; args.length\n",
488 top_address + output_frame_offset, output_frame_offset, value);
489 }
490
491 output_frame_offset -= kPointerSize;
492 value = frame_ptr - (output_frame_size - output_frame_offset) -
493 StandardFrameConstants::kMarkerOffset + kPointerSize;
494 output_frame->SetFrameSlot(output_frame_offset, value);
495 if (trace_) {
496 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
497 V8PRIxPTR " ; args*\n",
498 top_address + output_frame_offset, output_frame_offset, value);
499 }
500
501 // Copy the register parameters to the failure frame.
502 for (int i = 0; i < descriptor->register_param_count_; ++i) {
503 output_frame_offset -= kPointerSize;
504 DoTranslateCommand(iterator, 0, output_frame_offset);
505 }
506
507 ASSERT(0 == output_frame_offset);
508
509 for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) {
510 double double_value = input_->GetDoubleRegister(i);
511 output_frame->SetDoubleRegister(i, double_value);
512 }
513
514 intptr_t handler =
515 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_);
516 int params = descriptor->register_param_count_;
517 if (descriptor->stack_parameter_count_ != NULL) {
518 params++;
519 }
520 output_frame->SetRegister(rax.code(), params);
521 output_frame->SetRegister(rbx.code(), handler);
522
523 // Compute this frame's PC, state, and continuation.
524 Code* trampoline = NULL;
525 int extra = descriptor->extra_expression_stack_count_;
526 StubFailureTrampolineStub(extra).FindCodeInCache(&trampoline, isolate_);
527 ASSERT(trampoline != NULL);
528 output_frame->SetPc(reinterpret_cast<intptr_t>(
529 trampoline->instruction_start()));
530 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS));
531 Code* notify_failure =
532 isolate_->builtins()->builtin(Builtins::kNotifyStubFailure);
533 output_frame->SetContinuation(
534 reinterpret_cast<intptr_t>(notify_failure->entry()));
535 }
536
537
538 void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator,
539 int frame_index) {
540 Builtins* builtins = isolate_->builtins();
541 Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric);
542 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next()));
543 unsigned height = iterator->Next();
544 unsigned height_in_bytes = height * kPointerSize;
545 if (trace_) {
546 PrintF(" translating construct stub => height=%d\n", height_in_bytes);
547 }
548
549 unsigned fixed_frame_size = 7 * kPointerSize;
550 unsigned output_frame_size = height_in_bytes + fixed_frame_size;
551
552 // Allocate and store the output frame description.
553 FrameDescription* output_frame =
554 new(output_frame_size) FrameDescription(output_frame_size, function);
555 output_frame->SetFrameType(StackFrame::CONSTRUCT);
556
557 // Construct stub can not be topmost or bottommost.
558 ASSERT(frame_index > 0 && frame_index < output_count_ - 1);
559 ASSERT(output_[frame_index] == NULL);
560 output_[frame_index] = output_frame;
561
562 // The top address of the frame is computed from the previous
563 // frame's top and this frame's size.
564 intptr_t top_address;
565 top_address = output_[frame_index - 1]->GetTop() - output_frame_size;
566 output_frame->SetTop(top_address);
567
568 // Compute the incoming parameter translation.
569 int parameter_count = height;
570 unsigned output_offset = output_frame_size;
571 for (int i = 0; i < parameter_count; ++i) {
572 output_offset -= kPointerSize;
573 DoTranslateCommand(iterator, frame_index, output_offset);
574 }
575
576 // Read caller's PC from the previous frame.
577 output_offset -= kPointerSize;
578 intptr_t callers_pc = output_[frame_index - 1]->GetPc();
579 output_frame->SetFrameSlot(output_offset, callers_pc);
580 if (trace_) {
581 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
582 V8PRIxPTR " ; caller's pc\n",
583 top_address + output_offset, output_offset, callers_pc);
584 }
585
586 // Read caller's FP from the previous frame, and set this frame's FP.
587 output_offset -= kPointerSize;
588 intptr_t value = output_[frame_index - 1]->GetFp();
589 output_frame->SetFrameSlot(output_offset, value);
590 intptr_t fp_value = top_address + output_offset;
591 output_frame->SetFp(fp_value);
592 if (trace_) {
593 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
594 V8PRIxPTR " ; caller's fp\n",
595 fp_value, output_offset, value);
596 }
597
598 // The context can be gotten from the previous frame.
599 output_offset -= kPointerSize;
600 value = output_[frame_index - 1]->GetContext();
601 output_frame->SetFrameSlot(output_offset, value);
602 if (trace_) {
603 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
604 V8PRIxPTR " ; context\n",
605 top_address + output_offset, output_offset, value);
606 }
607
608 // A marker value is used in place of the function.
609 output_offset -= kPointerSize;
610 value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::CONSTRUCT));
611 output_frame->SetFrameSlot(output_offset, value);
612 if (trace_) {
613 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
614 V8PRIxPTR " ; function (construct sentinel)\n",
615 top_address + output_offset, output_offset, value);
616 }
617
618 // The output frame reflects a JSConstructStubGeneric frame.
619 output_offset -= kPointerSize;
620 value = reinterpret_cast<intptr_t>(construct_stub);
621 output_frame->SetFrameSlot(output_offset, value);
622 if (trace_) {
623 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
624 V8PRIxPTR " ; code object\n",
625 top_address + output_offset, output_offset, value);
626 }
627
628 // Number of incoming arguments.
629 output_offset -= kPointerSize;
630 value = reinterpret_cast<intptr_t>(Smi::FromInt(height - 1));
631 output_frame->SetFrameSlot(output_offset, value);
632 if (trace_) {
633 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
634 V8PRIxPTR " ; argc (%d)\n",
635 top_address + output_offset, output_offset, value, height - 1);
636 }
637
638 // The newly allocated object was passed as receiver in the artificial
639 // constructor stub environment created by HEnvironment::CopyForInlining().
640 output_offset -= kPointerSize;
641 value = output_frame->GetFrameSlot(output_frame_size - kPointerSize);
642 output_frame->SetFrameSlot(output_offset, value);
643 if (trace_) {
644 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08"
645 V8PRIxPTR " ; allocated receiver\n",
646 top_address + output_offset, output_offset, value);
647 }
648
649 ASSERT(0 == output_offset);
650
651 intptr_t pc = reinterpret_cast<intptr_t>(
652 construct_stub->instruction_start() +
653 isolate_->heap()->construct_stub_deopt_pc_offset()->value());
654 output_frame->SetPc(pc);
655 }
656
657
658 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, 351 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator,
659 int frame_index) { 352 int frame_index) {
660 BailoutId node_id = BailoutId(iterator->Next()); 353 BailoutId node_id = BailoutId(iterator->Next());
661 JSFunction* function; 354 JSFunction* function;
662 if (frame_index != 0) { 355 if (frame_index != 0) {
663 function = JSFunction::cast(ComputeLiteral(iterator->Next())); 356 function = JSFunction::cast(ComputeLiteral(iterator->Next()));
664 } else { 357 } else {
665 int closure_id = iterator->Next(); 358 int closure_id = iterator->Next();
666 USE(closure_id); 359 USE(closure_id);
667 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); 360 ASSERT_EQ(Translation::kSelfLiteralId, closure_id);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 input_->SetDoubleRegister(i, 0.0); 532 input_->SetDoubleRegister(i, 0.0);
840 } 533 }
841 534
842 // Fill the frame content from the actual data on the frame. 535 // Fill the frame content from the actual data on the frame.
843 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { 536 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) {
844 input_->SetFrameSlot(i, Memory::uint64_at(tos + i)); 537 input_->SetFrameSlot(i, Memory::uint64_at(tos + i));
845 } 538 }
846 } 539 }
847 540
848 541
542 void Deoptimizer::SetPlatformCompiledStubRegisters(
543 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) {
544 intptr_t handler =
545 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_);
546 int params = descriptor->register_param_count_;
547 if (descriptor->stack_parameter_count_ != NULL) {
548 params++;
549 }
550 output_frame->SetRegister(rax.code(), params);
551 output_frame->SetRegister(rbx.code(), handler);
552 }
553
554
555 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) {
556 for (int i = 0; i < XMMRegister::NumAllocatableRegisters(); ++i) {
557 double double_value = input_->GetDoubleRegister(i);
558 output_frame->SetDoubleRegister(i, double_value);
559 }
560 }
561
562
849 #define __ masm()-> 563 #define __ masm()->
850 564
851 void Deoptimizer::EntryGenerator::Generate() { 565 void Deoptimizer::EntryGenerator::Generate() {
852 GeneratePrologue(); 566 GeneratePrologue();
853 567
854 // Save all general purpose registers before messing with them. 568 // Save all general purpose registers before messing with them.
855 const int kNumberOfRegisters = Register::kNumRegisters; 569 const int kNumberOfRegisters = Register::kNumRegisters;
856 570
857 const int kDoubleRegsSize = kDoubleSize * 571 const int kDoubleRegsSize = kDoubleSize *
858 XMMRegister::NumAllocatableRegisters(); 572 XMMRegister::NumAllocatableRegisters();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 } 781 }
1068 __ bind(&done); 782 __ bind(&done);
1069 } 783 }
1070 784
1071 #undef __ 785 #undef __
1072 786
1073 787
1074 } } // namespace v8::internal 788 } } // namespace v8::internal
1075 789
1076 #endif // V8_TARGET_ARCH_X64 790 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/mips/frames-mips.h ('k') | src/x64/frames-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698