1 /* 2 * Copyright (c) 2015, 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 8134031 27 * @summary Bad rewiring of memory edges when we split unique types during EA 28 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,TestEABadMergeMem::m_notinlined TestEABadMergeMem 29 * 30 */ 31 32 public class TestEABadMergeMem { 33 34 static class Box { 35 int i; 36 } 37 38 static void m_notinlined() { 39 } 40 41 static float dummy1; 42 static float dummy2; 43 44 static int test(Box a, Box c, int i, int j, int k, boolean flag1, boolean flag2) { 45 Box b = new Box(); // non escaping 46 a.i = i; 47 b.i = j; 48 c.i = k; 49 50 m_notinlined(); 51 52 boolean flag3 = false; 53 if (flag1) { 54 for (int ii = 0; ii < 100; ii++) { 55 if (flag2) { 56 dummy1 = (float)ii; 57 } else { 58 dummy2 = (float)ii; 59 } 60 } 61 flag3 = true; 62 } 63 // Memory Phi here with projection of not inlined call as one edge, MergeMem as other 64 65 if (flag3) { // will split through Phi during loopopts 66 int res = c.i + b.i; 67 m_notinlined(); // prevents split through phi during igvn 68 return res; 69 } else { 70 return 44 + 43; 71 } 72 } 73 74 static public void main(String[] args) { 75 for (int i = 0; i < 20000; i++) { 76 // m(2); 77 Box a = new Box(); 78 Box c = new Box(); 79 int res = test(a, c, 42, 43, 44, (i%2) == 0, (i%3) == 0); 80 if (res != 44 + 43) { 81 throw new RuntimeException("Bad result " + res); 82 } 83 } 84 } 85 86 }