Reviewers: Rodolph Perfetta (ARM), ulan,

Description:
A64: Fix code patching

- The offset passed to Assembler:B() is in number of instructions, not bytes
- The ok label is actually 6 instructions after the B.pl
- The imm of the load instruction must be relative to the load instruction

[email protected],[email protected]
BUG=none
LOG=y

Please review this at https://codereview.chromium.org/154523002/

SVN Base: https://v8.googlecode.com/svn/branches/experimental/a64

Affected files (+12, -4 lines):
  M src/a64/full-codegen-a64.cc


Index: src/a64/full-codegen-a64.cc
diff --git a/src/a64/full-codegen-a64.cc b/src/a64/full-codegen-a64.cc
index e06c01295cb7b4f62f4192c29b71f77d11915797..88db2c41f8ca0c86071a52addd75834e9d32a049 100644
--- a/src/a64/full-codegen-a64.cc
+++ b/src/a64/full-codegen-a64.cc
@@ -4957,9 +4957,12 @@ void BackEdgeTable::PatchAt(Code* unoptimized_code,
       //  .. .. .. ..       b.pl ok
       //  .. .. .. ..       ldr x16, pc+<interrupt stub address>
       //  .. .. .. ..       blr x16
+      //  ... more instructions.
       //  ok-label
-      // Jump offset is 4 instructions.
-      patcher.b(4 * kInstructionSize, pl);
+      // Jump offset is 6 instructions.
+      ASSERT(Instruction::Cast(branch_address)
+                 ->IsNop(Assembler::INTERRUPT_CODE_NOP));
+      patcher.b(6, pl);
       break;
     case ON_STACK_REPLACEMENT:
     case OSR_AFTER_STACK_CHECK:
@@ -4967,13 +4970,17 @@ void BackEdgeTable::PatchAt(Code* unoptimized_code,
       //  .. .. .. ..       mov x0, x0 (NOP)
       //  .. .. .. ..       ldr x16, pc+<on-stack replacement address>
       //  .. .. .. ..       blr x16
+      ASSERT(Instruction::Cast(branch_address)->IsCondBranchImm());
+      ASSERT(Instruction::Cast(branch_address)->ImmPCOffset() ==
+             6 * kInstructionSize);
       patcher.nop(Assembler::INTERRUPT_CODE_NOP);
       break;
   }

   // Replace the call address.
   Instruction* load = Instruction::Cast(pc)->preceding(2);
-  Address interrupt_address_pointer = pc + load->ImmPCOffset();
+  Address interrupt_address_pointer =
+      reinterpret_cast<Address>(load) + load->ImmPCOffset();
   Memory::uint64_at(interrupt_address_pointer) =
       reinterpret_cast<uint64_t>(replacement_code->entry());

@@ -4993,7 +5000,8 @@ BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState(

   if (jump_or_nop->IsNop(Assembler::INTERRUPT_CODE_NOP)) {
     Instruction* load = Instruction::Cast(pc)->preceding(2);
-    uint64_t entry = Memory::uint64_at(pc + load->ImmPCOffset());
+    uint64_t entry = Memory::uint64_at(reinterpret_cast<Address>(load) +
+                                       load->ImmPCOffset());
     if (entry == reinterpret_cast<uint64_t>(
         isolate->builtins()->OnStackReplacement()->entry())) {
       return ON_STACK_REPLACEMENT;


--
--
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.

Reply via email to