Chromium Code Reviews| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // | |
| 225 // The patched back edge looks like this: | |
| 226 // | |
| 227 // sub <profiling_counter>, <delta> ;; Not changed | |
| 228 // nop | |
| 229 // nop | |
| 230 // call <on-stack replacment> | |
| 219 | 231 |
| 220 void Deoptimizer::PatchStackCheckCodeAt(Code* unoptimized_code, | 232 void Deoptimizer::PatchInterruptCodeAt(Code* unoptimized_code, |
| 221 Address pc_after, | 233 Address pc_after, |
| 222 Code* check_code, | 234 Code* interrupt_code, |
| 223 Code* replacement_code) { | 235 Code* replacement_code) { |
| 236 ASSERT(!InterruptCodeIsPatched(unoptimized_code, | |
| 237 pc_after, | |
| 238 interrupt_code, | |
| 239 replacement_code)); | |
| 240 // Turn the jump into nops. | |
| 224 Address call_target_address = pc_after - kIntSize; | 241 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: ... | |
|
Jakob Kummerow
2013/04/09 17:23:25
This label got lost when you moved the comment. Pl
Yang
2013/04/10 08:08:30
Done.
| |
| 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)); | |
|
Jakob Kummerow
2013/04/09 17:23:25
I have to say that I preferred this version of the
Yang
2013/04/10 08:08:30
As discussed offline, this was refactored to be re
| |
| 245 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); | |
| 246 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | |
| 247 *(call_target_address - 3) = kNopByteOne; | 242 *(call_target_address - 3) = kNopByteOne; |
| 248 *(call_target_address - 2) = kNopByteTwo; | 243 *(call_target_address - 2) = kNopByteTwo; |
| 244 // Replace the call address. | |
| 249 Assembler::set_target_address_at(call_target_address, | 245 Assembler::set_target_address_at(call_target_address, |
| 250 replacement_code->entry()); | 246 replacement_code->entry()); |
| 251 | 247 |
| 252 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 248 unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 253 unoptimized_code, call_target_address, replacement_code); | 249 unoptimized_code, call_target_address, replacement_code); |
| 254 } | 250 } |
| 255 | 251 |
| 256 | 252 |
| 257 void Deoptimizer::RevertStackCheckCodeAt(Code* unoptimized_code, | 253 void Deoptimizer::RevertInterruptCodeAt(Code* unoptimized_code, |
| 258 Address pc_after, | 254 Address pc_after, |
| 259 Code* check_code, | 255 Code* interrupt_code, |
| 260 Code* replacement_code) { | 256 Code* replacement_code) { |
| 257 ASSERT(InterruptCodeIsPatched(unoptimized_code, | |
| 258 pc_after, | |
| 259 interrupt_code, | |
| 260 replacement_code)); | |
| 261 // Restore the original jump. | |
| 261 Address call_target_address = pc_after - kIntSize; | 262 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; | 263 *(call_target_address - 3) = kJnsInstruction; |
| 271 *(call_target_address - 2) = kJnsOffset; | 264 *(call_target_address - 2) = kJnsOffset; |
| 265 // Restore the original call address. | |
| 272 Assembler::set_target_address_at(call_target_address, | 266 Assembler::set_target_address_at(call_target_address, |
| 273 check_code->entry()); | 267 interrupt_code->entry()); |
| 274 | 268 |
| 275 check_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( | 269 interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 276 unoptimized_code, call_target_address, check_code); | 270 unoptimized_code, call_target_address, interrupt_code); |
| 277 } | 271 } |
| 278 | 272 |
| 279 | 273 |
| 274 #ifdef DEBUG | |
| 275 bool Deoptimizer::InterruptCodeIsPatched(Code* unoptimized_code, | |
| 276 Address pc_after, | |
| 277 Code* interrupt_code, | |
| 278 Code* replacement_code) { | |
| 279 Address call_target_address = pc_after - kIntSize; | |
| 280 ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); | |
| 281 if (*(call_target_address - 3) == kNopByteOne) { | |
| 282 ASSERT_EQ(replacement_code->entry(), | |
| 283 Assembler::target_address_at(call_target_address)); | |
| 284 ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); | |
| 285 return true; | |
| 286 } else { | |
| 287 ASSERT_EQ(interrupt_code->entry(), | |
| 288 Assembler::target_address_at(call_target_address)); | |
| 289 ASSERT_EQ(kJnsInstruction, *(call_target_address - 3)); | |
| 290 ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); | |
| 291 return false; | |
| 292 } | |
| 293 } | |
| 294 #endif // DEBUG | |
| 295 | |
| 296 | |
| 280 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { | 297 static int LookupBailoutId(DeoptimizationInputData* data, BailoutId ast_id) { |
| 281 ByteArray* translations = data->TranslationByteArray(); | 298 ByteArray* translations = data->TranslationByteArray(); |
| 282 int length = data->DeoptCount(); | 299 int length = data->DeoptCount(); |
| 283 for (int i = 0; i < length; i++) { | 300 for (int i = 0; i < length; i++) { |
| 284 if (data->AstId(i) == ast_id) { | 301 if (data->AstId(i) == ast_id) { |
| 285 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | 302 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
| 286 int value = it.Next(); | 303 int value = it.Next(); |
| 287 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); | 304 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); |
| 288 // Read the number of frames. | 305 // Read the number of frames. |
| 289 value = it.Next(); | 306 value = it.Next(); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 903 } | 920 } |
| 904 __ bind(&done); | 921 __ bind(&done); |
| 905 } | 922 } |
| 906 | 923 |
| 907 #undef __ | 924 #undef __ |
| 908 | 925 |
| 909 | 926 |
| 910 } } // namespace v8::internal | 927 } } // namespace v8::internal |
| 911 | 928 |
| 912 #endif // V8_TARGET_ARCH_IA32 | 929 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |