OSDN Git Service

Check if the type of an instruction is erroneous before inlining.
authorNicolas Geoffray <ngeoffray@google.com>
Fri, 18 Mar 2016 11:36:20 +0000 (11:36 +0000)
committerNicolas Geoffray <ngeoffray@google.com>
Mon, 21 Mar 2016 11:23:28 +0000 (11:23 +0000)
We can get HInstructions typed with a class that is in an error state.
For such classes, we cannot look at the vtable or imt table as they
are not cleanly populated.

bug:27683927

Change-Id: I0d64ca470e1cb6cf9b40e9f02bb9b0bb12c2bac1

compiler/optimizing/inliner.cc
test/587-inline-class-error/expected.txt [new file with mode: 0644]
test/587-inline-class-error/info.txt [new file with mode: 0644]
test/587-inline-class-error/smali/SuperVerifyError.smali [new file with mode: 0644]
test/587-inline-class-error/smali/TestCase.smali [new file with mode: 0644]
test/587-inline-class-error/smali/VerifyError.smali [new file with mode: 0644]
test/587-inline-class-error/src/Main.java [new file with mode: 0644]

index 573b583..440a282 100644 (file)
@@ -144,6 +144,10 @@ static ArtMethod* FindVirtualOrInterfaceTarget(HInvoke* invoke, ArtMethod* resol
   } else if (!resolved_method->GetDeclaringClass()->IsAssignableFrom(info.GetTypeHandle().Get())) {
     // The method that we're trying to call is not in the receiver's class or super classes.
     return nullptr;
+  } else if (info.GetTypeHandle()->IsErroneous()) {
+    // If the type is erroneous, do not go further, as we are going to query the vtable or
+    // imt table, that we can only safely do on non-erroneous classes.
+    return nullptr;
   }
 
   ClassLinker* cl = Runtime::Current()->GetClassLinker();
diff --git a/test/587-inline-class-error/expected.txt b/test/587-inline-class-error/expected.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/587-inline-class-error/info.txt b/test/587-inline-class-error/info.txt
new file mode 100644 (file)
index 0000000..7f244f6
--- /dev/null
@@ -0,0 +1,2 @@
+Regression test for the inliner that used to crash while
+trying to find a method for an erroneous class.
diff --git a/test/587-inline-class-error/smali/SuperVerifyError.smali b/test/587-inline-class-error/smali/SuperVerifyError.smali
new file mode 100644 (file)
index 0000000..b63cba0
--- /dev/null
@@ -0,0 +1,27 @@
+# Copyright (C) 2016 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.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LSuperVerifyError;
+
+.super Ljava/lang/Object;
+
+.method public final foo()V
+  .registers 1
+  return-void
+.end method
+
+.method public bar()V
+  .registers 1
+  return-void
+.end method
diff --git a/test/587-inline-class-error/smali/TestCase.smali b/test/587-inline-class-error/smali/TestCase.smali
new file mode 100644 (file)
index 0000000..7c991ed
--- /dev/null
@@ -0,0 +1,33 @@
+# Copyright (C) 2016 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.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public LTestCase;
+
+.super Ljava/lang/Object;
+
+.method public static topLevel()V
+  .registers 2
+  const v0, 0x1
+  new-array v0, v0, [LVerifyError;
+  invoke-static {v0}, LTestCase;->test([LVerifyError;)V
+  return-void
+.end method
+
+.method public static test([LVerifyError;)V
+   .registers 2
+   const v0, 0x0
+   aget-object v1, v1, v0
+   invoke-virtual {v1}, LSuperVerifyError;->bar()V
+   return-void
+.end method
diff --git a/test/587-inline-class-error/smali/VerifyError.smali b/test/587-inline-class-error/smali/VerifyError.smali
new file mode 100644 (file)
index 0000000..b821b71
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright (C) 2016 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.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+.class public final LVerifyError;
+
+.super LSuperVerifyError;
+
+# Override a final method to put this class in the error state.
+.method public foo()V
+  .registers 1
+  return-void
+.end method
+
+# Having a static field in the class is needed to get the
+# right initialization for the embedded vtable length of a
+# class.
+.field public static i:I
diff --git a/test/587-inline-class-error/src/Main.java b/test/587-inline-class-error/src/Main.java
new file mode 100644 (file)
index 0000000..3402fab
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.lang.reflect.InvocationTargetException;
+
+public class Main {
+  public static void main(String[] args) throws Exception {
+    try {
+      Class<?> v = Class.forName("VerifyError");
+      throw new Error("Expected LinkageError");
+    } catch (LinkageError e) {
+      // expected
+    }
+
+    try {
+      Class.forName("TestCase").getMethod("topLevel").invoke(null);
+      throw new Error("Expected InvocationTargetException");
+    } catch (InvocationTargetException e) {
+      if (!(e.getCause() instanceof NullPointerException)) {
+        throw new Error("Expected NullPointerException, got " + e.getCause());
+      }
+    }
+  }
+}