Commit 99767387 authored by Mathieu Chartier's avatar Mathieu Chartier
Browse files

Fix proxy handling in FindDeclaredVirtualMethod

Added missing GetInterfaceMethodIfProxy and test.

Fixed formatting.

Bug: 22411819
https://code.google.com/p/android-developer-preview/issues/detail?id=2635

(cherry picked from commit 72156e28)

Change-Id: I3eece9c72091bb9d0262aacf0a75ec6908b5f4d2
parent 25e1af5b
......@@ -471,7 +471,8 @@ ArtMethod* Class::FindDirectMethod(
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 Strin
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;
}
}
......
......@@ -626,3 +626,7 @@ extern "C" JNIEXPORT void JNICALL Java_Main_testNewStringObject(JNIEnv* env, jcl
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"));
}
......@@ -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 @@ public class Main {
testCallNonvirtual();
testNewStringObject();
testRemoveLocalObject();
testProxyGetMethodID();
}
private static native void testFindClassOnAttachedNativeThread();
......@@ -194,6 +197,31 @@ public class Main {
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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment