Revision: 18854
Author: [email protected]
Date: Mon Jan 27 14:32:55 2014 UTC
Log: A64: Implement LOsrEntry and LUnknownOSRValue
BUG=314606
[email protected], [email protected]
Review URL: https://codereview.chromium.org/145713002
http://code.google.com/p/v8/source/detail?r=18854
Modified:
/branches/experimental/a64/src/a64/assembler-a64.h
/branches/experimental/a64/src/a64/builtins-a64.cc
/branches/experimental/a64/src/a64/deoptimizer-a64.cc
/branches/experimental/a64/src/a64/full-codegen-a64.cc
/branches/experimental/a64/src/a64/lithium-a64.cc
/branches/experimental/a64/src/a64/lithium-a64.h
/branches/experimental/a64/src/a64/lithium-codegen-a64.cc
=======================================
--- /branches/experimental/a64/src/a64/assembler-a64.h Wed Jan 22 12:46:44
2014 UTC
+++ /branches/experimental/a64/src/a64/assembler-a64.h Mon Jan 27 14:32:55
2014 UTC
@@ -1389,8 +1389,9 @@
// states of the generated code.
enum NopMarkerTypes {
DEBUG_BREAK_NOP,
+ INTERRUPT_CODE_NOP,
FIRST_NOP_MARKER = DEBUG_BREAK_NOP,
- LAST_NOP_MARKER = DEBUG_BREAK_NOP
+ LAST_NOP_MARKER = INTERRUPT_CODE_NOP
};
inline void nop(NopMarkerTypes n) {
=======================================
--- /branches/experimental/a64/src/a64/builtins-a64.cc Fri Jan 24 14:09:40
2014 UTC
+++ /branches/experimental/a64/src/a64/builtins-a64.cc Mon Jan 27 14:32:55
2014 UTC
@@ -919,12 +919,50 @@
void Builtins::Generate_NotifyOSR(MacroAssembler* masm) {
- ASM_UNIMPLEMENTED_BREAK("Implement Generate_NotifyOSR");
+ // For now, we are relying on the fact that Runtime::NotifyOSR
+ // doesn't do any garbage collection which allows us to save/restore
+ // the registers without worrying about which of them contain
+ // pointers. This seems a bit fragile.
+ //
+ // TODO(jochen): Is it correct (and appropriate) to use safepoint
+ // registers here? According to the comment above, we should only need to
+ // preserve the registers with parameters.
+ __ PushXRegList(kSafepointSavedRegisters);
+ {
+ FrameScope scope(masm, StackFrame::INTERNAL);
+ __ CallRuntime(Runtime::kNotifyOSR, 0);
+ }
+ __ PopXRegList(kSafepointSavedRegisters);
+ __ Ret();
}
void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
- ASM_UNIMPLEMENTED_BREAK("Implement Generate_OnStackReplacement");
+ // Lookup the function in the JavaScript frame and push it as an
+ // argument to the on-stack replacement function.
+ __ Ldr(x0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
+ {
+ FrameScope scope(masm, StackFrame::INTERNAL);
+ __ Push(x0);
+ __ CallRuntime(Runtime::kCompileForOnStackReplacement, 1);
+ }
+
+ // If the result was -1 it means that we couldn't optimize the
+ // function. Just return and continue in the unoptimized version.
+ Label skip;
+ __ Cmp(x0, Operand(Smi::FromInt(-1)));
+ __ B(ne, &skip);
+ __ Ret();
+
+ __ Bind(&skip);
+ // Untag the AST id and push it on the stack.
+ __ SmiUntag(x0);
+ __ Push(x0);
+
+ // Generate the code for doing the frame-to-frame translation using
+ // the deoptimizer infrastructure.
+ Deoptimizer::EntryGenerator generator(masm, Deoptimizer::OSR);
+ generator.Generate();
}
=======================================
--- /branches/experimental/a64/src/a64/deoptimizer-a64.cc Wed Jan 22
12:46:44 2014 UTC
+++ /branches/experimental/a64/src/a64/deoptimizer-a64.cc Mon Jan 27
14:32:55 2014 UTC
@@ -112,15 +112,43 @@
}
+// The back edge bookkeeping code matches the pattern:
+//
+// <decrement profiling counter>
+// .. .. .. .. b.pl ok
+// .. .. .. .. ldr x16, pc+<interrupt stub address>
+// .. .. .. .. blr x16
+// ok-label
+//
+// We patch the code to the following form:
+//
+// <decrement profiling counter>
+// .. .. .. .. mov x0, x0 (NOP)
+// .. .. .. .. ldr x16, pc+<on-stack replacement address>
+// .. .. .. .. blr x16
void Deoptimizer::PatchInterruptCodeAt(Code* unoptimized_code,
Address pc_after,
Code* interrupt_code,
Code* replacement_code) {
- UNIMPLEMENTED();
ASSERT(!InterruptCodeIsPatched(unoptimized_code,
pc_after,
interrupt_code,
replacement_code));
+
+ // Turn the jump into a nop.
+ Instruction* jump = Instruction::Cast(pc_after)->preceding(3);
+ PatchingAssembler patcher(jump, 1);
+ patcher.nop(Assembler::INTERRUPT_CODE_NOP);
+
+ // Replace the call address.
+ Instruction* load = Instruction::Cast(pc_after)->preceding(2);
+ Address interrupt_address_pointer =
+ reinterpret_cast<Address>(load) + load->ImmPCOffset();
+ Memory::uint64_at(interrupt_address_pointer) =
+ reinterpret_cast<uint64_t>(replacement_code->entry());
+
+
unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
+ unoptimized_code, pc_after - 2 * kInstructionSize, replacement_code);
}
@@ -128,11 +156,25 @@
Address pc_after,
Code* interrupt_code,
Code* replacement_code) {
- UNIMPLEMENTED();
ASSERT(InterruptCodeIsPatched(unoptimized_code,
pc_after,
interrupt_code,
replacement_code));
+
+ // Turn the nop into a jump.
+ Instruction* jump = Instruction::Cast(pc_after)->preceding(3);
+ PatchingAssembler patcher(jump, 1);
+ patcher.b(6, pl); // The ok label is 6 instructions later.
+
+ // Replace the call address.
+ Instruction* load = Instruction::Cast(pc_after)->preceding(2);
+ Address interrupt_address_pointer =
+ reinterpret_cast<Address>(load) + load->ImmPCOffset();
+ Memory::uint64_at(interrupt_address_pointer) =
+ reinterpret_cast<uint64_t>(interrupt_code->entry());
+
+ interrupt_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch(
+ unoptimized_code, pc_after - 2 * kInstructionSize, interrupt_code);
}
@@ -141,14 +183,172 @@
Address pc_after,
Code* interrupt_code,
Code* replacement_code) {
- UNIMPLEMENTED();
- return false;
+ Instruction* jump_or_nop = Instruction::Cast(pc_after)->preceding(3);
+ return jump_or_nop->IsNop(Assembler::INTERRUPT_CODE_NOP);
}
#endif
+static int LookupBailoutId(DeoptimizationInputData* data, BailoutId
ast_id) {
+ ByteArray* translations = data->TranslationByteArray();
+ int length = data->DeoptCount();
+ for (int i = 0; i < length; i++) {
+ if (data->AstId(i) == 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(
+ compiled_code_->deoptimization_data());
+ unsigned ast_id = data->OsrAstId()->value();
+
+ int bailout_id = LookupBailoutId(data, BailoutId(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();
+ iterator.Skip(1); // Drop JS frame count.
+ ASSERT(count == 1);
+ USE(count);
+
+ opcode = static_cast<Translation::Opcode>(iterator.Next());
+ USE(opcode);
+ ASSERT(Translation::JS_FRAME == opcode);
+ unsigned node_id = iterator.Next();
+ USE(node_id);
+ ASSERT(node_id == ast_id);
+ int closure_id = iterator.Next();
+ USE(closure_id);
+ ASSERT_EQ(Translation::kSelfLiteralId, closure_id);
+ 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 = compiled_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_));
+ PrintFunctionName();
+ 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_);
+ output_[0]->SetFrameType(StackFrame::JAVA_SCRIPT);
+
+ // 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 = StandardFrameConstants::kCallerPCOffset;
+ ok && i >= StandardFrameConstants::kMarkerOffset;
+ i -= kPointerSize) {
+ uint32_t input_value = input_->GetFrameSlot(input_offset);
+ if (FLAG_trace_osr) {
+ const char* name = "UNKNOWN";
+ switch (i) {
+ case StandardFrameConstants::kCallerPCOffset:
+ name = "caller's pc";
+ break;
+ case StandardFrameConstants::kCallerFPOffset:
+ name = "fp";
+ break;
+ case StandardFrameConstants::kContextOffset:
+ name = "context";
+ break;
+ case StandardFrameConstants::kMarkerOffset:
+ name = "function";
+ break;
+ }
+ PrintF(" [sp + %d] <- 0x%08x ; [sp + %d] (fixed part - %s)\n",
+ output_offset,
+ input_value,
+ input_offset,
+ name);
+ }
+
+ 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<uint64_t>(from_));
+ } else {
+ // Set up 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();
+ uint64_t pc = reinterpret_cast<uint64_t>(
+ compiled_code_->entry() + pc_offset);
+ output_[0]->SetPc(pc);
+ }
+ Code* continuation = isolate_->builtins()->builtin(Builtins::kNotifyOSR);
+ output_[0]->SetContinuation(
+ reinterpret_cast<uint64_t>(continuation->entry()));
+
+ if (FLAG_trace_osr) {
+ PrintF("[on-stack replacement translation %s: 0x%08" V8PRIxPTR " ",
+ ok ? "finished" : "aborted",
+ reinterpret_cast<intptr_t>(function_));
+ PrintFunctionName();
+ PrintF(" => pc=0x%0lx]\n", output_[0]->GetPc());
+ }
}
@@ -244,7 +444,11 @@
masm()->StackPointer(),
kSavedRegistersAreaSize + (1 * kPointerSize));
} else if (type() == OSR) {
- UNIMPLEMENTED();
+ __ Mov(code_object, lr);
+ // Correct one word for bailout id.
+ __ Add(fp_to_sp,
+ masm()->StackPointer(),
+ kSavedRegistersAreaSize + (1 * kPointerSize));
} else {
__ Mov(code_object, lr);
// Correct two words for bailout id and return address.
=======================================
--- /branches/experimental/a64/src/a64/full-codegen-a64.cc Fri Jan 24
14:09:40 2014 UTC
+++ /branches/experimental/a64/src/a64/full-codegen-a64.cc Mon Jan 27
14:32:55 2014 UTC
@@ -366,17 +366,19 @@
InterruptStub stub;
__ CallStub(&stub);
- // TODO(all): Implement OSR/Crankshaft code.
+ // Record a mapping of this PC offset to the OSR id. This is used to
find
+ // the AST id from the unoptimized code in order to use it as a key into
+ // the deoptimization input data found in the optimized code.
+ RecordBackEdge(stmt->OsrEntryId());
EmitProfilingCounterReset();
__ Bind(&ok);
PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
-
- // TODO(all): Implement OSR/Crankshaft code.
- ASM_UNIMPLEMENTED(
- "FullCodeGenerator::EmitBackEdgeBookkeeping "
- "Implement OSR/Crankshaft code.");
+ // Record a mapping of the OSR id to this PC. This is used if the OSR
+ // entry becomes the target of a bailout. We don't expect it to be, but
+ // we want it to work if it is.
+ PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS);
}
=======================================
--- /branches/experimental/a64/src/a64/lithium-a64.cc Mon Jan 27 12:55:12
2014 UTC
+++ /branches/experimental/a64/src/a64/lithium-a64.cc Mon Jan 27 14:32:55
2014 UTC
@@ -1891,7 +1891,10 @@
LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) {
- UNIMPLEMENTED_INSTRUCTION();
+ ASSERT(argument_count_ == 0);
+ allocator_->MarkAsOsrEntry();
+ current_block_->last_environment()->set_ast_id(instr->ast_id());
+ return AssignEnvironment(new(zone()) LOsrEntry);
}
@@ -2465,7 +2468,12 @@
LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) {
- UNIMPLEMENTED_INSTRUCTION();
+ int spill_index = chunk_->GetNextSpillIndex();
+ if (spill_index > LUnallocated::kMaxFixedSlotIndex) {
+ Abort("Too many spill slots needed for OSR");
+ spill_index = 0;
+ }
+ return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index);
}
=======================================
--- /branches/experimental/a64/src/a64/lithium-a64.h Mon Jan 27 12:55:12
2014 UTC
+++ /branches/experimental/a64/src/a64/lithium-a64.h Mon Jan 27 14:32:55
2014 UTC
@@ -194,6 +194,7 @@
V(Typeof) \
V(TypeofIsAndBranch) \
V(Uint32ToDouble) \
+ V(UnknownOSRValue) \
V(ValueOf) \
V(CheckMapValue) \
V(LoadFieldByIndex) \
@@ -323,6 +324,13 @@
};
+class LUnknownOSRValue: public LTemplateInstruction<1, 0, 0> {
+ public:
+ virtual bool HasInterestingComment(LCodeGen* gen) const { return false; }
+ DECLARE_CONCRETE_INSTRUCTION(UnknownOSRValue, "unknown-osr-value")
+};
+
+
template<int I, int T>
class LControlInstruction: public LTemplateInstruction<0, I, T> {
public:
=======================================
--- /branches/experimental/a64/src/a64/lithium-codegen-a64.cc Mon Jan 27
14:06:43 2014 UTC
+++ /branches/experimental/a64/src/a64/lithium-codegen-a64.cc Mon Jan 27
14:32:55 2014 UTC
@@ -1921,6 +1921,12 @@
UNREACHABLE();
}
}
+
+
+void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) {
+ // Record the address of the first unknown OSR value as the place to
enter.
+ if (osr_pc_offset_ == -1) osr_pc_offset_ = masm()->pc_offset();
+}
void LCodeGen::DoCheckMaps(LCheckMaps* instr) {
@@ -4416,7 +4422,19 @@
void LCodeGen::DoOsrEntry(LOsrEntry* instr) {
- ASM_UNIMPLEMENTED_BREAK("DoOsrEntry");
+ // This is a pseudo-instruction that ensures that the environment here is
+ // properly registered for deoptimization and records the assembler's PC
+ // offset.
+ LEnvironment* environment = instr->environment();
+
+ // If the environment were already registered, we would have no way of
+ // backpatching it with the spill slot operands.
+ ASSERT(!environment->HasBeenRegistered());
+ RegisterEnvironmentForDeoptimization(environment,
Safepoint::kNoLazyDeopt);
+
+ // Normally we record the first unknown OSR value as the entrypoint to
the OSR
+ // code, but if there were none, record the entrypoint here.
+ if (osr_pc_offset_ == -1) osr_pc_offset_ = masm()->pc_offset();
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.