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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::DoComputeJSFrame(TranslationIterator* iterator, | 351 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, |
539 int frame_index) { | 352 int frame_index) { |
540 BailoutId node_id = BailoutId(iterator->Next()); | 353 BailoutId node_id = BailoutId(iterator->Next()); |
541 JSFunction* function; | 354 JSFunction* function; |
542 if (frame_index != 0) { | 355 if (frame_index != 0) { |
543 function = JSFunction::cast(ComputeLiteral(iterator->Next())); | 356 function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
544 } else { | 357 } else { |
545 int closure_id = iterator->Next(); | 358 int closure_id = iterator->Next(); |
546 USE(closure_id); | 359 USE(closure_id); |
547 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 Loading... |
719 input_->SetDoubleRegister(i, 0.0); | 532 input_->SetDoubleRegister(i, 0.0); |
720 } | 533 } |
721 | 534 |
722 // Fill the frame content from the actual data on the frame. | 535 // Fill the frame content from the actual data on the frame. |
723 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { | 536 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
724 input_->SetFrameSlot(i, Memory::uint64_at(tos + i)); | 537 input_->SetFrameSlot(i, Memory::uint64_at(tos + i)); |
725 } | 538 } |
726 } | 539 } |
727 | 540 |
728 | 541 |
| 542 void Deoptimizer::FillStubFailureTrampolineFrame( |
| 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 |
729 #define __ masm()-> | 563 #define __ masm()-> |
730 | 564 |
731 void Deoptimizer::EntryGenerator::Generate() { | 565 void Deoptimizer::EntryGenerator::Generate() { |
732 GeneratePrologue(); | 566 GeneratePrologue(); |
733 | 567 |
734 // Save all general purpose registers before messing with them. | 568 // Save all general purpose registers before messing with them. |
735 const int kNumberOfRegisters = Register::kNumRegisters; | 569 const int kNumberOfRegisters = Register::kNumRegisters; |
736 | 570 |
737 const int kDoubleRegsSize = kDoubleSize * | 571 const int kDoubleRegsSize = kDoubleSize * |
738 XMMRegister::NumAllocatableRegisters(); | 572 XMMRegister::NumAllocatableRegisters(); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 } | 781 } |
948 __ bind(&done); | 782 __ bind(&done); |
949 } | 783 } |
950 | 784 |
951 #undef __ | 785 #undef __ |
952 | 786 |
953 | 787 |
954 } } // namespace v8::internal | 788 } } // namespace v8::internal |
955 | 789 |
956 #endif // V8_TARGET_ARCH_X64 | 790 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |