Better detail messages in ArrayIndexOutOfBoundExceptions.

The RI only includes the index. We've traditionally included nothing. This
patch fixes the portable interpreter to include both the index and the array
length.

Later patches will address the ARM- and x86-specific code.

Change-Id: I9d0e6baacced4e1d33e6cd75965017a38571af67
diff --git a/vm/Exception.c b/vm/Exception.c
index 9ca80e6..7b0a835 100644
--- a/vm/Exception.c
+++ b/vm/Exception.c
@@ -1353,3 +1353,9 @@
         exception = cause;
     }
 }
+
+void dvmThrowAIOOBE(int index, int length)
+{
+    dvmThrowExceptionFmt("Ljava/lang/ArrayIndexOutOfBoundsException;",
+        "index=%d length=%d", index, length);
+}
diff --git a/vm/Exception.h b/vm/Exception.h
index b812f73..559e47f 100644
--- a/vm/Exception.h
+++ b/vm/Exception.h
@@ -36,6 +36,12 @@
 }
 
 /*
+ * Throw an ArrayIndexOutOfBoundsException in the current thread, using the given
+ * index and array length in the detail message.
+ */
+void dvmThrowAIOOBE(int index, int length);
+
+/*
  * Like dvmThrowChainedException, but takes printf-style args for the message.
  */
 void dvmThrowExceptionFmtV(const char* exceptionDescriptor, const char* fmt,
diff --git a/vm/Jni.c b/vm/Jni.c
index 4a8d2b8..3b24e13 100644
--- a/vm/Jni.c
+++ b/vm/Jni.c
@@ -3113,6 +3113,17 @@
     return newArray;
 }
 
+static bool checkArrayElementBounds(ArrayObject* arrayObj, jsize index) {
+    assert(arrayObj != NULL);
+    if (index < 0 || index >= (int) arrayObj->length) {
+        dvmThrowExceptionFmt("Ljava/lang/ArrayIndexOutOfBoundsException;",
+            "%s index=%d length=%d", arrayObj->obj.clazz->descriptor, index,
+            arrayObj->length);
+        return false;
+    }
+    return true;
+}
+
 /*
  * Get one element of an Object array.
  *
@@ -3125,13 +3136,7 @@
 
     ArrayObject* arrayObj = (ArrayObject*) dvmDecodeIndirectRef(env, jarr);
     jobject retval = NULL;
-
-    assert(arrayObj != NULL);
-
-    /* check the array bounds */
-    if (index < 0 || index >= (int) arrayObj->length) {
-        dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
-            arrayObj->obj.clazz->descriptor);
+    if (!checkArrayElementBounds(arrayObj, index)) {
         goto bail;
     }
 
@@ -3152,13 +3157,7 @@
     JNI_ENTER();
 
     ArrayObject* arrayObj = (ArrayObject*) dvmDecodeIndirectRef(env, jarr);
-
-    assert(arrayObj != NULL);
-
-    /* check the array bounds */
-    if (index < 0 || index >= (int) arrayObj->length) {
-        dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
-            arrayObj->obj.clazz->descriptor);
+    if (!checkArrayElementBounds(arrayObj, index)) {
         goto bail;
     }
 
@@ -3244,6 +3243,15 @@
         JNI_EXIT();                                                         \
     }
 
+static void throwArrayRegionOutOfBounds(ArrayObject* arrayObj, jsize start,
+    jsize len, const char* arrayIdentifier)
+{
+    dvmThrowExceptionFmt("Ljava/lang/ArrayIndexOutOfBoundsException;",
+        "%s offset=%d length=%d %s.length=%d",
+        arrayObj->obj.clazz->descriptor, start, len, arrayIdentifier,
+        arrayObj->length);
+}
+
 /*
  * Copy a section of a primitive array to a buffer.
  */
@@ -3256,8 +3264,7 @@
             (ArrayObject*) dvmDecodeIndirectRef(env, jarr);                 \
         _ctype* data = (_ctype*) arrayObj->contents;                        \
         if (start < 0 || len < 0 || start + len > (int) arrayObj->length) { \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                arrayObj->obj.clazz->descriptor);                           \
