From c136312832d4be25db2ecc5673967d71d0ad4b9c Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Thu, 9 Apr 2015 14:13:13 +0100 Subject: Avoid using dex cache array pointers in libart. In preparation for making dex cache arrays native, avoid using them in Java code. This causes a performance regression for our reflection benchmarks. Class_getDeclaredMethod and Class_getMethod take an up to 30% hit, measured using the Quick compiler. We accept this hit at this stage and we will tune the performance after we're done with the larger effort. Companion libcore/ change: https://android-review.googlesource.com/146069 Bug: 20134538 Change-Id: Ibbef3b50043a1311cd40723ed42e1f1c609b8fc1 --- runtime/native/java_lang_Class.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'runtime/native/java_lang_Class.cc') diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index c893f0a6a0..b657aec30d 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -91,6 +91,18 @@ static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean return soa.AddLocalReference(c.Get()); } +static jobject Class_findOverriddenMethodIfProxy(JNIEnv* env, jclass, jobject art_method) { + ScopedFastNativeObjectAccess soa(env); + mirror::ArtMethod* method = soa.Decode(art_method); + mirror::Class* declaring_klass = method->GetDeclaringClass(); + if (!declaring_klass->IsProxyClass()) { + return art_method; + } + uint32_t dex_method_index = method->GetDexMethodIndex(); + mirror::ArtMethod* overriden_method = method->GetDexCacheResolvedMethods()->Get(dex_method_index); + return soa.AddLocalReference(overriden_method); +} + static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) { ScopedFastNativeObjectAccess soa(env); StackHandleScope<1> hs(soa.Self()); @@ -264,6 +276,8 @@ static jobject Class_getDeclaredField(JNIEnv* env, jobject javaThis, jstring nam static JNINativeMethod gMethods[] = { NATIVE_METHOD(Class, classForName, "!(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"), + NATIVE_METHOD(Class, findOverriddenMethodIfProxy, + "!(Ljava/lang/reflect/ArtMethod;)Ljava/lang/reflect/ArtMethod;"), NATIVE_METHOD(Class, getNameNative, "!()Ljava/lang/String;"), NATIVE_METHOD(Class, getProxyInterfaces, "!()[Ljava/lang/Class;"), NATIVE_METHOD(Class, getDeclaredFields, "!()[Ljava/lang/reflect/Field;"), -- cgit v1.2.3-59-g8ed1b