From be6fa5eb4a571e14481cf43f4cb264629c069153 Mon Sep 17 00:00:00 2001 From: Brian Carlstrom Date: Tue, 9 Dec 2014 20:15:42 -0800 Subject: [PATCH] Fix verifier bug caused by confusing ArtMethod::IsDirect vs ArtMethod::IsStatic semantics. Bug: 18485243 Change-Id: I011872446490628b51fb38a353abd1d499cc1290 --- runtime/verifier/method_verifier.cc | 2 +- test/118-noimage-dex2oat/expected.txt | 3 +++ test/118-noimage-dex2oat/smali/b_18485243.smali | 22 ++++++++++++++++++++++ test/118-noimage-dex2oat/src/Main.java | 18 ++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/118-noimage-dex2oat/smali/b_18485243.smali diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index c206b94ec..441a08abe 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -3168,7 +3168,7 @@ mirror::ArtMethod* MethodVerifier::ResolveMethodAndCheckAccess(uint32_t dex_meth } // See if the method type implied by the invoke instruction matches the access flags for the // target method. - if ((method_type == METHOD_DIRECT && !res_method->IsDirect()) || + if ((method_type == METHOD_DIRECT && (!res_method->IsDirect() || res_method->IsStatic())) || (method_type == METHOD_STATIC && !res_method->IsStatic()) || ((method_type == METHOD_VIRTUAL || method_type == METHOD_INTERFACE) && res_method->IsDirect()) ) { diff --git a/test/118-noimage-dex2oat/expected.txt b/test/118-noimage-dex2oat/expected.txt index 6825fae41..bcb695d23 100644 --- a/test/118-noimage-dex2oat/expected.txt +++ b/test/118-noimage-dex2oat/expected.txt @@ -1,6 +1,9 @@ Run -Xnoimage-dex2oat Has image is false, is image dex2oat enabled is false, is BOOTCLASSPATH on disk is false. +testB18485243 PASS Run -Ximage-dex2oat Has image is true, is image dex2oat enabled is true, is BOOTCLASSPATH on disk is true. +testB18485243 PASS Run default Has image is true, is image dex2oat enabled is true, is BOOTCLASSPATH on disk is true. +testB18485243 PASS diff --git a/test/118-noimage-dex2oat/smali/b_18485243.smali b/test/118-noimage-dex2oat/smali/b_18485243.smali new file mode 100644 index 000000000..41fbc7467 --- /dev/null +++ b/test/118-noimage-dex2oat/smali/b_18485243.smali @@ -0,0 +1,22 @@ +.class public LB18485243; +.super Ljava/lang/Object; +.source "b_18485243.smali" + +.method public constructor ()V + .registers 2 + invoke-direct {p0}, Ljava/lang/Object;->()V + return-void +.end method + +.method private static toInt()I + .registers 1 + const v0, 0 + return v0 +.end method + +.method public run()I + .registers 3 + invoke-direct {p0}, LB18485243;->toInt()I + move-result v0 + return v0 +.end method diff --git a/test/118-noimage-dex2oat/src/Main.java b/test/118-noimage-dex2oat/src/Main.java index c83b84de6..9bf5bb3b0 100644 --- a/test/118-noimage-dex2oat/src/Main.java +++ b/test/118-noimage-dex2oat/src/Main.java @@ -14,6 +14,7 @@ * limitations under the License. */ +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { @@ -36,6 +37,8 @@ public class Main { } else if (!hasImage && isBootClassPathOnDisk) { throw new Error("Image with dex2oat enabled runs without an image file"); } + + testB18485243(); } static { @@ -67,4 +70,19 @@ public class Main { return (boolean) isBootClassPathOnDiskMethod.invoke(null, instructionSet); } } + + private static void testB18485243() throws Exception { + Class k = Class.forName("B18485243"); + Object o = k.newInstance(); + Method m = k.getDeclaredMethod("run"); + try { + m.invoke(o); + } catch (InvocationTargetException e) { + Throwable actual = e.getTargetException(); + if (!(actual instanceof IncompatibleClassChangeError)) { + throw new AssertionError("Expected IncompatibleClassChangeError", actual); + } + } + System.out.println("testB18485243 PASS"); + } } -- 2.11.0