+            throwArrayRegionOutOfBounds(arrayObj, start, len, "src");       \
         } else {                                                            \
             memcpy(buf, data + start, len * sizeof(_ctype));                \
         }                                                                   \
@@ -3276,8 +3283,7 @@
             (ArrayObject*) dvmDecodeIndirectRef(env, jarr);                 \
         _ctype* data = (_ctype*) arrayObj->contents;                        \
         if (start < 0 || len < 0 || start + len > (int) arrayObj->length) { \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                arrayObj->obj.clazz->descriptor);                           \
+            throwArrayRegionOutOfBounds(arrayObj, start, len, "dst");       \
         } else {                                                            \
             memcpy(data + start, buf, len * sizeof(_ctype));                \
         }                                                                   \
diff --git a/vm/interp/Interp.c b/vm/interp/Interp.c
index 9f44a13..b082ce4 100644
--- a/vm/interp/Interp.c
+++ b/vm/interp/Interp.c
@@ -942,7 +942,7 @@
     size = arrayData[2] | (((u4)arrayData[3]) << 16);
 
     if (size > arrayObj->length) {
-        dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", NULL);
+        dvmThrowAIOOBE(size, arrayObj->length);
         return false;
     }
     copySwappedArrayData(arrayObj->contents, &arrayData[4], size, width);
diff --git a/vm/mterp/c/OP_APUT_OBJECT.c b/vm/mterp/c/OP_APUT_OBJECT.c
index 07e48c6..2b48eac 100644
--- a/vm/mterp/c/OP_APUT_OBJECT.c
+++ b/vm/mterp/c/OP_APUT_OBJECT.c
@@ -13,8 +13,7 @@
         if (!checkForNull((Object*) arrayObj))
             GOTO_exceptionThrown();
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
-                NULL);
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);
             GOTO_exceptionThrown();
         }
         obj = (Object*) GET_REGISTER(vdst);
diff --git a/vm/mterp/c/opcommon.c b/vm/mterp/c/opcommon.c
index 43ee5bc..9c7da89 100644
--- a/vm/mterp/c/opcommon.c
+++ b/vm/mterp/c/opcommon.c
@@ -458,10 +458,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -485,8 +482,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpAsm-armv7-a-neon.S b/vm/mterp/out/InterpAsm-armv7-a-neon.S
index 6340fe5..63ffa8b 100644
--- a/vm/mterp/out/InterpAsm-armv7-a-neon.S
+++ b/vm/mterp/out/InterpAsm-armv7-a-neon.S
@@ -263,7 +263,7 @@
  */
 .macro  SMP_DMB_ST
 #if ANDROID_SMP != 0
-    dmb                                 @ TODO: want "dmb st" here
+    dmb     st
 #else
     /* not SMP */
 #endif
diff --git a/vm/mterp/out/InterpAsm-armv7-a.S b/vm/mterp/out/InterpAsm-armv7-a.S
index 246da07..11dabde 100644
--- a/vm/mterp/out/InterpAsm-armv7-a.S
+++ b/vm/mterp/out/InterpAsm-armv7-a.S
@@ -263,7 +263,7 @@
  */
 .macro  SMP_DMB_ST
 #if ANDROID_SMP != 0
-    dmb                                 @ TODO: want "dmb st" here
+    dmb     st
 #else
     /* not SMP */
 #endif
diff --git a/vm/mterp/out/InterpC-allstubs.c b/vm/mterp/out/InterpC-allstubs.c
index b3e42c5..198d623 100644
--- a/vm/mterp/out/InterpC-allstubs.c
+++ b/vm/mterp/out/InterpC-allstubs.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
@@ -2080,8 +2076,7 @@
         if (!checkForNull((Object*) arrayObj))
             GOTO_exceptionThrown();
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
-                NULL);
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);
             GOTO_exceptionThrown();
         }
         obj = (Object*) GET_REGISTER(vdst);
