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 // ok: |
| 131 // |
| 132 // We will patch away the branch so the code is: |
| 133 // |
| 134 // add <profiling_counter>, <-delta> ;; Not changed |
| 135 // nop |
| 136 // nop |
| 137 // call <on-stack replacment> |
| 138 // ok: |
| 139 |
| 140 void Deoptimizer::PatchInterruptCodeAt(Code* unoptimized_code, |
| 141 Address pc_after, |
| 142 Code* interrupt_code, |
| 143 Code* replacement_code) { |
| 144 ASSERT(!InterruptCodeIsPatched(unoptimized_code, |
| 145 pc_after, |
| 146 interrupt_code, |
| 147 replacement_code)); |
| 148 // Turn the jump into nops. |
129 Address call_target_address = pc_after - kIntSize; | 149 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; | 150 *(call_target_address - 3) = kNopByteOne; |
153 *(call_target_address - 2) = kNopByteTwo; | 151 *(call_target_address - 2) = kNopByteTwo; |
| 152 // Replace the call address. |
154 Assembler::set_target_address_at(call_target_address, | 153 Assembler::set_target_address_at(call_target_address, |
155 replacement_code->entry()); | 154 replacement_code->entry()); |
156 | 155 |
157 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 156 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
158 unoptimized_code, call_target_address, replacement_code); | 157 unoptimized_code, call_target_address, replacement_code); |
159 } | 158 } |
160 | 159 |
161 | 160 |
162 void Deoptimizer::RevertStackCheckCodeAt(Code* unoptimized_code, | 161 void Deoptimizer::RevertInterruptCodeAt(Code* unoptimized_code, |
163 Address pc_after, | 162 Address pc_after, |
164 Code* check_code, | 163 Code* interrupt_code, |
165 Code* replacement_code) { | 164 Code* replacement_code) { |
| 165 ASSERT(InterruptCodeIsPatched(unoptimized_code, |
| 166 pc_after, |
| 167 interrupt_code, |
| 168 replacement_code)); |
| 169 // Restore the original jump. |
166 Address call_target_address = pc_after - kIntSize; | 170 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; | 171 *(call_target_address - 3) = kJnsInstruction; |
175 *(call_target_address - 2) = kJnsOffset; | 172 *(call_target_address - 2) = kJnsOffset; |
| 173 // Restore the original call address. |
176 Assembler::set_target_address_at(call_target_address, | 174 Assembler::set_target_address_at(call_target_address, |
177 check_code->entry()); | 175 interrupt_code->entry()); |
178 | 176 |
179 check_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 177 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
180 unoptimized_code, call_target_address, check_code); | 178 unoptimized_code, call_target_address, interrupt_code); |
181 } | 179 } |
182 | 180 |
183 | 181 |
| 182 #ifdef DEBUG |
| 183 bool Deoptimizer::InterruptCodeIsPatched(Code* unoptimized_code, |
| 184 Address pc_after, |
| 185 Code* interrupt_code, |
| 186 Code* replacement_code) { |
| 187 Address call_target_address = pc_after - kIntSize; |
| 188 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
| 189 if (*(call_target_address - 3) == kNopByteOne) { |
| 190 ASSERT(replacement_code->entry() == |
| 191 Assembler::target_address_at(call_target_address)); |
| 192 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 193 return true; |
| 194 } else { |
| 195 ASSERT_EQ(interrupt_code->entry(), |
| 196 Assembler::target_address_at(call_target_address)); |
| 197 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); |
| 198 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 199 return false; |
| 200 } |
| 201 } |
| 202 #endif // DEBUG |
| 203 |
| 204 |
184 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { | 205 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { |
185 ByteArray* translations = data->TranslationByteArray(); | 206 ByteArray* translations = data->TranslationByteArray(); |
186 int length = data->DeoptCount(); | 207 int length = data->DeoptCount(); |
187 for (int i = 0; i < length; i++) { | 208 for (int i = 0; i < length; i++) { |
188 if (data->AstId(i) == ast_id) { | 209 if (data->AstId(i) == ast_id) { |
189 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 210 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
190 int value = it.Next(); | 211 int value = it.Next(); |
191 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); | 212 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); |
192 // Read the number of frames. | 213 // Read the number of frames. |
193 value = it.Next(); | 214 value = it.Next(); |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 } | 802 } |
782 __ bind(&done); | 803 __ bind(&done); |
783 } | 804 } |
784 | 805 |
785 #undef __ | 806 #undef __ |
786 | 807 |
787 | 808 |
788 } } // namespace v8::internal | 809 } } // namespace v8::internal |
789 | 810 |
790 #endif // V8_TARGET_ARCH_X64 | 811 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |