Remove FieldHelper.

Change-Id: I2d74e2d5b3c35a691c95339de0db9361847fca11
diff --git a/runtime/Android.mk b/runtime/Android.mk
index 087c0ea..d4548a2 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -42,7 +42,6 @@
   dex_file_verifier.cc \
   dex_instruction.cc \
   elf_file.cc \
-  field_helper.cc \
   gc/allocator/dlmalloc.cc \
   gc/allocator/rosalloc.cc \
   gc/accounting/card_table.cc \
diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc
index fe5b765..e45d3a3 100644
--- a/runtime/check_jni.cc
+++ b/runtime/check_jni.cc
@@ -24,7 +24,6 @@
 #include "class_linker.h"
 #include "class_linker-inl.h"
 #include "dex_file-inl.h"
-#include "field_helper.h"
 #include "gc/space/space.h"
 #include "java_vm_ext.h"
 #include "jni_internal.h"
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 99d0746..ac078aa 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -23,7 +23,6 @@
 #include "common_runtime_test.h"
 #include "dex_file.h"
 #include "entrypoints/entrypoint_utils-inl.h"
-#include "field_helper.h"
 #include "gc/heap.h"
 #include "mirror/art_field-inl.h"
 #include "mirror/art_method.h"
@@ -178,9 +177,7 @@
     EXPECT_TRUE(field->GetClass() != nullptr);
     EXPECT_EQ(klass, field->GetDeclaringClass());
     EXPECT_TRUE(field->GetName() != nullptr);
-    StackHandleScope<1> hs(Thread::Current());
-    FieldHelper fh(hs.NewHandle(field));
-    EXPECT_TRUE(fh.GetType() != nullptr);
+    EXPECT_TRUE(field->GetType(true) != nullptr);
   }
 
   void AssertClass(const std::string& descriptor, Handle<mirror::Class> klass)
