Add support for Value Format VALUE_TYPE in the encoded_array_item used for initial values of static field references from a class_def_item

Bug: 7356558
Change-Id: I2bef6de9b41605f17518bbcc72907bf5a92c6c26
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 0373b58..5d89c40 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -373,6 +373,7 @@
 
 
 LIBART_ENUM_OPERATOR_OUT_HEADER_FILES := \
+	src/dex_file.h \
 	src/dex_instruction.h \
 	src/gc/space.h \
 	src/heap.h \
diff --git a/src/class_linker.cc b/src/class_linker.cc
index 0903781..007b8a6 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -2807,7 +2807,8 @@
   const DexFile::ClassDef* dex_class_def = kh.GetClassDef();
   CHECK(dex_class_def != NULL);
   const DexFile& dex_file = kh.GetDexFile();
-  EncodedStaticFieldValueIterator it(dex_file, dex_cache, this, *dex_class_def);
+  EncodedStaticFieldValueIterator it(dex_file, dex_cache, klass->GetClassLoader(),
+                                     this, *dex_class_def);
 
   if (it.HasNext()) {
     // We reordered the fields, so we need to be able to map the field indexes to the right fields.
diff --git a/src/dex_file.cc b/src/dex_file.cc
index d918152..c433f3d 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -901,10 +901,11 @@
 
 EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(const DexFile& dex_file,
                                                                  DexCache* dex_cache,
+                                                                 ClassLoader* class_loader,
                                                                  ClassLinker* linker,
                                                                  const DexFile::ClassDef& class_def)
-    : dex_file_(dex_file), dex_cache_(dex_cache), linker_(linker), array_size_(), pos_(-1),
-      type_(0) {
+    : dex_file_(dex_file), dex_cache_(dex_cache), class_loader_(class_loader), linker_(linker),
+      array_size_(), pos_(-1), type_(kByte) {
   ptr_ = dex_file.GetEncodedStaticFieldValuesArray(class_def);
   if (ptr_ == NULL) {
     array_size_ = 0;
@@ -924,7 +925,7 @@
   byte value_type = *ptr_++;
   byte value_arg = value_type >> kEncodedValueArgShift;
   size_t width = value_arg + 1;  // assume and correct later
-  type_ = value_type & kEncodedValueTypeMask;
+  type_ = static_cast<ValueType>(value_type & kEncodedValueTypeMask);
   switch (type_) {
   case kBoolean:
     jval_.i = (value_arg != 0) ? 1 : 0;
@@ -956,11 +957,11 @@
     break;
   case kString:
   case kType:
-  case kMethod:
-  case kEnum:
     jval_.i = ReadUnsignedInt(ptr_, value_arg, false);
     break;
   case kField:
+  case kMethod:
+  case kEnum:
   case kArray:
   case kAnnotation:
     UNIMPLEMENTED(FATAL) << ": type " << type_;
@@ -991,6 +992,11 @@
       field->SetObject(NULL, resolved);
       break;
     }
+    case kType: {
+      Class* resolved = linker_->ResolveType(dex_file_, jval_.i, dex_cache_, class_loader_);
+      field->SetObject(NULL, resolved);
+      break;
+    }
     default: UNIMPLEMENTED(FATAL) << ": type " << type_;
   }
 }
diff --git a/src/dex_file.h b/src/dex_file.h
index cca3935..f5e62c1 100644
--- a/src/dex_file.h
+++ b/src/dex_file.h
@@ -1115,12 +1115,13 @@
 };
 
 class ClassLinker;
+class ClassLoader;
 class DexCache;
 class Field;
 
 class EncodedStaticFieldValueIterator {
  public:
-  EncodedStaticFieldValueIterator(const DexFile& dex_file, DexCache* dex_cache,
+  EncodedStaticFieldValueIterator(const DexFile& dex_file, DexCache* dex_cache, ClassLoader* class_loader,
                                   ClassLinker* linker, const DexFile::ClassDef& class_def)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
@@ -1131,7 +1132,6 @@
 
   void Next();
 
- private:
   enum ValueType {
     kByte = 0x00,
     kShort = 0x02,
@@ -1151,19 +1151,22 @@
     kBoolean = 0x1f
   };
 
+ private:
   static const byte kEncodedValueTypeMask = 0x1f;  // 0b11111
   static const byte kEncodedValueArgShift = 5;
 
   const DexFile& dex_file_;
   DexCache* dex_cache_;  // dex cache to resolve literal objects
+  ClassLoader* class_loader_;  // ClassLoader to resolve types
   ClassLinker* linker_;  // linker to resolve literal objects
   size_t array_size_;  // size of array
   size_t pos_;  // current position
   const byte* ptr_;  // pointer into encoded data array
-  byte type_;  // type of current encoded value
+  ValueType type_;  // type of current encoded value
   jvalue jval_;  // value of current encoded value
   DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedStaticFieldValueIterator);
 };
+std::ostream& operator<<(std::ostream& os, const EncodedStaticFieldValueIterator::ValueType& code);
 
 class CatchHandlerIterator {
   public: