Reviewers: akos.palfi.imgtec, dusmil.imgtec,

Message:
Tested to not break anything under existing tests, but I can't repro the
code-age problem, so this is a swag at that. PTAL. For testing only, do not
commit.

Description:
MIPS: Avoid use of a0 as return address in jalr.

Trial fix for code-aging issue.

BUG=

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+14, -6 lines):
  M src/mips/builtins-mips.cc
  M src/mips/codegen-mips.cc
  M src/mips/macro-assembler-mips.cc


Index: src/mips/builtins-mips.cc
diff --git a/src/mips/builtins-mips.cc b/src/mips/builtins-mips.cc
index b5a67b47dc59892991d1f785619f6191d77b8631..20b19295eb94ed8e46c2deb4d9581cc54c132a1a 100644
--- a/src/mips/builtins-mips.cc
+++ b/src/mips/builtins-mips.cc
@@ -1024,9 +1024,12 @@ static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) { // internal frame to make the code faster, since we shouldn't have to do stack
   // crawls in MakeCodeYoung. This seems a bit fragile.

-  // Set a0 to point to the head of the PlatformCodeAge sequence.
+ // Set a0 to point to the head of the PlatformCodeAge sequence, using ret adr.
+  __ mov(a0, ra);
   __ Subu(a0, a0,
       Operand(kNoCodeAgeSequenceLength - Assembler::kInstrSize));
+  // Restore the original return address of the function
+  __ mov(ra, at);

// The following registers must be saved and restored when calling through to
   // the runtime:
@@ -1063,9 +1066,12 @@ void Builtins::Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm) { // save/restore the registers without worrying about which of them contain
   // pointers.

-  // Set a0 to point to the head of the PlatformCodeAge sequence.
+ // Set a0 to point to the head of the PlatformCodeAge sequence, using ret adr.
+  __ mov(a0, ra);
   __ Subu(a0, a0,
       Operand(kNoCodeAgeSequenceLength - Assembler::kInstrSize));
+  // Restore the original return address of the function
+  __ mov(ra, at);

// The following registers must be saved and restored when calling through to
   // the runtime:
Index: src/mips/codegen-mips.cc
diff --git a/src/mips/codegen-mips.cc b/src/mips/codegen-mips.cc
index 23780d8b2597679c747b7eefa78bbcd34e4685de..956407bc578b7cc3633aa9282e0b8ba504e0dae3 100644
--- a/src/mips/codegen-mips.cc
+++ b/src/mips/codegen-mips.cc
@@ -1252,8 +1252,9 @@ void Code::PatchPlatformCodeAge(Isolate* isolate,
         t9,
         Operand(reinterpret_cast<uint32_t>(stub->instruction_start())),
         CONSTANT_SIZE);
-    patcher.masm()->nop();  // Prevent jalr to jal optimization.
-    patcher.masm()->jalr(t9, a0);
+    // Save the function's original return address.
+ patcher.masm()->mov(at, ra); // This also prevents jalr->jal optimization.
+    patcher.masm()->jalr(t9);
     patcher.masm()->nop();  // Branch delay slot nop.
     patcher.masm()->nop();  // Pad the empty space.
   }
Index: src/mips/macro-assembler-mips.cc
diff --git a/src/mips/macro-assembler-mips.cc b/src/mips/macro-assembler-mips.cc index f554b0c1efc84757d5edc7bd2923272dc1522598..8ca73e60e6cc9ab26736ffd5484e3e553a441853 100644
--- a/src/mips/macro-assembler-mips.cc
+++ b/src/mips/macro-assembler-mips.cc
@@ -4892,8 +4892,9 @@ void MacroAssembler::Prologue(bool code_pre_aging) {
     li(t9,
        Operand(reinterpret_cast<uint32_t>(stub->instruction_start())),
        CONSTANT_SIZE);
-    nop();  // Prevent jalr to jal optimization.
-    jalr(t9, a0);
+    // Save the function's original return address.
+    mov(at, ra);  // This also prevents jalr->jal optimization.
+    jalr(t9);
     nop();  // Branch delay slot nop.
     nop();  // Pad the empty space.
   } else {


--
--
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/d/optout.

Reply via email to