@@ -286,8 +283,7 @@
     for (size_t i = 0; i < klass->NumInstanceFields(); i++) {
       mirror::ArtField* field = klass->GetInstanceField(i);
       fhandle.Assign(field);
-      FieldHelper fh(fhandle);
-      mirror::Class* field_type = fh.GetType();
+      mirror::Class* field_type = fhandle->GetType(true);
       ASSERT_TRUE(field_type != nullptr);
       if (!field->IsPrimitiveType()) {
         ASSERT_TRUE(!field_type->IsPrimitive());
@@ -295,7 +291,7 @@
         if (current_ref_offset.Uint32Value() == end_ref_offset.Uint32Value()) {
           // While Reference.referent is not primitive, the ClassLinker
           // treats it as such so that the garbage collector won't scan it.
-          EXPECT_EQ(PrettyField(fh.GetField()),
+          EXPECT_EQ(PrettyField(fhandle.Get()),
                     "java.lang.Object java.lang.ref.Reference.referent");
         } else {
           current_ref_offset = MemberOffset(current_ref_offset.Uint32Value() +
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 49b132d..dae1566 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -25,7 +25,6 @@
 #include "class_linker-inl.h"
 #include "dex_file-inl.h"
 #include "dex_instruction.h"
-#include "field_helper.h"
 #include "gc/accounting/card_table-inl.h"
 #include "gc/space/large_object_space.h"
 #include "gc/space/space-inl.h"
@@ -1924,7 +1923,7 @@
         HandleWrapper<mirror::Object> h_v(hs.NewHandleWrapper(&v));
         HandleWrapper<mirror::ArtField> h_f(hs.NewHandleWrapper(&f));
         HandleWrapper<mirror::Object> h_o(hs.NewHandleWrapper(&o));
-        field_type = FieldHelper(h_f).GetType();
+        field_type = h_f->GetType(true);
       }
       if (!field_type->IsAssignableFrom(v->GetClass())) {
         return JDWP::ERR_INVALID_OBJECT;
diff --git a/runtime/field_helper.cc b/runtime/field_helper.cc
deleted file mode 100644
index 5c85c46..0000000
--- a/runtime/field_helper.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "field_helper.h"
-
-#include "class_linker-inl.h"
-#include "dex_file.h"
-#include "mirror/dex_cache.h"
-#include "runtime.h"
-#include "thread-inl.h"
-
-namespace art {
-
-mirror::Class* FieldHelper::GetType(bool resolve) {
-  uint32_t field_index = field_->GetDexFieldIndex();
-  if (UNLIKELY(field_->GetDeclaringClass()->IsProxyClass())) {
-    return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(),
-                                                                 field_->GetTypeDescriptor());
-  }
-  const DexFile* dex_file = field_->GetDexFile();
-  const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index);
-  mirror::Class* type = field_->GetDexCache()->GetResolvedType(field_id.type_idx_);
-  if (resolve && (type == nullptr)) {
-    type = Runtime::Current()->GetClassLinker()->ResolveType(field_id.type_idx_, field_.Get());
-    CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
-  }
-  return type;
-}
-
-const char* FieldHelper::GetDeclaringClassDescriptor() {
-  return field_->GetDeclaringClass()->GetDescriptor(&declaring_class_descriptor_);
-}
-
-}  // namespace art
diff --git a/runtime/field_helper.h b/runtime/field_helper.h
deleted file mode 100644
index 8097025..0000000
--- a/runtime/field_helper.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ART_RUNTIME_FIELD_HELPER_H_
-#define ART_RUNTIME_FIELD_HELPER_H_
-
-#include "base/macros.h"
-#include "handle.h"
-#include "mirror/art_field.h"
-
-namespace art {
-
-class FieldHelper {
- public:
-  explicit FieldHelper(Handle<mirror::ArtField> f) : field_(f) {}
-
-  mirror::ArtField* GetField() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    return field_.Get();
-  }
-
-  mirror::Class* GetType(bool resolve = true) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
-  // The returned const char* is only guaranteed to be valid for the lifetime of the FieldHelper.
-  // If you need it longer, copy it into a std::string.
-  const char* GetDeclaringClassDescriptor() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
- private:
-  Handle<mirror::ArtField> field_;
-  std::string declaring_class_descriptor_;
-
-  DISALLOW_COPY_AND_ASSIGN(FieldHelper);
-};
-
-}  // namespace art
-
-#endif  // ART_RUNTIME_FIELD_HELPER_H_
diff --git a/runtime/interpreter/interpreter_common.cc b/runtime/interpreter/interpreter_common.cc
index 5340bee..041650f 100644
--- a/runtime/interpreter/interpreter_common.cc
+++ b/runtime/interpreter/interpreter_common.cc
@@ -16,7 +16,6 @@
 
 #include "interpreter_common.h"
 
-#include "field_helper.h"
 #include "mirror/array-inl.h"
 
 namespace art {
@@ -267,8 +266,7 @@
           HandleWrapper<mirror::ArtField> h_f(hs.NewHandleWrapper(&f));
           HandleWrapper<mirror::Object> h_reg(hs.NewHandleWrapper(&reg));
           HandleWrapper<mirror::Object> h_obj(hs.NewHandleWrapper(&obj));
-          FieldHelper fh(h_f);
-          field_class = fh.GetType();
+          field_class = h_f->GetType(true);
         }
         if (!reg->VerifierInstanceOf(field_class)) {
           // This should never happen.
diff --git a/runtime/mirror/art_field-inl.h b/runtime/mirror/art_field-inl.h
index 03425cc..2b406bd 100644
--- a/runtime/mirror/art_field-inl.h
+++ b/runtime/mirror/art_field-inl.h
@@ -20,6 +20,7 @@
 #include "art_field.h"
 
 #include "base/logging.h"
+#include "class_linker.h"
 #include "dex_cache.h"
 #include "gc/accounting/card_table-inl.h"
 #include "jvalue.h"
@@ -289,6 +290,22 @@
   return GetTypeAsPrimitiveType() != Primitive::kPrimNot;
 }
 
+inline Class* ArtField::GetType(bool resolve) {
+  uint32_t field_index = GetDexFieldIndex();
+  if (UNLIKELY(GetDeclaringClass()->IsProxyClass())) {
+    return Runtime::Current()->GetClassLinker()->FindSystemClass(Thread::Current(),
+                                                                 GetTypeDescriptor());
+  }
+  const DexFile* dex_file = GetDexFile();
+  const DexFile::FieldId& field_id = dex_file->GetFieldId(field_index);
+  mirror::Class* type = GetDexCache()->GetResolvedType(field_id.type_idx_);
+  if (resolve && (type == nullptr)) {
+    type = Runtime::Current()->GetClassLinker()->ResolveType(field_id.type_idx_, this);
+    CHECK(type != nullptr || Thread::Current()->IsExceptionPending());
+  }
+  return type;
+}
+
 inline size_t ArtField::FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
   return Primitive::ComponentSize(GetTypeAsPrimitiveType());
 }
diff --git a/runtime/mirror/art_field.h b/runtime/mirror/art_field.h
index 50299b6..a1d8844 100644
--- a/runtime/mirror/art_field.h
+++ b/runtime/mirror/art_field.h
@@ -161,6 +161,8 @@
 
   bool IsPrimitiveType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
+  Class* GetType(bool resolve) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
   size_t FieldSize() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   mirror::DexCache* GetDexCache() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
diff --git a/runtime/mirror/object.cc b/runtime/mirror/object.cc
index fa1f226..65d6ade 100644
--- a/runtime/mirror/object.cc
+++ b/runtime/mirror/object.cc
@@ -24,7 +24,6 @@
 #include "class.h"
 #include "class-inl.h"
 #include "class_linker-inl.h"
-#include "field_helper.h"
 #include "gc/accounting/card_table-inl.h"
 #include "gc/heap.h"
 #include "iftable-inl.h"
@@ -202,12 +201,16 @@
     if (fields != NULL) {
       size_t num_ifields = fields->GetLength();
       for (size_t i = 0; i < num_ifields; ++i) {
+        StackHandleScope<1> hs(Thread::Current());
+        Handle<Object> h_object(hs.NewHandle(new_value));
         ArtField* field = fields->Get(i);
         if (field->GetOffset().Int32Value() == field_offset.Int32Value()) {
           CHECK_NE(field->GetTypeAsPrimitiveType(), Primitive::kPrimNot);
-          StackHandleScope<1> hs(Thread::Current());
-          FieldHelper fh(hs.NewHandle(field));
-          CHECK(fh.GetType()->IsAssignableFrom(new_value->GetClass()));
+          // TODO: resolve the field type for moving GC.
+          mirror::Class* field_type = field->GetType(!kMovingCollector);
+          if (field_type != nullptr) {
+            CHECK(field_type->IsAssignableFrom(new_value->GetClass()));
+          }
           return;
         }
       }
@@ -225,9 +228,11 @@
         ArtField* field = fields->Get(i);
         if (field->GetOffset().Int32Value() == field_offset.Int32Value()) {
           CHECK_NE(field->GetTypeAsPrimitiveType(), Primitive::kPrimNot);
-          StackHandleScope<1> hs(Thread::Current());
-          FieldHelper fh(hs.NewHandle(field));
-          CHECK(fh.GetType()->IsAssignableFrom(new_value->GetClass()));
+          // TODO: resolve the field type for moving GC.
+          mirror::Class* field_type = field->GetType(!kMovingCollector);
+          if (field_type != nullptr) {
+            CHECK(field_type->IsAssignableFrom(new_value->GetClass()));
+          }
           return;
         }
       }
@@ -235,6 +240,7 @@
   }
   LOG(FATAL) << "Failed to find field for assignment to " << reinterpret_cast<void*>(this)
       << " of type " << PrettyDescriptor(c) << " at offset " << field_offset;
+  UNREACHABLE();
 }
 
 }  // namespace mirror
diff --git a/runtime/native/java_lang_reflect_Field.cc b/runtime/native/java_lang_reflect_Field.cc
index a042620..2cebf02 100644
--- a/runtime/native/java_lang_reflect_Field.cc
+++ b/runtime/native/java_lang_reflect_Field.cc
@@ -20,7 +20,6 @@
 #include "class_linker-inl.h"
 #include "common_throws.h"
 #include "dex_file-inl.h"
-#include "field_helper.h"
 #include "jni_internal.h"
 #include "mirror/art_field-inl.h"
 #include "mirror/art_method-inl.h"
@@ -294,9 +293,8 @@
     StackHandleScope<2> hs(soa.Self());
     HandleWrapper<mirror::Object> h_o(hs.NewHandleWrapper(&o));
     HandleWrapper<mirror::ArtField> h_f(hs.NewHandleWrapper(&f));
-    FieldHelper fh(h_f);
     // May cause resolution.
-    field_type = fh.GetType(true);
+    field_type = h_f->GetType(true);
     if (field_type == nullptr) {
       DCHECK(soa.Self()->IsExceptionPending());
       return;
diff --git a/runtime/proxy_test.cc b/runtime/proxy_test.cc
index 1eded62..3260992 100644
--- a/runtime/proxy_test.cc
+++ b/runtime/proxy_test.cc
@@ -18,7 +18,6 @@
 #include <vector>
 
 #include "common_compiler_test.h"
-#include "field_helper.h"
 #include "mirror/art_field-inl.h"
 #include "scoped_thread_state_change.h"
 
@@ -184,21 +183,20 @@
 
   // Test "Class[] interfaces" field.
   MutableHandle<mirror::ArtField> fhandle = hs.NewHandle(static_fields->Get(0));
-  FieldHelper fh(fhandle);
-  EXPECT_EQ("interfaces", std::string(fh.GetField()->GetName()));
-  EXPECT_EQ("[Ljava/lang/Class;", std::string(fh.GetField()->GetTypeDescriptor()));
-  EXPECT_EQ(interfacesFieldClass.Get(), fh.GetType());
-  EXPECT_EQ("L$Proxy1234;", std::string(fh.GetDeclaringClassDescriptor()));
-  EXPECT_FALSE(fh.GetField()->IsPrimitiveType());
+  EXPECT_EQ("interfaces", std::string(fhandle->GetName()));
+  EXPECT_EQ("[Ljava/lang/Class;", std::string(fhandle->GetTypeDescriptor()));
+  EXPECT_EQ(interfacesFieldClass.Get(), fhandle->GetType(true));
+  std::string temp;
+  EXPECT_EQ("L$Proxy1234;", std::string(fhandle->GetDeclaringClass()->GetDescriptor(&temp)));
+  EXPECT_FALSE(fhandle->IsPrimitiveType());
 
   // Test "Class[][] throws" field.
   fhandle.Assign(static_fields->Get(1));
-  FieldHelper fh2(fhandle);
-  EXPECT_EQ("throws", std::string(fh2.GetField()->GetName()));
-  EXPECT_EQ("[[Ljava/lang/Class;", std::string(fh2.GetField()->GetTypeDescriptor()));
-  EXPECT_EQ(throwsFieldClass.Get(), fh2.GetType());
-  EXPECT_EQ("L$Proxy1234;", std::string(fh2.GetDeclaringClassDescriptor()));
-  EXPECT_FALSE(fh2.GetField()->IsPrimitiveType());
+  EXPECT_EQ("throws", std::string(fhandle->GetName()));
+  EXPECT_EQ("[[Ljava/lang/Class;", std::string(fhandle->GetTypeDescriptor()));
+  EXPECT_EQ(throwsFieldClass.Get(), fhandle->GetType(true));
+  EXPECT_EQ("L$Proxy1234;", std::string(fhandle->GetDeclaringClass()->GetDescriptor(&temp)));
+  EXPECT_FALSE(fhandle->IsPrimitiveType());
 }
 
 }  // namespace art
