Revert "Revert "ART: Compiler support for invoke-polymorphic.""

This reverts commit 0fb5af1c8287b1ec85c55c306a1c43820c38a337.

This takes us back to the original change and attempts to fix the
issues encountered:

- Adds transition record push/pop around artInvokePolymorphic.
- Changes X86/X64 relocations for MacSDK.
- Implements MIPS entrypoint for art_quick_invoke_polymorphic.
- Corrects size of returned reference in art_quick_invoke_polymorphic
  on ARM.

Bug: 30550796,33191393
Test: art/test/run-test 953
Test: m test-art-run-test

Change-Id: Ib6b93e00b37b9d4ab743a3470ab3d77fe857cda8
diff --git a/runtime/arch/mips/quick_entrypoints_mips.S b/runtime/arch/mips/quick_entrypoints_mips.S
index 964ea56..3acc0a9 100644
--- a/runtime/arch/mips/quick_entrypoints_mips.S
+++ b/runtime/arch/mips/quick_entrypoints_mips.S
@@ -2230,7 +2230,7 @@
   li    $v0, -1         #     return -1;
 
   sll   $v0, $a2, 1     # $a0 += $a2 * 2
-  addu  $a0, $a0, $v0   #  "  "   "  " "
+  addu  $a0, $a0, $v0   #  "  ditto  "
   move  $v0, $a2        # Set i to fromIndex.
 
 1:
@@ -2280,3 +2280,65 @@
   j      $ra
   nop
 END art_quick_string_compareto
+
+.extern artInvokePolymorphic
+ENTRY art_quick_invoke_polymorphic
+    SETUP_SAVE_REFS_AND_ARGS_FRAME
+    move  $a2, rSELF                          # Make $a2 an alias for the current Thread.
+    move  $a3, $sp                            # Make $a3 a pointer to the saved frame context.
+    addiu $sp, $sp, -24                       # Reserve space for JValue result and 4 words for callee.
+    .cfi_adjust_cfa_offset 24
+    sw    $zero, 20($sp)                      # Initialize JValue result.
+    sw    $zero, 16($sp)
+    addiu $a0, $sp, 16                        # Make $a0 a pointer to the JValue result
+    la    $t9, artInvokePolymorphic
+    jalr  $t9                                 # (result, receiver, Thread*, context)
+    nop
+.macro MATCH_RETURN_TYPE c, handler
+    li    $t0, \c
+    beq   $v0, $t0, \handler
+.endm
+    MATCH_RETURN_TYPE 'V', .Lcleanup_and_return
+    MATCH_RETURN_TYPE 'L', .Lstore_int_result
+    MATCH_RETURN_TYPE 'I', .Lstore_int_result
+    MATCH_RETURN_TYPE 'J', .Lstore_long_result
+    MATCH_RETURN_TYPE 'B', .Lstore_int_result
+    MATCH_RETURN_TYPE 'C', .Lstore_char_result
+    MATCH_RETURN_TYPE 'D', .Lstore_double_result
+    MATCH_RETURN_TYPE 'F', .Lstore_float_result
+    MATCH_RETURN_TYPE 'S', .Lstore_int_result
+.purgem MATCH_RETURN_TYPE
+    nop
+    b .Lcleanup_and_return
+    nop
+.Lstore_boolean_result:
+    lbu   $v0, 16($sp)                        # Move byte from JValue result to return value register.
+    b .Lcleanup_and_return
+    nop
+.Lstore_char_result:
+    lhu   $v0, 16($sp)                        # Move char from JValue result to return value register.
+    b .Lcleanup_and_return
+    nop
+.Lstore_double_result:
+.Lstore_float_result:
+    LDu   $f0, $f1, 16, $sp, $t0              # Move double/float from JValue result to return value register.
+    b .Lcleanup_and_return
+    nop
+.Lstore_long_result:
+    lw    $v1, 20($sp)                        # Move upper bits from JValue result to return value register.
+    // Fall-through for lower bits.
+.Lstore_int_result:
+    lw    $v0, 16($sp)                        # Move lower bits from JValue result to return value register.
+    // Fall-through to clean up and return.
+.Lcleanup_and_return:
+    addiu $sp, $sp, 24                        # Remove space for JValue result and the 4 words for the callee.
+    .cfi_adjust_cfa_offset -24
+    lw    $t7, THREAD_EXCEPTION_OFFSET(rSELF) # Load Thread::Current()->exception_
+    RESTORE_SAVE_REFS_AND_ARGS_FRAME
+    bnez  $t7, 1f                             # Success if no exception is pending.
+    nop
+    jalr  $zero, $ra
+    nop
+1:
+    DELIVER_PENDING_EXCEPTION
+END art_quick_invoke_polymorphic