1 /* 2 * Copyright (c) 2013, 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 8027571 27 * @summary meet of TopPTR exact array with constant array is not symmetric 28 * 29 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseOnStackReplacement 30 * -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation 31 * -XX:-BackgroundCompilation 32 * compiler.types.TestMeetTopArrayExactConstantArray 33 */ 34 35 package compiler.types; 36 37 public class TestMeetTopArrayExactConstantArray { 38 39 static class A { 40 } 41 42 static class B { 43 } 44 45 static class C extends A { 46 } 47 48 static class D extends C { 49 } 50 51 final static B[] b = new B[10]; 52 53 static void m0(Object[] o) { 54 if (o.getClass() == Object[].class) { 55 } 56 } 57 58 static void m1(Object[] o, boolean cond) { 59 if (cond) { 60 o = b; 61 } 62 m0(o); 63 } 64 65 static void m2(Object[] o, boolean cond1, boolean cond2) { 66 if (cond1) { 67 m1(o, cond2); 68 } 69 } 70 71 static void m3(C[] o, boolean cond1, boolean cond2, boolean cond3) { 72 if (cond1) { 73 m2(o, cond2, cond3); 74 } 75 } 76 77 static public void main(String[] args) { 78 A[] a = new A[10]; 79 D[] d = new D[10]; 80 Object[] o = new Object[10]; 81 for (int i = 0; i < 5000; i++) { 82 // record in profiling that the if in m0 succeeds 83 m0(o); 84 // record some profiling for m2 and m1 85 m2(a, true, (i%2) == 0); 86 // record some profiling for m3 and conflicting profile for m2 87 m3(d, true, false, (i%2) == 0); 88 } 89 90 // get m3 compiled. The if in m0 will be optimized because of argument profiling in m3 91 C[] c = new C[10]; 92 for (int i = 0; i < 20000; i++) { 93 m3(c, true, false, (i%2) == 0); 94 } 95 // make m3 not entrant and the if in m0 fail 96 m3(c, true, true, false); 97 m3(c, true, true, false); 98 m3(c, true, true, false); 99 m3(c, true, true, false); 100 101 // make m3 recompile, this time with if the not optimized 102 // on entry to m3, argument o is of type C[], profiled C[] 103 // on entry to m1, argument o is of type C[], speculative C[] exact, profiled A[]. Speculative becomes AnyNull 104 // after the if in m1, speculative type of o becomes constant from final field b 105 // the true if branch in m0 does a join between the type of o of speculative type constant from final field b and exact klass Object[] 106 for (int i = 0; i < 20000; i++) { 107 m3(c, true, false, (i%2) == 0); 108 } 109 110 System.out.println("TEST PASSED"); 111 } 112 }