From: Nicolas Geoffray Date: Thu, 2 Mar 2017 16:14:53 +0000 (+0000) Subject: Don't inline methods that throw in graph with irreducible loops. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=1eede6ae9b08d305d0c1123284ff958373916474;p=android-x86%2Fart.git Don't inline methods that throw in graph with irreducible loops. Re-computing the loop information is not supported in graphs with irreducible loops, as it is not deterministic, and the loop header of a loop could change. That would lead to having the suspend check in the wrong block. Test: test-art-host Test: 641-irreducible-inline bug: 35757766 Change-Id: I6a435885461fbeca035e4f5d94f055fc3262adca --- diff --git a/compiler/optimizing/inliner.cc b/compiler/optimizing/inliner.cc index 3e340908b..14437dea3 100644 --- a/compiler/optimizing/inliner.cc +++ b/compiler/optimizing/inliner.cc @@ -1380,6 +1380,13 @@ bool HInliner::TryBuildAndInlineHelper(HInvoke* invoke_instruction, << " could not be inlined because one branch always throws and" << " caller does not have an exit block"; return false; + } else if (graph_->HasIrreducibleLoops()) { + // TODO(ngeoffray): Support re-computing loop information to graphs with + // irreducible loops? + VLOG(compiler) << "Method " << callee_dex_file.PrettyMethod(method_index) + << " could not be inlined because one branch always throws and" + << " caller has irreducible loops"; + return false; } } else { has_one_return = true; diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc index 62c89100e..020e4463d 100644 --- a/compiler/optimizing/nodes.cc +++ b/compiler/optimizing/nodes.cc @@ -2179,6 +2179,9 @@ HInstruction* HGraph::InlineInto(HGraph* outer_graph, HInvoke* invoke) { } } if (rerun_loop_analysis) { + DCHECK(!outer_graph->HasIrreducibleLoops()) + << "Recomputing loop information in graphs with irreducible loops " + << "is unsupported, as it could lead to loop header changes"; outer_graph->ClearLoopInformation(); outer_graph->ClearDominanceInformation(); outer_graph->BuildDominatorTree(); diff --git a/test/641-irreducible-inline/expected.txt b/test/641-irreducible-inline/expected.txt new file mode 100644 index 000000000..d81cc0710 --- /dev/null +++ b/test/641-irreducible-inline/expected.txt @@ -0,0 +1 @@ +42 diff --git a/test/641-irreducible-inline/info.txt b/test/641-irreducible-inline/info.txt new file mode 100644 index 000000000..ec6d0d25c --- /dev/null +++ b/test/641-irreducible-inline/info.txt @@ -0,0 +1,2 @@ +Regression test for optimizing in the presence of +inlining a method that throws in an irreducible loop diff --git a/test/641-irreducible-inline/smali/IrreducibleLoop.smali b/test/641-irreducible-inline/smali/IrreducibleLoop.smali new file mode 100644 index 000000000..3e6c1f1ba --- /dev/null +++ b/test/641-irreducible-inline/smali/IrreducibleLoop.smali @@ -0,0 +1,54 @@ +# Copyright (C) 2017 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 LIrreducibleLoop; + +.super Ljava/lang/Object; + +.method public static simpleLoop(I)I + .registers 3 + const/16 v0, 42 + if-eqz p0, :loop_entry + goto :other_loop_pre_entry + + # The then part: beginning of the irreducible loop. + :loop_entry + if-nez p0, :exit + invoke-static {v0},LIrreducibleLoop;->foo(I)V + :other_loop_entry + goto :loop_entry + + # The else part. + :other_loop_pre_entry + if-eqz p0, :other_loop_entry + invoke-static {v0},LIrreducibleLoop;->foo(I)V + goto :other_loop_entry + + :exit + return v0 +.end method + +.method public static foo(I)V + .registers 3 + const/16 v0, 0 + sget-boolean v1,LIrreducibleLoop;->doThrow:Z + if-eqz v1, :exit + # Inlining a method that throws requires re-computing loop information + # which is unsupported when the caller has an irreducible loop. + throw v0 + :exit + return-void +.end method + +.field public static doThrow:Z diff --git a/test/641-irreducible-inline/src/Main.java b/test/641-irreducible-inline/src/Main.java new file mode 100644 index 000000000..53244f7c3 --- /dev/null +++ b/test/641-irreducible-inline/src/Main.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2017 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.Method; + +public class Main { + // Workaround for b/18051191. + class InnerClass {} + + public static void main(String[] args) throws Exception { + Class c = Class.forName("IrreducibleLoop"); + Method m = c.getMethod("simpleLoop", int.class); + Object[] arguments = { 42 }; + System.out.println(m.invoke(null, arguments)); + } +}