Remove static GcRoot<>s from Field, Method, Constructor.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 31113334
Change-Id: I648b88339995761fb81180286ef48a42bbd2f83d
diff --git a/runtime/check_jni.cc b/runtime/check_jni.cc
index f8b977e..0ff55ae 100644
--- a/runtime/check_jni.cc
+++ b/runtime/check_jni.cc
@@ -31,6 +31,7 @@
 #include "base/time_utils.h"
 #include "class_linker-inl.h"
 #include "class_linker.h"
+#include "class_root.h"
 #include "dex/descriptors_names.h"
 #include "dex/dex_file-inl.h"
 #include "gc/space/space.h"
@@ -638,8 +639,11 @@
       AbortF("expected non-null method");
       return false;
     }
+    ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots =
+        Runtime::Current()->GetClassLinker()->GetClassRoots();
     ObjPtr<mirror::Class> c = method->GetClass();
-    if (mirror::Method::StaticClass() != c && mirror::Constructor::StaticClass() != c) {
+    if (c != GetClassRoot<mirror::Method>(class_roots) &&
+        c != GetClassRoot<mirror::Constructor>(class_roots)) {
       AbortF("expected java.lang.reflect.Method or "
           "java.lang.reflect.Constructor but got object of type %s: %p",
           method->PrettyTypeOf().c_str(), jmethod);
@@ -669,7 +673,7 @@
       return false;
     }
     ObjPtr<mirror::Class> c = field->GetClass();
-    if (mirror::Field::StaticClass() != c) {
+    if (GetClassRoot<mirror::Field>() != c) {
       AbortF("expected java.lang.reflect.Field but got object of type %s: %p",
              field->PrettyTypeOf().c_str(), jfield);
       return false;