| OLD | NEW |
| 1 // Copyright 2010 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #if defined(V8_TARGET_ARCH_IA32) |
| 31 |
| 30 #include "codegen.h" | 32 #include "codegen.h" |
| 31 #include "deoptimizer.h" | 33 #include "deoptimizer.h" |
| 32 #include "full-codegen.h" | 34 #include "full-codegen.h" |
| 33 #include "safepoint-table.h" | 35 #include "safepoint-table.h" |
| 34 | 36 |
| 35 namespace v8 { | 37 namespace v8 { |
| 36 namespace internal { | 38 namespace internal { |
| 37 | 39 |
| 38 | 40 |
| 39 int Deoptimizer::table_entry_size_ = 10; | 41 int Deoptimizer::table_entry_size_ = 10; |
| 40 | 42 |
| 41 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { | 43 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
| 42 AssertNoAllocation no_allocation; | 44 AssertNoAllocation no_allocation; |
| 43 | 45 |
| 44 if (!function->IsOptimized()) return; | 46 if (!function->IsOptimized()) return; |
| 45 | 47 |
| 46 // Get the optimized code. | 48 // Get the optimized code. |
| 47 Code* code = function->code(); | 49 Code* code = function->code(); |
| 48 | 50 |
| 49 // Invalidate the relocation information, as it will become invalid by the | 51 // Invalidate the relocation information, as it will become invalid by the |
| 50 // code patching below, and is not needed any more. | 52 // code patching below, and is not needed any more. |
| 51 code->InvalidateRelocation(); | 53 code->InvalidateRelocation(); |
| 52 | 54 |
| 53 // For each return after a safepoint insert a absolute call to the | 55 // For each return after a safepoint insert a absolute call to the |
| 54 // corresponding deoptimization entry. | 56 // corresponding deoptimization entry. |
| 55 unsigned last_pc_offset = 0; | 57 unsigned last_pc_offset = 0; |
| 56 SafepointTable table(function->code()); | 58 SafepointTable table(function->code()); |
| 57 for (unsigned i = 0; i < table.length(); i++) { | 59 for (unsigned i = 0; i < table.length(); i++) { |
| 58 unsigned pc_offset = table.GetPcOffset(i); | 60 unsigned pc_offset = table.GetPcOffset(i); |
| 59 int deoptimization_index = table.GetDeoptimizationIndex(i); | 61 SafepointEntry safepoint_entry = table.GetEntry(i); |
| 60 int gap_code_size = table.GetGapCodeSize(i); | 62 int deoptimization_index = safepoint_entry.deoptimization_index(); |
| 63 int gap_code_size = safepoint_entry.gap_code_size(); |
| 61 #ifdef DEBUG | 64 #ifdef DEBUG |
| 62 // Destroy the code which is not supposed to run again. | 65 // Destroy the code which is not supposed to run again. |
| 63 unsigned instructions = pc_offset - last_pc_offset; | 66 unsigned instructions = pc_offset - last_pc_offset; |
| 64 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 67 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
| 65 instructions); | 68 instructions); |
| 66 for (unsigned i = 0; i < instructions; i++) { | 69 for (unsigned i = 0; i < instructions; i++) { |
| 67 destroyer.masm()->int3(); | 70 destroyer.masm()->int3(); |
| 68 } | 71 } |
| 69 #endif | 72 #endif |
| 70 last_pc_offset = pc_offset; | 73 last_pc_offset = pc_offset; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 99 if (FLAG_trace_deopt) { | 102 if (FLAG_trace_deopt) { |
| 100 PrintF("[forced deoptimization: "); | 103 PrintF("[forced deoptimization: "); |
| 101 function->PrintName(); | 104 function->PrintName(); |
| 102 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | 105 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); |
| 103 } | 106 } |
| 104 } | 107 } |
| 105 | 108 |
| 106 | 109 |
| 107 void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo, | 110 void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo, |
| 108 Code* replacement_code) { | 111 Code* replacement_code) { |
| 109 // The stack check code matches the pattern (on ia32, for example): | 112 // The stack check code matches the pattern: |
| 110 // | 113 // |
| 111 // cmp esp, <limit> | 114 // cmp esp, <limit> |
| 112 // jae ok | 115 // jae ok |
| 113 // call <stack guard> | 116 // call <stack guard> |
| 117 // test eax, <loop nesting depth> |
| 114 // ok: ... | 118 // ok: ... |
| 115 // | 119 // |
| 116 // We will patch the code to: | 120 // We will patch away the branch so the code is: |
| 117 // | 121 // |
| 118 // cmp esp, <limit> ;; Not changed | 122 // cmp esp, <limit> ;; Not changed |
| 119 // nop | 123 // nop |
| 120 // nop | 124 // nop |
| 121 // call <on-stack replacment> | 125 // call <on-stack replacment> |
| 126 // test eax, <loop nesting depth> |
| 122 // ok: | 127 // ok: |
| 123 Address call_target_address = rinfo->pc(); | 128 Address call_target_address = rinfo->pc(); |
| 124 ASSERT(*(call_target_address - 3) == 0x73 && // jae | 129 ASSERT(*(call_target_address - 3) == 0x73 && // jae |
| 125 *(call_target_address - 2) == 0x05 && // offset | 130 *(call_target_address - 2) == 0x07 && // offset |
| 126 *(call_target_address - 1) == 0xe8); // call | 131 *(call_target_address - 1) == 0xe8); // call |
| 127 *(call_target_address - 3) = 0x90; // nop | 132 *(call_target_address - 3) = 0x90; // nop |
| 128 *(call_target_address - 2) = 0x90; // nop | 133 *(call_target_address - 2) = 0x90; // nop |
| 129 rinfo->set_target_address(replacement_code->entry()); | 134 rinfo->set_target_address(replacement_code->entry()); |
| 130 } | 135 } |
| 131 | 136 |
| 132 | 137 |
| 133 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) { | 138 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) { |
| 139 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to |
| 140 // restore the conditional branch. |
| 134 Address call_target_address = rinfo->pc(); | 141 Address call_target_address = rinfo->pc(); |
| 135 ASSERT(*(call_target_address - 3) == 0x90 && // nop | 142 ASSERT(*(call_target_address - 3) == 0x90 && // nop |
| 136 *(call_target_address - 2) == 0x90 && // nop | 143 *(call_target_address - 2) == 0x90 && // nop |
| 137 *(call_target_address - 1) == 0xe8); // call | 144 *(call_target_address - 1) == 0xe8); // call |
| 138 *(call_target_address - 3) = 0x73; // jae | 145 *(call_target_address - 3) = 0x73; // jae |
| 139 *(call_target_address - 2) = 0x05; // offset | 146 *(call_target_address - 2) = 0x07; // offset |
| 140 rinfo->set_target_address(check_code->entry()); | 147 rinfo->set_target_address(check_code->entry()); |
| 141 } | 148 } |
| 142 | 149 |
| 143 | 150 |
| 144 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { | 151 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { |
| 145 ByteArray* translations = data->TranslationByteArray(); | 152 ByteArray* translations = data->TranslationByteArray(); |
| 146 int length = data->DeoptCount(); | 153 int length = data->DeoptCount(); |
| 147 for (int i = 0; i < length; i++) { | 154 for (int i = 0; i < length; i++) { |
| 148 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { | 155 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { |
| 149 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 156 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 __ jmp(&done); | 616 __ jmp(&done); |
| 610 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 617 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
| 611 } | 618 } |
| 612 __ bind(&done); | 619 __ bind(&done); |
| 613 } | 620 } |
| 614 | 621 |
| 615 #undef __ | 622 #undef __ |
| 616 | 623 |
| 617 | 624 |
| 618 } } // namespace v8::internal | 625 } } // namespace v8::internal |
| 626 |
| 627 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |