diff options
author | 2017-10-10 16:20:10 -0700 | |
---|---|---|
committer | 2017-10-10 16:20:10 -0700 | |
commit | a03a9eeb9d1b2ebca17cc326f52c84a5abca6707 (patch) | |
tree | 3a52462cba8002df6c086ee57d6b7e71a400c74a /test/1914-get-local-instance | |
parent | baeedfee3521c295916e3ae85afa2cb5dee7d6a5 (diff) |
Ensure Proxy frames work with JVMTI stack frame functions
We were incorrectly returning errors and crashing when stack frame
JVMTI functions were used with Proxy methods. This fixes those issues
and adds a test for them.
Bug: 66903662
Test: ./test.py --host -j40
Change-Id: Ia7c768d631c5ac4d8339d70a9d4761d5b4bc284e
Diffstat (limited to 'test/1914-get-local-instance')
-rw-r--r-- | test/1914-get-local-instance/expected.txt | 3 | ||||
-rw-r--r-- | test/1914-get-local-instance/src/art/Test1914.java | 30 |
2 files changed, 31 insertions, 2 deletions
diff --git a/test/1914-get-local-instance/expected.txt b/test/1914-get-local-instance/expected.txt index 4117942392..09f0df1937 100644 --- a/test/1914-get-local-instance/expected.txt +++ b/test/1914-get-local-instance/expected.txt @@ -10,3 +10,6 @@ Running public void art.Test1914$TargetClass.InstanceMethod(java.lang.Runnable) Running public native void art.Test1914$TargetClass.NativeInstanceMethod(java.lang.Runnable) with "GetThis" on remote thread. "GetThis" on public native void art.Test1914$TargetClass.NativeInstanceMethod(java.lang.Runnable) got value: TargetClass("NativeInstanceMethodObject") Value is 'TargetClass("NativeInstanceMethodObject")' (class: class art.Test1914$TargetClass) +Running public abstract void art.Test1914$Foo.InterfaceProxyMethod(java.lang.Runnable) with "GetThis" on remote thread. +"GetThis" on public abstract void art.Test1914$Foo.InterfaceProxyMethod(java.lang.Runnable) got value: Proxy for [interface art.Test1914$Foo] + Value is 'Proxy for [interface art.Test1914$Foo]' (class: PROXY CLASS) diff --git a/test/1914-get-local-instance/src/art/Test1914.java b/test/1914-get-local-instance/src/art/Test1914.java index c09f519db8..e47f9cbf38 100644 --- a/test/1914-get-local-instance/src/art/Test1914.java +++ b/test/1914-get-local-instance/src/art/Test1914.java @@ -18,7 +18,9 @@ package art; import java.lang.reflect.Constructor; import java.lang.reflect.Executable; +import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.nio.ByteBuffer; import java.util.concurrent.Semaphore; import java.util.Arrays; @@ -35,7 +37,7 @@ public class Test1914 { public static void reportValue(Object val) { System.out.println("\tValue is '" + val + "' (class: " - + (val != null ? val.getClass() : "NULL") + ")"); + + (val != null ? (val instanceof Proxy ? "PROXY CLASS" : val.getClass()) : "NULL") + ")"); } public static void StaticMethod(Runnable safepoint) { @@ -151,7 +153,10 @@ public class Test1914 { private StackTrace.StackFrameData findStackFrame(Thread thr) { for (StackTrace.StackFrameData frame : StackTrace.GetStackTrace(thr)) { - if (frame.method.equals(target)) { + if (frame.method.equals(target) || + (frame.method.getName().equals(target.getName()) && + Arrays.deepEquals(frame.method.getParameterTypes(), target.getParameterTypes()) && + ((Method)frame.method).getReturnType().equals(target.getReturnType()))) { return frame; } } @@ -163,6 +168,25 @@ public class Test1914 { return klass.getDeclaredMethod(name, Runnable.class); } + public static interface Foo { + public void InterfaceProxyMethod(Runnable r); + } + + public static Object getProxyObject(final Class... k) { + return Proxy.newProxyInstance( + Test1914.class.getClassLoader(), + k, + (p, m, a) -> { + if (m.getName().equals("toString")) { + return "Proxy for " + Arrays.toString(k); + } else { + ((Runnable)a[0]).run(); + reportValue(p); + return null; + } + }); + } + public static void run() throws Exception { Locals.EnableLocalVariableAccess(); final TestCase[] MAIN_TEST_CASES = new TestCase[] { @@ -172,6 +196,8 @@ public class Test1914 { getMethod(TargetClass.class, "InstanceMethod")), new TestCase(new TargetClass("NativeInstanceMethodObject"), getMethod(TargetClass.class, "NativeInstanceMethod")), + new TestCase(getProxyObject(Foo.class), + getMethod(Foo.class, "InterfaceProxyMethod")), }; for (TestCase t: MAIN_TEST_CASES) { |