diff --git a/runtime/utils.cc b/runtime/utils.cc
index ad46be6..1211547 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -28,7 +28,6 @@
 #include "base/stl_util.h"
 #include "base/unix_file/fd_file.h"
 #include "dex_file-inl.h"
-#include "field_helper.h"
 #include "mirror/art_field-inl.h"
 #include "mirror/art_method-inl.h"
 #include "mirror/class-inl.h"
@@ -324,8 +323,8 @@
     result += PrettyDescriptor(f->GetTypeDescriptor());
     result += ' ';
   }
-  StackHandleScope<1> hs(Thread::Current());
-  result += PrettyDescriptor(FieldHelper(hs.NewHandle(f)).GetDeclaringClassDescriptor());
+  std::string temp;
+  result += PrettyDescriptor(f->GetDeclaringClass()->GetDescriptor(&temp));
   result += '.';
   result += f->GetName();
   return result;
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc
index f9098c7..1b3cc8f 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -25,7 +25,6 @@
 #include "dex_file-inl.h"
 #include "dex_instruction-inl.h"
 #include "dex_instruction_visitor.h"
-#include "field_helper.h"
 #include "gc/accounting/card_table-inl.h"
 #include "indenter.h"
 #include "intern_table.h"
@@ -3826,7 +3825,7 @@
     {
       StackHandleScope<1> hs(self_);
       HandleWrapper<mirror::ArtField> h_field(hs.NewHandleWrapper(&field));
-      field_type_class = FieldHelper(h_field).GetType(can_load_classes_);
+      field_type_class = h_field->GetType(can_load_classes_);
     }
     if (field_type_class != nullptr) {
       field_type = &reg_types_.FromClass(field->GetTypeDescriptor(), field_type_class,
@@ -3950,7 +3949,7 @@
     {
       StackHandleScope<1> hs(Thread::Current());
       HandleWrapper<mirror::ArtField> h_field(hs.NewHandleWrapper(&field));
-      field_type_class = FieldHelper(h_field).GetType(can_load_classes_);
+      field_type_class = h_field->GetType(can_load_classes_);
     }
 
     if (field_type_class != nullptr) {