Path: blob/master/test/hotspot/jtreg/compiler/macronodes/TestEliminateAllocationPhi.java
41149 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 804669826* @summary PhiNode inserted between AllocateNode and Initialization node confuses allocation elimination27* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement28* compiler.macronodes.TestEliminateAllocationPhi29*/3031package compiler.macronodes;3233public class TestEliminateAllocationPhi {3435// This will return I when called from m(0 and once optimized will36// go away but this will confuse escape analysis in m(): it will37// find I as non escaping but non scalar replaceable. In its own38// method so that we can make the profile of the if() branch look39// like it's taken sometimes.40static Integer m2(Integer I, int i) {41for (; i < 10; i=(i+2)*(i+2)) {42}43if (i == 121) {44return II;45}46return I;47}4849static Integer II = new Integer(42);5051static int m(int[] integers, boolean flag) {52int j = 0;53while(true) {54try {55int k = integers[j++];56// A branch that will cause loop unswitching57if (flag) {58k += 42;59}60if (k < 1000) {61throw new Exception();62}63// Because of the try/catch the Allocate node for this64// new will be in the loop while the Initialization65// node will be outside the loop. When loop66// unswitching happens, the Allocate node will be67// cloned and the results of both will be inputs to a68// Phi that will be between the Allocate nodes and the69// Initialization nodes.70Integer I = new Integer(k);7172I = m2(I, 0);7374int i = I.intValue();75return i;76} catch(Exception e) {77}78}79}8081static public void main(String[] args) {82for (int i = 0; i < 5000; i++) {83m2(null, 1);84}8586int[] integers = { 2000 };87for (int i = 0; i < 6000; i++) {88m(integers, (i%2) == 0);89}90int[] integers2 = { 1, 2, 3, 4, 5, 2000 };91for (int i = 0; i < 10000; i++) {92m(integers2, (i%2) == 0);93}94}95}969798