--- old/src/hotspot/share/c1/c1_Compilation.cpp 2017-10-02 11:11:42.623792151 +0200 +++ new/src/hotspot/share/c1/c1_Compilation.cpp 2017-10-02 11:11:41.655792933 +0200 @@ -500,11 +500,13 @@ scope_depths->trunc_to(0); pcos->trunc_to(0); + DEBUG_ONLY(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()); + 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 @@ -521,13 +523,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"); - } + } + DEBUG_ONLY(prev_scope = handler->scope_count()); } exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos); } --- /dev/null 2017-09-29 08:45:25.790492889 +0200 +++ new/test/hotspot/jtreg/compiler/c1/TestC1ExceptionHandlersSameBCI.java 2017-10-02 11:11:42.712792079 +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(); + } + } +}