|
| 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 | + * @test TypeProfileCasts |
| 26 | + * @summary Check that turning of TypeProfileCasts is tolerated |
| 27 | + * @requires vm.debug == true |
| 28 | + * @modules java.base/jdk.internal.misc |
| 29 | + * java.management |
| 30 | + * |
| 31 | + * @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:-TypeProfileCasts |
| 32 | + * -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_instanceof |
| 33 | + * compiler.tiered.TypeProfileCasts |
| 34 | + * @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:+TypeProfileCasts |
| 35 | + * -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_instanceof |
| 36 | + * compiler.tiered.TypeProfileCasts |
| 37 | + * @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:-TypeProfileCasts |
| 38 | + * -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_checkcast |
| 39 | + * compiler.tiered.TypeProfileCasts |
| 40 | + * @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:+TypeProfileCasts |
| 41 | + * -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_checkcast |
| 42 | + * compiler.tiered.TypeProfileCasts |
| 43 | + * @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:-TypeProfileCasts |
| 44 | + * -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_array_store |
| 45 | + * compiler.tiered.TypeProfileCasts |
| 46 | + * @run main/othervm -XX:+TieredCompilation -XX:-BackgroundCompilation -XX:+TypeProfileCasts |
| 47 | + * -XX:CompileCommand=compileonly,compiler.tiered.TypeProfileCasts::test_array_store |
| 48 | + * compiler.tiered.TypeProfileCasts |
| 49 | + */ |
| 50 | + |
| 51 | +package compiler.tiered; |
| 52 | + |
| 53 | +public class TypeProfileCasts { |
| 54 | + static class Foo { } |
| 55 | + public static int sideEffect = 0; |
| 56 | + |
| 57 | + private static void test_instanceof(Object o) { |
| 58 | + // instanceof |
| 59 | + if (o instanceof Foo) { |
| 60 | + sideEffect++; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + private static void test_checkcast(Object o) { |
| 65 | + // checkcast |
| 66 | + Foo f = (Foo) o; |
| 67 | + |
| 68 | + sideEffect++; |
| 69 | + } |
| 70 | + |
| 71 | + private static void test_array_store(Object o) { |
| 72 | + // array store type check |
| 73 | + Foo[] fs = new Foo[1]; |
| 74 | + Object[] os = fs; |
| 75 | + os[0] = o; |
| 76 | + |
| 77 | + sideEffect++; |
| 78 | + } |
| 79 | + |
| 80 | + public static void main(String... args) { |
| 81 | + for (int i = 0; i < 100_000; i++) { |
| 82 | + test_instanceof(new Foo()); |
| 83 | + test_checkcast(new Foo()); |
| 84 | + test_array_store(new Foo()); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments