| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 int Deoptimizer::patch_size() { | 44 int Deoptimizer::patch_size() { |
| 45 return Assembler::kCallSequenceLength; | 45 return Assembler::kCallSequenceLength; |
| 46 } | 46 } |
| 47 | 47 |
| 48 | 48 |
| 49 void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { | 49 void Deoptimizer::PatchCodeForDeoptimization(Isolate* isolate, Code* code) { |
| 50 // Invalidate the relocation information, as it will become invalid by the | 50 // Invalidate the relocation information, as it will become invalid by the |
| 51 // code patching below, and is not needed any more. | 51 // code patching below, and is not needed any more. |
| 52 code->InvalidateRelocation(); | 52 code->InvalidateRelocation(); |
| 53 | 53 |
| 54 if (FLAG_zap_code_space) { |
| 55 // Fail hard and early if we enter this code object again. |
| 56 byte* pointer = code->FindCodeAgeSequence(); |
| 57 if (pointer != NULL) { |
| 58 pointer += kNoCodeAgeSequenceLength; |
| 59 } else { |
| 60 pointer = code->instruction_start(); |
| 61 } |
| 62 CodePatcher patcher(pointer, 1); |
| 63 patcher.masm()->int3(); |
| 64 |
| 65 DeoptimizationInputData* data = |
| 66 DeoptimizationInputData::cast(code->deoptimization_data()); |
| 67 int osr_offset = data->OsrPcOffset()->value(); |
| 68 if (osr_offset > 0) { |
| 69 CodePatcher osr_patcher(code->instruction_start() + osr_offset, 1); |
| 70 osr_patcher.masm()->int3(); |
| 71 } |
| 72 } |
| 73 |
| 54 // For each LLazyBailout instruction insert a absolute call to the | 74 // For each LLazyBailout instruction insert a absolute call to the |
| 55 // corresponding deoptimization entry, or a short call to an absolute | 75 // corresponding deoptimization entry, or a short call to an absolute |
| 56 // jump if space is short. The absolute jumps are put in a table just | 76 // jump if space is short. The absolute jumps are put in a table just |
| 57 // before the safepoint table (space was allocated there when the Code | 77 // before the safepoint table (space was allocated there when the Code |
| 58 // object was created, if necessary). | 78 // object was created, if necessary). |
| 59 | 79 |
| 60 Address instruction_start = code->instruction_start(); | 80 Address instruction_start = code->instruction_start(); |
| 61 #ifdef DEBUG | 81 #ifdef DEBUG |
| 62 Address prev_call_address = NULL; | 82 Address prev_call_address = NULL; |
| 63 #endif | 83 #endif |
| 64 DeoptimizationInputData* deopt_data = | 84 DeoptimizationInputData* deopt_data = |
| 65 DeoptimizationInputData::cast(code->deoptimization_data()); | 85 DeoptimizationInputData::cast(code->deoptimization_data()); |
| 86 SharedFunctionInfo* shared = |
| 87 SharedFunctionInfo::cast(deopt_data->SharedFunctionInfo()); |
| 88 shared->EvictFromOptimizedCodeMap(code, "deoptimized code"); |
| 89 deopt_data->SetSharedFunctionInfo(Smi::FromInt(0)); |
| 90 // For each LLazyBailout instruction insert a call to the corresponding |
| 91 // deoptimization entry. |
| 66 for (int i = 0; i < deopt_data->DeoptCount(); i++) { | 92 for (int i = 0; i < deopt_data->DeoptCount(); i++) { |
| 67 if (deopt_data->Pc(i)->value() == -1) continue; | 93 if (deopt_data->Pc(i)->value() == -1) continue; |
| 68 // Position where Call will be patched in. | 94 // Position where Call will be patched in. |
| 69 Address call_address = instruction_start + deopt_data->Pc(i)->value(); | 95 Address call_address = instruction_start + deopt_data->Pc(i)->value(); |
| 70 // There is room enough to write a long call instruction because we pad | 96 // There is room enough to write a long call instruction because we pad |
| 71 // LLazyBailout instructions with nops if necessary. | 97 // LLazyBailout instructions with nops if necessary. |
| 72 CodePatcher patcher(call_address, Assembler::kCallSequenceLength); | 98 CodePatcher patcher(call_address, Assembler::kCallSequenceLength); |
| 73 patcher.masm()->Call(GetDeoptimizationEntry(isolate, i, LAZY), | 99 patcher.masm()->Call(GetDeoptimizationEntry(isolate, i, LAZY), |
| 74 RelocInfo::NONE64); | 100 Assembler::RelocInfoNone()); |
| 75 ASSERT(prev_call_address == NULL || | 101 ASSERT(prev_call_address == NULL || |
| 76 call_address >= prev_call_address + patch_size()); | 102 call_address >= prev_call_address + patch_size()); |
| 77 ASSERT(call_address + patch_size() <= code->instruction_end()); | 103 ASSERT(call_address + patch_size() <= code->instruction_end()); |
| 78 #ifdef DEBUG | 104 #ifdef DEBUG |
| 79 prev_call_address = call_address; | 105 prev_call_address = call_address; |
| 80 #endif | 106 #endif |
| 81 } | 107 } |
| 82 } | 108 } |
| 83 | 109 |
| 84 | 110 |
| 85 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { | 111 void Deoptimizer::FillInputFrame(Address tos, JavaScriptFrame* frame) { |
| 86 // Set the register values. The values are not important as there are no | 112 // Set the register values. The values are not important as there are no |
| 87 // callee saved registers in JavaScript frames, so all registers are | 113 // callee saved registers in JavaScript frames, so all registers are |
| 88 // spilled. Registers rbp and rsp are set to the correct values though. | 114 // spilled. Registers rbp and rsp are set to the correct values though. |
| 89 for (int i = 0; i < Register::kNumRegisters; i++) { | 115 for (int i = 0; i < Register::kNumRegisters; i++) { |
| 90 input_->SetRegister(i, i * 4); | 116 input_->SetRegister(i, i * 4); |
| 91 } | 117 } |
| 92 input_->SetRegister(rsp.code(), reinterpret_cast<intptr_t>(frame->sp())); | 118 input_->SetRegister(rsp.code(), reinterpret_cast<intptr_t>(frame->sp())); |
| 93 input_->SetRegister(rbp.code(), reinterpret_cast<intptr_t>(frame->fp())); | 119 input_->SetRegister(rbp.code(), reinterpret_cast<intptr_t>(frame->fp())); |
| 94 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { | 120 for (int i = 0; i < DoubleRegister::NumAllocatableRegisters(); i++) { |
| 95 input_->SetDoubleRegister(i, 0.0); | 121 input_->SetDoubleRegister(i, 0.0); |
| 96 } | 122 } |
| 97 | 123 |
| 98 // Fill the frame content from the actual data on the frame. | 124 // Fill the frame content from the actual data on the frame. |
| 99 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { | 125 for (unsigned i = 0; i < input_->GetFrameSize(); i += kPointerSize) { |
| 100 input_->SetFrameSlot(i, Memory::uint64_at(tos + i)); | 126 input_->SetFrameSlot(i, Memory::uintptr_at(tos + i)); |
| 101 } | 127 } |
| 102 } | 128 } |
| 103 | 129 |
| 104 | 130 |
| 105 void Deoptimizer::SetPlatformCompiledStubRegisters( | 131 void Deoptimizer::SetPlatformCompiledStubRegisters( |
| 106 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { | 132 FrameDescription* output_frame, CodeStubInterfaceDescriptor* descriptor) { |
| 107 intptr_t handler = | 133 intptr_t handler = |
| 108 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); | 134 reinterpret_cast<intptr_t>(descriptor->deoptimization_handler_); |
| 109 int params = descriptor->GetHandlerParameterCount(); | 135 int params = descriptor->GetHandlerParameterCount(); |
| 110 output_frame->SetRegister(rax.code(), params); | 136 output_frame->SetRegister(rax.code(), params); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // Allocate a new deoptimizer object. | 205 // Allocate a new deoptimizer object. |
| 180 __ PrepareCallCFunction(6); | 206 __ PrepareCallCFunction(6); |
| 181 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 207 __ movp(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
| 182 __ movp(arg_reg_1, rax); | 208 __ movp(arg_reg_1, rax); |
| 183 __ Set(arg_reg_2, type()); | 209 __ Set(arg_reg_2, type()); |
| 184 // Args 3 and 4 are already in the right registers. | 210 // Args 3 and 4 are already in the right registers. |
| 185 | 211 |
| 186 // On windows put the arguments on the stack (PrepareCallCFunction | 212 // On windows put the arguments on the stack (PrepareCallCFunction |
| 187 // has created space for this). On linux pass the arguments in r8 and r9. | 213 // has created space for this). On linux pass the arguments in r8 and r9. |
| 188 #ifdef _WIN64 | 214 #ifdef _WIN64 |
| 189 __ movp(Operand(rsp, 4 * kPointerSize), arg5); | 215 __ movq(Operand(rsp, 4 * kRegisterSize), arg5); |
| 190 __ LoadAddress(arg5, ExternalReference::isolate_address(isolate())); | 216 __ LoadAddress(arg5, ExternalReference::isolate_address(isolate())); |
| 191 __ movp(Operand(rsp, 5 * kPointerSize), arg5); | 217 __ movq(Operand(rsp, 5 * kRegisterSize), arg5); |
| 192 #else | 218 #else |
| 193 __ movp(r8, arg5); | 219 __ movp(r8, arg5); |
| 194 __ LoadAddress(r9, ExternalReference::isolate_address(isolate())); | 220 __ LoadAddress(r9, ExternalReference::isolate_address(isolate())); |
| 195 #endif | 221 #endif |
| 196 | 222 |
| 197 { AllowExternalCallThatCantCauseGC scope(masm()); | 223 { AllowExternalCallThatCantCauseGC scope(masm()); |
| 198 __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6); | 224 __ CallCFunction(ExternalReference::new_deoptimizer_function(isolate()), 6); |
| 199 } | 225 } |
| 200 // Preserve deoptimizer object in register rax and get the input | 226 // Preserve deoptimizer object in register rax and get the input |
| 201 // frame descriptor pointer. | 227 // frame descriptor pointer. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 SetFrameSlot(offset, value); | 360 SetFrameSlot(offset, value); |
| 335 } | 361 } |
| 336 | 362 |
| 337 | 363 |
| 338 #undef __ | 364 #undef __ |
| 339 | 365 |
| 340 | 366 |
| 341 } } // namespace v8::internal | 367 } } // namespace v8::internal |
| 342 | 368 |
| 343 #endif // V8_TARGET_ARCH_X64 | 369 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |