Path: blob/master/test/hotspot/jtreg/compiler/exceptions/CatchInlineExceptions.java
41152 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 805929926* @summary assert(adr_type != NULL) failed: expecting TypeKlassPtr27*28* @run main/othervm -Xbatch compiler.exceptions.CatchInlineExceptions29*/3031package compiler.exceptions;3233public class CatchInlineExceptions {34static class Exception1 extends Exception {};35static class Exception2 extends Exception {};36private static int counter0;37private static int counter1;38private static int counter2;39private static int counter;4041static void foo(int i) throws Exception {42if ((i & 1023) == 2) {43counter0++;44throw new Exception2();45}46}4748static void test(int i) throws Exception {49try {50foo(i);51}52catch (Exception e) {53if (e instanceof Exception1) {54counter1++;55} else if (e instanceof Exception2) {56counter2++;57}58counter++;59throw e;60}61}6263public static void main(String[] args) throws Throwable {64for (int i = 0; i < 15000; i++) {65try {66test(i);67} catch (Exception e) {68// expected69}70}71if (counter1 != 0) {72throw new RuntimeException("Failed: counter1(" + counter1 + ") != 0");73}74if (counter2 != counter0) {75throw new RuntimeException("Failed: counter2(" + counter2 + ") != counter0(" + counter0 + ")");76}77if (counter2 != counter) {78throw new RuntimeException("Failed: counter2(" + counter2 + ") != counter(" + counter + ")");79}80System.out.println("TEST PASSED");81}82}838485