Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetExceptionTableTest.java
41153 views
/*1* Copyright (c) 2015, 2019, 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 813642126* @requires vm.jvmci27* @library /test/lib /28* @library ../common/patches29* @modules java.base/jdk.internal.misc30* @modules java.base/jdk.internal.org.objectweb.asm31* java.base/jdk.internal.org.objectweb.asm.tree32* jdk.internal.vm.ci/jdk.vm.ci.hotspot33* jdk.internal.vm.ci/jdk.vm.ci.code34* jdk.internal.vm.ci/jdk.vm.ci.meta35* jdk.internal.vm.ci/jdk.vm.ci.runtime36*37* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper38* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI39* -XX:-UseJVMCICompiler40* compiler.jvmci.compilerToVM.GetExceptionTableTest41*/4243package compiler.jvmci.compilerToVM;4445import compiler.jvmci.common.CTVMUtilities;46import jdk.test.lib.Asserts;47import jdk.vm.ci.hotspot.CompilerToVMHelper;48import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;4950import java.io.IOException;51import java.lang.reflect.Executable;52import java.net.Socket;53import java.util.HashMap;54import java.util.Map;5556public class GetExceptionTableTest {5758public static final int TRY_CATCH_COUNT = 3;59public static final int TRY_CATCH_FINALLY_COUNT = 8;60public static final int TRY_WITH_RESOURCES_COUNT = 5;61public static final int EMPTY_COUNT = 0;6263public static void main(String[] args) {64Map<Executable, Integer> testCases = createTestCases();65testCases.forEach(GetExceptionTableTest::runSanityTest);66}6768private static Map<Executable, Integer> createTestCases() {69HashMap<Executable, Integer> methods = new HashMap<>();70try {71Class<?> aClass = GetExceptionTableTest.DummyClass.class;72methods.put(aClass.getMethod("tryCatchDummy"), TRY_CATCH_COUNT);73methods.put(aClass.getMethod("tryCatchFinallyDummy"),74TRY_CATCH_FINALLY_COUNT);75methods.put(aClass.getMethod("tryWithResourcesDummy"),76TRY_WITH_RESOURCES_COUNT);77methods.put(aClass.getMethod("emptyFunction"), EMPTY_COUNT);78} catch (NoSuchMethodException e) {79throw new Error("TEST BUG", e);80}81return methods;82}8384private static void runSanityTest(Executable aMethod,85Integer expectedTableLength) {86HotSpotResolvedJavaMethod method = CTVMUtilities87.getResolvedMethod(aMethod);88int tableLength = CompilerToVMHelper.getExceptionTableLength(method);89Asserts.assertEQ(tableLength, expectedTableLength, aMethod90+ " incorrect exception table length.");9192long tableStart = CompilerToVMHelper.getExceptionTableStart(method);93if (tableLength > 0) {94Asserts.assertNE(tableStart, 0L, aMethod + " exception table starts "95+ "at 0.");96}97}9899private static class DummyClass {100public static void emptyFunction() {}101public static void tryCatchDummy() throws Throwable {102try {103throw new Exception("Dummy exception");104} catch (ArithmeticException ex) {105throw new IOException(ex.getMessage());106} catch (IOException ex) {107throw new Exception(ex);108} catch (Exception ex) {109throw new Exception(ex);110}111}112113public int tryCatchFinallyDummy() {114// 4 times catch/finally = 8 catch-blocks and finally-blocks115try {116throw new Exception("Dummy exception");117} catch (IndexOutOfBoundsException ex) {118return 1;119} catch (ArithmeticException ex) {120return 2;121} catch (IOException ex) {122return 3;123} catch (Exception ex) {124return 4;125} finally {126return 0;127}128}129130public static int tryWithResourcesDummy() throws Throwable {131try (Socket socket = new Socket()) {132throw new Exception("Dummy exception");133} catch (ArithmeticException ex) {134return 1;135} catch (IOException ex) {136return 2;137} catch (Exception ex) {138return 3;139}140}141}142}143144145