Increase use of ScopedJniThreadState.

Move the routines for changing Object* to jobject and vice-versa
(AddLocalReference and Decode) to ScopedJniThreadState to enforce use of
Object*s in the Runnable thread state. In the Runnable thread state
suspension is necessary before GC can take place.

Reduce use of const ClassLoader* as the code bottoms out in FindClass
and with a field assignment where the const is cast away (ie if we're
not going to enforce the const-ness we shouldn't pretend it is).

Refactor the Thread::Attach API so that we're not handling raw Objects on
unattached threads.

Remove some unreachable code.

Change-Id: I0fa969f49ee6a8f10752af74a6b0e04d46b4cd97
diff --git a/src/object.cc b/src/object.cc
index b728e28..94e1759 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -322,35 +322,6 @@
   java_lang_reflect_Method_ = NULL;
 }
 
-Class* ExtractNextClassFromSignature(ClassLinker* class_linker, const ClassLoader* cl, const char*& p) {
-  if (*p == '[') {
-    // Something like "[[[Ljava/lang/String;".
-    const char* start = p;
-    while (*p == '[') {
-      ++p;
-    }
-    if (*p == 'L') {
-      while (*p != ';') {
-        ++p;
-      }
-    }
-    ++p; // Either the ';' or the primitive type.
-
-    std::string descriptor(start, (p - start));
-    return class_linker->FindClass(descriptor.c_str(), cl);
-  } else if (*p == 'L') {
-    const char* start = p;
-    while (*p != ';') {
-      ++p;
-    }
-    ++p;
-    std::string descriptor(start, (p - start));
-    return class_linker->FindClass(descriptor.c_str(), cl);
-  } else {
-    return class_linker->FindPrimitiveClass(*p++);
-  }
-}
-
 ObjectArray<String>* Method::GetDexCacheStrings() const {
   return GetFieldObject<ObjectArray<String>*>(
       OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_strings_), false);
@@ -937,8 +908,7 @@
   return GetFieldObject<ClassLoader*>(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), false);
 }
 
-void Class::SetClassLoader(const ClassLoader* new_cl) {
-  ClassLoader* new_class_loader = const_cast<ClassLoader*>(new_cl);
+void Class::SetClassLoader(ClassLoader* new_class_loader) {
   SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), new_class_loader, false);
 }