summaryrefslogtreecommitdiffstats
path: root/test/478-checker-clinit-check-pruning
diff options
context:
space:
mode:
authorRoland Levillain <rpl@google.com>2015-04-24 19:14:22 +0100
committerRoland Levillain <rpl@google.com>2015-04-24 19:18:27 +0100
commit5f02c6caf9f38be49e655f8bdeeeb99b6faf9383 (patch)
treee0675b7691662a452a2bb48ebbf5410ceac51c85 /test/478-checker-clinit-check-pruning
parenteb5459ca861b58ee8a9907789f11400dcdddb87b (diff)
downloadart-5f02c6caf9f38be49e655f8bdeeeb99b6faf9383.tar.gz
art-5f02c6caf9f38be49e655f8bdeeeb99b6faf9383.tar.bz2
art-5f02c6caf9f38be49e655f8bdeeeb99b6faf9383.zip
Reduce the number of explicit clinit checks for static invokes.
Do not generate explicit clinit checks for static invokes when the class of the called method is a super class of the caller method's class (referrer class). Change-Id: I86ba18facef261fbb71f7ed20867756630ed3c53
Diffstat (limited to 'test/478-checker-clinit-check-pruning')
-rw-r--r--test/478-checker-clinit-check-pruning/expected.txt2
-rw-r--r--test/478-checker-clinit-check-pruning/src/Main.java76
2 files changed, 78 insertions, 0 deletions
diff --git a/test/478-checker-clinit-check-pruning/expected.txt b/test/478-checker-clinit-check-pruning/expected.txt
index 39d9d75df5..387e1a7cb1 100644
--- a/test/478-checker-clinit-check-pruning/expected.txt
+++ b/test/478-checker-clinit-check-pruning/expected.txt
@@ -2,3 +2,5 @@ Main$ClassWithClinit1's static initializer
Main$ClassWithClinit2's static initializer
Main$ClassWithClinit3's static initializer
Main$ClassWithClinit4's static initializer
+Main$ClassWithClinit5's static initializer
+Main$ClassWithClinit6's static initializer
diff --git a/test/478-checker-clinit-check-pruning/src/Main.java b/test/478-checker-clinit-check-pruning/src/Main.java
index 5370f8645f..6da8945c43 100644
--- a/test/478-checker-clinit-check-pruning/src/Main.java
+++ b/test/478-checker-clinit-check-pruning/src/Main.java
@@ -186,6 +186,80 @@ public class Main {
}
}
+ /*
+ * Ensure an inlined call to a static method whose declaring class
+ * is a super class of the caller's class does not require an
+ * explicit clinit check.
+ */
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() builder (after)
+ // CHECK-DAG: InvokeStaticOrDirect
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() builder (after)
+ // CHECK-NOT: LoadClass
+ // CHECK-NOT: ClinitCheck
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit5.invokeStaticInlined() inliner (after)
+ // CHECK-NOT: LoadClass
+ // CHECK-NOT: ClinitCheck
+ // CHECK-NOT: InvokeStaticOrDirect
+
+ static class ClassWithClinit5 {
+ static void $opt$inline$StaticMethod() {
+ }
+
+ static {
+ System.out.println("Main$ClassWithClinit5's static initializer");
+ }
+ }
+
+ static class SubClassOfClassWithClinit5 extends ClassWithClinit5 {
+ static void invokeStaticInlined() {
+ ClassWithClinit5.$opt$inline$StaticMethod();
+ }
+ }
+
+ /*
+ * Ensure an non-inlined call to a static method whose declaring
+ * class is a super class of the caller's class does not require an
+ * explicit clinit check.
+ */
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() builder (after)
+ // CHECK-DAG: InvokeStaticOrDirect
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() builder (after)
+ // CHECK-NOT: LoadClass
+ // CHECK-NOT: ClinitCheck
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() inliner (after)
+ // CHECK-DAG: InvokeStaticOrDirect
+
+ // CHECK-START: void Main$SubClassOfClassWithClinit6.invokeStaticNotInlined() inliner (after)
+ // CHECK-NOT: LoadClass
+ // CHECK-NOT: ClinitCheck
+
+ static class ClassWithClinit6 {
+ static boolean doThrow = false;
+
+ static void staticMethod() {
+ if (doThrow) {
+ // Try defeating inlining.
+ throw new Error();
+ }
+ }
+
+ static {
+ System.out.println("Main$ClassWithClinit6's static initializer");
+ }
+ }
+
+ static class SubClassOfClassWithClinit6 extends ClassWithClinit6 {
+ static void invokeStaticNotInlined() {
+ ClassWithClinit6.staticMethod();
+ }
+ }
+
// TODO: Add a test for the case of a static method whose declaring
// class type index is not available (i.e. when `storage_index`
// equals `DexFile::kDexNoIndex` in
@@ -196,5 +270,7 @@ public class Main {
invokeStaticNotInlined();
ClassWithClinit3.invokeStaticInlined();
ClassWithClinit4.invokeStaticNotInlined();
+ SubClassOfClassWithClinit5.invokeStaticInlined();
+ SubClassOfClassWithClinit6.invokeStaticNotInlined();
}
}