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