From 681652d8e8a33bc07c5c082a71aea13d0f15e0a0 Mon Sep 17 00:00:00 2001 From: Mingyao Yang Date: Wed, 22 Jul 2015 15:56:34 -0700 Subject: HDeoptimize should hold values live in env. Values that are not live in compiled code anymore may still be needed in interpreter, due to code motion, etc. (cherry-picked from commit 718493c6c3c8e380663cb8a94e57ce160a6c473f) Bug: 22665511 Change-Id: I8b85833c5c462f8fe36f86d6026a51b07563995a --- compiler/optimizing/ssa_liveness_analysis.cc | 2 +- compiler/optimizing/ssa_liveness_analysis.h | 8 +++++++- test/449-checker-bce/expected.txt | 1 + test/449-checker-bce/src/Main.java | 23 +++++++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/compiler/optimizing/ssa_liveness_analysis.cc b/compiler/optimizing/ssa_liveness_analysis.cc index 250eb04a1c..ce376da70d 100644 --- a/compiler/optimizing/ssa_liveness_analysis.cc +++ b/compiler/optimizing/ssa_liveness_analysis.cc @@ -225,7 +225,7 @@ void SsaLivenessAnalysis::ComputeLiveRanges() { // SsaLivenessAnalysis. for (size_t i = 0, e = environment->Size(); i < e; ++i) { HInstruction* instruction = environment->GetInstructionAt(i); - bool should_be_live = ShouldBeLiveForEnvironment(instruction); + bool should_be_live = ShouldBeLiveForEnvironment(current, instruction); if (should_be_live) { DCHECK(instruction->HasSsaIndex()); live_in->SetBit(instruction->GetSsaIndex()); diff --git a/compiler/optimizing/ssa_liveness_analysis.h b/compiler/optimizing/ssa_liveness_analysis.h index 82c5454bb0..c46fac27df 100644 --- a/compiler/optimizing/ssa_liveness_analysis.h +++ b/compiler/optimizing/ssa_liveness_analysis.h @@ -1190,8 +1190,14 @@ class SsaLivenessAnalysis : public ValueObject { // Update the live_out set of the block and returns whether it has changed. bool UpdateLiveOut(const HBasicBlock& block); - static bool ShouldBeLiveForEnvironment(HInstruction* instruction) { + // Returns whether `instruction` in an HEnvironment held by `env_holder` + // should be kept live by the HEnvironment. + static bool ShouldBeLiveForEnvironment(HInstruction* env_holder, + HInstruction* instruction) { if (instruction == nullptr) return false; + // A value that's not live in compiled code may still be needed in interpreter, + // due to code motion, etc. + if (env_holder->IsDeoptimize()) return true; if (instruction->GetBlock()->GetGraph()->IsDebuggable()) return true; return instruction->GetType() == Primitive::kPrimNot; } diff --git a/test/449-checker-bce/expected.txt b/test/449-checker-bce/expected.txt index e69de29bb2..e114c50371 100644 --- a/test/449-checker-bce/expected.txt +++ b/test/449-checker-bce/expected.txt @@ -0,0 +1 @@ +java.lang.ArrayIndexOutOfBoundsException: length=5; index=82 diff --git a/test/449-checker-bce/src/Main.java b/test/449-checker-bce/src/Main.java index 7a45ce357d..c7246e0aa4 100644 --- a/test/449-checker-bce/src/Main.java +++ b/test/449-checker-bce/src/Main.java @@ -1101,6 +1101,28 @@ public class Main { } + public void testExceptionMessage() { + short[] B1 = new short[5]; + int[] B2 = new int[5]; + Exception err = null; + try { + testExceptionMessage1(B1, B2, null, -1, 6); + } catch (Exception e) { + err = e; + } + System.out.println(err); + } + + void testExceptionMessage1(short[] a1, int[] a2, long a3[], int start, int finish) { + int j = finish + 77; + // Bug: 22665511 + // A deoptimization will be triggered here right before the loop. Need to make + // sure the value of j is preserved for the interpreter. + for (int i = start; i <= finish; i++) { + a2[j - 1] = a1[i + 1]; + } + } + // Make sure this method is compiled with optimizing. // CHECK-START: void Main.main(java.lang.String[]) register (after) // CHECK: ParallelMove @@ -1141,6 +1163,7 @@ public class Main { }; testUnknownBounds(); + new Main().testExceptionMessage(); } } -- cgit v1.2.3