Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: src/a64/deoptimizer-a64.cc

Issue 145713002: A64: Implement LOsrEntry and LUnknownOSRValue (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: updates Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/a64/builtins-a64.cc ('k') | src/a64/full-codegen-a64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/a64/deoptimizer-a64.cc
diff --git a/src/a64/deoptimizer-a64.cc b/src/a64/deoptimizer-a64.cc
index a335ecef44eea297ffff42f553a3556ea5d5ecd7..1356f3090277eacacf997c1ec1d61cc3ca61933a 100644
--- a/src/a64/deoptimizer-a64.cc
+++ b/src/a64/deoptimizer-a64.cc
@@ -112,15 +112,43 @@ void Deoptimizer::DeoptimizeFunctionWithPreparedFunctionList(
}
+// 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 @@ void Deoptimizer::RevertInterruptCodeAt(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 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 @@ bool Deoptimizer::InterruptCodeIsPatched(Code* unoptimized_code,
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 @@ void Deoptimizer::EntryGenerator::Generate() {
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.
« no previous file with comments | « src/a64/builtins-a64.cc ('k') | src/a64/full-codegen-a64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698