Determine HLoadClass/String load kind early.

This helps save memory by avoiding the allocation of
HEnvironment and related objects for AOT references to
boot image strings and classes (kBootImage* load kinds)
and also for JIT references (kJitTableAddress).

Compiling aosp_taimen-userdebug boot image, the most memory
hungry method BatteryStats.dumpLocked() needs
  - before:
    Used 55105384 bytes of arena memory...
    ...
    UseListNode    10009704
    Environment      423248
    EnvVRegs       20676560
    ...
  - after:
    Used 50559176 bytes of arena memory...
    ...
    UseListNode     8568936
    Environment      365680
    EnvVRegs       17628704
    ...

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing --jit
Bug: 34053922
Change-Id: I68e73a438e6ac8e8908e6fccf53bbeea8a64a077
diff --git a/runtime/entrypoints/entrypoint_utils-inl.h b/runtime/entrypoints/entrypoint_utils-inl.h
index 8253739..475c1e7 100644
--- a/runtime/entrypoints/entrypoint_utils-inl.h
+++ b/runtime/entrypoints/entrypoint_utils-inl.h
@@ -245,7 +245,7 @@
     *slow_path = true;
     return nullptr;  // Failure
   }
-  mirror::Class* klass = method->GetDexCache()->GetResolvedType(type_idx);
+  ObjPtr<mirror::Class> klass = method->GetDexCache()->GetResolvedType(type_idx);
   if (UNLIKELY(klass == nullptr)) {  // Not in dex cache so try to resolve
     ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
     klass = class_linker->ResolveType(type_idx, method);
@@ -264,7 +264,7 @@
       return nullptr;  // Failure
     }
   }
-  return klass;
+  return klass.Ptr();
 }
 
 // Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
@@ -500,7 +500,8 @@
       Handle<mirror::Class> h_referring_class(hs2.NewHandle(referrer->GetDeclaringClass()));
       const dex::TypeIndex method_type_idx =
           referrer->GetDexFile()->GetMethodId(method_idx).class_idx_;
-      mirror::Class* method_reference_class = class_linker->ResolveType(method_type_idx, referrer);
+      ObjPtr<mirror::Class> method_reference_class =
+          class_linker->ResolveType(method_type_idx, referrer);
       if (UNLIKELY(method_reference_class == nullptr)) {
         // Bad type idx.
         CHECK(self->IsExceptionPending());
@@ -711,13 +712,13 @@
   }
 }
 
-inline mirror::Class* ResolveVerifyAndClinit(dex::TypeIndex type_idx,
-                                             ArtMethod* referrer,
-                                             Thread* self,
-                                             bool can_run_clinit,
-                                             bool verify_access) {
+inline ObjPtr<mirror::Class> ResolveVerifyAndClinit(dex::TypeIndex type_idx,
+                                                    ArtMethod* referrer,
+                                                    Thread* self,
+                                                    bool can_run_clinit,
+                                                    bool verify_access) {
   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
-  mirror::Class* klass = class_linker->ResolveType(type_idx, referrer);
+  ObjPtr<mirror::Class> klass = class_linker->ResolveType(type_idx, referrer);
   if (UNLIKELY(klass == nullptr)) {
     CHECK(self->IsExceptionPending());
     return nullptr;  // Failure - Indicate to caller to deliver exception
@@ -748,9 +749,9 @@
   return h_class.Get();
 }
 
-static inline mirror::String* ResolveString(ClassLinker* class_linker,
-                                            dex::StringIndex string_idx,
-                                            ArtMethod* referrer)
+static inline ObjPtr<mirror::String> ResolveString(ClassLinker* class_linker,
+                                                   dex::StringIndex string_idx,
+                                                   ArtMethod* referrer)
     REQUIRES_SHARED(Locks::mutator_lock_) {
   Thread::PoisonObjectPointersIfDebug();
   ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx);
@@ -760,10 +761,11 @@
     const DexFile& dex_file = *dex_cache->GetDexFile();
     string = class_linker->ResolveString(dex_file, string_idx, dex_cache);
   }
-  return string.Ptr();
+  return string;
 }
 
-inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, dex::StringIndex string_idx) {
+inline ObjPtr<mirror::String> ResolveStringFromCode(ArtMethod* referrer,
+                                                    dex::StringIndex string_idx) {
   Thread::PoisonObjectPointersIfDebug();
   ObjPtr<mirror::String> string = referrer->GetDexCache()->GetResolvedString(string_idx);
   if (UNLIKELY(string == nullptr)) {
@@ -773,7 +775,7 @@
     ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
     string = class_linker->ResolveString(dex_file, string_idx, dex_cache);
   }
-  return string.Ptr();
+  return string;
 }
 
 inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self) {