x86: Improve ArrayIndexOutOfBoundsException detail messages

issue 3122084

Changes the x86 interpreter to use the new dvmThrowAIOOBE call
for out of bounds exception w/ more useful info.

Change-Id: Ic196cc99c561bf31953993a6928f574e5c5bf831
diff --git a/vm/mterp/out/InterpAsm-x86.S b/vm/mterp/out/InterpAsm-x86.S
index aada215..c2ce035 100644
--- a/vm/mterp/out/InterpAsm-x86.S
+++ b/vm/mterp/out/InterpAsm-x86.S
@@ -1939,7 +1939,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     movl     offArrayObject_contents(%eax,%ecx,4),%eax
 .LOP_AGET_finish:
     FETCH_INST_OPCODE 2 %edx
@@ -1964,7 +1966,9 @@
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
     jb        .LOP_AGET_WIDE_finish        # index < length, OK
-    jmp       common_errArrayIndex      # index >= length, bail
+    jmp       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
 
 /* ------------------------------ */
     .balign 64
@@ -1984,7 +1988,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     movl     offArrayObject_contents(%eax,%ecx,4),%eax
 .LOP_AGET_OBJECT_finish:
     FETCH_INST_OPCODE 2 %edx
@@ -2011,7 +2017,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     movzbl     offArrayObject_contents(%eax,%ecx,1),%eax
 .LOP_AGET_BOOLEAN_finish:
     FETCH_INST_OPCODE 2 %edx
@@ -2038,7 +2046,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     movsbl     offArrayObject_contents(%eax,%ecx,1),%eax
 .LOP_AGET_BYTE_finish:
     FETCH_INST_OPCODE 2 %edx
@@ -2065,7 +2075,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     movzwl     offArrayObject_contents(%eax,%ecx,2),%eax
 .LOP_AGET_CHAR_finish:
     FETCH_INST_OPCODE 2 %edx
@@ -2092,7 +2104,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     movswl     offArrayObject_contents(%eax,%ecx,2),%eax
 .LOP_AGET_SHORT_finish:
     FETCH_INST_OPCODE 2 %edx
@@ -2118,7 +2132,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
     leal      offArrayObject_contents(%eax,%ecx,4),%eax
 .LOP_APUT_finish:
     GET_VREG_R  %ecx rINST
@@ -2144,7 +2160,9 @@
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
     jb        .LOP_APUT_WIDE_finish        # index < length, OK
-    jmp       common_errArrayIndex      # index >= length, bail
+    jmp       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
 
 /* ------------------------------ */
     .balign 64
@@ -2165,7 +2183,9 @@
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
     jb        .LOP_APUT_OBJECT_continue
-    jmp       common_errArrayIndex      # index >= length, bail
+    jmp       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
 
 /* ------------------------------ */
     .balign 64
@@ -2185,7 +2205,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
     leal      offArrayObject_contents(%eax,%ecx,1),%eax
 .LOP_APUT_BOOLEAN_finish:
     GET_VREG_R  %ecx rINST
@@ -2213,7 +2235,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
     leal      offArrayObject_contents(%eax,%ecx,1),%eax
 .LOP_APUT_BYTE_finish:
     GET_VREG_R  %ecx rINST
@@ -2241,7 +2265,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
     leal      offArrayObject_contents(%eax,%ecx,2),%eax
 .LOP_APUT_CHAR_finish:
     GET_VREG_R  %ecx rINST
@@ -2269,7 +2295,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
     leal      offArrayObject_contents(%eax,%ecx,2),%eax
 .LOP_APUT_SHORT_finish:
     GET_VREG_R  %ecx rINST
@@ -9508,14 +9536,16 @@
 
 /*
  * Array index exceeds max.
+ * On entry:
+ *    eax <- array object
+ *    ecx <- index
  */
 common_errArrayIndex:
     EXPORT_PC
-    movl    $.LstrArrayIndexException,%eax
-    movl    %eax,OUT_ARG0(%esp)
-    xorl    %eax,%eax
+    movl    offArrayObject_length(%eax), %eax
+    movl    %ecx,OUT_ARG0(%esp)
     movl    %eax,OUT_ARG1(%esp)
