Fix hardcoded offsets in x86 String.indexOf.

Use runtime code that will work for 32 and 64 bit too.  The old code
copied constants from the runtime .S file and is correct for 32 bit code
only.

Change-Id: I668e1d7f2db8186518c358bde0759633be0d7c40
Signed-off-by: Mark Mendell <mark.p.mendell@intel.com>
diff --git a/compiler/dex/quick/x86/target_x86.cc b/compiler/dex/quick/x86/target_x86.cc
index ad5b154..eea7191 100644
--- a/compiler/dex/quick/x86/target_x86.cc
+++ b/compiler/dex/quick/x86/target_x86.cc
@@ -20,6 +20,8 @@
 #include "codegen_x86.h"
 #include "dex/compiler_internals.h"
 #include "dex/quick/mir_to_lir-inl.h"
+#include "mirror/array.h"
+#include "mirror/string.h"
 #include "x86_lir.h"
 
 namespace art {
@@ -944,12 +946,6 @@
   Mir2Lir::InstallLiteralPools();
 }
 
-// Offsets within java.lang.String.
-#define STRING_VALUE_OFFSET 8
-#define STRING_COUNT_OFFSET 12
-#define STRING_OFFSET_OFFSET 20
-#define STRING_DATA_OFFSET 12
-
 /*
  * Fast string.index_of(I) & (II).  Inline check for simple case of char <= 0xffff,
  * otherwise bails to standard library code.
@@ -1001,6 +997,14 @@
   }
 
   // From here down, we know that we are looking for a char that fits in 16 bits.
+  // Location of reference to data array within the String object.
+  int value_offset = mirror::String::ValueOffset().Int32Value();
+  // Location of count within the String object.
+  int count_offset = mirror::String::CountOffset().Int32Value();
+  // Starting offset within data array.
+  int offset_offset = mirror::String::OffsetOffset().Int32Value();
+  // Start of char data with array_.
+  int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
 
   // Character is in EAX.
   // Object pointer is in EDX.
@@ -1010,7 +1014,7 @@
   NewLIR1(kX86Push32R, rDI);
 
   // Compute the number of words to search in to rCX.
-  LoadWordDisp(rDX, STRING_COUNT_OFFSET, rCX);
+  LoadWordDisp(rDX, count_offset, rCX);
   LIR *length_compare = nullptr;
   int start_value = 0;
   if (zero_based) {
@@ -1048,10 +1052,10 @@
   // ECX now contains the count in words to be searched.
 
   // Load the address of the string into EBX.
-  // The string starts at VALUE(String) + 2 * OFFSET(String) + STRING_DATA_OFFSET.
-  LoadWordDisp(rDX, STRING_VALUE_OFFSET, rDI);
-  LoadWordDisp(rDX, STRING_OFFSET_OFFSET, rBX);
-  OpLea(rBX, rDI, rBX, 1, STRING_DATA_OFFSET);
+  // The string starts at VALUE(String) + 2 * OFFSET(String) + DATA_OFFSET.
+  LoadWordDisp(rDX, value_offset, rDI);
+  LoadWordDisp(rDX, offset_offset, rBX);
+  OpLea(rBX, rDI, rBX, 1, data_offset);
 
   // Now compute into EDI where the search will start.
   if (zero_based || rl_start.is_const) {