Use accessor methods for Object fields.

Ensure that Object fields are modified via accessors so that it's easy
to insert barriers (make all fields within Objects private). Add validity
checks to Field and Method accessors to ensure they are accessed when a
Class is in a suitable state. Add validity checks to all Object
accessors to check heap isn't corrupted. Remove hacked in strings from Field
and Method; make type fields used the dex cache that is lazily initialized.
Clean up various other TODOs and lint issues.

Change-Id: Iac0afc515c01f5419874d9cdcdb9a7b45443e3fb
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 36787d8..125401e 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -346,12 +346,26 @@
   }
 
   Field* field = NULL;
-  if (is_static) {
-    field = c->FindStaticField(name, sig);
+  Class* field_type;
+  ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
+  if (sig[1] != '\0') {
+    // TODO: need to get the appropriate ClassLoader.
+    const ClassLoader* cl = ts.Self()->GetClassLoaderOverride();
+    field_type = class_linker->FindClass(sig, cl);
   } else {
-    field = c->FindInstanceField(name, sig);
+    field_type = class_linker->FindPrimitiveClass(*sig);
   }
-
+  if (field_type == NULL) {
+    // Failed to find type from the signature of the field.
+    // TODO: Linkage or NoSuchFieldError?
+    CHECK(ts.Self()->IsExceptionPending());
+    return NULL;
+  }
+  if (is_static) {
+    field = c->FindStaticField(name, field_type);
+  } else {
+    field = c->FindInstanceField(name, field_type);
+  }
   if (field == NULL) {
     Thread* self = Thread::Current();
     std::string class_descriptor(c->GetDescriptor()->ToModifiedUtf8());
@@ -360,7 +374,9 @@
         name, class_descriptor.c_str());
     return NULL;
   }
-
+  // Check invariant that all jfieldIDs have resolved types (how else would
+  // the type equality in Find...Field hold?)
+  DCHECK(field->GetType() != NULL);
   jweak fid = AddWeakGlobalReference(ts, field);
   return reinterpret_cast<jfieldID>(fid);
 }