1/* 2 * Copyright (c) 2016, 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 26 * @bug 8149797 27 * @summary node replaced by dominating dead cast during parsing 28 * 29 * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation 30 * -XX:TypeProfileLevel=200 31 * -XX:CompileCommand=dontinline,compiler.c2.TestDominatingDeadCheckCast::not_inlined 32 * compiler.c2.TestDominatingDeadCheckCast 33 */ 34 35package compiler.c2; 36 37public class TestDominatingDeadCheckCast { 38 39 static class A { 40 int f; 41 } 42 43 static class B extends A { 44 } 45 46 static A not_inlined() { 47 return new A(); 48 } 49 50 static void inlined(A param) { 51 param.f = 42; 52 } 53 54 static A field; 55 56 static void test(boolean flag1, boolean flag2, boolean flag3, boolean flag4, boolean flag5) { 57 // Go through memory rather than through a local to defeat C2's replace_in_map 58 field = not_inlined(); 59 // Speculation adds a CheckCast on entry of this inlined 60 // method for the parameter 61 inlined(field); 62 // Walk up the dominators is depth limited, make the CheckCast 63 // above unreachable from the last inlined call 64 if (flag1) { 65 if (flag2) { 66 if (flag3) { 67 // Speculation adds a CheckCast on entry of this 68 // inlined method for the parameter. This 69 // CheckCast is replaced by the CheckCast of the 70 // first inlined method call but the replaced 71 // CheckCast is still around during parsing. 72 inlined(field); 73 // Same as above, some useless control 74 if (flag4) { 75 if (flag5) { 76 // Speculation adds a CheckCast on entry 77 // of this inlined method for the 78 // parameter. This CheckCast is replaced 79 // by the dead CheckCast of the previous 80 // inlined() call. 81 inlined(field); 82 } 83 } 84 } 85 } 86 } 87 } 88 89 static public void main(String[] args) { 90 field = new A(); 91 for (int i = 0; i < 20000; i++) { 92 test(true, true, true, true, true); 93 } 94 } 95} 96