| Index: src/arm/deoptimizer-arm.cc
|
| ===================================================================
|
| --- src/arm/deoptimizer-arm.cc (revision 6800)
|
| +++ src/arm/deoptimizer-arm.cc (working copy)
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2010 the V8 project authors. All rights reserved.
|
| +// Copyright 2011 the V8 project authors. All rights reserved.
|
| // Redistribution and use in source and binary forms, with or without
|
| // modification, are permitted provided that the following conditions are
|
| // met:
|
| @@ -37,6 +37,14 @@
|
|
|
| int Deoptimizer::table_entry_size_ = 16;
|
|
|
| +
|
| +int Deoptimizer::patch_size() {
|
| + const int kCallInstructionSizeInWords = 3;
|
| + return kCallInstructionSizeInWords * Assembler::kInstrSize;
|
| +}
|
| +
|
| +
|
| +
|
| void Deoptimizer::DeoptimizeFunction(JSFunction* function) {
|
| AssertNoAllocation no_allocation;
|
|
|
| @@ -51,12 +59,15 @@
|
|
|
| // For each return after a safepoint insert an absolute call to the
|
| // corresponding deoptimization entry.
|
| + ASSERT(patch_size() % Assembler::kInstrSize == 0);
|
| + int call_size_in_words = patch_size() / Assembler::kInstrSize;
|
| unsigned last_pc_offset = 0;
|
| SafepointTable table(function->code());
|
| for (unsigned i = 0; i < table.length(); i++) {
|
| unsigned pc_offset = table.GetPcOffset(i);
|
| - int deoptimization_index = table.GetDeoptimizationIndex(i);
|
| - int gap_code_size = table.GetGapCodeSize(i);
|
| + SafepointEntry safepoint_entry = table.GetEntry(i);
|
| + int deoptimization_index = safepoint_entry.deoptimization_index();
|
| + int gap_code_size = safepoint_entry.gap_code_size();
|
| // Check that we did not shoot past next safepoint.
|
| // TODO(srdjan): How do we guarantee that safepoint code does not
|
| // overlap other safepoint patching code?
|
| @@ -72,14 +83,13 @@
|
| #endif
|
| last_pc_offset = pc_offset;
|
| if (deoptimization_index != Safepoint::kNoDeoptimizationIndex) {
|
| - const int kCallInstructionSizeInWords = 3;
|
| - CodePatcher patcher(code->instruction_start() + pc_offset + gap_code_size,
|
| - kCallInstructionSizeInWords);
|
| + last_pc_offset += gap_code_size;
|
| + CodePatcher patcher(code->instruction_start() + last_pc_offset,
|
| + call_size_in_words);
|
| Address deoptimization_entry = Deoptimizer::GetDeoptimizationEntry(
|
| deoptimization_index, Deoptimizer::LAZY);
|
| patcher.masm()->Call(deoptimization_entry, RelocInfo::NONE);
|
| - last_pc_offset +=
|
| - gap_code_size + kCallInstructionSizeInWords * Assembler::kInstrSize;
|
| + last_pc_offset += patch_size();
|
| }
|
| }
|
|
|
| @@ -87,7 +97,7 @@
|
| #ifdef DEBUG
|
| // Destroy the code which is not supposed to be run again.
|
| int instructions =
|
| - (code->safepoint_table_start() - last_pc_offset) / Assembler::kInstrSize;
|
| + (code->safepoint_table_offset() - last_pc_offset) / Assembler::kInstrSize;
|
| CodePatcher destroyer(code->instruction_start() + last_pc_offset,
|
| instructions);
|
| for (int x = 0; x < instructions; x++) {
|
| @@ -111,19 +121,207 @@
|
| }
|
|
|
|
|
| -void Deoptimizer::PatchStackCheckCode(RelocInfo* rinfo,
|
| - Code* replacement_code) {
|
| - UNIMPLEMENTED();
|
| +void Deoptimizer::PatchStackCheckCodeAt(Address pc_after,
|
| + Code* check_code,
|
| + Code* replacement_code) {
|
| + const int kInstrSize = Assembler::kInstrSize;
|
| + // The call of the stack guard check has the following form:
|
| + // e1 5d 00 0c cmp sp, <limit>
|
| + // 2a 00 00 01 bcs ok
|
| + // e5 9f c? ?? ldr ip, [pc, <stack guard address>]
|
| + // e1 2f ff 3c blx ip
|
| + ASSERT(Memory::int32_at(pc_after - kInstrSize) ==
|
| + (al | B24 | B21 | 15*B16 | 15*B12 | 15*B8 | BLX | ip.code()));
|
| + ASSERT(Assembler::IsLdrPcImmediateOffset(
|
| + Assembler::instr_at(pc_after - 2 * kInstrSize)));
|
| +
|
| + // We patch the code to the following form:
|
| + // e1 5d 00 0c cmp sp, <limit>
|
| + // e1 a0 00 00 mov r0, r0 (NOP)
|
| + // e5 9f c? ?? ldr ip, [pc, <on-stack replacement address>]
|
| + // e1 2f ff 3c blx ip
|
| + // and overwrite the constant containing the
|
| + // address of the stack check stub.
|
| +
|
| + // Replace conditional jump with NOP.
|
| + CodePatcher patcher(pc_after - 3 * kInstrSize, 1);
|
| + patcher.masm()->nop();
|
| +
|
| + // Replace the stack check address in the constant pool
|
| + // with the entry address of the replacement code.
|
| + uint32_t stack_check_address_offset = Memory::uint16_at(pc_after -
|
| + 2 * kInstrSize) & 0xfff;
|
| + Address stack_check_address_pointer = pc_after + stack_check_address_offset;
|
| + ASSERT(Memory::uint32_at(stack_check_address_pointer) ==
|
| + reinterpret_cast<uint32_t>(check_code->entry()));
|
| + Memory::uint32_at(stack_check_address_pointer) =
|
| + reinterpret_cast<uint32_t>(replacement_code->entry());
|
| }
|
|
|
|
|
| -void Deoptimizer::RevertStackCheckCode(RelocInfo* rinfo, Code* check_code) {
|
| - UNIMPLEMENTED();
|
| +void Deoptimizer::RevertStackCheckCodeAt(Address pc_after,
|
| + Code* check_code,
|
| + Code* replacement_code) {
|
| + const int kInstrSize = Assembler::kInstrSize;
|
| + ASSERT(Memory::uint32_at(pc_after - kInstrSize) == 0xe12fff3c);
|
| + ASSERT(Memory::uint8_at(pc_after - kInstrSize - 1) == 0xe5);
|
| + ASSERT(Memory::uint8_at(pc_after - kInstrSize - 2) == 0x9f);
|
| +
|
| + // Replace NOP with conditional jump.
|
| + CodePatcher patcher(pc_after - 3 * kInstrSize, 1);
|
| + patcher.masm()->b(+4, cs);
|
| +
|
| + // Replace the stack check address in the constant pool
|
| + // with the entry address of the replacement code.
|
| + uint32_t stack_check_address_offset = Memory::uint16_at(pc_after -
|
| + 2 * kInstrSize) & 0xfff;
|
| + Address stack_check_address_pointer = pc_after + stack_check_address_offset;
|
| + ASSERT(Memory::uint32_at(stack_check_address_pointer) ==
|
| + reinterpret_cast<uint32_t>(replacement_code->entry()));
|
| + Memory::uint32_at(stack_check_address_pointer) =
|
| + reinterpret_cast<uint32_t>(check_code->entry());
|
| }
|
|
|
|
|
| +static int LookupBailoutId(DeoptimizationInputData* data, unsigned ast_id) {
|
| + ByteArray* translations = data->TranslationByteArray();
|
| + int length = data->DeoptCount();
|
| + for (int i = 0; i < length; i++) {
|
| + if (static_cast<unsigned>(data->AstId(i)->value()) == ast_id) {
|
| + TranslationIterator it(translations, data->TranslationIndex(i)->value());
|
| + int value = it.Next();
|
| + ASSERT(Translation::BEGIN == static_cast<Translation::Opcode>(value));
|
| + // Read the number of frames.
|
| + value = it.Next();
|
| + if (value == 1) return i;
|
| + }
|
| + }
|
| + UNREACHABLE();
|
| + return -1;
|
| +}
|
| +
|
| +
|
| void Deoptimizer::DoComputeOsrOutputFrame() {
|
| - UNIMPLEMENTED();
|
| + DeoptimizationInputData* data = DeoptimizationInputData::cast(
|
| + optimized_code_->deoptimization_data());
|
| + unsigned ast_id = data->OsrAstId()->value();
|
| +
|
| + int bailout_id = LookupBailoutId(data, ast_id);
|
| + unsigned translation_index = data->TranslationIndex(bailout_id)->value();
|
| + ByteArray* translations = data->TranslationByteArray();
|
| +
|
| + TranslationIterator iterator(translations, translation_index);
|
| + Translation::Opcode opcode =
|
| + static_cast<Translation::Opcode>(iterator.Next());
|
| + ASSERT(Translation::BEGIN == opcode);
|
| + USE(opcode);
|
| + int count = iterator.Next();
|
| + ASSERT(count == 1);
|
| + USE(count);
|
| +
|
| + opcode = static_cast<Translation::Opcode>(iterator.Next());
|
| + USE(opcode);
|
| + ASSERT(Translation::FRAME == opcode);
|
| + unsigned node_id = iterator.Next();
|
| + USE(node_id);
|
| + ASSERT(node_id == ast_id);
|
| + JSFunction* function = JSFunction::cast(ComputeLiteral(iterator.Next()));
|
| + USE(function);
|
| + ASSERT(function == function_);
|
| + unsigned height = iterator.Next();
|
| + unsigned height_in_bytes = height * kPointerSize;
|
| + USE(height_in_bytes);
|
| +
|
| + unsigned fixed_size = ComputeFixedSize(function_);
|
| + unsigned input_frame_size = input_->GetFrameSize();
|
| + ASSERT(fixed_size + height_in_bytes == input_frame_size);
|
| +
|
| + unsigned stack_slot_size = optimized_code_->stack_slots() * kPointerSize;
|
| + unsigned outgoing_height = data->ArgumentsStackHeight(bailout_id)->value();
|
| + unsigned outgoing_size = outgoing_height * kPointerSize;
|
| + unsigned output_frame_size = fixed_size + stack_slot_size + outgoing_size;
|
| + ASSERT(outgoing_size == 0); // OSR does not happen in the middle of a call.
|
| +
|
| + if (FLAG_trace_osr) {
|
| + PrintF("[on-stack replacement: begin 0x%08" V8PRIxPTR " ",
|
| + reinterpret_cast<intptr_t>(function_));
|
| + function_->PrintName();
|
| + PrintF(" => node=%u, frame=%d->%d]\n",
|
| + ast_id,
|
| + input_frame_size,
|
| + output_frame_size);
|
| + }
|
| +
|
| + // There's only one output frame in the OSR case.
|
| + output_count_ = 1;
|
| + output_ = new FrameDescription*[1];
|
| + output_[0] = new(output_frame_size) FrameDescription(
|
| + output_frame_size, function_);
|
| +
|
| + // Clear the incoming parameters in the optimized frame to avoid
|
| + // confusing the garbage collector.
|
| + unsigned output_offset = output_frame_size - kPointerSize;
|
| + int parameter_count = function_->shared()->formal_parameter_count() + 1;
|
| + for (int i = 0; i < parameter_count; ++i) {
|
| + output_[0]->SetFrameSlot(output_offset, 0);
|
| + output_offset -= kPointerSize;
|
| + }
|
| +
|
| + // Translate the incoming parameters. This may overwrite some of the
|
| + // incoming argument slots we've just cleared.
|
| + int input_offset = input_frame_size - kPointerSize;
|
| + bool ok = true;
|
| + int limit = input_offset - (parameter_count * kPointerSize);
|
| + while (ok && input_offset > limit) {
|
| + ok = DoOsrTranslateCommand(&iterator, &input_offset);
|
| + }
|
| +
|
| + // There are no translation commands for the caller's pc and fp, the
|
| + // context, and the function. Set them up explicitly.
|
| + for (int i = 0; ok && i < 4; i++) {
|
| + uint32_t input_value = input_->GetFrameSlot(input_offset);
|
| + if (FLAG_trace_osr) {
|
| + PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part)\n",
|
| + output_offset,
|
| + input_value,
|
| + input_offset);
|
| + }
|
| + output_[0]->SetFrameSlot(output_offset, input_->GetFrameSlot(input_offset));
|
| + input_offset -= kPointerSize;
|
| + output_offset -= kPointerSize;
|
| + }
|
| +
|
| + // Translate the rest of the frame.
|
| + while (ok && input_offset >= 0) {
|
| + ok = DoOsrTranslateCommand(&iterator, &input_offset);
|
| + }
|
| +
|
| + // If translation of any command failed, continue using the input frame.
|
| + if (!ok) {
|
| + delete output_[0];
|
| + output_[0] = input_;
|
| + output_[0]->SetPc(reinterpret_cast<uint32_t>(from_));
|
| + } else {
|
| + // Setup the frame pointer and the context pointer.
|
| + output_[0]->SetRegister(fp.code(), input_->GetRegister(fp.code()));
|
| + output_[0]->SetRegister(cp.code(), input_->GetRegister(cp.code()));
|
| +
|
| + unsigned pc_offset = data->OsrPcOffset()->value();
|
| + uint32_t pc = reinterpret_cast<uint32_t>(
|
| + optimized_code_->entry() + pc_offset);
|
| + output_[0]->SetPc(pc);
|
| + }
|
| + Code* continuation = Builtins::builtin(Builtins::NotifyOSR);
|
| + output_[0]->SetContinuation(
|
| + reinterpret_cast<uint32_t>(continuation->entry()));
|
| +
|
| + if (FLAG_trace_osr) {
|
| + PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ",
|
| + ok ? "finished" : "aborted",
|
| + reinterpret_cast<intptr_t>(function));
|
| + function->PrintName();
|
| + PrintF(" => pc=0x%0x]\n", output_[0]->GetPc());
|
| + }
|
| }
|
|
|
|
|
| @@ -305,7 +503,6 @@
|
| // easily ported.
|
| void Deoptimizer::EntryGenerator::Generate() {
|
| GeneratePrologue();
|
| - // TOS: bailout-id; TOS+1: return address if not EAGER.
|
| CpuFeatures::Scope scope(VFP3);
|
| // Save all general purpose registers before messing with them.
|
| const int kNumberOfRegisters = Register::kNumRegisters;
|
| @@ -340,6 +537,10 @@
|
| __ mov(r3, Operand(0));
|
| // Correct one word for bailout id.
|
| __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize)));
|
| + } else if (type() == OSR) {
|
| + __ mov(r3, lr);
|
| + // Correct one word for bailout id.
|
| + __ add(r4, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize)));
|
| } else {
|
| __ mov(r3, lr);
|
| // Correct two words for bailout id and return address.
|
| @@ -362,11 +563,10 @@
|
| // frame descriptor pointer to r1 (deoptimizer->input_);
|
| __ ldr(r1, MemOperand(r0, Deoptimizer::input_offset()));
|
|
|
| -
|
| // Copy core registers into FrameDescription::registers_[kNumRegisters].
|
| ASSERT(Register::kNumRegisters == kNumberOfRegisters);
|
| for (int i = 0; i < kNumberOfRegisters; i++) {
|
| - int offset = (i * kIntSize) + FrameDescription::registers_offset();
|
| + int offset = (i * kPointerSize) + FrameDescription::registers_offset();
|
| __ ldr(r2, MemOperand(sp, i * kPointerSize));
|
| __ str(r2, MemOperand(r1, offset));
|
| }
|
| @@ -383,7 +583,7 @@
|
|
|
| // Remove the bailout id, eventually return address, and the saved registers
|
| // from the stack.
|
| - if (type() == EAGER) {
|
| + if (type() == EAGER || type() == OSR) {
|
| __ add(sp, sp, Operand(kSavedRegistersAreaSize + (1 * kPointerSize)));
|
| } else {
|
| __ add(sp, sp, Operand(kSavedRegistersAreaSize + (2 * kPointerSize)));
|
| @@ -437,11 +637,6 @@
|
| __ cmp(r0, r1);
|
| __ b(lt, &outer_push_loop);
|
|
|
| - // In case of OSR, we have to restore the XMM registers.
|
| - if (type() == OSR) {
|
| - UNIMPLEMENTED();
|
| - }
|
| -
|
| // Push state, pc, and continuation from the last output frame.
|
| if (type() != OSR) {
|
| __ ldr(r6, MemOperand(r2, FrameDescription::state_offset()));
|
| @@ -455,7 +650,7 @@
|
|
|
| // Push the registers from the last output frame.
|
| for (int i = kNumberOfRegisters - 1; i >= 0; i--) {
|
| - int offset = (i * kIntSize) + FrameDescription::registers_offset();
|
| + int offset = (i * kPointerSize) + FrameDescription::registers_offset();
|
| __ ldr(r6, MemOperand(r2, offset));
|
| __ push(r6);
|
| }
|
|
|