OSDN Git Service

Quick: Don't expect move-exception in every catch block.
authorVladimir Marko <vmarko@google.com>
Thu, 18 Jun 2015 16:40:00 +0000 (17:40 +0100)
committerVladimir Marko <vmarko@google.com>
Thu, 18 Jun 2015 18:25:42 +0000 (19:25 +0100)
The dalvik bytecode doesn't require a move-exception in
a catch handler that ignores the exception.

Bug: 21873167

(cherry picked from commit 2d1a0a408fd148f7b2a2d670e6942ec3d920f875)

Change-Id: Ia00e5791fabdd1b88e9a63b741600ed63d918703

compiler/dex/mir_graph.cc
test/800-smali/expected.txt
test/800-smali/smali/b_21873167.smali [new file with mode: 0644]
test/800-smali/src/Main.java

index 9fa5148..920be0b 100644 (file)
@@ -398,12 +398,13 @@ bool MIRGraph::IsBadMonitorExitCatch(NarrowDexOffset monitor_exit_offset,
   DCHECK(monitor_exit->Opcode() == Instruction::MONITOR_EXIT);
   int monitor_reg = monitor_exit->VRegA_11x();
   const Instruction* check_insn = Instruction::At(current_code_item_->insns_ + catch_offset);
-  DCHECK(check_insn->Opcode() == Instruction::MOVE_EXCEPTION);
-  if (check_insn->VRegA_11x() == monitor_reg) {
-    // Unexpected move-exception to the same register. Probably not the pattern we're looking for.
-    return false;
+  if (check_insn->Opcode() == Instruction::MOVE_EXCEPTION) {
+    if (check_insn->VRegA_11x() == monitor_reg) {
+      // Unexpected move-exception to the same register. Probably not the pattern we're looking for.
+      return false;
+    }
+    check_insn = check_insn->Next();
   }
-  check_insn = check_insn->Next();
   while (true) {
     int dest = -1;
     bool wide = false;
index a6b216b..c5728b5 100644 (file)
@@ -16,4 +16,5 @@ MoveExc
 MoveExceptionOnEntry
 EmptySparseSwitch
 b/20224106
+b/21873167
 Done!
diff --git a/test/800-smali/smali/b_21873167.smali b/test/800-smali/smali/b_21873167.smali
new file mode 100644 (file)
index 0000000..c0c09cb
--- /dev/null
@@ -0,0 +1,18 @@
+.class public LB21873167;
+.super Ljava/lang/Object;
+
+.method public constructor <init>()V
+    .registers 1
+    invoke-direct {p0}, Ljava/lang/Object;-><init>()V
+    return-void
+.end method
+
+.method public test()V
+    .registers 1
+    :start
+    monitor-enter p0
+    monitor-exit  p0
+    :end
+    return-void
+    .catchall {:start .. :end} :end
+.end method
index 3e88364..7196de1 100644 (file)
@@ -81,6 +81,7 @@ public class Main {
                 null));
         testCases.add(new TestCase("b/20224106", "B20224106", "run", null, new VerifyError(),
                 0));
+        testCases.add(new TestCase("b/21873167", "B21873167", "test", null, null, null));
     }
 
     public void runTests() {