Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 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 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 void Deoptimizer::RevertStackCheckCodeAt(Address pc_after, | 131 void Deoptimizer::RevertStackCheckCodeAt(Address pc_after, |
| 132 Code* check_code, | 132 Code* check_code, |
| 133 Code* replacement_code) { | 133 Code* replacement_code) { |
| 134 UNIMPLEMENTED(); | 134 UNIMPLEMENTED(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { | |
| 139 ByteArray* translations = data->TranslationByteArray(); | |
| 140 int length = data->DeoptCount(); | |
| 141 for (int i = 0; i < length; i++) { | |
| 142 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { | |
| 143 TranslationIterator it(translations, data->TranslationIndex(i)->value()); | |
| 144 int value = it.Next(); | |
| 145 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); | |
| 146 // Read the number of frames. | |
| 147 value = it.Next(); | |
| 148 if (value == 1) return i; | |
| 149 } | |
| 150 } | |
| 151 UNREACHABLE(); | |
| 152 return -1; | |
| 153 } | |
| 154 | |
| 155 | |
| 138 void Deoptimizer::DoComputeOsrOutputFrame() { | 156 void Deoptimizer::DoComputeOsrOutputFrame() { |
| 139 UNIMPLEMENTED(); | 157 DeoptimizationInputData* data = DeoptimizationInputData::cast( |
| 158 optimized_code_->deoptimization_data()); | |
| 159 unsigned ast_id = data->OsrAstId()->value(); | |
| 160 | |
| 161 int bailout_id = LookupBailoutId(data, ast_id); | |
| 162 unsigned translation_index = data->TranslationIndex(bailout_id)->value(); | |
| 163 ByteArray* translations = data->TranslationByteArray(); | |
| 164 | |
| 165 TranslationIterator iterator(translations, translation_index); | |
| 166 Translation::Opcode opcode = | |
| 167 static_cast<Translation::Opcode>(iterator.Next()); | |
| 168 ASSERT(Translation::BEGIN == opcode); | |
| 169 USE(opcode); | |
| 170 int count = iterator.Next(); | |
|
Søren Thygesen Gjesse
2011/02/09 15:12:55
count -> frame_count for clarity?
| |
| 171 ASSERT(count == 1); | |
| 172 USE(count); | |
| 173 | |
| 174 opcode = static_cast<Translation::Opcode>(iterator.Next()); | |
| 175 USE(opcode); | |
| 176 ASSERT(Translation::FRAME == opcode); | |
| 177 unsigned node_id = iterator.Next(); | |
| 178 USE(node_id); | |
| 179 ASSERT(node_id == ast_id); | |
| 180 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator.Next())); | |
| 181 USE(function); | |
| 182 ASSERT(function == function_); | |
| 183 unsigned height = iterator.Next(); | |
| 184 unsigned height_in_bytes = height * kPointerSize; | |
| 185 USE(height_in_bytes); | |
| 186 | |
| 187 unsigned fixed_size = ComputeFixedSize(function_); | |
| 188 unsigned input_frame_size = input_->GetFrameSize(); | |
| 189 ASSERT(fixed_size + height_in_bytes == input_frame_size); | |
| 190 | |
| 191 unsigned stack_slot_size = optimized_code_->stack_slots() * kPointerSize; | |
| 192 unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value(); | |
| 193 unsigned outgoing_size = outgoing_height * kPointerSize; | |
| 194 unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size; | |
| 195 ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call. | |
| 196 | |
| 197 if (FLAG_trace_osr) { | |
| 198 PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ", | |
| 199 reinterpret_cast<intptr_t>(function_)); | |
| 200 function_->PrintName(); | |
| 201 PrintF(" => node=%u, frame=%d->%d]\n", | |
| 202 ast_id, | |
| 203 input_frame_size, | |
| 204 output_frame_size); | |
| 205 } | |
| 206 | |
| 207 // There's only one output frame in the OSR case. | |
| 208 output_count_ = 1; | |
| 209 output_ = new FrameDescription*[1]; | |
| 210 output_[0] = new(output_frame_size) FrameDescription( | |
| 211 output_frame_size, function_); | |
| 212 | |
| 213 // Clear the incoming parameters in the optimized frame to avoid | |
| 214 // confusing the garbage collector. | |
| 215 unsigned output_offset = output_frame_size - kPointerSize; | |
| 216 int parameter_count = function_->shared()->formal_parameter_count() + 1; | |
| 217 for (int i = 0; i < parameter_count; ++i) { | |
| 218 output_[0]->SetFrameSlot(output_offset, 0); | |
| 219 output_offset -= kPointerSize; | |
| 220 } | |
| 221 | |
| 222 // Translate the incoming parameters. This may overwrite some of the | |
| 223 // incoming argument slots we've just cleared. | |
| 224 int input_offset = input_frame_size - kPointerSize; | |
| 225 bool ok = true; | |
| 226 int limit = input_offset - (parameter_count * kPointerSize); | |
| 227 while (ok && input_offset > limit) { | |
| 228 ok = DoOsrTranslateCommand(&iterator, &input_offset); | |
| 229 } | |
| 230 | |
| 231 // There are no translation commands for the caller's pc and fp, the | |
| 232 // context, and the function. Set them up explicitly. | |
| 233 for (int i = 0; ok && i < 4; i++) { | |
| 234 uint32_t input_value = input_->GetFrameSlot(input_offset); | |
| 235 if (FLAG_trace_osr) { | |
| 236 PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part)\n", | |
| 237 output_offset, | |
| 238 input_value, | |
| 239 input_offset); | |
| 240 } | |
| 241 output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset)); | |
| 242 input_offset -= kPointerSize; | |
| 243 output_offset -= kPointerSize; | |
| 244 } | |
| 245 | |
| 246 // Translate the rest of the frame. | |
| 247 while (ok && input_offset >= 0) { | |
| 248 ok = DoOsrTranslateCommand(&iterator, &input_offset); | |
| 249 } | |
| 250 | |
| 251 // If translation of any command failed, continue using the input frame. | |
| 252 if (!ok) { | |
| 253 delete output_[0]; | |
| 254 output_[0] = input_; | |
| 255 output_[0]->SetPc(reinterpret_cast<uint32_t>(from_)); | |
| 256 } else { | |
| 257 // Setup the frame pointer and the context pointer. | |
| 258 output_[0]->SetRegister(fp.code(), input_->GetRegister(fp.code())); | |
| 259 output_[0]->SetRegister(cp.code(), input_->GetRegister(cp.code())); | |
| 260 | |
| 261 unsigned pc_offset = data->OsrPcOffset()->value(); | |
| 262 uint32_t pc = reinterpret_cast<uint32_t>( | |
| 263 optimized_code_->entry() + pc_offset); | |
| 264 output_[0]->SetPc(pc); | |
| 265 } | |
| 266 Code* continuation = Builtins::builtin(Builtins::NotifyOSR); | |
| 267 output_[0]->SetContinuation( | |
| 268 reinterpret_cast<uint32_t>(continuation->entry())); | |
| 269 | |
| 270 if (FLAG_trace_osr) { | |
| 271 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", | |
| 272 ok ? "finished" : "aborted", | |
| 273 reinterpret_cast<intptr_t>(function)); | |
| 274 function->PrintName(); | |
| 275 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); | |
| 276 } | |
| 140 } | 277 } |
| 141 | 278 |
| 142 | 279 |
| 143 // This code is very similar to ia32 code, but relies on register names (fp, sp) | 280 // This code is very similar to ia32 code, but relies on register names (fp, sp) |
| 144 // and how the frame is laid out. | 281 // and how the frame is laid out. |
| 145 void Deoptimizer::DoComputeFrame(TranslationIterator* iterator, | 282 void Deoptimizer::DoComputeFrame(TranslationIterator* iterator, |
| 146 int frame_index) { | 283 int frame_index) { |
| 147 // Read the ast node id, function, and frame height for this output frame. | 284 // Read the ast node id, function, and frame height for this output frame. |
| 148 Translation::Opcode opcode = | 285 Translation::Opcode opcode = |
| 149 static_cast<Translation::Opcode>(iterator->Next()); | 286 static_cast<Translation::Opcode>(iterator->Next()); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 } | 448 } |
| 312 | 449 |
| 313 | 450 |
| 314 #define __ masm()-> | 451 #define __ masm()-> |
| 315 | 452 |
| 316 | 453 |
| 317 // This code tries to be close to ia32 code so that any changes can be | 454 // This code tries to be close to ia32 code so that any changes can be |
| 318 // easily ported. | 455 // easily ported. |
| 319 void Deoptimizer::EntryGenerator::Generate() { | 456 void Deoptimizer::EntryGenerator::Generate() { |
| 320 GeneratePrologue(); | 457 GeneratePrologue(); |
| 321 // TOS: bailout-id; TOS+1: return address if not EAGER. | |
| 322 CpuFeatures::Scope scope(VFP3); | 458 CpuFeatures::Scope scope(VFP3); |
| 323 // Save all general purpose registers before messing with them. | 459 // Save all general purpose registers before messing with them. |
| 324 const int kNumberOfRegisters = Register::kNumRegisters; | 460 const int kNumberOfRegisters = Register::kNumRegisters; |
| 325 | 461 |
| 326 // Everything but pc, lr and ip which will be saved but not restored. | 462 // Everything but pc, lr and ip which will be saved but not restored. |
| 327 RegList restored_regs = kJSCallerSaved | kCalleeSaved | ip.bit(); | 463 RegList restored_regs = kJSCallerSaved | kCalleeSaved | ip.bit(); |
| 328 | 464 |
| 329 const int kDoubleRegsSize = | 465 const int kDoubleRegsSize = |
| 330 kDoubleSize * DwVfpRegister::kNumAllocatableRegisters; | 466 kDoubleSize * DwVfpRegister::kNumAllocatableRegisters; |
| 331 | 467 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 346 // Get the bailout id from the stack. | 482 // Get the bailout id from the stack. |
| 347 __ ldr(r2, MemOperand(sp, kSavedRegistersAreaSize)); | 483 __ ldr(r2, MemOperand(sp, kSavedRegistersAreaSize)); |
| 348 | 484 |
| 349 // Get the address of the location in the code object if possible (r3) (return | 485 // Get the address of the location in the code object if possible (r3) (return |
| 350 // address for lazy deoptimization) and compute the fp-to-sp delta in | 486 // address for lazy deoptimization) and compute the fp-to-sp delta in |
| 351 // register r4. | 487 // register r4. |
| 352 if (type() == EAGER) { | 488 if (type() == EAGER) { |
| 353 __ mov(r3, Operand(0)); | 489 __ mov(r3, Operand(0)); |
| 354 // Correct one word for bailout id. | 490 // Correct one word for bailout id. |
| 355 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); | 491 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
| 492 } else if (type() == OSR) { | |
| 493 __ mov(r3, lr); | |
| 494 // Correct one word for bailout id. | |
| 495 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); | |
| 356 } else { | 496 } else { |
| 357 __ mov(r3, lr); | 497 __ mov(r3, lr); |
| 358 // Correct two words for bailout id and return address. | 498 // Correct two words for bailout id and return address. |
|
Søren Thygesen Gjesse
2011/02/09 15:12:55
Looking at TableEntryGenerator::GeneratePrologue d
| |
| 359 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); | 499 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); |
| 360 } | 500 } |
| 361 __ sub(r4, fp, r4); | 501 __ sub(r4, fp, r4); |
| 362 | 502 |
| 363 // Allocate a new deoptimizer object. | 503 // Allocate a new deoptimizer object. |
| 364 // Pass four arguments in r0 to r3 and fifth argument on stack. | 504 // Pass four arguments in r0 to r3 and fifth argument on stack. |
| 365 __ PrepareCallCFunction(5, r5); | 505 __ PrepareCallCFunction(5, r5); |
| 366 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 506 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 367 __ mov(r1, Operand(type())); // bailout type, | 507 __ mov(r1, Operand(type())); // bailout type, |
| 368 // r2: bailout id already loaded. | 508 // r2: bailout id already loaded. |
| 369 // r3: code address or 0 already loaded. | 509 // r3: code address or 0 already loaded. |
| 370 __ str(r4, MemOperand(sp, 0 * kPointerSize)); // Fp-to-sp delta. | 510 __ str(r4, MemOperand(sp, 0 * kPointerSize)); // Fp-to-sp delta. |
| 371 // Call Deoptimizer::New(). | 511 // Call Deoptimizer::New(). |
| 372 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5); | 512 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5); |
| 373 | 513 |
| 374 // Preserve "deoptimizer" object in register r0 and get the input | 514 // Preserve "deoptimizer" object in register r0 and get the input |
| 375 // frame descriptor pointer to r1 (deoptimizer->input_); | 515 // frame descriptor pointer to r1 (deoptimizer->input_); |
| 376 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset())); | 516 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset())); |
| 377 | 517 |
| 378 | |
| 379 // Copy core registers into FrameDescription::registers_[kNumRegisters]. | 518 // Copy core registers into FrameDescription::registers_[kNumRegisters]. |
| 380 ASSERT(Register::kNumRegisters == kNumberOfRegisters); | 519 ASSERT(Register::kNumRegisters == kNumberOfRegisters); |
| 381 for (int i = 0; i < kNumberOfRegisters; i++) { | 520 for (int i = 0; i < kNumberOfRegisters; i++) { |
| 382 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); | 521 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 383 __ ldr(r2, MemOperand(sp, i * kPointerSize)); | 522 __ ldr(r2, MemOperand(sp, i * kPointerSize)); |
| 384 __ str(r2, MemOperand(r1, offset)); | 523 __ str(r2, MemOperand(r1, offset)); |
| 385 } | 524 } |
| 386 | 525 |
| 387 // Copy VFP registers to | 526 // Copy VFP registers to |
| 388 // double_registers_[DoubleRegister::kNumAllocatableRegisters] | 527 // double_registers_[DoubleRegister::kNumAllocatableRegisters] |
| 389 int double_regs_offset = FrameDescription::double_registers_offset(); | 528 int double_regs_offset = FrameDescription::double_registers_offset(); |
| 390 for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; ++i) { | 529 for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; ++i) { |
| 391 int dst_offset = i * kDoubleSize + double_regs_offset; | 530 int dst_offset = i * kDoubleSize + double_regs_offset; |
| 392 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; | 531 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; |
| 393 __ vldr(d0, sp, src_offset); | 532 __ vldr(d0, sp, src_offset); |
| 394 __ vstr(d0, r1, dst_offset); | 533 __ vstr(d0, r1, dst_offset); |
| 395 } | 534 } |
| 396 | 535 |
| 397 // Remove the bailout id, eventually return address, and the saved registers | 536 // Remove the bailout id, eventually return address, and the saved registers |
| 398 // from the stack. | 537 // from the stack. |
| 399 if (type() == EAGER) { | 538 if (type() == EAGER || type() == OSR) { |
| 400 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); | 539 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
| 401 } else { | 540 } else { |
| 402 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); | 541 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); |
| 403 } | 542 } |
| 404 | 543 |
| 405 // Compute a pointer to the unwinding limit in register r2; that is | 544 // Compute a pointer to the unwinding limit in register r2; that is |
| 406 // the first stack slot not part of the input frame. | 545 // the first stack slot not part of the input frame. |
| 407 __ ldr(r2, MemOperand(r1, FrameDescription::frame_size_offset())); | 546 __ ldr(r2, MemOperand(r1, FrameDescription::frame_size_offset())); |
| 408 __ add(r2, r2, sp); | 547 __ add(r2, r2, sp); |
| 409 | 548 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 // __ add(r6, r2, Operand(r3, LSL, 1)); | 582 // __ add(r6, r2, Operand(r3, LSL, 1)); |
| 444 __ add(r6, r2, Operand(r3)); | 583 __ add(r6, r2, Operand(r3)); |
| 445 __ ldr(r7, MemOperand(r6, FrameDescription::frame_content_offset())); | 584 __ ldr(r7, MemOperand(r6, FrameDescription::frame_content_offset())); |
| 446 __ push(r7); | 585 __ push(r7); |
| 447 __ cmp(r3, Operand(0)); | 586 __ cmp(r3, Operand(0)); |
| 448 __ b(ne, &inner_push_loop); // test for gt? | 587 __ b(ne, &inner_push_loop); // test for gt? |
| 449 __ add(r0, r0, Operand(kPointerSize)); | 588 __ add(r0, r0, Operand(kPointerSize)); |
| 450 __ cmp(r0, r1); | 589 __ cmp(r0, r1); |
| 451 __ b(lt, &outer_push_loop); | 590 __ b(lt, &outer_push_loop); |
| 452 | 591 |
| 453 // In case of OSR, we have to restore the XMM registers. | |
| 454 if (type() == OSR) { | |
| 455 UNIMPLEMENTED(); | |
| 456 } | |
| 457 | |
| 458 // Push state, pc, and continuation from the last output frame. | 592 // Push state, pc, and continuation from the last output frame. |
| 459 if (type() != OSR) { | 593 if (type() != OSR) { |
| 460 __ ldr(r6, MemOperand(r2, FrameDescription::state_offset())); | 594 __ ldr(r6, MemOperand(r2, FrameDescription::state_offset())); |
| 461 __ push(r6); | 595 __ push(r6); |
| 462 } | 596 } |
| 463 | 597 |
| 464 __ ldr(r6, MemOperand(r2, FrameDescription::pc_offset())); | 598 __ ldr(r6, MemOperand(r2, FrameDescription::pc_offset())); |
| 465 __ push(r6); | 599 __ push(r6); |
| 466 __ ldr(r6, MemOperand(r2, FrameDescription::continuation_offset())); | 600 __ ldr(r6, MemOperand(r2, FrameDescription::continuation_offset())); |
| 467 __ push(r6); | 601 __ push(r6); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 __ push(ip); | 641 __ push(ip); |
| 508 __ b(&done); | 642 __ b(&done); |
| 509 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 643 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
| 510 } | 644 } |
| 511 __ bind(&done); | 645 __ bind(&done); |
| 512 } | 646 } |
| 513 | 647 |
| 514 #undef __ | 648 #undef __ |
| 515 | 649 |
| 516 } } // namespace v8::internal | 650 } } // namespace v8::internal |
| OLD | NEW |