Fix ordering of fields with the same name.

While the Java language doesn't allow multiple fields with
the same name in a single class (excluding fields from super
classes), the bytecode specification permits it and tools
such as proguard actually generate them. Define the order of
these fields by their dex file index and relax the check of
field ordering to permit identical names.

Bug: 18211592

(cherry picked from commit 7a7c1db21782fb922d3ffc5c576117812624ea58)

Change-Id: I8547eeac890b7483c8925367a85382197be9ea7a
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index eb3ee0d..6dbd16d 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5160,8 +5160,10 @@
       // Primitive types differ but sizes match. Arbitrarily order by primitive type.
       return type1 < type2;
     }
-    // same basic group? then sort by string.
-    return strcmp(field1->GetName(), field2->GetName()) < 0;
+    // Same basic group? Then sort by dex field index. This is guaranteed to be sorted
+    // by name and for equal names by type id index.
+    // NOTE: This works also for proxies. Their static fields are assigned appropriate indexes.
+    return field1->GetDexFieldIndex() < field2->GetDexFieldIndex();
   }
 };
 
@@ -5303,7 +5305,9 @@
       }
       if (i != 0) {
         mirror::ArtField* prev_field = fields->Get(i - 1u);
-        CHECK_LT(strcmp(prev_field->GetName(), field->GetName()), 0);
+        // NOTE: The field names can be the same. This is not possible in the Java language
+        // but it's valid Java/dex bytecode and for example proguard can generate such bytecode.
+        CHECK_LE(strcmp(prev_field->GetName(), field->GetName()), 0);
       }
       Primitive::Type type = field->GetTypeAsPrimitiveType();
       bool is_primitive = type != Primitive::kPrimNot;
diff --git a/runtime/oat.cc b/runtime/oat.cc
index a1b99db..4819396 100644
--- a/runtime/oat.cc
+++ b/runtime/oat.cc
@@ -23,7 +23,7 @@
 namespace art {
 
 const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' };
-const uint8_t OatHeader::kOatVersion[] = { '0', '4', '2', '\0' };
+const uint8_t OatHeader::kOatVersion[] = { '0', '4', '3', '\0' };
 
 static size_t ComputeOatHeaderSize(const SafeMap<std::string, std::string>* variable_data) {
   size_t estimate = 0U;