summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2020-09-03 15:07:20 +0100
committer Vladimir Marko <vmarko@google.com> 2020-09-07 08:17:59 +0000
commitb3732f82f915e0dd6a49b9d82af7ac58b049d25f (patch)
treed9a159b893b85d904de50c66c240f9f907c6a708
parent4717175e40a19e79af904dfb7b7dd13f046debd7 (diff)
Add a test to 536-checker-needs-access-check.
We are currently not inlining methods that failed access checks during verification (soft-fail) but we're planning to remove those checks from the verifier. Add a test case that would expose a dex2oatd crash when we do so to make sure we fix the crash when or before relaxing the verification. Test: testrunner.py --host --optimizing -t 536 Test: Repeat the above with code modification to suppress the soft-failure in the verifier: - const RegType& res_type = ResolveClass<CheckAccess::kYes>(dex::TypeIndex(inst->VRegB_21c())); + bool hack = dex_file_->PrettyMethod(dex_method_idx_, false) == + "other2.GetInaccessibleClass.get"; + const RegType& res_type = hack + ? ResolveClass<CheckAccess::kNo>(dex::TypeIndex(inst->VRegB_21c())) + : ResolveClass<CheckAccess::kYes>(dex::TypeIndex(inst->VRegB_21c())); dex2oatd crashes: Check failed: !is_referrers_class || !needs_access_check Bug: 28313047 Change-Id: I00707232b6027574a57aa8d43b790e346d8fd959
-rw-r--r--test/536-checker-needs-access-check/src/Main.java3
-rw-r--r--test/536-checker-needs-access-check/src/other/InaccessibleClass.java9
-rw-r--r--test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java14
-rw-r--r--test/536-checker-needs-access-check/src/other2/GetInaccessibleClass.java (renamed from test/536-checker-needs-access-check/src2/other/InaccessibleClassProxy.java)14
-rw-r--r--test/536-checker-needs-access-check/src2/other/InaccessibleClass.java21
5 files changed, 56 insertions, 5 deletions
diff --git a/test/536-checker-needs-access-check/src/Main.java b/test/536-checker-needs-access-check/src/Main.java
index 7bd49c1c8c..00934e4c3c 100644
--- a/test/536-checker-needs-access-check/src/Main.java
+++ b/test/536-checker-needs-access-check/src/Main.java
@@ -42,6 +42,9 @@ public class Main {
} catch (IllegalAccessError e) {
System.out.println("Got expected error instanceof (keep LoadClass with access check)");
}
+
+ InaccessibleClassProxy.testGetReferrersClass();
+ InaccessibleClassProxy.testGetReferrersClassViaAnotherClass();
}
/// CHECK-START: boolean Main.testInstanceOf() register (after)
diff --git a/test/536-checker-needs-access-check/src/other/InaccessibleClass.java b/test/536-checker-needs-access-check/src/other/InaccessibleClass.java
index de2e1d7830..ab2c9dd990 100644
--- a/test/536-checker-needs-access-check/src/other/InaccessibleClass.java
+++ b/test/536-checker-needs-access-check/src/other/InaccessibleClass.java
@@ -17,4 +17,13 @@
package other;
public class InaccessibleClass {
+ public static Class<?> $noinline$getReferrersClass() {
+ // The actual test is in src2/ .
+ throw new Error("Unreachable");
+ }
+
+ public static Class<?> $noinline$getReferrersClassViaAnotherClass() {
+ // The actual test is in src2/ .
+ throw new Error("Unreachable");
+ }
}
diff --git a/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java b/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java
index 4c005e4dfe..e69531ba2a 100644
--- a/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java
+++ b/test/536-checker-needs-access-check/src/other/InaccessibleClassProxy.java
@@ -20,4 +20,18 @@ public class InaccessibleClassProxy {
public static boolean test(Object o) {
return o instanceof InaccessibleClass;
}
+
+ public static void testGetReferrersClass() {
+ Class<?> klass = InaccessibleClass.$noinline$getReferrersClass();
+ if (klass == null) {
+ throw new Error("Expected non-null klass");
+ }
+ }
+
+ public static void testGetReferrersClassViaAnotherClass() {
+ Class<?> klass = InaccessibleClass.$noinline$getReferrersClassViaAnotherClass();
+ if (klass != null) {
+ throw new Error("Expected non-null klass");
+ }
+ }
}
diff --git a/test/536-checker-needs-access-check/src2/other/InaccessibleClassProxy.java b/test/536-checker-needs-access-check/src/other2/GetInaccessibleClass.java
index 4c005e4dfe..172dbe5568 100644
--- a/test/536-checker-needs-access-check/src2/other/InaccessibleClassProxy.java
+++ b/test/536-checker-needs-access-check/src/other2/GetInaccessibleClass.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,10 +14,14 @@
* limitations under the License.
*/
-package other;
+package other2;
-public class InaccessibleClassProxy {
- public static boolean test(Object o) {
- return o instanceof InaccessibleClass;
+import other.InaccessibleClass;
+
+public class GetInaccessibleClass {
+ // TODO: Make this method `$inline$` once we do not flag access check
+ // failures as soft-fail in the verifier. b/28313047
+ public static Class<?> get() {
+ return InaccessibleClass.class;
}
}
diff --git a/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java b/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java
index 273226375e..743d1ff2e0 100644
--- a/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java
+++ b/test/536-checker-needs-access-check/src2/other/InaccessibleClass.java
@@ -16,5 +16,26 @@
package other;
+import other2.GetInaccessibleClass;
+
/*package*/ class InaccessibleClass {
+ /// CHECK-START: java.lang.Class other.InaccessibleClass.$noinline$getReferrersClass() builder (after)
+ /// CHECK: LoadClass class_name:other.InaccessibleClass needs_access_check:false
+ public static Class<?> $noinline$getReferrersClass() {
+ return InaccessibleClass.class;
+ }
+
+ /// CHECK-START: java.lang.Class other.InaccessibleClass.$noinline$getReferrersClassViaAnotherClass() builder (after)
+ // CHECK: LoadClass class_name:other.InaccessibleClass needs_access_check:true
+ public static Class<?> $noinline$getReferrersClassViaAnotherClass() {
+ // TODO: Make the called method `$inline$` and enable the CHECK above
+ // once we do not flag access check failures as soft-fail in the verifier.
+ // b/28313047
+ Class<?> klass = null;
+ try {
+ klass = GetInaccessibleClass.get();
+ throw new Error("Unreachable");
+ } catch (IllegalAccessError expected) {}
+ return klass;
+ }
}