OSDN Git Service

Fix LinkFieldsComparator.
authorVladimir Marko <vmarko@google.com>
Wed, 12 Nov 2014 17:02:02 +0000 (17:02 +0000)
committerVladimir Marko <vmarko@google.com>
Fri, 14 Nov 2014 18:09:56 +0000 (18:09 +0000)
Define order for primitive types with the same sizes.
Previously, the comparator would consider the fields equal
so the order would depend on std::sort() implementation.
Changing the STL implementation could silently change the
field offsets. (And, unlike std::stable_sort(), the
std::sort() doesn't even need to be deterministic.)

Change-Id: I91fa562f82447606aced64643bea8c70784766b5

runtime/class_linker.cc
runtime/oat.cc

index fb90b91..ea48a32 100644 (file)
@@ -5202,17 +5202,22 @@ struct LinkFieldsComparator {
     Primitive::Type type1 = field1->GetTypeAsPrimitiveType();
     Primitive::Type type2 = field2->GetTypeAsPrimitiveType();
     if (type1 != type2) {
-      bool is_primitive1 = type1 != Primitive::kPrimNot;
-      bool is_primitive2 = type2 != Primitive::kPrimNot;
-      if (type1 != type2) {
-        if (is_primitive1 && is_primitive2) {
-          // Larger primitive types go first.
-          return Primitive::ComponentSize(type1) > Primitive::ComponentSize(type2);
-        } else {
-          // Reference always goes first.
-          return !is_primitive1;
-        }
+      if (type1 == Primitive::kPrimNot) {
+        // Reference always goes first.
+        return true;
+      }
+      if (type2 == Primitive::kPrimNot) {
+        // Reference always goes first.
+        return false;
+      }
+      size_t size1 = Primitive::ComponentSize(type1);
+      size_t size2 = Primitive::ComponentSize(type2);
+      if (size1 != size2) {
+        // Larger primitive types go first.
+        return size1 > size2;
       }
+      // 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;
index 0749c06..b280e04 100644 (file)
@@ -23,7 +23,7 @@
 namespace art {
 
 const uint8_t OatHeader::kOatMagic[] = { 'o', 'a', 't', '\n' };
-const uint8_t OatHeader::kOatVersion[] = { '0', '4', '6', '\0' };
+const uint8_t OatHeader::kOatVersion[] = { '0', '4', '7', '\0' };
 
 static size_t ComputeOatHeaderSize(const SafeMap<std::string, std::string>* variable_data) {
   size_t estimate = 0U;