Fix inliner crash related to type propagation.
- Do not agressively try to resolve a return type.
- Deal with unresolved return type.
bug:25492619
Change-Id: Idc9c96a0b376fe5ee86b411c02ce7078c7f48c84
diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc
index d861e39..fe528a0 100644
--- a/compiler/optimizing/inliner.cc
+++ b/compiler/optimizing/inliner.cc
@@ -1279,10 +1279,14 @@
// some functionality from the reference type propagation.
DCHECK(return_replacement->IsPhi());
size_t pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
- ReferenceTypeInfo::TypeHandle return_handle =
- handles_->NewHandle(resolved_method->GetReturnType(true /* resolve */, pointer_size));
- return_replacement->SetReferenceTypeInfo(ReferenceTypeInfo::Create(
- return_handle, return_handle->CannotBeAssignedFromOtherTypes() /* is_exact */));
+ mirror::Class* cls = resolved_method->GetReturnType(false /* resolve */, pointer_size);
+ if (cls != nullptr) {
+ ReferenceTypeInfo::TypeHandle return_handle= handles_->NewHandle(cls);
+ return_replacement->SetReferenceTypeInfo(ReferenceTypeInfo::Create(
+ return_handle, return_handle->CannotBeAssignedFromOtherTypes() /* is_exact */));
+ } else {
+ return_replacement->SetReferenceTypeInfo(graph_->GetInexactObjectRti());
+ }
}
if (do_rtp) {
diff --git a/test/585-inline-unresolved/expected.txt b/test/585-inline-unresolved/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/585-inline-unresolved/expected.txt
diff --git a/test/585-inline-unresolved/info.txt b/test/585-inline-unresolved/info.txt
new file mode 100644
index 0000000..414f638
--- /dev/null
+++ b/test/585-inline-unresolved/info.txt
@@ -0,0 +1,2 @@
+Regression test for optimizing that used to crash when inlining
+a method whose return type is unresolved.
diff --git a/test/585-inline-unresolved/smali/TestCase.smali b/test/585-inline-unresolved/smali/TestCase.smali
new file mode 100644
index 0000000..f260092
--- /dev/null
+++ b/test/585-inline-unresolved/smali/TestCase.smali
@@ -0,0 +1,48 @@
+# 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;
+
+.field static private test1:Z
+
+.method public static topLevel()V
+ .registers 1
+ invoke-static {}, LTestCase;->$inline$foo()LUnresolved;
+ return-void
+.end method
+
+# We need multiple returns to trigger the crash.
+.method public static $inline$foo()LUnresolved;
+ .registers 2
+ const v1, 0x0
+ sget-boolean v0, LTestCase;->test1:Z
+ if-eqz v0, :other_return
+ return-object v1
+ :other_return
+ invoke-static {}, LTestCase;->$noinline$bar()LUnresolved;
+ move-result-object v0
+ return-object v0
+.end method
+
+.method public static $noinline$bar()LUnresolved;
+ .registers 2
+ const v1, 0x0
+ sget-boolean v0, LTestCase;->test1:Z
+ if-eqz v0, :return
+ throw v1
+ :return
+ return-object v1
+.end method
diff --git a/test/585-inline-unresolved/src/Main.java b/test/585-inline-unresolved/src/Main.java
new file mode 100644
index 0000000..67ad4d2
--- /dev/null
+++ b/test/585-inline-unresolved/src/Main.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+public class Main {
+ public static void main(String[] args) throws Exception {
+ Class<?> c = Class.forName("TestCase");
+ c.getMethod("topLevel").invoke(null);
+ }
+}
diff --git a/test/etc/default-build b/test/etc/default-build
index 2eb7760..d048757 100755
--- a/test/etc/default-build
+++ b/test/etc/default-build
@@ -131,16 +131,14 @@
jar cf classes.jill.jar -C classes .
jar cf classes-ex.jill.jar -C classes-ex .
- ${JACK} --import classes.jill.jar --output-dex .
- zip $TEST_NAME.jar classes.dex
${JACK} --import classes-ex.jill.jar --output-dex .
zip ${TEST_NAME}-ex.jar classes.dex
+ ${JACK} --import classes.jill.jar --output-dex .
else
if [ ${NEED_DEX} = "true" ]; then
- ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex --dump-width=1000 classes
- zip $TEST_NAME.jar classes.dex
${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes.dex --dump-width=1000 classes-ex
zip ${TEST_NAME}-ex.jar classes.dex
+ ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex --dump-width=1000 classes
fi
fi
else
@@ -200,63 +198,62 @@
fi
fi
fi
+fi
- if [ "${HAS_SMALI}" = "true" ]; then
- # Compile Smali classes
- ${SMALI} -JXmx512m ${SMALI_ARGS} --output smali_classes.dex `find smali -name '*.smali'`
+if [ "${HAS_SMALI}" = "true" ]; then
+ # Compile Smali classes
+ ${SMALI} -JXmx512m ${SMALI_ARGS} --output smali_classes.dex `find smali -name '*.smali'`
- # Don't bother with dexmerger if we provide our own main function in a smali file.
- if [ ${SKIP_DX_MERGER} = "false" ]; then
- ${DXMERGER} classes.dex classes.dex smali_classes.dex
- else
- mv smali_classes.dex classes.dex
+ # Don't bother with dexmerger if we provide our own main function in a smali file.
+ if [ ${SKIP_DX_MERGER} = "false" ]; then
+ ${DXMERGER} classes.dex classes.dex smali_classes.dex
+ else
+ mv smali_classes.dex classes.dex
+ fi
+fi
+
+if [ "${HAS_SMALI_MULTIDEX}" = "true" ]; then
+ # Compile Smali classes
+ ${SMALI} -JXmx512m ${SMALI_ARGS} --output smali_classes2.dex `find smali-multidex -name '*.smali'`
+
+ # Don't bother with dexmerger if we provide our own main function in a smali file.
+ if [ ${HAS_SRC_MULTIDEX} = "true" ]; then
+ ${DXMERGER} classes2.dex classes2.dex smali_classes2.dex
+ else
+ mv smali_classes2.dex classes2.dex
+ fi
+fi
+
+
+if [ ${HAS_SRC_EX} = "true" ]; then
+ if [ ${USE_JACK} = "true" ]; then
+ # Rename previous "classes.dex" so it is not overwritten.
+ mv classes.dex classes-1.dex
+ #TODO find another way to append src.jack to the jack classpath
+ ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex
+ zip $TEST_NAME-ex.jar classes.dex
+ # Restore previous "classes.dex" so it can be zipped.
+ mv classes-1.dex classes.dex
+ else
+ mkdir classes-ex
+ ${JAVAC} ${JAVAC_ARGS} -d classes-ex -cp classes `find src-ex -name '*.java'`
+ if [ ${NEED_DEX} = "true" ]; then
+ ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \
+ --dump-width=1000 ${DX_FLAGS} classes-ex
+
+ # quick shuffle so that the stored name is "classes.dex"
+ mv classes.dex classes-1.dex
+ mv classes-ex.dex classes.dex
+ zip $TEST_NAME-ex.jar classes.dex
+ mv classes.dex classes-ex.dex
+ mv classes-1.dex classes.dex
fi
fi
-
- if [ "${HAS_SMALI_MULTIDEX}" = "true" ]; then
- # Compile Smali classes
- ${SMALI} -JXmx512m ${SMALI_ARGS} --output smali_classes2.dex `find smali-multidex -name '*.smali'`
-
- # Don't bother with dexmerger if we provide our own main function in a smali file.
- if [ ${HAS_SRC_MULTIDEX} = "true" ]; then
- ${DXMERGER} classes2.dex classes2.dex smali_classes2.dex
- else
- mv smali_classes2.dex classes2.dex
- fi
- fi
-
-
- if [ ${HAS_SRC_EX} = "true" ]; then
- if [ ${USE_JACK} = "true" ]; then
- # Rename previous "classes.dex" so it is not overwritten.
- mv classes.dex classes-1.dex
- #TODO find another way to append src.jack to the jack classpath
- ${JACK}:src.jack ${JACK_ARGS} --output-dex . src-ex
- zip $TEST_NAME-ex.jar classes.dex
- # Restore previous "classes.dex" so it can be zipped.
- mv classes-1.dex classes.dex
- else
- mkdir classes-ex
- ${JAVAC} ${JAVAC_ARGS} -d classes-ex -cp classes `find src-ex -name '*.java'`
- if [ ${NEED_DEX} = "true" ]; then
- ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \
- --dump-width=1000 ${DX_FLAGS} classes-ex
-
- # quick shuffle so that the stored name is "classes.dex"
- mv classes.dex classes-1.dex
- mv classes-ex.dex classes.dex
- zip $TEST_NAME-ex.jar classes.dex
- mv classes.dex classes-ex.dex
- mv classes-1.dex classes.dex
- fi
- fi
- fi
+fi
# Create a single jar with two dex files for multidex.
- if [ ${HAS_SRC_MULTIDEX} = "true" ] || [ ${HAS_SMALI_MULTIDEX} = "true" ]; then
- zip $TEST_NAME.jar classes.dex classes2.dex
- elif [ ${NEED_DEX} = "true" ]; then
- zip $TEST_NAME.jar classes.dex
- fi
-
+if [ ${HAS_SRC_MULTIDEX} = "true" ] || [ ${HAS_SMALI_MULTIDEX} = "true" ]; then
+ zip $TEST_NAME.jar classes.dex classes2.dex
+elif [ ${NEED_DEX} = "true" ]; then
+ zip $TEST_NAME.jar classes.dex
fi