am ea093986: am ec97825f: Merge "Fix proxy handling in FindDeclaredVirtualMethod"
* commit 'ea093986219743556b058fcac86ab565e1354821':
Fix proxy handling in FindDeclaredVirtualMethod
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index f0b7bfd..5bd6583 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -471,7 +471,8 @@
ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const StringPiece& signature,
size_t pointer_size) {
for (auto& method : GetVirtualMethods(pointer_size)) {
- if (name == method.GetName() && method.GetSignature() == signature) {
+ ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
+ if (name == np_method->GetName() && np_method->GetSignature() == signature) {
return &method;
}
}
@@ -481,7 +482,8 @@
ArtMethod* Class::FindDeclaredVirtualMethod(const StringPiece& name, const Signature& signature,
size_t pointer_size) {
for (auto& method : GetVirtualMethods(pointer_size)) {
- if (name == method.GetName() && signature == method.GetSignature()) {
+ ArtMethod* const np_method = method.GetInterfaceMethodIfProxy(pointer_size);
+ if (name == np_method->GetName() && signature == np_method->GetSignature()) {
return &method;
}
}
diff --git a/test/004-JniTest/jni_test.cc b/test/004-JniTest/jni_test.cc
index ca256ec..db0dd32 100644
--- a/test/004-JniTest/jni_test.cc
+++ b/test/004-JniTest/jni_test.cc
@@ -626,3 +626,7 @@
assert(strcmp(test_array, chars6) == 0);
env->ReleaseStringUTFChars(s6, chars6);
}
+
+extern "C" JNIEXPORT jlong JNICALL Java_Main_testGetMethodID(JNIEnv* env, jclass, jclass c) {
+ return reinterpret_cast<jlong>(env->GetMethodID(c, "a", "()V"));
+}
diff --git a/test/004-JniTest/src/Main.java b/test/004-JniTest/src/Main.java
index a81ec6d..decefac 100644
--- a/test/004-JniTest/src/Main.java
+++ b/test/004-JniTest/src/Main.java
@@ -14,7 +14,9 @@
* limitations under the License.
*/
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
public class Main {
public static void main(String[] args) {
@@ -35,6 +37,7 @@
testCallNonvirtual();
testNewStringObject();
testRemoveLocalObject();
+ testProxyGetMethodID();
}
private static native void testFindClassOnAttachedNativeThread();
@@ -194,6 +197,31 @@
private static native void testCallNonvirtual();
private static native void testNewStringObject();
+
+ private interface SimpleInterface {
+ void a();
+ }
+
+ private static class DummyInvocationHandler implements InvocationHandler {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return null;
+ }
+ }
+
+ private static void testProxyGetMethodID() {
+ InvocationHandler handler = new DummyInvocationHandler();
+ SimpleInterface proxy =
+ (SimpleInterface) Proxy.newProxyInstance(SimpleInterface.class.getClassLoader(),
+ new Class[] {SimpleInterface.class}, handler);
+ if (testGetMethodID(SimpleInterface.class) == 0) {
+ throw new AssertionError();
+ }
+ if (testGetMethodID(proxy.getClass()) == 0) {
+ throw new AssertionError();
+ }
+ }
+
+ private static native long testGetMethodID(Class<?> c);
}
class JniCallNonvirtualTest {