Add missing callee save restore to quick entrypoints.

Added callee save restoration to art_quick_proxy_invoke_handler,
art_quick_resolution_trampoline, art_quick_to_interpreter_bridge.

Bug: 8981901

Change-Id: Iaa5bf862834b49cc48bce4f4ffa34a6797024e6d
diff --git a/runtime/arch/arm/quick_entrypoints_arm.S b/runtime/arch/arm/quick_entrypoints_arm.S
index c98b764..736ce2f 100644
--- a/runtime/arch/arm/quick_entrypoints_arm.S
+++ b/runtime/arch/arm/quick_entrypoints_arm.S
@@ -48,7 +48,7 @@
 
     /*
      * Macro that sets up the callee save frame to conform with
-     * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes non-moving GC.
+     * Runtime::CreateCalleeSaveMethod(kRefsOnly).
      */
 .macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME
     push {r5-r8, r10-r11, lr} @ 7 words of callee saves
@@ -81,7 +81,7 @@
 
     /*
      * Macro that sets up the callee save frame to conform with
-     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
+     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
      */
 .macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
     push {r1-r3, r5-r8, r10-r11, lr}  @ 10 words of callee saves
@@ -1030,12 +1030,13 @@
     mov     r3, sp                 @ pass SP
     blx     artQuickProxyInvokeHandler  @ (Method* proxy method, receiver, Thread*, SP)
     ldr     r2, [r9, #THREAD_EXCEPTION_OFFSET]  @ load Thread::Current()->exception_
-    ldr     lr,  [sp, #44]         @ restore lr
-    add     sp,  #48               @ pop frame
-    .cfi_adjust_cfa_offset -48
+    add     sp, #16                @ skip r1-r3, 4 bytes padding.
+    .cfi_adjust_cfa_offset -16
     cbnz    r2, 1f                 @ success if no exception is pending
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     bx      lr                     @ return on success
 1:
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     DELIVER_PENDING_EXCEPTION
 END art_quick_proxy_invoke_handler
 
@@ -1048,11 +1049,7 @@
     cbz     r0, 1f                 @ is code pointer null? goto exception
     mov     r12, r0
     ldr  r0, [sp, #0]              @ load resolved method in r0
-    ldr  r1, [sp, #8]              @ restore non-callee save r1
-    ldrd r2, [sp, #12]             @ restore non-callee saves r2-r3
-    ldr  lr, [sp, #44]             @ restore lr
-    add  sp, #48                   @ rewind sp
-    .cfi_adjust_cfa_offset -48
+    RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
     bx      r12                    @ tail-call into actual code
 1:
     RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
@@ -1066,12 +1063,13 @@
     mov     r2, sp                 @ pass SP
     blx     artQuickToInterpreterBridge    @ (Method* method, Thread*, SP)
     ldr     r2, [r9, #THREAD_EXCEPTION_OFFSET]  @ load Thread::Current()->exception_
-    ldr     lr,  [sp, #44]         @ restore lr
-    add     sp,  #48               @ pop frame
-    .cfi_adjust_cfa_offset -48
+    add     sp, #16                @ skip r1-r3, 4 bytes padding.
+    .cfi_adjust_cfa_offset -16
     cbnz    r2, 1f                 @ success if no exception is pending
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     bx    lr                       @ return on success
 1:
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     DELIVER_PENDING_EXCEPTION
 END art_quick_to_interpreter_bridge
 
diff --git a/runtime/arch/mips/quick_entrypoints_mips.S b/runtime/arch/mips/quick_entrypoints_mips.S
index 897aaf4..031d13a 100644
--- a/runtime/arch/mips/quick_entrypoints_mips.S
+++ b/runtime/arch/mips/quick_entrypoints_mips.S
@@ -1051,11 +1051,9 @@
     jal     artQuickProxyInvokeHandler  # (Method* proxy method, receiver, Thread*, SP)
     move    $a3, $sp               # pass $sp
     lw      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
-    lw      $gp, 52($sp)           # restore $gp
-    lw      $ra, 60($sp)           # restore $ra
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     bnez    $t0, 1f
-    addiu   $sp, $sp, 64           # pop frame
-    .cfi_adjust_cfa_offset -64
+    nop
     jr      $ra
     nop
 1:
@@ -1069,18 +1067,14 @@
     move    $a2, rSELF             # pass Thread::Current
     jal     artQuickResolutionTrampoline  # (Method* called, receiver, Thread*, SP)
     move    $a3, $sp               # pass $sp
-    lw      $gp, 52($sp)           # restore $gp
-    lw      $ra, 60($sp)           # restore $ra
     beqz    $v0, 1f
     lw      $a0, 0($sp)            # load resolved method to $a0
-    lw      $a1, 4($sp)            # restore non-callee save $a1
-    lw      $a2, 8($sp)            # restore non-callee save $a2
-    lw      $a3, 12($sp)           # restore non-callee save $a3
+    RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
     move    $t9, $v0               # code pointer must be in $t9 to generate the global pointer
     jr      $v0                    # tail call to method
+    nop
 1:
-    addiu   $sp, $sp, 64           # pop frame
-    .cfi_adjust_cfa_offset -64
+    RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
     DELIVER_PENDING_EXCEPTION
 END art_quick_resolution_trampoline
 
@@ -1092,11 +1086,9 @@
     jal     artQuickToInterpreterBridge    # (Method* method, Thread*, SP)
     move    $a2, $sp               # pass $sp
     lw      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
-    lw      $gp, 52($sp)           # restore $gp
-    lw      $ra, 60($sp)           # restore $ra
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     bnez    $t0, 1f
-    addiu   $sp, $sp, 64           # pop frame
-    .cfi_adjust_cfa_offset -64
+    nop
     jr      $ra
     nop
 1:
diff --git a/runtime/arch/x86/quick_entrypoints_x86.S b/runtime/arch/x86/quick_entrypoints_x86.S
index d7e1be8..805f6f4 100644
--- a/runtime/arch/x86/quick_entrypoints_x86.S
+++ b/runtime/arch/x86/quick_entrypoints_x86.S
@@ -1034,8 +1034,9 @@
     movd %eax, %xmm0              // place return value also into floating point return value
     movd %edx, %xmm1
     punpckldq %xmm1, %xmm0
-    addl LITERAL(44), %esp        // pop arguments
-    .cfi_adjust_cfa_offset -44
+    addl LITERAL(16), %esp        // pop arguments
+    .cfi_adjust_cfa_offset -16
+    RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
     RETURN_OR_DELIVER_PENDING_EXCEPTION    // return or deliver exception
 END_FUNCTION art_quick_to_interpreter_bridge