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 // 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) |
541 // and how the frame is laid out. | 360 // and how the frame is laid out. |
542 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, | 361 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, |
543 int frame_index) { | 362 int frame_index) { |
544 // 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. |
545 BailoutId node_id = BailoutId(iterator->Next()); | 364 BailoutId node_id = BailoutId(iterator->Next()); |
546 JSFunction* function; | 365 JSFunction* function; |
547 if (frame_index != 0) { | 366 if (frame_index != 0) { |
548 function = JSFunction::cast(ComputeLiteral(iterator->Next())); | 367 function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
549 } else { | 368 } else { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 input_->SetDoubleRegister(i, 0.0); | 547 input_->SetDoubleRegister(i, 0.0); |
729 } | 548 } |
730 | 549 |
731 // Fill the frame content from the actual data on the frame. | 550 // Fill the frame content from the actual data on the frame. |
732 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { | 551 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
733 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); | 552 input_->SetFrameSlot(i, Memory::uint32_at(tos + i)); |
734 } | 553 } |
735 } | 554 } |
736 | 555 |
737 | 556 |
557 void Deoptimizer::FillStubFailureTrampolineFrame( | |
danno
2013/03/05 13:54:04
The name is maybe a little bit misleading. How abo
Michael Starzinger
2013/03/08 11:54:09
Done. As discussed offline: IMHO the DoComputeFoo
| |
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 | |
738 #define __ masm()-> | 579 #define __ masm()-> |
739 | 580 |
740 // 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 |
741 // easily ported. | 582 // easily ported. |
742 void Deoptimizer::EntryGenerator::Generate() { | 583 void Deoptimizer::EntryGenerator::Generate() { |
743 GeneratePrologue(); | 584 GeneratePrologue(); |
744 | 585 |
745 Isolate* isolate = masm()->isolate(); | 586 Isolate* isolate = masm()->isolate(); |
746 | 587 |
747 // 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... | |
975 __ push(ip); | 816 __ push(ip); |
976 __ b(&done); | 817 __ b(&done); |
977 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 818 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
978 } | 819 } |
979 __ bind(&done); | 820 __ bind(&done); |
980 } | 821 } |
981 | 822 |
982 #undef __ | 823 #undef __ |
983 | 824 |
984 } } // namespace v8::internal | 825 } } // namespace v8::internal |
OLD | NEW |