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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 if (FLAG_trace_osr) { | 349 if (FLAG_trace_osr) { |
350 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | 350 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", |
351 ok ? "finished" : "aborted", | 351 ok ? "finished" : "aborted", |
352 reinterpret_cast<intptr_t>(function_)); | 352 reinterpret_cast<intptr_t>(function_)); |
353 function_->PrintName(); | 353 function_->PrintName(); |
354 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | 354 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 | 358 |
359 void Deoptimizer::DoComputeCompiledStubFrame(TranslationIterator* iterator, | |
360 int frame_index) { | |
361 // | |
362 // FROM TO | |
363 // | .... | | .... | | |
364 // +-------------------------+ +-------------------------+ | |
365 // | JSFunction continuation | | JSFunction continuation | | |
366 // +-------------------------+ +-------------------------+ | |
367 // | | saved frame (fp) | | saved frame (fp) | | |
368 // | +=========================+<-fp +=========================+<-fp | |
369 // | | JSFunction context | | JSFunction context | | |
370 // v +-------------------------+ +-------------------------| | |
371 // | COMPILED_STUB marker | | STUB_FAILURE marker | | |
372 // +-------------------------+ +-------------------------+ | |
373 // | | | caller args.arguments_ | | |
374 // | ... | +-------------------------+ | |
375 // | | | caller args.length_ | | |
376 // |-------------------------|<-sp +-------------------------+ | |
377 // | caller args pointer | | |
378 // +-------------------------+ | |
379 // | caller stack param 1 | | |
380 // parameters in registers +-------------------------+ | |
381 // and spilled to stack | .... | | |
382 // +-------------------------+ | |
383 // | caller stack param n | | |
384 // +-------------------------+<-sp | |
385 // r0 = number of parameters | |
386 // r1 = failure handler address | |
387 // fp = saved frame | |
388 // cp = JSFunction context | |
389 // | |
390 | |
391 ASSERT(compiled_code_->kind() == Code::COMPILED_STUB); | |
392 int major_key = compiled_code_->major_key(); | |
393 CodeStubInterfaceDescriptor* descriptor = | |
394 isolate_->code_stub_interface_descriptor(major_key); | |
395 | |
396 // The output frame must have room for all pushed register parameters | |
397 // and the standard stack frame slots. Include space for an argument | |
398 // object to the callee and optionally the space to pass the argument | |
399 // object to the stub failure handler. | |
400 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + | |
401 sizeof(Arguments) + kPointerSize; | |
402 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; | |
403 int input_frame_size = input_->GetFrameSize(); | |
404 int output_frame_size = height_in_bytes + fixed_frame_size; | |
405 if (trace_) { | |
406 PrintF(" translating %s => StubFailureTrampolineStub, height=%d\n", | |
407 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), | |
408 height_in_bytes); | |
409 } | |
410 | |
411 // The stub failure trampoline is a single frame. | |
412 FrameDescription* output_frame = | |
413 new(output_frame_size) FrameDescription(output_frame_size, NULL); | |
414 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); | |
415 ASSERT(frame_index == 0); | |
416 output_[frame_index] = output_frame; | |
417 | |
418 // The top address for the output frame can be computed from the input | |
419 // frame pointer and the output frame's height. Subtract space for the | |
420 // context and function slots. | |
421 intptr_t top_address = input_->GetRegister(fp.code()) - (2 * kPointerSize) - | |
422 height_in_bytes; | |
423 output_frame->SetTop(top_address); | |
424 | |
425 // Read caller's PC (JSFunction continuation) from the input frame. | |
426 intptr_t input_frame_offset = input_frame_size - kPointerSize; | |
427 intptr_t output_frame_offset = output_frame_size - kPointerSize; | |
428 intptr_t value = input_->GetFrameSlot(input_frame_offset); | |
429 output_frame->SetFrameSlot(output_frame_offset, value); | |
430 if (trace_) { | |
431 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n", | |
432 top_address + output_frame_offset, output_frame_offset, value); | |
433 } | |
434 | |
435 // Read caller's FP from the input frame, and set this frame's FP. | |
436 input_frame_offset -= kPointerSize; | |
437 value = input_->GetFrameSlot(input_frame_offset); | |
438 output_frame_offset -= kPointerSize; | |
439 output_frame->SetFrameSlot(output_frame_offset, value); | |
440 intptr_t frame_ptr = input_->GetRegister(fp.code()); | |
441 output_frame->SetRegister(fp.code(), frame_ptr); | |
442 output_frame->SetFp(frame_ptr); | |
443 if (trace_) { | |
444 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n", | |
445 top_address + output_frame_offset, output_frame_offset, value); | |
446 } | |
447 | |
448 // The context can be gotten from the input frame. | |
449 input_frame_offset -= kPointerSize; | |
450 value = input_->GetFrameSlot(input_frame_offset); | |
451 output_frame->SetRegister(cp.code(), value); | |
452 output_frame_offset -= kPointerSize; | |
453 output_frame->SetFrameSlot(output_frame_offset, value); | |
454 if (trace_) { | |
455 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n", | |
456 top_address + output_frame_offset, output_frame_offset, value); | |
457 } | |
458 | |
459 // A marker value is used in place of the function. | |
460 output_frame_offset -= kPointerSize; | |
461 value = reinterpret_cast<intptr_t>( | |
462 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); | |
463 output_frame->SetFrameSlot(output_frame_offset, value); | |
464 if (trace_) { | |
465 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function (stub fail sentinel)\n", | |
466 top_address + output_frame_offset, output_frame_offset, value); | |
467 } | |
468 | |
469 int caller_arg_count = 0; | |
470 if (descriptor->stack_parameter_count_ != NULL) { | |
471 caller_arg_count = | |
472 input_->GetRegister(descriptor->stack_parameter_count_->code()); | |
473 } | |
474 | |
475 // Build the Arguments object for the caller's parameters and a pointer to it. | |
476 output_frame_offset -= kPointerSize; | |
477 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + | |
478 (caller_arg_count - 1) * kPointerSize; | |
479 output_frame->SetFrameSlot(output_frame_offset, value); | |
480 if (trace_) { | |
481 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args.arguments\n", | |
482 top_address + output_frame_offset, output_frame_offset, value); | |
483 } | |
484 | |
485 output_frame_offset -= kPointerSize; | |
486 value = caller_arg_count; | |
487 output_frame->SetFrameSlot(output_frame_offset, value); | |
488 if (trace_) { | |
489 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args.length\n", | |
490 top_address + output_frame_offset, output_frame_offset, value); | |
491 } | |
492 | |
493 output_frame_offset -= kPointerSize; | |
494 value = frame_ptr - (output_frame_size - output_frame_offset) - | |
495 StandardFrameConstants::kMarkerOffset + kPointerSize; | |
496 output_frame->SetFrameSlot(output_frame_offset, value); | |
497 if (trace_) { | |
498 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; args*\n", | |
499 top_address + output_frame_offset, output_frame_offset, value); | |
500 } | |
501 | |
502 // Copy the register parameters to the failure frame. | |
503 for (int i = 0; i < descriptor->register_param_count_; ++i) { | |
504 output_frame_offset -= kPointerSize; | |
505 DoTranslateCommand(iterator, 0, output_frame_offset); | |
506 } | |
507 | |
508 ASSERT(0 == output_frame_offset); | |
509 | |
510 for (int i = 0; i < DwVfpRegister::kMaxNumRegisters; ++i) { | |
511 double double_value = input_->GetDoubleRegister(i); | |
512 output_frame->SetDoubleRegister(i, double_value); | |
513 } | |
514 | |
515 ApiFunction function(descriptor->deoptimization_handler_); | |
516 ExternalReference xref(&function, ExternalReference::BUILTIN_CALL, isolate_); | |
517 intptr_t handler = reinterpret_cast<intptr_t>(xref.address()); | |
518 int params = descriptor->register_param_count_; | |
519 if (descriptor->stack_parameter_count_ != NULL) { | |
520 params++; | |
521 } | |
522 output_frame->SetRegister(r0.code(), params); | |
523 output_frame->SetRegister(r1.code(), handler); | |
524 | |
525 // Compute this frame's PC, state, and continuation. | |
526 Code* trampoline = NULL; | |
527 int extra = descriptor->extra_expression_stack_count_; | |
528 StubFailureTrampolineStub(extra).FindCodeInCache(&trampoline, isolate_); | |
529 ASSERT(trampoline != NULL); | |
530 output_frame->SetPc(reinterpret_cast<intptr_t>( | |
531 trampoline->instruction_start())); | |
532 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); | |
533 Code* notify_failure = | |
534 isolate_->builtins()->builtin(Builtins::kNotifyStubFailure); | |
535 output_frame->SetContinuation( | |
536 reinterpret_cast<intptr_t>(notify_failure->entry())); | |
537 } | |
538 | |
539 | |
540 void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, | |
541 int frame_index) { | |
542 Builtins* builtins = isolate_->builtins(); | |
543 Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric); | |
544 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); | |
545 unsigned height = iterator->Next(); | |
546 unsigned height_in_bytes = height * kPointerSize; | |
547 if (FLAG_trace_deopt) { | |
548 PrintF(" translating construct stub => height=%d\n", height_in_bytes); | |
549 } | |
550 | |
551 unsigned fixed_frame_size = 8 * kPointerSize; | |
552 unsigned output_frame_size = height_in_bytes + fixed_frame_size; | |
553 | |
554 // Allocate and store the output frame description. | |
555 FrameDescription* output_frame = | |
556 new(output_frame_size) FrameDescription(output_frame_size, function); | |
557 output_frame->SetFrameType(StackFrame::CONSTRUCT); | |
558 | |
559 // Construct stub can not be topmost or bottommost. | |
560 ASSERT(frame_index > 0 && frame_index < output_count_ - 1); | |
561 ASSERT(output_[frame_index] == NULL); | |
562 output_[frame_index] = output_frame; | |
563 | |
564 // The top address of the frame is computed from the previous | |
565 // frame's top and this frame's size. | |
566 uint32_t top_address; | |
567 top_address = output_[frame_index - 1]->GetTop() - output_frame_size; | |
568 output_frame->SetTop(top_address); | |
569 | |
570 // Compute the incoming parameter translation. | |
571 int parameter_count = height; | |
572 unsigned output_offset = output_frame_size; | |
573 for (int i = 0; i < parameter_count; ++i) { | |
574 output_offset -= kPointerSize; | |
575 DoTranslateCommand(iterator, frame_index, output_offset); | |
576 } | |
577 | |
578 // Read caller's PC from the previous frame. | |
579 output_offset -= kPointerSize; | |
580 intptr_t callers_pc = output_[frame_index - 1]->GetPc(); | |
581 output_frame->SetFrameSlot(output_offset, callers_pc); | |
582 if (FLAG_trace_deopt) { | |
583 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n", | |
584 top_address + output_offset, output_offset, callers_pc); | |
585 } | |
586 | |
587 // Read caller's FP from the previous frame, and set this frame's FP. | |
588 output_offset -= kPointerSize; | |
589 intptr_t value = output_[frame_index - 1]->GetFp(); | |
590 output_frame->SetFrameSlot(output_offset, value); | |
591 intptr_t fp_value = top_address + output_offset; | |
592 output_frame->SetFp(fp_value); | |
593 if (trace_) { | |
594 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; 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%08x: [top + %d] <- 0x%08x ; context\n", | |
604 top_address + output_offset, output_offset, value); | |
605 } | |
606 | |
607 // A marker value is used in place of the function. | |
608 output_offset -= kPointerSize; | |
609 value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::CONSTRUCT)); | |
610 output_frame->SetFrameSlot(output_offset, value); | |
611 if (trace_) { | |
612 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function (construct sentinel)\n", | |
613 top_address + output_offset, output_offset, value); | |
614 } | |
615 | |
616 // The output frame reflects a JSConstructStubGeneric frame. | |
617 output_offset -= kPointerSize; | |
618 value = reinterpret_cast<intptr_t>(construct_stub); | |
619 output_frame->SetFrameSlot(output_offset, value); | |
620 if (trace_) { | |
621 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; code object\n", | |
622 top_address + output_offset, output_offset, value); | |
623 } | |
624 | |
625 // Number of incoming arguments. | |
626 output_offset -= kPointerSize; | |
627 value = reinterpret_cast<uint32_t>(Smi::FromInt(height - 1)); | |
628 output_frame->SetFrameSlot(output_offset, value); | |
629 if (trace_) { | |
630 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; argc (%d)\n", | |
631 top_address + output_offset, output_offset, value, height - 1); | |
632 } | |
633 | |
634 // Constructor function being invoked by the stub. | |
635 output_offset -= kPointerSize; | |
636 value = reinterpret_cast<intptr_t>(function); | |
637 output_frame->SetFrameSlot(output_offset, value); | |
638 if (trace_) { | |
639 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; constructor function\n", | |
640 top_address + output_offset, output_offset, value); | |
641 } | |
642 | |
643 // The newly allocated object was passed as receiver in the artificial | |
644 // constructor stub environment created by HEnvironment::CopyForInlining(). | |
645 output_offset -= kPointerSize; | |
646 value = output_frame->GetFrameSlot(output_frame_size - kPointerSize); | |
647 output_frame->SetFrameSlot(output_offset, value); | |
648 if (trace_) { | |
649 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; allocated receiver\n", | |
650 top_address + output_offset, output_offset, value); | |
651 } | |
652 | |
653 ASSERT(0 == output_offset); | |
654 | |
655 uint32_t pc = reinterpret_cast<uint32_t>( | |
656 construct_stub->instruction_start() + | |
657 isolate_->heap()->construct_stub_deopt_pc_offset()->value()); | |
658 output_frame->SetPc(pc); | |
659 } | |
660 | |
661 | |
662 // This code is very similar to ia32 code, but relies on register names (fp, sp) | 359 // This code is very similar to ia32 code, but relies on register names (fp, sp) |
663 // and how the frame is laid out. | 360 // and how the frame is laid out. |
664 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, | 361 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, |
665 int frame_index) { | 362 int frame_index) { |
666 // Read the ast node id, function, and frame height for this output frame. | 363 // Read the ast node id, function, and frame height for this output frame. |
667 BailoutId node_id = BailoutId(iterator->Next()); | 364 BailoutId node_id = BailoutId(iterator->Next()); |
668 JSFunction* function; | 365 JSFunction* function; |
669 if (frame_index != 0) { | 366 if (frame_index != 0) { |
670 function = JSFunction::cast(ComputeLiteral(iterator->Next())); | 367 function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
671 } else { | 368 } else { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 input_->SetDoubleRegister(i, 0.0); | 547 input_->SetDoubleRegister(i, 0.0); |
851 } | 548 } |
852 | 549 |
853 // Fill the frame content from the actual data on the frame. | 550 // Fill the frame content from the actual data on the frame. |
854 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { | 551 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
855 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); | 552 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); |
856 } | 553 } |
857 } | 554 } |
858 | 555 |
859 | 556 |
| 557 void Deoptimizer::SetPlatformCompiledStubRegisters( |
| 558 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { |
| 559 ApiFunction function(descriptor->deoptimization_handler_); |
| 560 ExternalReference xref(&function, ExternalReference::BUILTIN_CALL, isolate_); |
| 561 intptr_t handler = reinterpret_cast<intptr_t>(xref.address()); |
| 562 int params = descriptor->register_param_count_; |
| 563 if (descriptor->stack_parameter_count_ != NULL) { |
| 564 params++; |
| 565 } |
| 566 output_frame->SetRegister(r0.code(), params); |
| 567 output_frame->SetRegister(r1.code(), handler); |
| 568 } |
| 569 |
| 570 |
| 571 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { |
| 572 for (int i = 0; i < DwVfpRegister::kMaxNumRegisters; ++i) { |
| 573 double double_value = input_->GetDoubleRegister(i); |
| 574 output_frame->SetDoubleRegister(i, double_value); |
| 575 } |
| 576 } |
| 577 |
| 578 |
860 #define __ masm()-> | 579 #define __ masm()-> |
861 | 580 |
862 // This code tries to be close to ia32 code so that any changes can be | 581 // This code tries to be close to ia32 code so that any changes can be |
863 // easily ported. | 582 // easily ported. |
864 void Deoptimizer::EntryGenerator::Generate() { | 583 void Deoptimizer::EntryGenerator::Generate() { |
865 GeneratePrologue(); | 584 GeneratePrologue(); |
866 | 585 |
867 Isolate* isolate = masm()->isolate(); | 586 Isolate* isolate = masm()->isolate(); |
868 | 587 |
869 // Save all general purpose registers before messing with them. | 588 // Save all general purpose registers before messing with them. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 __ push(ip); | 816 __ push(ip); |
1098 __ b(&done); | 817 __ b(&done); |
1099 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 818 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
1100 } | 819 } |
1101 __ bind(&done); | 820 __ bind(&done); |
1102 } | 821 } |
1103 | 822 |
1104 #undef __ | 823 #undef __ |
1105 | 824 |
1106 } } // namespace v8::internal | 825 } } // namespace v8::internal |
OLD | NEW |