ART: Add GetMethodDeclaringClass

Support GetMethodDeclaringClass to retrieve the declaring class
of a JNI method.

Extend test 910. Also cover proxies.

Bug: 31684812
Test: m test-art-host-run-test-910-methods
Change-Id: I8508f96f88692e540ef53f693ff85590b7553f19
diff --git a/runtime/openjdkjvmti/ti_method.cc b/runtime/openjdkjvmti/ti_method.cc
index 8d943d9..4aae4d1 100644
--- a/runtime/openjdkjvmti/ti_method.cc
+++ b/runtime/openjdkjvmti/ti_method.cc
@@ -97,4 +97,21 @@
   return ERR(NONE);
 }
 
+jvmtiError MethodUtil::GetMethodDeclaringClass(jvmtiEnv* env ATTRIBUTE_UNUSED,
+                                               jmethodID method,
+                                               jclass* declaring_class_ptr) {
+  if (declaring_class_ptr == nullptr) {
+    return ERR(NULL_POINTER);
+  }
+
+  art::ScopedObjectAccess soa(art::Thread::Current());
+  art::ArtMethod* art_method = soa.DecodeMethod(method);
+  // Note: No GetInterfaceMethodIfProxy, we want to actual class.
+
+  art::mirror::Class* klass = art_method->GetDeclaringClass();
+  *declaring_class_ptr = soa.AddLocalReference<jclass>(klass);
+
+  return ERR(NONE);
+}
+
 }  // namespace openjdkjvmti