Check for temporary and retired classes in GetClassFields.

Bug: 62895303
Bug: 62902528
Test: stress --cpu 70 &; \
      while ./test/run-test --host --jit 990; do ; done

Change-Id: I623ed0a23e8ffb3c191ef66b8e3f101f3aca427f
diff --git a/runtime/openjdkjvmti/ti_class.cc b/runtime/openjdkjvmti/ti_class.cc
index 0ac08d9..b8e7955 100644
--- a/runtime/openjdkjvmti/ti_class.cc
+++ b/runtime/openjdkjvmti/ti_class.cc
@@ -598,6 +598,13 @@
     return ERR(INVALID_CLASS);
   }
 
+  // Check if this class is a temporary class object used for loading. Since we are seeing it the
+  // class must not have been prepared yet since otherwise the fixup would have gotten the jobject
+  // to point to the final class object.
+  if (klass->IsTemp() || klass->IsRetired()) {
+    return ERR(CLASS_NOT_PREPARED);
+  }
+
   if (field_count_ptr == nullptr || fields_ptr == nullptr) {
     return ERR(NULL_POINTER);
   }
@@ -639,6 +646,13 @@
     return ERR(INVALID_CLASS);
   }
 
+  // Check if this class is a temporary class object used for loading. Since we are seeing it the
+  // class must not have been prepared yet since otherwise the fixup would have gotten the jobject
+  // to point to the final class object.
+  if (klass->IsTemp() || klass->IsRetired()) {
+    return ERR(CLASS_NOT_PREPARED);
+  }
+
   if (method_count_ptr == nullptr || methods_ptr == nullptr) {
     return ERR(NULL_POINTER);
   }