8188151: "assert(entry_for(catch_pco, handler_bcis->at(i), scope_depth)->pco() == handler_pcos->at(i))" failure with C1
authorroland
Tue, 10 Oct 2017 14:05:04 +0200
changeset 47700 c6d2381c6932
parent 47699 068d316e905e
child 47701 be620a591379
child 47755 32201e2d5719
child 47756 55714c3d544c
8188151: "assert(entry_for(catch_pco, handler_bcis->at(i), scope_depth)->pco() == handler_pcos->at(i))" failure with C1 Reviewed-by: kvn, dlong
src/hotspot/share/c1/c1_Compilation.cpp
test/hotspot/jtreg/compiler/exceptions/TestC1ExceptionHandlersSameBCI.java
--- a/src/hotspot/share/c1/c1_Compilation.cpp	Thu Oct 26 05:59:15 2017 -0700
+++ b/src/hotspot/share/c1/c1_Compilation.cpp	Tue Oct 10 14:05:04 2017 +0200
@@ -500,18 +500,22 @@
     scope_depths->trunc_to(0);
     pcos->trunc_to(0);
 
+    int prev_scope = 0;
     for (int i = 0; i < handlers->length(); i++) {
       XHandler* handler = handlers->handler_at(i);
       assert(handler->entry_pco() != -1, "must have been generated");
+      assert(handler->scope_count() >= prev_scope, "handlers should be sorted by scope");
 
-      int e = bcis->find(handler->handler_bci());
-      if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
-        // two different handlers are declared to dispatch to the same
-        // catch bci.  During parsing we created edges for each
-        // handler but we really only need one.  The exception handler
-        // table will also get unhappy if we try to declare both since
-        // it's nonsensical.  Just skip this handler.
-        continue;
+      if (handler->scope_count() == prev_scope) {
+        int e = bcis->find_from_end(handler->handler_bci());
+        if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
+          // two different handlers are declared to dispatch to the same
+          // catch bci.  During parsing we created edges for each
+          // handler but we really only need one.  The exception handler
+          // table will also get unhappy if we try to declare both since
+          // it's nonsensical.  Just skip this handler.
+          continue;
+        }
       }
 
       bcis->append(handler->handler_bci());
@@ -521,13 +525,14 @@
         scope_depths->append(0);
       } else {
         scope_depths->append(handler->scope_count());
-    }
+      }
       pcos->append(handler->entry_pco());
 
       // stop processing once we hit a catch any
       if (handler->is_catch_all()) {
         assert(i == handlers->length() - 1, "catch all must be last handler");
-  }
+      }
+      prev_scope = handler->scope_count();
     }
     exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/exceptions/TestC1ExceptionHandlersSameBCI.java	Tue Oct 10 14:05:04 2017 +0200
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2017, Red Hat, Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8188151
+ * @summary assert failure with 2 handlers at same bci
+ * @run main/othervm -XX:-BackgroundCompilation -XX:CompileOnly=TestC1ExceptionHandlersSameBCI::test1 -XX:CompileOnly=TestC1ExceptionHandlersSameBCI::test2 -XX:CompileCommand=dontinline,TestC1ExceptionHandlersSameBCI::not_inline1 -XX:CompileCommand=dontinline,TestC1ExceptionHandlersSameBCI::not_inline2 TestC1ExceptionHandlersSameBCI
+ *
+ */
+
+public class TestC1ExceptionHandlersSameBCI {
+    static class Ex1 extends Exception {
+
+    }
+    static class Ex2 extends Exception {
+
+    }
+
+    static void not_inline1() throws Ex1, Ex2 {
+
+    }
+
+    static void not_inline2(int v) {
+
+    }
+
+    static void test1() throws Ex1, Ex2 {
+        int i = 0;
+        try {
+            not_inline1();
+            i = 1;
+            not_inline1();
+        } catch (Ex1|Ex2 ex) {
+            not_inline2(i);
+        }
+    }
+
+    static void test2() {
+        int i = 0;
+        try {
+            test1();
+            i = 1;
+            test1();
+        } catch (Ex1|Ex2 ex) {
+            not_inline2(i);
+        }
+    }
+
+    static public void main(String[] args) {
+        for (int i = 0; i < 5000; i++) {
+            test2();
+        }
+    }
+}