| OLD | NEW |
| 1 // Copyright 2010 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 30 #include "codegen.h" | 30 #include "codegen.h" |
| 31 #include "deoptimizer.h" | 31 #include "deoptimizer.h" |
| 32 #include "full-codegen.h" | 32 #include "full-codegen.h" |
| 33 #include "safepoint-table.h" | 33 #include "safepoint-table.h" |
| 34 | 34 |
| 35 namespace v8 { | 35 namespace v8 { |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 int Deoptimizer::table_entry_size_ = 16; | 38 int Deoptimizer::table_entry_size_ = 16; |
| 39 | 39 |
| 40 |
| 41 int Deoptimizer::patch_size() { |
| 42 const int kCallInstructionSizeInWords = 3; |
| 43 return kCallInstructionSizeInWords * Assembler::kInstrSize; |
| 44 } |
| 45 |
| 46 |
| 47 |
| 40 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { | 48 void Deoptimizer::DeoptimizeFunction(JSFunction* function) { |
| 41 AssertNoAllocation no_allocation; | 49 AssertNoAllocation no_allocation; |
| 42 | 50 |
| 43 if (!function->IsOptimized()) return; | 51 if (!function->IsOptimized()) return; |
| 44 | 52 |
| 45 // Get the optimized code. | 53 // Get the optimized code. |
| 46 Code* code = function->code(); | 54 Code* code = function->code(); |
| 47 | 55 |
| 48 // Invalidate the relocation information, as it will become invalid by the | 56 // Invalidate the relocation information, as it will become invalid by the |
| 49 // code patching below, and is not needed any more. | 57 // code patching below, and is not needed any more. |
| 50 code->InvalidateRelocation(); | 58 code->InvalidateRelocation(); |
| 51 | 59 |
| 52 // For each return after a safepoint insert an absolute call to the | 60 // For each return after a safepoint insert an absolute call to the |
| 53 // corresponding deoptimization entry. | 61 // corresponding deoptimization entry. |
| 62 ASSERT(patch_size() % Assembler::kInstrSize == 0); |
| 63 int call_size_in_words = patch_size() / Assembler::kInstrSize; |
| 54 unsigned last_pc_offset = 0; | 64 unsigned last_pc_offset = 0; |
| 55 SafepointTable table(function->code()); | 65 SafepointTable table(function->code()); |
| 56 for (unsigned i = 0; i < table.length(); i++) { | 66 for (unsigned i = 0; i < table.length(); i++) { |
| 57 unsigned pc_offset = table.GetPcOffset(i); | 67 unsigned pc_offset = table.GetPcOffset(i); |
| 58 int deoptimization_index = table.GetDeoptimizationIndex(i); | 68 SafepointEntry safepoint_entry = table.GetEntry(i); |
| 59 int gap_code_size = table.GetGapCodeSize(i); | 69 int deoptimization_index = safepoint_entry.deoptimization_index(); |
| 70 int gap_code_size = safepoint_entry.gap_code_size(); |
| 60 // Check that we did not shoot past next safepoint. | 71 // Check that we did not shoot past next safepoint. |
| 61 // TODO(srdjan): How do we guarantee that safepoint code does not | 72 // TODO(srdjan): How do we guarantee that safepoint code does not |
| 62 // overlap other safepoint patching code? | 73 // overlap other safepoint patching code? |
| 63 CHECK(pc_offset >= last_pc_offset); | 74 CHECK(pc_offset >= last_pc_offset); |
| 64 #ifdef DEBUG | 75 #ifdef DEBUG |
| 65 // Destroy the code which is not supposed to be run again. | 76 // Destroy the code which is not supposed to be run again. |
| 66 int instructions = (pc_offset - last_pc_offset) / Assembler::kInstrSize; | 77 int instructions = (pc_offset - last_pc_offset) / Assembler::kInstrSize; |
| 67 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 78 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
| 68 instructions); | 79 instructions); |
| 69 for (int x = 0; x < instructions; x++) { | 80 for (int x = 0; x < instructions; x++) { |
| 70 destroyer.masm()->bkpt(0); | 81 destroyer.masm()->bkpt(0); |
| 71 } | 82 } |
| 72 #endif | 83 #endif |
| 73 last_pc_offset = pc_offset; | 84 last_pc_offset = pc_offset; |
| 74 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { | 85 if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) { |
| 75 const int kCallInstructionSizeInWords = 3; | 86 last_pc_offset += gap_code_size; |
| 76 CodePatcher patcher(code->instruction_start() + pc_offset + gap_code_size, | 87 CodePatcher patcher(code->instruction_start() + last_pc_offset, |
| 77 kCallInstructionSizeInWords); | 88 call_size_in_words); |
| 78 Address deoptimization_entry = Deoptimizer::GetDeoptimizationEntry( | 89 Address deoptimization_entry = Deoptimizer::GetDeoptimizationEntry( |
| 79 deoptimization_index, Deoptimizer::LAZY); | 90 deoptimization_index, Deoptimizer::LAZY); |
| 80 patcher.masm()->Call(deoptimization_entry, RelocInfo::NONE); | 91 patcher.masm()->Call(deoptimization_entry, RelocInfo::NONE); |
| 81 last_pc_offset += | 92 last_pc_offset += patch_size(); |
| 82 gap_code_size + kCallInstructionSizeInWords * Assembler::kInstrSize; | |
| 83 } | 93 } |
| 84 } | 94 } |
| 85 | 95 |
| 86 | 96 |
| 87 #ifdef DEBUG | 97 #ifdef DEBUG |
| 88 // Destroy the code which is not supposed to be run again. | 98 // Destroy the code which is not supposed to be run again. |
| 89 int instructions = | 99 int instructions = |
| 90 (code->safepoint_table_start() - last_pc_offset) / Assembler::kInstrSize; | 100 (code->safepoint_table_offset() - last_pc_offset) / Assembler::kInstrSize; |
| 91 CodePatcher destroyer(code->instruction_start() + last_pc_offset, | 101 CodePatcher destroyer(code->instruction_start() + last_pc_offset, |
| 92 instructions); | 102 instructions); |
| 93 for (int x = 0; x < instructions; x++) { | 103 for (int x = 0; x < instructions; x++) { |
| 94 destroyer.masm()->bkpt(0); | 104 destroyer.masm()->bkpt(0); |
| 95 } | 105 } |
| 96 #endif | 106 #endif |
| 97 | 107 |
| 98 // Add the deoptimizing code to the list. | 108 // Add the deoptimizing code to the list. |
| 99 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code); | 109 DeoptimizingCodeListNode* node = new DeoptimizingCodeListNode(code); |
| 100 node->set_next(deoptimizing_code_list_); | 110 node->set_next(deoptimizing_code_list_); |
| 101 deoptimizing_code_list_ = node; | 111 deoptimizing_code_list_ = node; |
| 102 | 112 |
| 103 // Set the code for the function to non-optimized version. | 113 // Set the code for the function to non-optimized version. |
| 104 function->ReplaceCode(function->shared()->code()); | 114 function->ReplaceCode(function->shared()->code()); |
| 105 | 115 |
| 106 if (FLAG_trace_deopt) { | 116 if (FLAG_trace_deopt) { |
| 107 PrintF("[forced deoptimization: "); | 117 PrintF("[forced deoptimization: "); |
| 108 function->PrintName(); | 118 function->PrintName(); |
| 109 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); | 119 PrintF(" / %x]\n", reinterpret_cast<uint32_t>(function)); |
| 110 } | 120 } |
| 111 } | 121 } |
| 112 | 122 |
| 113 | 123 |
| 114 void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo, | 124 void Deoptimizer::PatchStackCheckCodeAt(Address pc_after, |
| 115 Code* replacement_code) { | 125 Code* check_code, |
| 116 UNIMPLEMENTED(); | 126 Code* replacement_code) { |
| 117 } | 127 const int kInstrSize = Assembler::kInstrSize; |
| 118 | 128 // The call of the stack guard check has the following form: |
| 119 | 129 // e1 5d 00 0c cmp sp, <limit> |
| 120 void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) { | 130 // 2a 00 00 01 bcs ok |
| 121 UNIMPLEMENTED(); | 131 // e5 9f c? ?? ldr ip, [pc, <stack guard address>] |
| 132 // e1 2f ff 3c blx ip |
| 133 ASSERT(Memory::int32_at(pc_after - kInstrSize) == |
| 134 (al | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | BLX | ip.code())); |
| 135 ASSERT(Assembler::IsLdrPcImmediateOffset( |
| 136 Assembler::instr_at(pc_after - 2 * kInstrSize))); |
| 137 |
| 138 // We patch the code to the following form: |
| 139 // e1 5d 00 0c cmp sp, <limit> |
| 140 // e1 a0 00 00 mov r0, r0 (NOP) |
| 141 // e5 9f c? ?? ldr ip, [pc, <on-stack replacement address>] |
| 142 // e1 2f ff 3c blx ip |
| 143 // and overwrite the constant containing the |
| 144 // address of the stack check stub. |
| 145 |
| 146 // Replace conditional jump with NOP. |
| 147 CodePatcher patcher(pc_after - 3 * kInstrSize, 1); |
| 148 patcher.masm()->nop(); |
| 149 |
| 150 // Replace the stack check address in the constant pool |
| 151 // with the entry address of the replacement code. |
| 152 uint32_t stack_check_address_offset = Memory::uint16_at(pc_after - |
| 153 2 * kInstrSize) & 0xfff; |
| 154 Address stack_check_address_pointer = pc_after + stack_check_address_offset; |
| 155 ASSERT(Memory::uint32_at(stack_check_address_pointer) == |
| 156 reinterpret_cast<uint32_t>(check_code->entry())); |
| 157 Memory::uint32_at(stack_check_address_pointer) = |
| 158 reinterpret_cast<uint32_t>(replacement_code->entry()); |
| 159 } |
| 160 |
| 161 |
| 162 void Deoptimizer::RevertStackCheckCodeAt(Address pc_after, |
| 163 Code* check_code, |
| 164 Code* replacement_code) { |
| 165 const int kInstrSize = Assembler::kInstrSize; |
| 166 ASSERT(Memory::uint32_at(pc_after - kInstrSize) == 0xe12fff3c); |
| 167 ASSERT(Memory::uint8_at(pc_after - kInstrSize - 1) == 0xe5); |
| 168 ASSERT(Memory::uint8_at(pc_after - kInstrSize - 2) == 0x9f); |
| 169 |
| 170 // Replace NOP with conditional jump. |
| 171 CodePatcher patcher(pc_after - 3 * kInstrSize, 1); |
| 172 patcher.masm()->b(+4, cs); |
| 173 |
| 174 // Replace the stack check address in the constant pool |
| 175 // with the entry address of the replacement code. |
| 176 uint32_t stack_check_address_offset = Memory::uint16_at(pc_after - |
| 177 2 * kInstrSize) & 0xfff; |
| 178 Address stack_check_address_pointer = pc_after + stack_check_address_offset; |
| 179 ASSERT(Memory::uint32_at(stack_check_address_pointer) == |
| 180 reinterpret_cast<uint32_t>(replacement_code->entry())); |
| 181 Memory::uint32_at(stack_check_address_pointer) = |
| 182 reinterpret_cast<uint32_t>(check_code->entry()); |
| 183 } |
| 184 |
| 185 |
| 186 static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) { |
| 187 ByteArray* translations = data->TranslationByteArray(); |
| 188 int length = data->DeoptCount(); |
| 189 for (int i = 0; i < length; i++) { |
| 190 if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) { |
| 191 TranslationIterator it(translations, data->TranslationIndex(i)->value()); |
| 192 int value = it.Next(); |
| 193 ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value)); |
| 194 // Read the number of frames. |
| 195 value = it.Next(); |
| 196 if (value == 1) return i; |
| 197 } |
| 198 } |
| 199 UNREACHABLE(); |
| 200 return -1; |
| 122 } | 201 } |
| 123 | 202 |
| 124 | 203 |
| 125 void Deoptimizer::DoComputeOsrOutputFrame() { | 204 void Deoptimizer::DoComputeOsrOutputFrame() { |
| 126 UNIMPLEMENTED(); | 205 DeoptimizationInputData* data = DeoptimizationInputData::cast( |
| 127 } | 206 optimized_code_->deoptimization_data()); |
| 128 | 207 unsigned ast_id = data->OsrAstId()->value(); |
| 129 | 208 |
| 209 int bailout_id = LookupBailoutId(data, ast_id); |
| 210 unsigned translation_index = data->TranslationIndex(bailout_id)->value(); |
| 211 ByteArray* translations = data->TranslationByteArray(); |
| 212 |
| 213 TranslationIterator iterator(translations, translation_index); |
| 214 Translation::Opcode opcode = |
| 215 static_cast<Translation::Opcode>(iterator.Next()); |
| 216 ASSERT(Translation::BEGIN == opcode); |
| 217 USE(opcode); |
| 218 int count = iterator.Next(); |
| 219 ASSERT(count == 1); |
| 220 USE(count); |
| 221 |
| 222 opcode = static_cast<Translation::Opcode>(iterator.Next()); |
| 223 USE(opcode); |
| 224 ASSERT(Translation::FRAME == opcode); |
| 225 unsigned node_id = iterator.Next(); |
| 226 USE(node_id); |
| 227 ASSERT(node_id == ast_id); |
| 228 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator.Next())); |
| 229 USE(function); |
| 230 ASSERT(function == function_); |
| 231 unsigned height = iterator.Next(); |
| 232 unsigned height_in_bytes = height * kPointerSize; |
| 233 USE(height_in_bytes); |
| 234 |
| 235 unsigned fixed_size = ComputeFixedSize(function_); |
| 236 unsigned input_frame_size = input_->GetFrameSize(); |
| 237 ASSERT(fixed_size + height_in_bytes == input_frame_size); |
| 238 |
| 239 unsigned stack_slot_size = optimized_code_->stack_slots() * kPointerSize; |
| 240 unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value(); |
| 241 unsigned outgoing_size = outgoing_height * kPointerSize; |
| 242 unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size; |
| 243 ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call. |
| 244 |
| 245 if (FLAG_trace_osr) { |
| 246 PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ", |
| 247 reinterpret_cast<intptr_t>(function_)); |
| 248 function_->PrintName(); |
| 249 PrintF(" => node=%u, frame=%d->%d]\n", |
| 250 ast_id, |
| 251 input_frame_size, |
| 252 output_frame_size); |
| 253 } |
| 254 |
| 255 // There's only one output frame in the OSR case. |
| 256 output_count_ = 1; |
| 257 output_ = new FrameDescription*[1]; |
| 258 output_[0] = new(output_frame_size) FrameDescription( |
| 259 output_frame_size, function_); |
| 260 |
| 261 // Clear the incoming parameters in the optimized frame to avoid |
| 262 // confusing the garbage collector. |
| 263 unsigned output_offset = output_frame_size - kPointerSize; |
| 264 int parameter_count = function_->shared()->formal_parameter_count() + 1; |
| 265 for (int i = 0; i < parameter_count; ++i) { |
| 266 output_[0]->SetFrameSlot(output_offset, 0); |
| 267 output_offset -= kPointerSize; |
| 268 } |
| 269 |
| 270 // Translate the incoming parameters. This may overwrite some of the |
| 271 // incoming argument slots we've just cleared. |
| 272 int input_offset = input_frame_size - kPointerSize; |
| 273 bool ok = true; |
| 274 int limit = input_offset - (parameter_count * kPointerSize); |
| 275 while (ok && input_offset > limit) { |
| 276 ok = DoOsrTranslateCommand(&iterator, &input_offset); |
| 277 } |
| 278 |
| 279 // There are no translation commands for the caller's pc and fp, the |
| 280 // context, and the function. Set them up explicitly. |
| 281 for (int i = 0; ok && i < 4; i++) { |
| 282 uint32_t input_value = input_->GetFrameSlot(input_offset); |
| 283 if (FLAG_trace_osr) { |
| 284 PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part)\n", |
| 285 output_offset, |
| 286 input_value, |
| 287 input_offset); |
| 288 } |
| 289 output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset)); |
| 290 input_offset -= kPointerSize; |
| 291 output_offset -= kPointerSize; |
| 292 } |
| 293 |
| 294 // Translate the rest of the frame. |
| 295 while (ok && input_offset >= 0) { |
| 296 ok = DoOsrTranslateCommand(&iterator, &input_offset); |
| 297 } |
| 298 |
| 299 // If translation of any command failed, continue using the input frame. |
| 300 if (!ok) { |
| 301 delete output_[0]; |
| 302 output_[0] = input_; |
| 303 output_[0]->SetPc(reinterpret_cast<uint32_t>(from_)); |
| 304 } else { |
| 305 // Setup the frame pointer and the context pointer. |
| 306 output_[0]->SetRegister(fp.code(), input_->GetRegister(fp.code())); |
| 307 output_[0]->SetRegister(cp.code(), input_->GetRegister(cp.code())); |
| 308 |
| 309 unsigned pc_offset = data->OsrPcOffset()->value(); |
| 310 uint32_t pc = reinterpret_cast<uint32_t>( |
| 311 optimized_code_->entry() + pc_offset); |
| 312 output_[0]->SetPc(pc); |
| 313 } |
| 314 Code* continuation = Builtins::builtin(Builtins::NotifyOSR); |
| 315 output_[0]->SetContinuation( |
| 316 reinterpret_cast<uint32_t>(continuation->entry())); |
| 317 |
| 318 if (FLAG_trace_osr) { |
| 319 PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ", |
| 320 ok ? "finished" : "aborted", |
| 321 reinterpret_cast<intptr_t>(function)); |
| 322 function->PrintName(); |
| 323 PrintF(" => pc=0x%0x]\n", output_[0]->GetPc()); |
| 324 } |
| 325 } |
| 326 |
| 327 |
| 130 // This code is very similar to ia32 code, but relies on register names (fp, sp) | 328 // This code is very similar to ia32 code, but relies on register names (fp, sp) |
| 131 // and how the frame is laid out. | 329 // and how the frame is laid out. |
| 132 void Deoptimizer::DoComputeFrame(TranslationIterator* iterator, | 330 void Deoptimizer::DoComputeFrame(TranslationIterator* iterator, |
| 133 int frame_index) { | 331 int frame_index) { |
| 134 // Read the ast node id, function, and frame height for this output frame. | 332 // Read the ast node id, function, and frame height for this output frame. |
| 135 Translation::Opcode opcode = | 333 Translation::Opcode opcode = |
| 136 static_cast<Translation::Opcode>(iterator->Next()); | 334 static_cast<Translation::Opcode>(iterator->Next()); |
| 137 USE(opcode); | 335 USE(opcode); |
| 138 ASSERT(Translation::FRAME == opcode); | 336 ASSERT(Translation::FRAME == opcode); |
| 139 int node_id = iterator->Next(); | 337 int node_id = iterator->Next(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 496 } |
| 299 | 497 |
| 300 | 498 |
| 301 #define __ masm()-> | 499 #define __ masm()-> |
| 302 | 500 |
| 303 | 501 |
| 304 // This code tries to be close to ia32 code so that any changes can be | 502 // This code tries to be close to ia32 code so that any changes can be |
| 305 // easily ported. | 503 // easily ported. |
| 306 void Deoptimizer::EntryGenerator::Generate() { | 504 void Deoptimizer::EntryGenerator::Generate() { |
| 307 GeneratePrologue(); | 505 GeneratePrologue(); |
| 308 // TOS: bailout-id; TOS+1: return address if not EAGER. | |
| 309 CpuFeatures::Scope scope(VFP3); | 506 CpuFeatures::Scope scope(VFP3); |
| 310 // Save all general purpose registers before messing with them. | 507 // Save all general purpose registers before messing with them. |
| 311 const int kNumberOfRegisters = Register::kNumRegisters; | 508 const int kNumberOfRegisters = Register::kNumRegisters; |
| 312 | 509 |
| 313 // Everything but pc, lr and ip which will be saved but not restored. | 510 // Everything but pc, lr and ip which will be saved but not restored. |
| 314 RegList restored_regs = kJSCallerSaved | kCalleeSaved | ip.bit(); | 511 RegList restored_regs = kJSCallerSaved | kCalleeSaved | ip.bit(); |
| 315 | 512 |
| 316 const int kDoubleRegsSize = | 513 const int kDoubleRegsSize = |
| 317 kDoubleSize * DwVfpRegister::kNumAllocatableRegisters; | 514 kDoubleSize * DwVfpRegister::kNumAllocatableRegisters; |
| 318 | 515 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 333 // Get the bailout id from the stack. | 530 // Get the bailout id from the stack. |
| 334 __ ldr(r2, MemOperand(sp, kSavedRegistersAreaSize)); | 531 __ ldr(r2, MemOperand(sp, kSavedRegistersAreaSize)); |
| 335 | 532 |
| 336 // Get the address of the location in the code object if possible (r3) (return | 533 // Get the address of the location in the code object if possible (r3) (return |
| 337 // address for lazy deoptimization) and compute the fp-to-sp delta in | 534 // address for lazy deoptimization) and compute the fp-to-sp delta in |
| 338 // register r4. | 535 // register r4. |
| 339 if (type() == EAGER) { | 536 if (type() == EAGER) { |
| 340 __ mov(r3, Operand(0)); | 537 __ mov(r3, Operand(0)); |
| 341 // Correct one word for bailout id. | 538 // Correct one word for bailout id. |
| 342 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); | 539 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
| 540 } else if (type() == OSR) { |
| 541 __ mov(r3, lr); |
| 542 // Correct one word for bailout id. |
| 543 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
| 343 } else { | 544 } else { |
| 344 __ mov(r3, lr); | 545 __ mov(r3, lr); |
| 345 // Correct two words for bailout id and return address. | 546 // Correct two words for bailout id and return address. |
| 346 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); | 547 __ add(r4, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); |
| 347 } | 548 } |
| 348 __ sub(r4, fp, r4); | 549 __ sub(r4, fp, r4); |
| 349 | 550 |
| 350 // Allocate a new deoptimizer object. | 551 // Allocate a new deoptimizer object. |
| 351 // Pass four arguments in r0 to r3 and fifth argument on stack. | 552 // Pass four arguments in r0 to r3 and fifth argument on stack. |
| 352 __ PrepareCallCFunction(5, r5); | 553 __ PrepareCallCFunction(5, r5); |
| 353 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 554 __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 354 __ mov(r1, Operand(type())); // bailout type, | 555 __ mov(r1, Operand(type())); // bailout type, |
| 355 // r2: bailout id already loaded. | 556 // r2: bailout id already loaded. |
| 356 // r3: code address or 0 already loaded. | 557 // r3: code address or 0 already loaded. |
| 357 __ str(r4, MemOperand(sp, 0 * kPointerSize)); // Fp-to-sp delta. | 558 __ str(r4, MemOperand(sp, 0 * kPointerSize)); // Fp-to-sp delta. |
| 358 // Call Deoptimizer::New(). | 559 // Call Deoptimizer::New(). |
| 359 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5); | 560 __ CallCFunction(ExternalReference::new_deoptimizer_function(), 5); |
| 360 | 561 |
| 361 // Preserve "deoptimizer" object in register r0 and get the input | 562 // Preserve "deoptimizer" object in register r0 and get the input |
| 362 // frame descriptor pointer to r1 (deoptimizer->input_); | 563 // frame descriptor pointer to r1 (deoptimizer->input_); |
| 363 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset())); | 564 __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset())); |
| 364 | 565 |
| 365 | |
| 366 // Copy core registers into FrameDescription::registers_[kNumRegisters]. | 566 // Copy core registers into FrameDescription::registers_[kNumRegisters]. |
| 367 ASSERT(Register::kNumRegisters == kNumberOfRegisters); | 567 ASSERT(Register::kNumRegisters == kNumberOfRegisters); |
| 368 for (int i = 0; i < kNumberOfRegisters; i++) { | 568 for (int i = 0; i < kNumberOfRegisters; i++) { |
| 369 int offset = (i * kIntSize) + FrameDescription::registers_offset(); | 569 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 370 __ ldr(r2, MemOperand(sp, i * kPointerSize)); | 570 __ ldr(r2, MemOperand(sp, i * kPointerSize)); |
| 371 __ str(r2, MemOperand(r1, offset)); | 571 __ str(r2, MemOperand(r1, offset)); |
| 372 } | 572 } |
| 373 | 573 |
| 374 // Copy VFP registers to | 574 // Copy VFP registers to |
| 375 // double_registers_[DoubleRegister::kNumAllocatableRegisters] | 575 // double_registers_[DoubleRegister::kNumAllocatableRegisters] |
| 376 int double_regs_offset = FrameDescription::double_registers_offset(); | 576 int double_regs_offset = FrameDescription::double_registers_offset(); |
| 377 for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; ++i) { | 577 for (int i = 0; i < DwVfpRegister::kNumAllocatableRegisters; ++i) { |
| 378 int dst_offset = i * kDoubleSize + double_regs_offset; | 578 int dst_offset = i * kDoubleSize + double_regs_offset; |
| 379 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; | 579 int src_offset = i * kDoubleSize + kNumberOfRegisters * kPointerSize; |
| 380 __ vldr(d0, sp, src_offset); | 580 __ vldr(d0, sp, src_offset); |
| 381 __ vstr(d0, r1, dst_offset); | 581 __ vstr(d0, r1, dst_offset); |
| 382 } | 582 } |
| 383 | 583 |
| 384 // Remove the bailout id, eventually return address, and the saved registers | 584 // Remove the bailout id, eventually return address, and the saved registers |
| 385 // from the stack. | 585 // from the stack. |
| 386 if (type() == EAGER) { | 586 if (type() == EAGER || type() == OSR) { |
| 387 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); | 587 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize))); |
| 388 } else { | 588 } else { |
| 389 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); | 589 __ add(sp, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize))); |
| 390 } | 590 } |
| 391 | 591 |
| 392 // Compute a pointer to the unwinding limit in register r2; that is | 592 // Compute a pointer to the unwinding limit in register r2; that is |
| 393 // the first stack slot not part of the input frame. | 593 // the first stack slot not part of the input frame. |
| 394 __ ldr(r2, MemOperand(r1, FrameDescription::frame_size_offset())); | 594 __ ldr(r2, MemOperand(r1, FrameDescription::frame_size_offset())); |
| 395 __ add(r2, r2, sp); | 595 __ add(r2, r2, sp); |
| 396 | 596 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // __ add(r6, r2, Operand(r3, LSL, 1)); | 630 // __ add(r6, r2, Operand(r3, LSL, 1)); |
| 431 __ add(r6, r2, Operand(r3)); | 631 __ add(r6, r2, Operand(r3)); |
| 432 __ ldr(r7, MemOperand(r6, FrameDescription::frame_content_offset())); | 632 __ ldr(r7, MemOperand(r6, FrameDescription::frame_content_offset())); |
| 433 __ push(r7); | 633 __ push(r7); |
| 434 __ cmp(r3, Operand(0)); | 634 __ cmp(r3, Operand(0)); |
| 435 __ b(ne, &inner_push_loop); // test for gt? | 635 __ b(ne, &inner_push_loop); // test for gt? |
| 436 __ add(r0, r0, Operand(kPointerSize)); | 636 __ add(r0, r0, Operand(kPointerSize)); |
| 437 __ cmp(r0, r1); | 637 __ cmp(r0, r1); |
| 438 __ b(lt, &outer_push_loop); | 638 __ b(lt, &outer_push_loop); |
| 439 | 639 |
| 440 // In case of OSR, we have to restore the XMM registers. | |
| 441 if (type() == OSR) { | |
| 442 UNIMPLEMENTED(); | |
| 443 } | |
| 444 | |
| 445 // Push state, pc, and continuation from the last output frame. | 640 // Push state, pc, and continuation from the last output frame. |
| 446 if (type() != OSR) { | 641 if (type() != OSR) { |
| 447 __ ldr(r6, MemOperand(r2, FrameDescription::state_offset())); | 642 __ ldr(r6, MemOperand(r2, FrameDescription::state_offset())); |
| 448 __ push(r6); | 643 __ push(r6); |
| 449 } | 644 } |
| 450 | 645 |
| 451 __ ldr(r6, MemOperand(r2, FrameDescription::pc_offset())); | 646 __ ldr(r6, MemOperand(r2, FrameDescription::pc_offset())); |
| 452 __ push(r6); | 647 __ push(r6); |
| 453 __ ldr(r6, MemOperand(r2, FrameDescription::continuation_offset())); | 648 __ ldr(r6, MemOperand(r2, FrameDescription::continuation_offset())); |
| 454 __ push(r6); | 649 __ push(r6); |
| 455 | 650 |
| 456 // Push the registers from the last output frame. | 651 // Push the registers from the last output frame. |
| 457 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { | 652 for (int i = kNumberOfRegisters - 1; i >= 0; i--) { |
| 458 int offset = (i * kIntSize) + FrameDescription::registers_offset(); | 653 int offset = (i * kPointerSize) + FrameDescription::registers_offset(); |
| 459 __ ldr(r6, MemOperand(r2, offset)); | 654 __ ldr(r6, MemOperand(r2, offset)); |
| 460 __ push(r6); | 655 __ push(r6); |
| 461 } | 656 } |
| 462 | 657 |
| 463 // Restore the registers from the stack. | 658 // Restore the registers from the stack. |
| 464 __ ldm(ia_w, sp, restored_regs); // all but pc registers. | 659 __ ldm(ia_w, sp, restored_regs); // all but pc registers. |
| 465 __ pop(ip); // remove sp | 660 __ pop(ip); // remove sp |
| 466 __ pop(ip); // remove lr | 661 __ pop(ip); // remove lr |
| 467 | 662 |
| 468 // Set up the roots register. | 663 // Set up the roots register. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 494 __ push(ip); | 689 __ push(ip); |
| 495 __ b(&done); | 690 __ b(&done); |
| 496 ASSERT(masm()->pc_offset() - start == table_entry_size_); | 691 ASSERT(masm()->pc_offset() - start == table_entry_size_); |
| 497 } | 692 } |
| 498 __ bind(&done); | 693 __ bind(&done); |
| 499 } | 694 } |
| 500 | 695 |
| 501 #undef __ | 696 #undef __ |
| 502 | 697 |
| 503 } } // namespace v8::internal | 698 } } // namespace v8::internal |
| OLD | NEW |