Path: blob/master/test/hotspot/jtreg/compiler/controldependency/TestEliminatedCastPPAtPhi.java
41149 views
/*1* Copyright (c) 2015, 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* @key stress randomness26* @bug 813977127* @summary Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash28* @requires vm.gc=="Serial" | vm.gc=="Parallel"29*30* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement31* -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions -XX:+StressGCM32* compiler.controldependency.TestEliminatedCastPPAtPhi33*34*/3536package compiler.controldependency;3738public class TestEliminatedCastPPAtPhi {3940static TestEliminatedCastPPAtPhi saved;41static TestEliminatedCastPPAtPhi saved_not_null;4243int f;4445static int test(TestEliminatedCastPPAtPhi obj, int[] array, boolean flag) {46int ret = array[0] + array[20];47saved = obj;48if (obj == null) {49return ret;50}51saved_not_null = obj;5253// empty loop to be optimized out. Delays range check smearing54// for the array access below until the if diamond is55// optimized out56int i = 0;57for (; i < 10; i++);5859ret += array[i];6061TestEliminatedCastPPAtPhi res;62if (flag) {63// load is optimized out and res is obj here64res = saved;65} else {66// load is optimized out and res is non null CastPP of res here67res = saved_not_null;68}69// null check + CastPP here for res field load below7071// 1) null check is pushed in the branches of the if above by72// split through phi because res is non null in the second73// branch and the null check can be optimized out in that74// branch. The Castpp stays here.7576// 2) null check in the first branch is also optimized out77// because a dominating null check is found (the explicit null78// check at the beggining of the test)7980// 3) the Phi for the if above merges a CastPP'ed value and81// the same value so it's optimized out and replaced by the82// uncasted value: obj8384// 4) the if above has 2 empty branches so it's optimized85// out. The control of the CastPP that is still here is now86// the success branch of the range check for the array access87// above8889// 5) the loop above is optimized out, i = 10, the range check90// for the array access above is optimized out and all its91// uses are replaced by the range check for the array accesses92// at the beginning of the method. The castPP here is one of93// the uses and so its control is now the range check at the94// beginning of the method: the control of the CastPP bypasses95// the explicit null check9697return ret + res.f;98}99100static public void main(String[] args) {101int[] array = new int[100];102TestEliminatedCastPPAtPhi obj = new TestEliminatedCastPPAtPhi();103for (int i = 0; i < 20000; i++) {104test(obj, array, (i%2) == 0);105}106test(null, array, true);107}108109}110111112