Improve verifier speed.

Main improvement is in the RegTypeCache::From() Class lookup, the cache is first
looked up for the passed descriptor instead of trying to resolve the class.
For cases when the descriptor is not found it is resolved to a class and a new type is
created and added to the cache.

Change-Id: I594a4c00b351843dd576b5af29e9dcaed18e04e8
diff --git a/src/class_linker.cc b/src/class_linker.cc
index d262a5d..e55fe78 100644
--- a/src/class_linker.cc
+++ b/src/class_linker.cc
@@ -2109,11 +2109,15 @@
   size_t hash = Hash(descriptor);
   MutexLock mu(Thread::Current(), *Locks::classlinker_classes_lock_);
   // TODO: determine if its better to search classes_ or image_classes_ first
-  mirror::Class* klass = LookupClassLocked(descriptor, class_loader, hash, classes_);
+  mirror::Class* klass = NULL;
+  // Use image class only if the class_loader is null.
+  if (class_loader == NULL) {
+    klass = LookupClassLocked(descriptor, class_loader, hash, image_classes_);
+  }
   if (klass != NULL) {
     return klass;
   }
-  return LookupClassLocked(descriptor, class_loader, hash, image_classes_);
+  return LookupClassLocked(descriptor, class_loader, hash, classes_);
 }
 
 mirror::Class* ClassLinker::LookupClassLocked(const char* descriptor,
diff --git a/src/verifier/reg_type.h b/src/verifier/reg_type.h
index 16be7c0..7c42536 100644
--- a/src/verifier/reg_type.h
+++ b/src/verifier/reg_type.h
@@ -211,8 +211,8 @@
            IsUnresolvedMergedReference() || IsUnresolvedSuperClass();
   }
   bool IsCategory1Types() const {
-    return (IsBoolean() || IsByte() || IsShort() || IsChar() || IsInteger() ||
-            IsFloat() || IsConstant());
+    return (IsChar() || IsInteger() || IsFloat() || IsConstant() || IsByte() ||
+        IsShort() || IsBoolean()  );
   }
   bool IsCategory2Types() const {
     return IsLowHalf();  // Don't expect explicit testing of high halves
@@ -221,7 +221,7 @@
     return IsBoolean() || IsConstantBoolean();
   }
   bool IsByteTypes() const {
-    return IsByte() || IsBoolean() || IsConstantByte();
+    return IsConstantByte() || IsByte() || IsBoolean();
   }
   bool IsShortTypes() const {
     return IsShort() || IsByte() || IsBoolean() || IsConstantShort();
@@ -230,18 +230,18 @@
     return IsChar() || IsBooleanTypes() || IsConstantChar();
   }
   bool IsIntegralTypes() const {
-    return (IsBoolean() || IsByte() || IsShort() || IsChar() || IsInteger() || IsConstant());
+    return (IsInteger() || IsConstant() || IsByte() || IsShort() || IsChar() || IsBoolean() );
   }
   inline virtual int32_t ConstantValue() const {
-    CHECK(IsConstant());
+    DCHECK(IsConstant());
     return -1;
   }
   inline virtual int32_t ConstantValueLo() const {
-    CHECK(IsConstantLo());
+    DCHECK(IsConstantLo());
     return -1;
   }
   inline virtual int32_t ConstantValueHi() const {
-    CHECK(IsConstantHi());
+    DCHECK(IsConstantHi());
     return -1;
   }
   bool IsArrayIndexTypes() const {
@@ -278,7 +278,7 @@
   Primitive::Type GetPrimitiveType() const ;
   bool IsJavaLangObjectArray() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   bool IsInstantiableTypes() const;
-  std::string GetDescriptor() const {
+  const std::string& GetDescriptor() const {
     DCHECK(IsUnresolvedTypes() && !IsUnresolvedMergedReference() && !IsUnresolvedSuperClass());
     return descriptor_;
   }
@@ -345,10 +345,10 @@
 
 class ConflictType : public RegType {
  public:
-  inline virtual bool IsConflict() const {
+  bool IsConflict() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static ConflictType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                       uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static ConflictType* GetInstance();
@@ -361,10 +361,10 @@
 
 class UndefinedType : public RegType {
  public:
-  inline virtual bool IsUndefined() const {
+  bool IsUndefined() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static UndefinedType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                        uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -382,10 +382,10 @@
 
 class IntegerType : public RegType {
  public:
-  inline virtual bool IsInteger() const {
+  bool IsInteger() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static IntegerType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                      uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -399,10 +399,10 @@
 
 class BooleanType : public RegType {
  public:
-  inline virtual bool IsBoolean() const {
+  bool IsBoolean() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static BooleanType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                      uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -416,10 +416,10 @@
 
 class ByteType : public RegType {
  public:
-  inline virtual bool IsByte() const {
+  bool IsByte() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static ByteType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                   uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -433,10 +433,10 @@
 
 class ShortType : public RegType {
  public:
-  inline virtual bool IsShort() const {
+  bool IsShort() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static ShortType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                    uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -450,10 +450,10 @@
 
 class CharType : public RegType {
  public:
-  inline virtual bool IsChar() const {
+  bool IsChar() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static CharType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                   uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -467,10 +467,10 @@
 
 class FloatType : public RegType {
  public:
-  inline virtual bool IsFloat() const {
+  bool IsFloat() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static FloatType* CreateInstance(mirror::Class* klass, std::string& descriptor,
                                    uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -484,11 +484,11 @@
 
 class LongLoType : public RegType {
  public:
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsLongLo() const {
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsLongLo() const {
     return true;
   }
-  inline virtual bool IsLong() const {
+  bool IsLong() const {
     return true;
   }
   static LongLoType* CreateInstance(mirror::Class* klass, std::string& descriptor,
@@ -504,8 +504,8 @@
 
 class LongHiType : public RegType {
  public:
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsLongHi() const {
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsLongHi() const {
     return true;
   }
   static LongHiType* CreateInstance(mirror::Class* klass, std::string& descriptor,
@@ -521,11 +521,11 @@
 
 class DoubleLoType : public RegType {
  public:
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsDoubleLo() const {
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsDoubleLo() const {
     return true;
   }
-  inline virtual bool IsDouble() const {
+  bool IsDouble() const {
     return true;
   }
   static DoubleLoType* CreateInstance(mirror::Class* klass, std::string& descriptor,
@@ -541,8 +541,8 @@
 
 class DoubleHiType : public RegType {
  public:
-  virtual std::string Dump() const;
-  inline virtual bool IsDoubleHi() const {
+  std::string Dump() const;
+  virtual bool IsDoubleHi() const {
     return true;
   }
   static DoubleHiType* CreateInstance(mirror::Class* klass, std::string& descriptor,
@@ -592,70 +592,76 @@
   }
   inline virtual bool IsConstantTypes() const { return true; }
 };
+
 class PreciseConstType : public ConstantType {
  public:
   PreciseConstType(uint32_t constat, uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
       : ConstantType(constat, cache_id) {
   }
 
-  inline virtual bool IsPreciseConstant() const {
+  bool IsPreciseConstant() const {
     return true;
   }
 
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
+
 class PreciseConstLoType : public ConstantType {
  public:
   PreciseConstLoType(uint32_t constat, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
       : ConstantType(constat, cache_id) {
   }
-  inline virtual bool IsPreciseConstantLo() const {
+  bool IsPreciseConstantLo() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
+
 class PreciseConstHiType : public ConstantType {
  public:
   PreciseConstHiType(uint32_t constat, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
       : ConstantType(constat, cache_id) {
   }
-  inline virtual bool IsPreciseConstantHi() const {
+  bool IsPreciseConstantHi() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
 
 class ImpreciseConstType : public ConstantType {
  public:
   ImpreciseConstType(uint32_t constat, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual  bool IsImpreciseConstant() const {
+  bool IsImpreciseConstant() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
+
 class ImpreciseConstLoType : public ConstantType {
  public:
   ImpreciseConstLoType(uint32_t constat, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : ConstantType(constat, cache_id) {
   }
-  inline virtual bool IsImpreciseConstantLo() const {
+  bool IsImpreciseConstantLo() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
+
 class ImpreciseConstHiType : public ConstantType {
  public:
   ImpreciseConstHiType(uint32_t constat, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : ConstantType(constat, cache_id) {
   }
-  inline virtual bool IsImpreciseConstantHi() const {
+  bool IsImpreciseConstantHi() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
+
 class UninitializedType : public RegType {
  public:
   UninitializedType(mirror::Class* klass, std::string& descriptor, uint32_t allocation_pc,
@@ -678,40 +684,41 @@
   UninitialisedReferenceType(mirror::Class* klass, std::string& descriptor, uint32_t allocation_pc,
                              uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-  inline virtual bool IsUninitializedReference() const {
+  bool IsUninitializedReference() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
 
 class UnresolvedUninitializedRefType : public UninitializedType {
  public:
   UnresolvedUninitializedRefType(std::string& descriptor, uint32_t allocation_pc,
                                  uint16_t cache_id) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsUnresolvedAndUninitializedReference() const {
+  void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsUnresolvedAndUninitializedReference() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
 
 class UninitialisedThisReferenceType : public UninitializedType {
  public:
   UninitialisedThisReferenceType(mirror::Class* klass, std::string& descriptor, uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   inline virtual bool IsUninitializedThisReference() const {
     return true;
   }
 };
+
 class UnresolvedUninitialisedThisRefType : public UninitializedType {
  public:
   UnresolvedUninitialisedThisRefType(std::string& descriptor, uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsUnresolvedAndUninitializedThisReference() const {
+  void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsUnresolvedAndUninitializedThisReference() const {
     return true;
   }
 };
@@ -720,18 +727,18 @@
  public:
   ReferenceType(mirror::Class* klass, std::string& descriptor, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsReference() const {
+  bool IsReference() const {
     return true;
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 };
 
 class PreciseReferenceType : public RegType {
  public:
   PreciseReferenceType(mirror::Class* klass, std::string& descriptor, uint16_t cache_id)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsPreciseReference() const {
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsPreciseReference() const {
     return true;
   }
 };
@@ -741,9 +748,9 @@
   UnresolvedReferenceType(std::string& descriptor, uint16_t cache_id)
      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : RegType(NULL, descriptor, cache_id) {
   }
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  inline virtual bool IsUnresolvedReference() const {
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  bool IsUnresolvedReference() const {
     return true;
   }
 };
@@ -755,19 +762,19 @@
       : RegType(NULL, "", cache_id), unresolved_child_id_(child_id),
         reg_type_cache_(reg_type_cache) {
   }
-  inline virtual bool IsUnresolvedSuperClass() const {
+  bool IsUnresolvedSuperClass() const {
     return true;
   }
   uint16_t GetUnresolvedSuperClassChildId() const {
     DCHECK(IsUnresolvedSuperClass());
     return static_cast<uint16_t>(unresolved_child_id_ & 0xFFFF);
   }
-  virtual void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
  private:
- const uint16_t unresolved_child_id_;
- const RegTypeCache* const reg_type_cache_;
+  const uint16_t unresolved_child_id_;
+  const RegTypeCache* const reg_type_cache_;
 };
 
 class UnresolvedMergedType : public RegType {
@@ -783,11 +790,11 @@
   }
   // The complete set of merged types.
   std::set<uint16_t> GetMergedTypes() const;
-  inline virtual bool IsUnresolvedMergedReference() const {
+  bool IsUnresolvedMergedReference() const {
     return true;
   }
-  virtual void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-  virtual std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  void CheckInvariants() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+  std::string Dump() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
  private:
   const RegTypeCache* const reg_type_cache_;
diff --git a/src/verifier/reg_type_cache.cc b/src/verifier/reg_type_cache.cc
index 7153768..aac7e37 100644
--- a/src/verifier/reg_type_cache.cc
+++ b/src/verifier/reg_type_cache.cc
@@ -114,24 +114,23 @@
 }
 
 bool RegTypeCache::MatchDescriptor(size_t idx, std::string& descriptor, bool precise) {
-  ClassHelper kh;
   RegType* cur_entry = entries_[idx];
-  // Check if we have matching descriptors and precision
-  // in cases where the descriptor available
-  if (cur_entry->descriptor_ != "" &&
-      MatchingPrecisionForClass(cur_entry, precise) &&
-      descriptor == cur_entry->descriptor_) {
-    return true;
-  }
-  // check resolved and unresolved references, ignore uninitialized references
   if (cur_entry->HasClass()) {
-    kh.ChangeClass(cur_entry->GetClass());
-    // So we might have cases where we have the class but not the descriptor
-    // for that class we need the class helper to get the descriptor
-    // and match it with the one we are given.
-    if (MatchingPrecisionForClass(cur_entry, precise) &&
-        (strcmp(descriptor.c_str(), kh.GetDescriptor()) == 0)) {
-      return true;
+    // Check the descriptor in the reg_type if available.
+    if(!cur_entry->descriptor_.empty()) {
+      if (descriptor == cur_entry->descriptor_ && MatchingPrecisionForClass(cur_entry, precise)) {
+        return true;
+      }
+    } else {
+      // Descriptor not found in reg_type , maybe available in Class object.
+      // So we might have cases where we have the class but not the descriptor
+      // for that class we need the class helper to get the descriptor
+      // and match it with the one we are given.
+      ClassHelper kh(cur_entry->GetClass());
+      if ((strcmp(descriptor.c_str(), kh.GetDescriptor()) == 0) &&
+          MatchingPrecisionForClass(cur_entry, precise)) {
+        return true;
+      }
     }
   } else if (cur_entry->IsUnresolvedReference() && cur_entry->GetDescriptor() == descriptor) {
     return true;
@@ -139,6 +138,7 @@
   return false;
 }
 
+
 mirror::Class* RegTypeCache::ResolveClass(std::string descriptor, mirror::ClassLoader* loader) {
   // Class was not found, must create new type.
   // Try resolving class
@@ -164,28 +164,25 @@
   }
 }
 const RegType& RegTypeCache::From(mirror::ClassLoader* loader, std::string descriptor, bool precise) {
+
+  // Try looking up the class in the cache first.
+  for (size_t i = primitive_count_; i < entries_.size(); i++) {
+    if (MatchDescriptor(i, descriptor, precise)) {
+      return *(entries_[i]);
+    }
+  }
+  // Class not found in the cache, will create a new type for that.
   // Try resolving class.
   mirror::Class* klass = ResolveClass(descriptor, loader);
   if (klass != NULL) {
     // Class resolved, first look for the class in the list of entries
-    for (size_t i = primitive_count_; i < entries_.size(); i++) {
-      if (entries_[i]->HasClass()) {
-        if (MatchDescriptor(i, descriptor, precise)) {
-          return *(entries_[i]);
-        }
-      }
-    }
     // Class was not found, must create new type.
-
     //To pass the verification, the type should be imprecise,
     // instantiable or an interface with the precise type set to false.
     DCHECK(!precise || klass->IsInstantiable());
-
     // Create a precise type if:
-    // 1- Class is final and NOT an interface. a precise interface
-    //    is meaningless !!
+    // 1- Class is final and NOT an interface. a precise interface is meaningless !!
     // 2- Precise Flag passed as true.
-
     RegType* entry;
     // Create an imprecise type if we can't tell for a fact that it is precise.
     if ((klass->IsFinal()) || precise) {
@@ -201,14 +198,6 @@
     // We tried loading the class and failed, this might get an exception raised
     // so we want to clear it before we go on.
     ClearException();
-    // Unable to resolve class. Look through unresolved types in the catch and see
-    // if we have it created before.
-    for (size_t i = primitive_count_; i < entries_.size(); i++) {
-      if (entries_[i]->IsUnresolvedReference() &&
-          entries_[i]->descriptor_ == descriptor) {
-        return *(entries_[i]);
-      }
-    }
     if (IsValidDescriptor(descriptor.c_str())) {
       RegType* entry = new UnresolvedReferenceType(descriptor, entries_.size());
       entries_.push_back(entry);
@@ -223,13 +212,12 @@
 const RegType& RegTypeCache::FromClass(mirror::Class* klass, bool precise) {
   if (klass->IsPrimitive()) {
     return RegTypeFromPrimitiveType(klass->GetPrimitiveType());
-
   } else {
     // Look for the reference in the list of entries to have.
     for (size_t i = primitive_count_; i < entries_.size(); i++) {
       RegType* cur_entry = entries_[i];
-      if ((cur_entry->HasClass()) &&
-          MatchingPrecisionForClass(cur_entry, precise) && cur_entry->GetClass() == klass) {
+      if ((cur_entry->HasClass()) && cur_entry->GetClass() == klass &&
+          MatchingPrecisionForClass(cur_entry, precise)) {
         return *cur_entry;
       }
     }