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 8007294 27 * @bug 8146999 28 * @summary ReduceFieldZeroing doesn't check for dependent load and can lead to incorrect execution 29 * 30 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+AlwaysIncrementalInline 31 * -XX:-UseOnStackReplacement -XX:-BackgroundCompilation 32 * compiler.c2.Test8007294 33 */ 34 35 package compiler.c2; 36 37 public class Test8007294 { 38 39 int i1; 40 int i2; 41 Test8007294(int i1, int i2)42 Test8007294(int i1, int i2) { 43 this.i1 = i1; 44 this.i2 = i2; 45 } 46 m(int v)47 static int m(int v) { 48 return v; 49 } 50 test1()51 static Test8007294 test1() { 52 Test8007294 obj = new Test8007294(10, 100); 53 int v1 = obj.i1; 54 55 int v3 = m(v1); 56 int v2 = obj.i2; 57 obj.i2 = v3; 58 obj.i1 = v2; 59 60 return obj; 61 } 62 test2(int i)63 static int test2(int i) { 64 int j = 0; 65 if (i > 0) { 66 j = 1; 67 } 68 69 int[] arr = new int[10]; 70 arr[0] = 1; 71 arr[1] = 2; 72 int v1 = arr[j]; 73 arr[0] = 3; 74 arr[1] = 4; 75 76 return v1; 77 } 78 main(String[] args)79 static public void main(String[] args) { 80 boolean failed = false; 81 for (int i = 0; i < 20000; i++) { 82 Test8007294 obj = test1(); 83 if (obj.i1 != 100 || obj.i2 != 10) { 84 System.out.println("FAILED test1 obj.i1 = " + obj.i1 +", obj.i2 = " + obj.i2); 85 failed = true; 86 break; 87 } 88 } 89 for (int i = 0; i < 20000; i++) { 90 test2(0); // pollute profile 91 int res = test2(1); 92 if (res != 2) { 93 System.out.println("FAILED test2 = " + res); 94 failed = true; 95 break; 96 } 97 } 98 if (failed) { 99 System.exit(97); 100 } else { 101 System.out.println("PASSED"); 102 } 103 } 104 } 105