Refactor java.lang.reflect implementation
Cherry-picked from commit ed41d5c44299ec5d44b8514f6e17f802f48094d1.
Move to ArtMethod/Field instead of AbstractMethod/Field and have
java.lang.reflect APIs delegate to ArtMethod/ArtField.
Bug: 10014286.
Change-Id: Iafc1d8c5b62562c9af8fb9fd8c5e1d61270536e7
diff --git a/runtime/native/java_lang_reflect_Method.cc b/runtime/native/java_lang_reflect_Method.cc
index 14dc6a4..d29de3d 100644
--- a/runtime/native/java_lang_reflect_Method.cc
+++ b/runtime/native/java_lang_reflect_Method.cc
@@ -16,26 +16,31 @@
#include "class_linker.h"
#include "jni_internal.h"
+#include "mirror/art_method.h"
+#include "mirror/art_method-inl.h"
#include "mirror/class-inl.h"
-#include "mirror/abstract_method.h"
-#include "mirror/abstract_method-inl.h"
#include "mirror/object-inl.h"
#include "mirror/object_array-inl.h"
#include "mirror/proxy.h"
#include "object_utils.h"
#include "reflection.h"
#include "scoped_thread_state_change.h"
+#include "well_known_classes.h"
namespace art {
-static jobject Method_invoke(JNIEnv* env, jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
+static jobject Method_invoke(JNIEnv* env,
+ jobject javaMethod, jobject javaReceiver, jobject javaArgs) {
ScopedObjectAccess soa(env);
return InvokeMethod(soa, javaMethod, javaReceiver, javaArgs);
}
static jobject Method_getExceptionTypesNative(JNIEnv* env, jobject javaMethod) {
ScopedObjectAccess soa(env);
- mirror::AbstractMethod* proxy_method = soa.Decode<mirror::Object*>(javaMethod)->AsMethod();
+ jobject art_method = soa.Env()->GetObjectField(
+ javaMethod, WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod);
+
+ mirror::ArtMethod* proxy_method = soa.Decode<mirror::Object*>(art_method)->AsArtMethod();
CHECK(proxy_method->GetDeclaringClass()->IsProxyClass());
mirror::SynthesizedProxyClass* proxy_class =
down_cast<mirror::SynthesizedProxyClass*>(proxy_method->GetDeclaringClass());
@@ -48,20 +53,14 @@
}
}
CHECK_NE(throws_index, -1);
- mirror::ObjectArray<mirror::Class>* declared_exceptions = proxy_class->GetThrows()->Get(throws_index);
+ mirror::ObjectArray<mirror::Class>* declared_exceptions =
+ proxy_class->GetThrows()->Get(throws_index);
return soa.AddLocalReference<jobject>(declared_exceptions->Clone(soa.Self()));
}
-static jobject Method_findOverriddenMethodNative(JNIEnv* env, jobject javaMethod) {
- ScopedObjectAccess soa(env);
- mirror::AbstractMethod* method = soa.Decode<mirror::Object*>(javaMethod)->AsMethod();
- return soa.AddLocalReference<jobject>(method->FindOverriddenMethod());
-}
-
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Method, invoke, "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"),
NATIVE_METHOD(Method, getExceptionTypesNative, "()[Ljava/lang/Class;"),
- NATIVE_METHOD(Method, findOverriddenMethodNative, "()Ljava/lang/reflect/Method;"),
};
void register_java_lang_reflect_Method(JNIEnv* env) {