| OLD | NEW |
| 1 | 1 |
| 2 // Copyright 2011 the V8 project authors. All rights reserved. | 2 // Copyright 2011 the V8 project authors. All rights reserved. |
| 3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
| 4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
| 5 // met: | 5 // met: |
| 6 // | 6 // |
| 7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
| 8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
| 9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
| 10 // copyright notice, this list of conditions and the following | 10 // copyright notice, this list of conditions and the following |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 if (FLAG_trace_osr) { | 359 if (FLAG_trace_osr) { |
| 360 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | 360 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", |
| 361 ok ? "finished" : "aborted", | 361 ok ? "finished" : "aborted", |
| 362 reinterpret_cast<intptr_t>(function_)); | 362 reinterpret_cast<intptr_t>(function_)); |
| 363 PrintFunctionName(); | 363 PrintFunctionName(); |
| 364 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | 364 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 | 368 |
| 369 // This code is very similar to ia32/arm code, but relies on register names | |
| 370 // (fp, sp) and how the frame is laid out. | |
| 371 void Deoptimizer::DoComputeJSFrame(TranslationIterator* iterator, | |
| 372 int frame_index) { | |
| 373 // Read the ast node id, function, and frame height for this output frame. | |
| 374 BailoutId node_id = BailoutId(iterator->Next()); | |
| 375 JSFunction* function; | |
| 376 if (frame_index != 0) { | |
| 377 function = JSFunction::cast(ComputeLiteral(iterator->Next())); | |
| 378 } else { | |
| 379 int closure_id = iterator->Next(); | |
| 380 USE(closure_id); | |
| 381 ASSERT_EQ(Translation::kSelfLiteralId, closure_id); | |
| 382 function = function_; | |
| 383 } | |
| 384 unsigned height = iterator->Next(); | |
| 385 unsigned height_in_bytes = height * kPointerSize; | |
| 386 if (trace_) { | |
| 387 PrintF(" translating "); | |
| 388 function->PrintName(); | |
| 389 PrintF(" => node=%d, height=%d\n", node_id.ToInt(), height_in_bytes); | |
| 390 } | |
| 391 | |
| 392 // The 'fixed' part of the frame consists of the incoming parameters and | |
| 393 // the part described by JavaScriptFrameConstants. | |
| 394 unsigned fixed_frame_size = ComputeFixedSize(function); | |
| 395 unsigned input_frame_size = input_->GetFrameSize(); | |
| 396 unsigned output_frame_size = height_in_bytes + fixed_frame_size; | |
| 397 | |
| 398 // Allocate and store the output frame description. | |
| 399 FrameDescription* output_frame = | |
| 400 new(output_frame_size) FrameDescription(output_frame_size, function); | |
| 401 output_frame->SetFrameType(StackFrame::JAVA_SCRIPT); | |
| 402 | |
| 403 bool is_bottommost = (0 == frame_index); | |
| 404 bool is_topmost = (output_count_ - 1 == frame_index); | |
| 405 ASSERT(frame_index >= 0 && frame_index < output_count_); | |
| 406 ASSERT(output_[frame_index] == NULL); | |
| 407 output_[frame_index] = output_frame; | |
| 408 | |
| 409 // The top address for the bottommost output frame can be computed from | |
| 410 // the input frame pointer and the output frame's height. For all | |
| 411 // subsequent output frames, it can be computed from the previous one's | |
| 412 // top address and the current frame's size. | |
| 413 uint32_t top_address; | |
| 414 if (is_bottommost) { | |
| 415 // 2 = context and function in the frame. | |
| 416 top_address = | |
| 417 input_->GetRegister(fp.code()) - (2 * kPointerSize) - height_in_bytes; | |
| 418 } else { | |
| 419 top_address = output_[frame_index - 1]->GetTop() - output_frame_size; | |
| 420 } | |
| 421 output_frame->SetTop(top_address); | |
| 422 | |
| 423 // Compute the incoming parameter translation. | |
| 424 int parameter_count = function->shared()->formal_parameter_count() + 1; | |
| 425 unsigned output_offset = output_frame_size; | |
| 426 unsigned input_offset = input_frame_size; | |
| 427 for (int i = 0; i < parameter_count; ++i) { | |
| 428 output_offset -= kPointerSize; | |
| 429 DoTranslateCommand(iterator, frame_index, output_offset); | |
| 430 } | |
| 431 input_offset -= (parameter_count * kPointerSize); | |
| 432 | |
| 433 // There are no translation commands for the caller's pc and fp, the | |
| 434 // context, and the function. Synthesize their values and set them up | |
| 435 // explicitly. | |
| 436 // | |
| 437 // The caller's pc for the bottommost output frame is the same as in the | |
| 438 // input frame. For all subsequent output frames, it can be read from the | |
| 439 // previous one. This frame's pc can be computed from the non-optimized | |
| 440 // function code and AST id of the bailout. | |
| 441 output_offset -= kPointerSize; | |
| 442 input_offset -= kPointerSize; | |
| 443 intptr_t value; | |
| 444 if (is_bottommost) { | |
| 445 value = input_->GetFrameSlot(input_offset); | |
| 446 } else { | |
| 447 value = output_[frame_index - 1]->GetPc(); | |
| 448 } | |
| 449 output_frame->SetFrameSlot(output_offset, value); | |
| 450 if (trace_) { | |
| 451 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's pc\n", | |
| 452 top_address + output_offset, output_offset, value); | |
| 453 } | |
| 454 | |
| 455 // The caller's frame pointer for the bottommost output frame is the same | |
| 456 // as in the input frame. For all subsequent output frames, it can be | |
| 457 // read from the previous one. Also compute and set this frame's frame | |
| 458 // pointer. | |
| 459 output_offset -= kPointerSize; | |
| 460 input_offset -= kPointerSize; | |
| 461 if (is_bottommost) { | |
| 462 value = input_->GetFrameSlot(input_offset); | |
| 463 } else { | |
| 464 value = output_[frame_index - 1]->GetFp(); | |
| 465 } | |
| 466 output_frame->SetFrameSlot(output_offset, value); | |
| 467 intptr_t fp_value = top_address + output_offset; | |
| 468 ASSERT(!is_bottommost || input_->GetRegister(fp.code()) == fp_value); | |
| 469 output_frame->SetFp(fp_value); | |
| 470 if (is_topmost) { | |
| 471 output_frame->SetRegister(fp.code(), fp_value); | |
| 472 } | |
| 473 if (trace_) { | |
| 474 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; caller's fp\n", | |
| 475 fp_value, output_offset, value); | |
| 476 } | |
| 477 | |
| 478 // For the bottommost output frame the context can be gotten from the input | |
| 479 // frame. For all subsequent output frames it can be gotten from the function | |
| 480 // so long as we don't inline functions that need local contexts. | |
| 481 output_offset -= kPointerSize; | |
| 482 input_offset -= kPointerSize; | |
| 483 if (is_bottommost) { | |
| 484 value = input_->GetFrameSlot(input_offset); | |
| 485 } else { | |
| 486 value = reinterpret_cast<intptr_t>(function->context()); | |
| 487 } | |
| 488 output_frame->SetFrameSlot(output_offset, value); | |
| 489 output_frame->SetContext(value); | |
| 490 if (is_topmost) output_frame->SetRegister(cp.code(), value); | |
| 491 if (trace_) { | |
| 492 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; context\n", | |
| 493 top_address + output_offset, output_offset, value); | |
| 494 } | |
| 495 | |
| 496 // The function was mentioned explicitly in the BEGIN_FRAME. | |
| 497 output_offset -= kPointerSize; | |
| 498 input_offset -= kPointerSize; | |
| 499 value = reinterpret_cast<uint32_t>(function); | |
| 500 // The function for the bottommost output frame should also agree with the | |
| 501 // input frame. | |
| 502 ASSERT(!is_bottommost || input_->GetFrameSlot(input_offset) == value); | |
| 503 output_frame->SetFrameSlot(output_offset, value); | |
| 504 if (trace_) { | |
| 505 PrintF(" 0x%08x: [top + %d] <- 0x%08x ; function\n", | |
| 506 top_address + output_offset, output_offset, value); | |
| 507 } | |
| 508 | |
| 509 // Translate the rest of the frame. | |
| 510 for (unsigned i = 0; i < height; ++i) { | |
| 511 output_offset -= kPointerSize; | |
| 512 DoTranslateCommand(iterator, frame_index, output_offset); | |
| 513 } | |
| 514 ASSERT(0 == output_offset); | |
| 515 | |
| 516 // Compute this frame's PC, state, and continuation. | |
| 517 Code* non_optimized_code = function->shared()->code(); | |
| 518 FixedArray* raw_data = non_optimized_code->deoptimization_data(); | |
| 519 DeoptimizationOutputData* data = DeoptimizationOutputData::cast(raw_data); | |
| 520 Address start = non_optimized_code->instruction_start(); | |
| 521 unsigned pc_and_state = GetOutputInfo(data, node_id, function->shared()); | |
| 522 unsigned pc_offset = FullCodeGenerator::PcField::decode(pc_and_state); | |
| 523 uint32_t pc_value = reinterpret_cast<uint32_t>(start + pc_offset); | |
| 524 output_frame->SetPc(pc_value); | |
| 525 | |
| 526 FullCodeGenerator::State state = | |
| 527 FullCodeGenerator::StateField::decode(pc_and_state); | |
| 528 output_frame->SetState(Smi::FromInt(state)); | |
| 529 | |
| 530 | |
| 531 // Set the continuation for the topmost frame. | |
| 532 if (is_topmost && bailout_type_ != DEBUGGER) { | |
| 533 Builtins* builtins = isolate_->builtins(); | |
| 534 Code* continuation = builtins->builtin(Builtins::kNotifyDeoptimized); | |
| 535 if (bailout_type_ == LAZY) { | |
| 536 continuation = builtins->builtin(Builtins::kNotifyLazyDeoptimized); | |
| 537 } else if (bailout_type_ == SOFT) { | |
| 538 continuation = builtins->builtin(Builtins::kNotifySoftDeoptimized); | |
| 539 } else { | |
| 540 ASSERT(bailout_type_ == EAGER); | |
| 541 } | |
| 542 output_frame->SetContinuation( | |
| 543 reinterpret_cast<uint32_t>(continuation->entry())); | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { | 369 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
| 548 // Set the register values. The values are not important as there are no | 370 // Set the register values. The values are not important as there are no |
| 549 // callee saved registers in JavaScript frames, so all registers are | 371 // callee saved registers in JavaScript frames, so all registers are |
| 550 // spilled. Registers fp and sp are set to the correct values though. | 372 // spilled. Registers fp and sp are set to the correct values though. |
| 551 | 373 |
| 552 for (int i = 0; i < Register::kNumRegisters; i++) { | 374 for (int i = 0; i < Register::kNumRegisters; i++) { |
| 553 input_->SetRegister(i, i * 4); | 375 input_->SetRegister(i, i * 4); |
| 554 } | 376 } |
| 555 input_->SetRegister(sp.code(), reinterpret_cast<intptr_t>(frame->sp())); | 377 input_->SetRegister(sp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
| 556 input_->SetRegister(fp.code(), reinterpret_cast<intptr_t>(frame->fp())); | 378 input_->SetRegister(fp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 581 | 403 |
| 582 | 404 |
| 583 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { | 405 void Deoptimizer::CopyDoubleRegisters(FrameDescription* output_frame) { |
| 584 for (int i = 0; i < DoubleRegister::kMaxNumRegisters; ++i) { | 406 for (int i = 0; i < DoubleRegister::kMaxNumRegisters; ++i) { |
| 585 double double_value = input_->GetDoubleRegister(i); | 407 double double_value = input_->GetDoubleRegister(i); |
| 586 output_frame->SetDoubleRegister(i, double_value); | 408 output_frame->SetDoubleRegister(i, double_value); |
| 587 } | 409 } |
| 588 } | 410 } |
| 589 | 411 |
| 590 | 412 |
| 413 bool Deoptimizer::HasAlignmentPadding(JSFunction* function) { |
| 414 // There is no dynamic alignment padding on MIPS in the input frame. |
| 415 return false; |
| 416 } |
| 417 |
| 418 |
| 591 #define __ masm()-> | 419 #define __ masm()-> |
| 592 | 420 |
| 593 | 421 |
| 594 // This code tries to be close to ia32 code so that any changes can be | 422 // This code tries to be close to ia32 code so that any changes can be |
| 595 // easily ported. | 423 // easily ported. |
| 596 void Deoptimizer::EntryGenerator::Generate() { | 424 void Deoptimizer::EntryGenerator::Generate() { |
| 597 GeneratePrologue(); | 425 GeneratePrologue(); |
| 598 | 426 |
| 599 // Unlike on ARM we don't save all the registers, just the useful ones. | 427 // Unlike on ARM we don't save all the registers, just the useful ones. |
| 600 // For the rest, there are gaps on the stack, so the offsets remain the same. | 428 // For the rest, there are gaps on the stack, so the offsets remain the same. |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 666 } |
| 839 | 667 |
| 840 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), | 668 ASSERT_EQ(masm()->SizeOfCodeGeneratedSince(&table_start), |
| 841 count() * table_entry_size_); | 669 count() * table_entry_size_); |
| 842 } | 670 } |
| 843 | 671 |
| 844 #undef __ | 672 #undef __ |
| 845 | 673 |
| 846 | 674 |
| 847 } } // namespace v8::internal | 675 } } // namespace v8::internal |
| OLD | NEW |