| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 function->ReplaceCode(function->shared()->code()); | 100 function->ReplaceCode(function->shared()->code()); |
| 101 | 101 |
| 102 if (FLAG_trace_deopt) { | 102 if (FLAG_trace_deopt) { |
| 103 PrintF("[forced deoptimization: "); | 103 PrintF("[forced deoptimization: "); |
| 104 function->PrintName(); | 104 function->PrintName(); |
| 105 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | 105 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo, | 110 void Deoptimizer::PatchStackCheckCode(Code* unoptimized_code, |
| 111 Code* check_code, |
| 111 Code* replacement_code) { | 112 Code* replacement_code) { |
| 112 // The stack check code matches the pattern: | 113 // Iterate the unoptimized code and patch every stack check except at |
| 113 // | 114 // the function entry. This code assumes the function entry stack |
| 114 // cmp esp, <limit> | 115 // check appears first i.e., is not deferred or otherwise reordered. |
| 115 // jae ok | 116 ASSERT(unoptimized_code->kind() == Code::FUNCTION); |
| 116 // call <stack guard> | 117 bool first = true; |
| 117 // test eax, <loop nesting depth> | 118 for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
| 118 // ok: ... | 119 !it.done(); |
| 119 // | 120 it.next()) { |
| 120 // We will patch away the branch so the code is: | 121 RelocInfo* rinfo = it.rinfo(); |
| 121 // | 122 if (rinfo->target_address() == Code::cast(check_code)->entry()) { |
| 122 // cmp esp, <limit> ;; Not changed | 123 if (first) { |
| 123 // nop | 124 first = false; |
| 124 // nop | 125 } else { |
| 125 // call <on-stack replacment> | 126 // The stack check code matches the pattern: |
| 126 // test eax, <loop nesting depth> | 127 // |
| 127 // ok: | 128 // cmp esp, <limit> |
| 128 Address call_target_address = rinfo->pc(); | 129 // jae ok |
| 129 ASSERT(*(call_target_address - 3) == 0x73 && // jae | 130 // call <stack guard> |
| 130 *(call_target_address - 2) == 0x07 && // offset | 131 // test eax, <loop nesting depth> |
| 131 *(call_target_address - 1) == 0xe8); // call | 132 // ok: ... |
| 132 *(call_target_address - 3) = 0x90; // nop | 133 // |
| 133 *(call_target_address - 2) = 0x90; // nop | 134 // We will patch away the branch so the code is: |
| 134 rinfo->set_target_address(replacement_code->entry()); | 135 // |
| 136 // cmp esp, <limit> ;; Not changed |
| 137 // nop |
| 138 // nop |
| 139 // call <on-stack replacment> |
| 140 // test eax, <loop nesting depth> |
| 141 // ok: |
| 142 Address call_target_address = rinfo->pc(); |
| 143 ASSERT(*(call_target_address - 3) == 0x73 && // jae |
| 144 *(call_target_address - 2) == 0x07 && // offset |
| 145 *(call_target_address - 1) == 0xe8); // call |
| 146 *(call_target_address - 3) = 0x90; // nop |
| 147 *(call_target_address - 2) = 0x90; // nop |
| 148 rinfo->set_target_address(replacement_code->entry()); |
| 149 } |
| 150 } |
| 151 } |
| 135 } | 152 } |
| 136 | 153 |
| 137 | 154 |
| 138 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) { | 155 void Deoptimizer::RevertStackCheckCode(Code* unoptimized_code, |
| 139 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to | 156 Code* check_code, |
| 140 // restore the conditional branch. | 157 Code* replacement_code) { |
| 141 Address call_target_address = rinfo->pc(); | 158 // Iterate the unoptimized code and revert all the patched stack checks. |
| 142 ASSERT(*(call_target_address - 3) == 0x90 && // nop | 159 for (RelocIterator it(unoptimized_code, RelocInfo::kCodeTargetMask); |
| 143 *(call_target_address - 2) == 0x90 && // nop | 160 !it.done(); |
| 144 *(call_target_address - 1) == 0xe8); // call | 161 it.next()) { |
| 145 *(call_target_address - 3) = 0x73; // jae | 162 RelocInfo* rinfo = it.rinfo(); |
| 146 *(call_target_address - 2) = 0x07; // offset | 163 if (rinfo->target_address() == replacement_code->entry()) { |
| 147 rinfo->set_target_address(check_code->entry()); | 164 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to |
| 165 // restore the conditional branch. |
| 166 Address call_target_address = rinfo->pc(); |
| 167 ASSERT(*(call_target_address - 3) == 0x90 && // nop |
| 168 *(call_target_address - 2) == 0x90 && // nop |
| 169 *(call_target_address - 1) == 0xe8); // call |
| 170 *(call_target_address - 3) = 0x73; // jae |
| 171 *(call_target_address - 2) = 0x07; // offset |
| 172 rinfo->set_target_address(check_code->entry()); |
| 173 } |
| 174 } |
| 148 } | 175 } |
| 149 | 176 |
| 150 | 177 |
| 151 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { | 178 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { |
| 152 ByteArray* translations = data->TranslationByteArray(); | 179 ByteArray* translations = data->TranslationByteArray(); |
| 153 int length = data->DeoptCount(); | 180 int length = data->DeoptCount(); |
| 154 for (int i = 0; i < length; i++) { | 181 for (int i = 0; i < length; i++) { |
| 155 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { | 182 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { |
| 156 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 183 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
| 157 int value = it.Next(); | 184 int value = it.Next(); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 __ mov(Operand(esp, 2 * kPointerSize), ebx); // Bailout id. | 530 __ mov(Operand(esp, 2 * kPointerSize), ebx); // Bailout id. |
| 504 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Code address or 0. | 531 __ mov(Operand(esp, 3 * kPointerSize), ecx); // Code address or 0. |
| 505 __ mov(Operand(esp, 4 * kPointerSize), edx); // Fp-to-sp delta. | 532 __ mov(Operand(esp, 4 * kPointerSize), edx); // Fp-to-sp delta. |
| 506 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5); | 533 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5); |
| 507 | 534 |
| 508 // Preserve deoptimizer object in register eax and get the input | 535 // Preserve deoptimizer object in register eax and get the input |
| 509 // frame descriptor pointer. | 536 // frame descriptor pointer. |
| 510 __ mov(ebx, Operand(eax, Deoptimizer::input_offset())); | 537 __ mov(ebx, Operand(eax, Deoptimizer::input_offset())); |
| 511 | 538 |
| 512 // Fill in the input registers. | 539 // Fill in the input registers. |
| 513 for (int i = 0; i < kNumberOfRegisters; i++) { | 540 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { |
| 514 int offset = (i * kIntSize) + FrameDescription::registers_offset(); | 541 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 515 __ mov(ecx, Operand(esp, (kNumberOfRegisters - 1 - i) * kPointerSize)); | 542 __ pop(Operand(ebx, offset)); |
| 516 __ mov(Operand(ebx, offset), ecx); | |
| 517 } | 543 } |
| 518 | 544 |
| 519 // Fill in the double input registers. | 545 // Fill in the double input registers. |
| 520 int double_regs_offset = FrameDescription::double_registers_offset(); | 546 int double_regs_offset = FrameDescription::double_registers_offset(); |
| 521 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { | 547 for (int i = 0; i < XMMRegister::kNumAllocatableRegisters; ++i) { |
| 522 int dst_offset = i * kDoubleSize + double_regs_offset; | 548 int dst_offset = i * kDoubleSize + double_regs_offset; |
| 523 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; | 549 int src_offset = i * kDoubleSize; |
| 524 __ movdbl(xmm0, Operand(esp, src_offset)); | 550 __ movdbl(xmm0, Operand(esp, src_offset)); |
| 525 __ movdbl(Operand(ebx, dst_offset), xmm0); | 551 __ movdbl(Operand(ebx, dst_offset), xmm0); |
| 526 } | 552 } |
| 527 | 553 |
| 528 // Remove the bailout id and the general purpose registers from the stack. | 554 // Remove the bailout id and the double registers from the stack. |
| 529 if (type() == EAGER) { | 555 if (type() == EAGER) { |
| 530 __ add(Operand(esp), Immediate(kSavedRegistersAreaSize + kPointerSize)); | 556 __ add(Operand(esp), Immediate(kDoubleRegsSize + kPointerSize)); |
| 531 } else { | 557 } else { |
| 532 __ add(Operand(esp), Immediate(kSavedRegistersAreaSize + 2 * kPointerSize)); | 558 __ add(Operand(esp), Immediate(kDoubleRegsSize + 2 * kPointerSize)); |
| 533 } | 559 } |
| 534 | 560 |
| 535 // Compute a pointer to the unwinding limit in register ecx; that is | 561 // Compute a pointer to the unwinding limit in register ecx; that is |
| 536 // the first stack slot not part of the input frame. | 562 // the first stack slot not part of the input frame. |
| 537 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); | 563 __ mov(ecx, Operand(ebx, FrameDescription::frame_size_offset())); |
| 538 __ add(ecx, Operand(esp)); | 564 __ add(ecx, Operand(esp)); |
| 539 | 565 |
| 540 // Unwind the stack down to - but not including - the unwinding | 566 // Unwind the stack down to - but not including - the unwinding |
| 541 // limit and copy the contents of the activation frame to the input | 567 // limit and copy the contents of the activation frame to the input |
| 542 // frame description. | 568 // frame description. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // Push state, pc, and continuation from the last output frame. | 613 // Push state, pc, and continuation from the last output frame. |
| 588 if (type() != OSR) { | 614 if (type() != OSR) { |
| 589 __ push(Operand(ebx, FrameDescription::state_offset())); | 615 __ push(Operand(ebx, FrameDescription::state_offset())); |
| 590 } | 616 } |
| 591 __ push(Operand(ebx, FrameDescription::pc_offset())); | 617 __ push(Operand(ebx, FrameDescription::pc_offset())); |
| 592 __ push(Operand(ebx, FrameDescription::continuation_offset())); | 618 __ push(Operand(ebx, FrameDescription::continuation_offset())); |
| 593 | 619 |
| 594 | 620 |
| 595 // Push the registers from the last output frame. | 621 // Push the registers from the last output frame. |
| 596 for (int i = 0; i < kNumberOfRegisters; i++) { | 622 for (int i = 0; i < kNumberOfRegisters; i++) { |
| 597 int offset = (i * kIntSize) + FrameDescription::registers_offset(); | 623 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 598 __ push(Operand(ebx, offset)); | 624 __ push(Operand(ebx, offset)); |
| 599 } | 625 } |
| 600 | 626 |
| 601 // Restore the registers from the stack. | 627 // Restore the registers from the stack. |
| 602 __ popad(); | 628 __ popad(); |
| 603 | 629 |
| 604 // Return to the continuation point. | 630 // Return to the continuation point. |
| 605 __ ret(0); | 631 __ ret(0); |
| 606 } | 632 } |
| 607 | 633 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 618 } | 644 } |
| 619 __ bind(&done); | 645 __ bind(&done); |
| 620 } | 646 } |
| 621 | 647 |
| 622 #undef __ | 648 #undef __ |
| 623 | 649 |
| 624 | 650 |
| 625 } } // namespace v8::internal | 651 } } // namespace v8::internal |
| 626 | 652 |
| 627 #endif // V8_TARGET_ARCH_IA32 | 653 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |