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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 110 |
111 if (FLAG_trace_deopt) { | 111 if (FLAG_trace_deopt) { |
112 PrintF("[forced deoptimization: "); | 112 PrintF("[forced deoptimization: "); |
113 function->PrintName(); | 113 function->PrintName(); |
114 PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); | 114 PrintF(" / %" V8PRIxPTR "]\n", reinterpret_cast<intptr_t>(function)); |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 | 118 |
119 static const byte kJnsInstruction = 0x79; | 119 static const byte kJnsInstruction = 0x79; |
120 static const byte kJnsOffset = 0x1f; | 120 static const byte kJnsOffset = 0x1d; |
121 static const byte kCallInstruction = 0xe8; | 121 static const byte kCallInstruction = 0xe8; |
122 static const byte kNopByteOne = 0x66; | 122 static const byte kNopByteOne = 0x66; |
123 static const byte kNopByteTwo = 0x90; | 123 static const byte kNopByteTwo = 0x90; |
124 | 124 |
125 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, | 125 // The back edge bookkeeping code matches the pattern: |
126 Address pc_after, | 126 // |
127 Code* check_code, | 127 // add <profiling_counter>, <-delta> |
128 Code* replacement_code) { | 128 // jns ok |
| 129 // call <stack guard> |
| 130 // |
| 131 // We will patch away the branch so the code is: |
| 132 // |
| 133 // add <profiling_counter>, <-delta> ;; Not changed |
| 134 // nop |
| 135 // nop |
| 136 // call <on-stack replacment> |
| 137 |
| 138 void Deoptimizer::PatchInterruptCodeAt(Code* unoptimized_code, |
| 139 Address pc_after, |
| 140 Code* interrupt_code, |
| 141 Code* replacement_code) { |
| 142 ASSERT(!InterruptCodeIsPatched(unoptimized_code, |
| 143 pc_after, |
| 144 interrupt_code, |
| 145 replacement_code)); |
| 146 // Turn the jump into nops. |
129 Address call_target_address = pc_after - kIntSize; | 147 Address call_target_address = pc_after - kIntSize; |
130 ASSERT_EQ(check_code->entry(), | |
131 Assembler::target_address_at(call_target_address)); | |
132 // The back edge bookkeeping code matches the pattern: | |
133 // | |
134 // add <profiling_counter>, <-delta> | |
135 // jns ok | |
136 // call <stack guard> | |
137 // test rax, <loop nesting depth> | |
138 // ok: ... | |
139 // | |
140 // We will patch away the branch so the code is: | |
141 // | |
142 // add <profiling_counter>, <-delta> ;; Not changed | |
143 // nop | |
144 // nop | |
145 // call <on-stack replacment> | |
146 // test rax, <loop nesting depth> | |
147 // ok: | |
148 // | |
149 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); | |
150 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); | |
151 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | |
152 *(call_target_address - 3) = kNopByteOne; | 148 *(call_target_address - 3) = kNopByteOne; |
153 *(call_target_address - 2) = kNopByteTwo; | 149 *(call_target_address - 2) = kNopByteTwo; |
| 150 // Replace the call address. |
154 Assembler::set_target_address_at(call_target_address, | 151 Assembler::set_target_address_at(call_target_address, |
155 replacement_code->entry()); | 152 replacement_code->entry()); |
156 | 153 |
157 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 154 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
158 unoptimized_code, call_target_address, replacement_code); | 155 unoptimized_code, call_target_address, replacement_code); |
159 } | 156 } |
160 | 157 |
161 | 158 |
162 void Deoptimizer::RevertStackCheckCodeAt(Code* unoptimized_code, | 159 void Deoptimizer::RevertInterruptCodeAt(Code* unoptimized_code, |
163 Address pc_after, | 160 Address pc_after, |
164 Code* check_code, | 161 Code* interrupt_code, |
165 Code* replacement_code) { | 162 Code* replacement_code) { |
| 163 ASSERT(InterruptCodeIsPatched(unoptimized_code, |
| 164 pc_after, |
| 165 interrupt_code, |
| 166 replacement_code)); |
| 167 // Restore the original jump. |
166 Address call_target_address = pc_after - kIntSize; | 168 Address call_target_address = pc_after - kIntSize; |
167 ASSERT(replacement_code->entry() == | |
168 Assembler::target_address_at(call_target_address)); | |
169 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to | |
170 // restore the conditional branch. | |
171 ASSERT_EQ(kNopByteOne, *(call_target_address - 3)); | |
172 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); | |
173 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | |
174 *(call_target_address - 3) = kJnsInstruction; | 169 *(call_target_address - 3) = kJnsInstruction; |
175 *(call_target_address - 2) = kJnsOffset; | 170 *(call_target_address - 2) = kJnsOffset; |
| 171 // Restore the original call address. |
176 Assembler::set_target_address_at(call_target_address, | 172 Assembler::set_target_address_at(call_target_address, |
177 check_code->entry()); | 173 interrupt_code->entry()); |
178 | 174 |
179 check_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 175 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
180 unoptimized_code, call_target_address, check_code); | 176 unoptimized_code, call_target_address, interrupt_code); |
181 } | 177 } |
182 | 178 |
183 | 179 |
| 180 #ifdef DEBUG |
| 181 bool Deoptimizer::InterruptCodeIsPatched(Code* unoptimized_code, |
| 182 Address pc_after, |
| 183 Code* interrupt_code, |
| 184 Code* replacement_code) { |
| 185 Address call_target_address = pc_after - kIntSize; |
| 186 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
| 187 if (*(call_target_address - 3) == kNopByteOne) { |
| 188 ASSERT(replacement_code->entry() == |
| 189 Assembler::target_address_at(call_target_address)); |
| 190 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 191 return true; |
| 192 } else { |
| 193 ASSERT_EQ(interrupt_code->entry(), |
| 194 Assembler::target_address_at(call_target_address)); |
| 195 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); |
| 196 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 197 return false; |
| 198 } |
| 199 } |
| 200 #endif // DEBUG |
| 201 |
| 202 |
184 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { | 203 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { |
185 ByteArray* translations = data->TranslationByteArray(); | 204 ByteArray* translations = data->TranslationByteArray(); |
186 int length = data->DeoptCount(); | 205 int length = data->DeoptCount(); |
187 for (int i = 0; i < length; i++) { | 206 for (int i = 0; i < length; i++) { |
188 if (data->AstId(i) == ast_id) { | 207 if (data->AstId(i) == ast_id) { |
189 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 208 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
190 int value = it.Next(); | 209 int value = it.Next(); |
191 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); | 210 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); |
192 // Read the number of frames. | 211 // Read the number of frames. |
193 value = it.Next(); | 212 value = it.Next(); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 } | 800 } |
782 __ bind(&done); | 801 __ bind(&done); |
783 } | 802 } |
784 | 803 |
785 #undef __ | 804 #undef __ |
786 | 805 |
787 | 806 |
788 } } // namespace v8::internal | 807 } } // namespace v8::internal |
789 | 808 |
790 #endif // V8_TARGET_ARCH_X64 | 809 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |