Refactor ClassRoot/GetClassRoot().

Move it outside the ClassLinker, into its own header file,
and add retrieval based on a mirror class template argument.
Keep the SetClassRoot() as a private member of ClassLinker.

Make the new GetClassRoot()s return ObjPtr<>.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: Icbc6b62b41f6ffd65b437297a21eadbb0454e2b7
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index ffa000e..6900cd8 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -20,6 +20,7 @@
 #include "base/enums.h"
 #include "builder.h"
 #include "class_linker.h"
+#include "class_root.h"
 #include "constant_folding.h"
 #include "data_type-inl.h"
 #include "dead_code_elimination.h"
@@ -537,7 +538,7 @@
   Handle<mirror::ObjectArray<mirror::Class>> inline_cache = hs->NewHandle(
       mirror::ObjectArray<mirror::Class>::Alloc(
           self,
-          class_linker->GetClassRoot(ClassLinker::kClassArrayClass),
+          GetClassRoot<mirror::ObjectArray<mirror::Class>>(class_linker),
           InlineCache::kIndividualCacheSize));
   if (inline_cache == nullptr) {
     // We got an OOME. Just clear the exception, and don't inline.
@@ -777,7 +778,7 @@
 HInstanceFieldGet* HInliner::BuildGetReceiverClass(ClassLinker* class_linker,
                                                    HInstruction* receiver,
                                                    uint32_t dex_pc) const {
-  ArtField* field = class_linker->GetClassRoot(ClassLinker::kJavaLangObject)->GetInstanceField(0);
+  ArtField* field = GetClassRoot<mirror::Object>(class_linker)->GetInstanceField(0);
   DCHECK_EQ(std::string(field->GetName()), "shadow$_klass_");
   HInstanceFieldGet* result = new (graph_->GetAllocator()) HInstanceFieldGet(
       receiver,
@@ -2120,9 +2121,8 @@
         return true;
       } else if (return_replacement->IsInstanceFieldGet()) {
         HInstanceFieldGet* field_get = return_replacement->AsInstanceFieldGet();
-        ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
         if (field_get->GetFieldInfo().GetField() ==
-              class_linker->GetClassRoot(ClassLinker::kJavaLangObject)->GetInstanceField(0)) {
+                GetClassRoot<mirror::Object>()->GetInstanceField(0)) {
           return true;
         }
       }