diff --git a/vm/mterp/out/InterpC-armv4t.c b/vm/mterp/out/InterpC-armv4t.c
index 6184760..9a2df92 100644
--- a/vm/mterp/out/InterpC-armv4t.c
+++ b/vm/mterp/out/InterpC-armv4t.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpC-armv5te-vfp.c b/vm/mterp/out/InterpC-armv5te-vfp.c
index b07eeed..2ccc43c 100644
--- a/vm/mterp/out/InterpC-armv5te-vfp.c
+++ b/vm/mterp/out/InterpC-armv5te-vfp.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpC-armv5te.c b/vm/mterp/out/InterpC-armv5te.c
index 40679ac..fcd2182 100644
--- a/vm/mterp/out/InterpC-armv5te.c
+++ b/vm/mterp/out/InterpC-armv5te.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpC-armv7-a-neon.c b/vm/mterp/out/InterpC-armv7-a-neon.c
index d3f653e..edb59f9 100644
--- a/vm/mterp/out/InterpC-armv7-a-neon.c
+++ b/vm/mterp/out/InterpC-armv7-a-neon.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpC-armv7-a.c b/vm/mterp/out/InterpC-armv7-a.c
index 832f090..80a8320 100644
--- a/vm/mterp/out/InterpC-armv7-a.c
+++ b/vm/mterp/out/InterpC-armv7-a.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpC-portdbg.c b/vm/mterp/out/InterpC-portdbg.c
index 269ccd1..e32a9ce 100644
--- a/vm/mterp/out/InterpC-portdbg.c
+++ b/vm/mterp/out/InterpC-portdbg.c
@@ -989,10 +989,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1016,8 +1013,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
@@ -2436,8 +2432,7 @@
         if (!checkForNull((Object*) arrayObj))
             GOTO_exceptionThrown();
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
-                NULL);
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);
             GOTO_exceptionThrown();
         }
         obj = (Object*) GET_REGISTER(vdst);
diff --git a/vm/mterp/out/InterpC-portstd.c b/vm/mterp/out/InterpC-portstd.c
index ad85a5f..6070ec3 100644
--- a/vm/mterp/out/InterpC-portstd.c
+++ b/vm/mterp/out/InterpC-portstd.c
@@ -980,10 +980,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1007,8 +1004,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
@@ -2186,8 +2182,7 @@
         if (!checkForNull((Object*) arrayObj))
             GOTO_exceptionThrown();
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;",
-                NULL);
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);
             GOTO_exceptionThrown();
         }
         obj = (Object*) GET_REGISTER(vdst);
diff --git a/vm/mterp/out/InterpC-x86-atom.c b/vm/mterp/out/InterpC-x86-atom.c
index d192ddf..587dcd5 100644
--- a/vm/mterp/out/InterpC-x86-atom.c
+++ b/vm/mterp/out/InterpC-x86-atom.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\
diff --git a/vm/mterp/out/InterpC-x86.c b/vm/mterp/out/InterpC-x86.c
index dc1e06d..8a7a1d5 100644
--- a/vm/mterp/out/InterpC-x86.c
+++ b/vm/mterp/out/InterpC-x86.c
@@ -1003,10 +1003,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            LOGV("Invalid array access: %p %d (len=%d)\n",                  \
-                arrayObj, vsrc2, arrayObj->length);                         \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         SET_REGISTER##_regsize(vdst,                                        \
@@ -1030,8 +1027,7 @@
         if (!checkForNull((Object*) arrayObj))                              \
             GOTO_exceptionThrown();                                         \
         if (GET_REGISTER(vsrc2) >= arrayObj->length) {                      \
-            dvmThrowException("Ljava/lang/ArrayIndexOutOfBoundsException;", \
-                NULL);                                                      \
+            dvmThrowAIOOBE(GET_REGISTER(vsrc2), arrayObj->length);          \
             GOTO_exceptionThrown();                                         \
         }                                                                   \
         ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\