|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +/* |
| 26 | + * @test id=return |
| 27 | + * @bug 8336906 |
| 28 | + * @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after return. |
| 29 | + * @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java |
| 30 | + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp |
| 31 | + * -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test* |
| 32 | + * compiler.interpreter.TestVerifyStackWithUnreachableBytecode return |
| 33 | + */ |
| 34 | + |
| 35 | +/* |
| 36 | + * @test id=areturn |
| 37 | + * @bug 8336906 |
| 38 | + * @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after areturn. |
| 39 | + * @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java |
| 40 | + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp |
| 41 | + * -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test* |
| 42 | + * compiler.interpreter.TestVerifyStackWithUnreachableBytecode areturn |
| 43 | + */ |
| 44 | + |
| 45 | +/* |
| 46 | + * @test id=goto |
| 47 | + * @bug 8336906 8271055 |
| 48 | + * @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after goto. |
| 49 | + * @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java |
| 50 | + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp |
| 51 | + * -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test* |
| 52 | + * compiler.interpreter.TestVerifyStackWithUnreachableBytecode goto |
| 53 | + */ |
| 54 | + |
| 55 | +/* |
| 56 | + * @test id=gotow |
| 57 | + * @bug 8336906 8271055 |
| 58 | + * @summary Ensure VerifyStack does not crash on bytecodes in unreachable basic blocks after gotow. |
| 59 | + * @compile TestVerifyStackWithUnreachableBytecodeImpl.jasm TestVerifyStackWithUnreachableBytecode.java |
| 60 | + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+VerifyStack -Xcomp |
| 61 | + * -XX:CompileCommand=compileonly,compiler/interpreter/TestVerifyStackWithUnreachableBytecodeImpl.test* |
| 62 | + * compiler.interpreter.TestVerifyStackWithUnreachableBytecode gotow |
| 63 | + */ |
| 64 | + |
| 65 | +package compiler.interpreter; |
| 66 | + |
| 67 | +import compiler.interpreter.TestVerifyStackWithUnreachableBytecodeImpl; |
| 68 | + |
| 69 | +public class TestVerifyStackWithUnreachableBytecode { |
| 70 | + public static void main(String[] args) { |
| 71 | + TestCase t = testCaseFromString(args[0]); |
| 72 | + |
| 73 | + // The following is designed to cause a deopt with the reason `null_assert_or_unreached0` |
| 74 | + // when accessing A.val using getstatic due to the class B not being loaded and the consequent |
| 75 | + // assumption of A.val == null. |
| 76 | + TestVerifyStackWithUnreachableBytecodeA.val = null; |
| 77 | + dispatchTest(t); |
| 78 | + TestVerifyStackWithUnreachableBytecodeA.val = new TestVerifyStackWithUnreachableBytecodeB(42); |
| 79 | + dispatchTest(t); |
| 80 | + } |
| 81 | + |
| 82 | + private enum TestCase { |
| 83 | + ARETURN, |
| 84 | + GOTO, |
| 85 | + GOTOW, |
| 86 | + RETURN; |
| 87 | + } |
| 88 | + |
| 89 | + private static TestCase testCaseFromString(String s) { |
| 90 | + return switch (s) { |
| 91 | + case "areturn" -> TestCase.ARETURN; |
| 92 | + case "return" -> TestCase.RETURN; |
| 93 | + case "goto" -> TestCase.GOTO; |
| 94 | + case "gotow" -> TestCase.GOTOW; |
| 95 | + default -> throw new RuntimeException("Test argument not recognized: " + s); |
| 96 | + }; |
| 97 | + } |
| 98 | + |
| 99 | + private static void dispatchTest(TestCase testCase) { |
| 100 | + switch (testCase) { |
| 101 | + case ARETURN -> TestVerifyStackWithUnreachableBytecodeImpl.testAreturn(); |
| 102 | + case RETURN -> TestVerifyStackWithUnreachableBytecodeImpl.testReturn(); |
| 103 | + case GOTO -> TestVerifyStackWithUnreachableBytecodeImpl.testGoto(); |
| 104 | + case GOTOW -> TestVerifyStackWithUnreachableBytecodeImpl.testGotow(); |
| 105 | + } |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +class TestVerifyStackWithUnreachableBytecodeA { |
| 110 | + public static TestVerifyStackWithUnreachableBytecodeB val = null; |
| 111 | +} |
| 112 | + |
| 113 | +class TestVerifyStackWithUnreachableBytecodeB { |
| 114 | + public int val = 0; |
| 115 | + |
| 116 | + TestVerifyStackWithUnreachableBytecodeB(int v) { this.val = v; } |
| 117 | +} |
0 commit comments