Revert "Revert^2: Deopt does not throw"
This reverts commit 240384b7d96c2d579bf58ed7a3e9c9ba1911dae3.
Reason for revert: P1 b/78360004 points to this so reverting for now (will triage later)
Change-Id: I041c1d9fc045391c73e887268c3b1b9b69fcc216
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index 79bb70b..f784f8f 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -1916,6 +1916,15 @@
}
}
+bool HBasicBlock::HasThrowingInstructions() const {
+ for (HInstructionIterator it(GetInstructions()); !it.Done(); it.Advance()) {
+ if (it.Current()->CanThrow()) {
+ return true;
+ }
+ }
+ return false;
+}
+
static bool HasOnlyOneInstruction(const HBasicBlock& block) {
return block.GetPhis().IsEmpty()
&& !block.GetInstructions().IsEmpty()
diff --git a/compiler/optimizing/nodes.h b/compiler/optimizing/nodes.h
index b315c81..79d7330 100644
--- a/compiler/optimizing/nodes.h
+++ b/compiler/optimizing/nodes.h
@@ -1272,6 +1272,8 @@
// the appropriate try entry will be returned.
const HTryBoundary* ComputeTryEntryOfSuccessors() const;
+ bool HasThrowingInstructions() const;
+
// Returns whether this block dominates the blocked passed as parameter.
bool Dominates(HBasicBlock* block) const;
@@ -2130,7 +2132,6 @@
!CanThrow() &&
!IsSuspendCheck() &&
!IsControlFlow() &&
- !IsDeoptimize() &&
!IsNativeDebugInfo() &&
!IsParameterValue() &&
// If we added an explicit barrier then we should keep it.
@@ -3237,9 +3238,7 @@
bool NeedsEnvironment() const OVERRIDE { return true; }
- // Even though deoptimize is often used for "exceptional cases" to go back to
- // the interpreter, it never throws an exception.
- bool CanThrow() const OVERRIDE { return false; }
+ bool CanThrow() const OVERRIDE { return true; }
DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); }
diff --git a/test/683-deopt-regression/expected.txt b/test/683-deopt-regression/expected.txt
deleted file mode 100644
index b0aad4d..0000000
--- a/test/683-deopt-regression/expected.txt
+++ /dev/null
@@ -1 +0,0 @@
-passed
diff --git a/test/683-deopt-regression/info.txt b/test/683-deopt-regression/info.txt
deleted file mode 100644
index 0c2cb81..0000000
--- a/test/683-deopt-regression/info.txt
+++ /dev/null
@@ -1 +0,0 @@
-Regression test on deopt from BCE
diff --git a/test/683-deopt-regression/smali/Deopt.smali b/test/683-deopt-regression/smali/Deopt.smali
deleted file mode 100644
index 3bd9f6c..0000000
--- a/test/683-deopt-regression/smali/Deopt.smali
+++ /dev/null
@@ -1,60 +0,0 @@
-# Copyright (C) 2018 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 LDeopt;
-
-.super Ljava/lang/Object;
-
-.method public constructor <init>()V
-.registers 1
- invoke-direct {v0}, Ljava/lang/Object;-><init>()V
- return-void
-.end method
-
-.method public static testCase([I)I
- .registers 8
-
- const v0, 0x0 # counter
- const v1, 0xF # loop max
- const v2, 0x0 # result
-
- :try_start
- # Something throwing to start the try block. v6 contains a reference.
- move-object v6, p0
- aget v3, p0, v0
-
- # Invalidate v6 before entering the loop.
- const-wide v5, 0x0
-
- :loop_start
- # Set v6 to a different reference (creates a catch phi).
- const v6, 0x0
-
- aget v3, p0, v0
- add-int/2addr v2, v3
- add-int/lit8 v0, v0, 0x1
- if-lt v0, v1, :loop_start
-
- :try_end
- .catchall {:try_start .. :try_end} :catch
-
- :exit
- return v2
-
- :catch
- invoke-virtual {v6}, Ljava/lang/Object;->hashCode()I # use v6 as a reference
- goto :exit
-
-.end method
-
diff --git a/test/683-deopt-regression/src/Main.java b/test/683-deopt-regression/src/Main.java
deleted file mode 100644
index 326fe47..0000000
--- a/test/683-deopt-regression/src/Main.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2018 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 {
- public static void main(String[] args) throws Exception {
- if (System.getProperty("java.vm.name").equals("Dalvik")) {
- Class<?> c = Class.forName("Deopt");
- Method m = c.getMethod("testCase", int[].class);
- int[] p = null;
- try {
- m.invoke(null, p);
- System.out.println("should not reach");
- } catch (Exception e) {
- // Tried to invoke hashCode on incoming null.
- }
- int result;
- int[] q = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
- result = ((Integer) m.invoke(null, q));
- expectEquals(120, result);
- int[] r = { };
- result = ((Integer) m.invoke(null, r));
- expectEquals(0, result);
- int[] s = { 1 };
- try {
- m.invoke(null, s);
- System.out.println("should not reach");
- } catch (Exception e) {
- // Tried to invoke hashCode on generated null.
- }
- }
- System.out.println("passed");
- }
-
- private static void expectEquals(int expected, int result) {
- if (expected != result) {
- throw new Error("Expected: " + expected + ", found: " + result);
- }
- }
-}