Support for unresolved types in new-instance during verification.

Also, ensure that classes that don't load are erroneous, warn early
about exceptions left on a thread by the verifier/compiler, factor out
slowpath checks for the compiler and fix the slowpath selector for
const-class.

This change causes more dex cache misses at runtime (more slowpath
execution). It also requires a "mm clean-oat".

Change-Id: I014b49ebdd7d8f7dd2e39cc0958fc0b708d58c4c
diff --git a/src/compiler.h b/src/compiler.h
index 0fc68df..55bab59 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -55,6 +55,21 @@
   const CompiledMethod* GetCompiledMethod(const Method* method) const;
   const CompiledInvokeStub* GetCompiledInvokeStub(const Method* method) const;
 
+  // Callbacks from OAT/ART compiler to see what runtime checks must be generated
+  bool CanAssumeTypeIsPresentInDexCache(const Method* referrer, uint32_t type_idx) const {
+    return IsImage() && referrer->GetDexCacheResolvedTypes()->Get(type_idx) != NULL;
+  }
+  bool CanAssumeStringIsPresentInDexCache(const Method* referrer, uint32_t string_idx) const {
+    return IsImage() && referrer->GetDexCacheStrings()->Get(string_idx) != NULL;
+  }
+  bool CanAccessTypeWithoutChecks(const Method* referrer, uint32_t type_idx) const {
+    Class* resolved_class = referrer->GetDexCacheResolvedTypes()->Get(type_idx);
+    // We should never ask whether a type needs access checks to raise a verification error,
+    // all other cases where this following test could fail should have been rewritten by the
+    // verifier to verification errors.
+    DCHECK(resolved_class == NULL || referrer->GetDeclaringClass()->CanAccess(resolved_class));
+    return resolved_class != NULL;
+  }
  private:
   // Attempt to resolve all type, methods, fields, and strings
   // referenced from code in the dex file following PathClassLoader