Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: src/ia32/deoptimizer-ia32.cc

Issue 13811014: Fix OSR for nested loops. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/builtins-ia32.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 if (FLAG_trace_deopt) { 205 if (FLAG_trace_deopt) {
206 PrintF("[forced deoptimization: "); 206 PrintF("[forced deoptimization: ");
207 function->PrintName(); 207 function->PrintName();
208 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); 208 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function));
209 } 209 }
210 } 210 }
211 211
212 212
213 static const byte kJnsInstruction = 0x79; 213 static const byte kJnsInstruction = 0x79;
214 static const byte kJnsOffset = 0x13; 214 static const byte kJnsOffset = 0x11;
215 static const byte kCallInstruction = 0xe8; 215 static const byte kCallInstruction = 0xe8;
216 static const byte kNopByteOne = 0x66; 216 static const byte kNopByteOne = 0x66;
217 static const byte kNopByteTwo = 0x90; 217 static const byte kNopByteTwo = 0x90;
218 218
219 // The back edge bookkeeping code matches the pattern:
220 //
221 // sub <profiling_counter>, <delta>
222 // jns ok
223 // call <interrupt stub>
224 // ok:
225 //
226 // The patched back edge looks like this:
227 //
228 // sub <profiling_counter>, <delta> ;; Not changed
229 // nop
230 // nop
231 // call <on-stack replacment>
232 // ok:
219 233
220 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, 234 void Deoptimizer::PatchInterruptCodeAt(Code* unoptimized_code,
221 Address pc_after, 235 Address pc_after,
222 Code* check_code, 236 Code* interrupt_code,
223 Code* replacement_code) { 237 Code* replacement_code) {
238 ASSERT(!InterruptCodeIsPatched(unoptimized_code,
239 pc_after,
240 interrupt_code,
241 replacement_code));
242 // Turn the jump into nops.
224 Address call_target_address = pc_after - kIntSize; 243 Address call_target_address = pc_after - kIntSize;
225 ASSERT_EQ(check_code->entry(),
226 Assembler::target_address_at(call_target_address));
227 // The back edge bookkeeping code matches the pattern:
228 //
229 // sub <profiling_counter>, <delta>
230 // jns ok
231 // call <stack guard>
232 // test eax, <loop nesting depth>
233 // ok: ...
234 //
235 // We will patch away the branch so the code is:
236 //
237 // sub <profiling_counter>, <delta> ;; Not changed
238 // nop
239 // nop
240 // call <on-stack replacment>
241 // test eax, <loop nesting depth>
242 // ok:
243
244 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3));
245 ASSERT_EQ(kJnsOffset, *(call_target_address - 2));
246 ASSERT_EQ(kCallInstruction, *(call_target_address - 1));
247 *(call_target_address - 3) = kNopByteOne; 244 *(call_target_address - 3) = kNopByteOne;
248 *(call_target_address - 2) = kNopByteTwo; 245 *(call_target_address - 2) = kNopByteTwo;
246 // Replace the call address.
249 Assembler::set_target_address_at(call_target_address, 247 Assembler::set_target_address_at(call_target_address,
250 replacement_code->entry()); 248 replacement_code->entry());
251 249
252 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( 250 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
253 unoptimized_code, call_target_address, replacement_code); 251 unoptimized_code, call_target_address, replacement_code);
254 } 252 }
255 253
256 254
257 void Deoptimizer::RevertStackCheckCodeAt(Code* unoptimized_code, 255 void Deoptimizer::RevertInterruptCodeAt(Code* unoptimized_code,
258 Address pc_after, 256 Address pc_after,
259 Code* check_code, 257 Code* interrupt_code,
260 Code* replacement_code) { 258 Code* replacement_code) {
259 ASSERT(InterruptCodeIsPatched(unoptimized_code,
260 pc_after,
261 interrupt_code,
262 replacement_code));
263 // Restore the original jump.
261 Address call_target_address = pc_after - kIntSize; 264 Address call_target_address = pc_after - kIntSize;
262 ASSERT_EQ(replacement_code->entry(),
263 Assembler::target_address_at(call_target_address));
264
265 // Replace the nops from patching (Deoptimizer::PatchStackCheckCode) to
266 // restore the conditional branch.
267 ASSERT_EQ(kNopByteOne, *(call_target_address - 3));
268 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2));
269 ASSERT_EQ(kCallInstruction, *(call_target_address - 1));
270 *(call_target_address - 3) = kJnsInstruction; 265 *(call_target_address - 3) = kJnsInstruction;
271 *(call_target_address - 2) = kJnsOffset; 266 *(call_target_address - 2) = kJnsOffset;
267 // Restore the original call address.
272 Assembler::set_target_address_at(call_target_address, 268 Assembler::set_target_address_at(call_target_address,
273 check_code->entry()); 269 interrupt_code->entry());
274 270
275 check_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( 271 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
276 unoptimized_code, call_target_address, check_code); 272 unoptimized_code, call_target_address, interrupt_code);
277 } 273 }
278 274
279 275
276 #ifdef DEBUG
277 bool Deoptimizer::InterruptCodeIsPatched(Code* unoptimized_code,
278 Address pc_after,
279 Code* interrupt_code,
280 Code* replacement_code) {
281 Address call_target_address = pc_after - kIntSize;
282 ASSERT_EQ(kCallInstruction, *(call_target_address - 1));
283 if (*(call_target_address - 3) == kNopByteOne) {
284 ASSERT_EQ(replacement_code->entry(),
285 Assembler::target_address_at(call_target_address));
286 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2));
287 return true;
288 } else {
289 ASSERT_EQ(interrupt_code->entry(),
290 Assembler::target_address_at(call_target_address));
291 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3));
292 ASSERT_EQ(kJnsOffset, *(call_target_address - 2));
293 return false;
294 }
295 }
296 #endif // DEBUG
297
298
280 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { 299 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) {
281 ByteArray* translations = data->TranslationByteArray(); 300 ByteArray* translations = data->TranslationByteArray();
282 int length = data->DeoptCount(); 301 int length = data->DeoptCount();
283 for (int i = 0; i < length; i++) { 302 for (int i = 0; i < length; i++) {
284 if (data->AstId(i) == ast_id) { 303 if (data->AstId(i) == ast_id) {
285 TranslationIterator it(translations, data->TranslationIndex(i)->value()); 304 TranslationIterator it(translations, data->TranslationIndex(i)->value());
286 int value = it.Next(); 305 int value = it.Next();
287 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); 306 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value));
288 // Read the number of frames. 307 // Read the number of frames.
289 value = it.Next(); 308 value = it.Next();
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 } 922 }
904 __ bind(&done); 923 __ bind(&done);
905 } 924 }
906 925
907 #undef __ 926 #undef __
908 927
909 928
910 } } // namespace v8::internal 929 } } // namespace v8::internal
911 930
912 #endif // V8_TARGET_ARCH_IA32 931 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/builtins-ia32.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698