-    call    dvmThrowException
+    call    dvmThrowAIOOBE        # dvmThrowAIOO(index, length)
     jmp     common_exceptionThrown
 /*
  * Invalid array value.
@@ -9562,8 +9592,6 @@
     .asciz  "Ljava/lang/ArithmeticException;"
 .LstrDivideByZero:
     .asciz  "divide by zero"
-.LstrArrayIndexException:
-    .asciz  "Ljava/lang/ArrayIndexOutOfBoundsException;"
 .LstrArrayStoreException:
     .asciz  "Ljava/lang/ArrayStoreException;"
 .LstrNegativeArraySizeException:
diff --git a/vm/mterp/x86-atom/TODO.txt b/vm/mterp/x86-atom/TODO.txt
index 91a9522..0d50d2e 100644
--- a/vm/mterp/x86-atom/TODO.txt
+++ b/vm/mterp/x86-atom/TODO.txt
@@ -11,6 +11,7 @@
 
 (md) Correct OP_MONITOR_EXIT (need to adjust PC before throw)
 (md) OP_THROW needs to export the PC
+(md) Use dvmThrowAIOOBE(index, lentgh) for array bounds error.
 
 (lo) Implement OP_BREAKPOINT
 (lo) Implement OP_EXECUTE_INLINE_RANGE
diff --git a/vm/mterp/x86/OP_AGET.S b/vm/mterp/x86/OP_AGET.S
index adcd403..65ff582 100644
--- a/vm/mterp/x86/OP_AGET.S
+++ b/vm/mterp/x86/OP_AGET.S
@@ -13,7 +13,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
     $load     offArrayObject_contents(%eax,%ecx,$shift),%eax
 .L${opcode}_finish:
     FETCH_INST_OPCODE 2 %edx
diff --git a/vm/mterp/x86/OP_AGET_WIDE.S b/vm/mterp/x86/OP_AGET_WIDE.S
index 008aab1..96d1c89 100644
--- a/vm/mterp/x86/OP_AGET_WIDE.S
+++ b/vm/mterp/x86/OP_AGET_WIDE.S
@@ -12,7 +12,9 @@
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
     jb        .L${opcode}_finish        # index < length, OK
-    jmp       common_errArrayIndex      # index >= length, bail
+    jmp       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
 %break
 
 .L${opcode}_finish:
diff --git a/vm/mterp/x86/OP_APUT.S b/vm/mterp/x86/OP_APUT.S
index 93be490..797b692 100644
--- a/vm/mterp/x86/OP_APUT.S
+++ b/vm/mterp/x86/OP_APUT.S
@@ -13,7 +13,9 @@
     testl     %eax,%eax                 # null array object?
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
-    jae       common_errArrayIndex      # index >= length, bail
+    jae       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
     leal      offArrayObject_contents(%eax,%ecx,$shift),%eax
 .L${opcode}_finish:
     GET_VREG_R  %ecx rINST
diff --git a/vm/mterp/x86/OP_APUT_OBJECT.S b/vm/mterp/x86/OP_APUT_OBJECT.S
index f9af064..3476433 100644
--- a/vm/mterp/x86/OP_APUT_OBJECT.S
+++ b/vm/mterp/x86/OP_APUT_OBJECT.S
@@ -14,7 +14,9 @@
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
     jb        .L${opcode}_continue
-    jmp       common_errArrayIndex      # index >= length, bail
+    jmp       common_errArrayIndex      # index >= length, bail.  Expects
+                                        #    arrayObj in eax
+                                        #    index in ecx
 %break
 
     /* On entry:
diff --git a/vm/mterp/x86/OP_APUT_WIDE.S b/vm/mterp/x86/OP_APUT_WIDE.S
index 95b7151..3647c3e 100644
--- a/vm/mterp/x86/OP_APUT_WIDE.S
+++ b/vm/mterp/x86/OP_APUT_WIDE.S
@@ -12,7 +12,9 @@
     je        common_errNullObject      # bail if so
     cmpl      offArrayObject_length(%eax),%ecx
     jb        .L${opcode}_finish        # index < length, OK
-    jmp       common_errArrayIndex      # index >= length, bail
+    jmp       common_errArrayIndex      # index >= length, bail.  Expects:
+                                        #   arrayObj in eax
+                                        #   index in ecx
 %break
 
 .L${opcode}_finish:
diff --git a/vm/mterp/x86/footer.S b/vm/mterp/x86/footer.S
index cbb86e1..fb6df27 100644
--- a/vm/mterp/x86/footer.S
+++ b/vm/mterp/x86/footer.S
@@ -440,14 +440,16 @@
 
 /*
  * Array index exceeds max.
+ * On entry:
+ *    eax <- array object
+ *    ecx <- index
  */
 common_errArrayIndex:
     EXPORT_PC
-    movl    $$.LstrArrayIndexException,%eax
-    movl    %eax,OUT_ARG0(%esp)
-    xorl    %eax,%eax
+    movl    offArrayObject_length(%eax), %eax
+    movl    %ecx,OUT_ARG0(%esp)
     movl    %eax,OUT_ARG1(%esp)
-    call    dvmThrowException
+    call    dvmThrowAIOOBE        # dvmThrowAIOO(index, length)
     jmp     common_exceptionThrown
 /*
  * Invalid array value.
@@ -494,8 +496,6 @@
     .asciz  "Ljava/lang/ArithmeticException;"
 .LstrDivideByZero:
     .asciz  "divide by zero"
-.LstrArrayIndexException:
-    .asciz  "Ljava/lang/ArrayIndexOutOfBoundsException;"
 .LstrArrayStoreException:
     .asciz  "Ljava/lang/ArrayStoreException;"
 .LstrNegativeArraySizeException: