hotspot/test/compiler/loopopts/BadPredicateAfterPartialPeel.java
changeset 35558 9b3b2740c3ec
child 40059 c2304140ed64
equal deleted inserted replaced
35557:029dcb9bfa8b 35558:9b3b2740c3ec
       
     1 /*
       
     2  * Copyright (c) 2016, 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 /**
       
    26  * @test
       
    27  * @bug 8146792
       
    28  * @summary Predicate moved after partial peel may lead to broken graph
       
    29  * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileOnly=BadPredicateAfterPartialPeel::m -XX:CompileCommand=dontinline,BadPredicateAfterPartialPeel::not_inlined* -XX:CompileCommand=quiet BadPredicateAfterPartialPeel
       
    30  *
       
    31  */
       
    32 
       
    33 public class BadPredicateAfterPartialPeel {
       
    34 
       
    35     static void not_inlined1() {}
       
    36     static void not_inlined4() {}
       
    37 
       
    38     static int m_helper(int i, int i3, int i4) {
       
    39         return i3 == 4 ? i4 : i;
       
    40     }
       
    41 
       
    42     static float[] array = new float[1000];
       
    43     static int[] array2 = new int[1000];
       
    44 
       
    45     boolean flag;
       
    46     int j;
       
    47 
       
    48     static void m(BadPredicateAfterPartialPeel o1, BadPredicateAfterPartialPeel o2, BadPredicateAfterPartialPeel o, int i4) {
       
    49         int i1 = 1;
       
    50 
       
    51         // To delay partial peeling to the loop opts pass right before CCP
       
    52         int i2 = 0;
       
    53         for (; i2 < 10; i2 += i1);
       
    54         i2 = i2 / 10;
       
    55 
       
    56         // Simplified during CCP:
       
    57         int i3 = 2;
       
    58         for (; i3 < 4; i3 *= 2);
       
    59 
       
    60         // Loop is partial peeled right before CCP
       
    61         int i = 0;
       
    62         boolean b = true;
       
    63 
       
    64         not_inlined1();
       
    65 
       
    66         array[0] = -1;
       
    67         do {
       
    68             // peeled section starts here
       
    69             o.flag = false;
       
    70             o.j = 0;
       
    71 
       
    72             if (b) {
       
    73                 // The following store will be pinned between
       
    74                 // predicates and the loop after partial peeling. All
       
    75                 // control flow will be optimized out and so nothing
       
    76                 // will prevent predicates from being moved out the
       
    77                 // loop.
       
    78                 array[i] = 0;
       
    79             }
       
    80             if (array[0] != 0) {
       
    81             }
       
    82             if (i >= 10) {
       
    83                 // peeled section ends here
       
    84                 return;
       
    85             }
       
    86             i += i2;
       
    87             b = false;
       
    88             int i5 = m_helper(i, i3, i4); // This will be simpliflied during CCP
       
    89             if (array[i5] != 0) { // and this will become a predicate
       
    90             }
       
    91             if (o2.flag) {
       
    92             }
       
    93             // A bunch of stuff to grow loop body size and prevent peeling:
       
    94             array2[0] = 0;
       
    95             array2[1] = 0;
       
    96             array2[2] = 0;
       
    97             array2[3] = 0;
       
    98             array2[4] = 0;
       
    99             array2[5] = 0;
       
   100             array2[6] = 0;
       
   101             array2[7] = 0;
       
   102             array2[8] = 0;
       
   103             array2[9] = 0;
       
   104             array2[10] = 0;
       
   105             array2[11] = 0;
       
   106             array2[12] = 0;
       
   107             array2[13] = 0;
       
   108             array2[14] = 0;
       
   109             array2[15] = 0;
       
   110             array2[16] = 0;
       
   111             array2[17] = 0;
       
   112             array2[18] = 0;
       
   113             array2[19] = 0;
       
   114             array2[20] = 0;
       
   115             array2[21] = 0;
       
   116             array2[22] = 0;
       
   117             array2[23] = 0;
       
   118             array2[24] = 0;
       
   119             array2[25] = 0;
       
   120             array2[26] = 0;
       
   121             array2[27] = 0;
       
   122             array2[28] = 0;
       
   123             array2[29] = 0;
       
   124             array2[30] = 0;
       
   125             array2[31] = 0;
       
   126             array2[32] = 0;
       
   127             array2[33] = 0;
       
   128             array2[34] = 0;
       
   129             array2[35] = 0;
       
   130             array2[36] = 0;
       
   131             array2[37] = 0;
       
   132             array2[38] = 0;
       
   133             array2[39] = 0;
       
   134             array2[40] = 0;
       
   135             array2[41] = 0;
       
   136             array2[42] = 0;
       
   137             array2[43] = 0;
       
   138             array2[44] = 0;
       
   139             array2[45] = 0;
       
   140             array2[46] = 0;
       
   141             array2[47] = 0;
       
   142             array2[48] = 0;
       
   143             array2[49] = 0;
       
   144             array2[50] = 0;
       
   145             array2[51] = 0;
       
   146             array2[52] = 0;
       
   147             array2[53] = 0;
       
   148             array2[54] = 0;
       
   149             array2[55] = 0;
       
   150             array2[56] = 0;
       
   151             array2[57] = 0;
       
   152             array2[58] = 0;
       
   153             array2[59] = 0;
       
   154             array2[60] = 0;
       
   155             array2[61] = 0;
       
   156             array2[62] = 0;
       
   157             array2[63] = 0;
       
   158             array2[64] = 0;
       
   159             array2[65] = 0;
       
   160             array2[66] = 0;
       
   161             array2[67] = 0;
       
   162             array2[68] = 0;
       
   163             array2[69] = 0;
       
   164             array2[70] = 0;
       
   165             array2[71] = 0;
       
   166             array2[72] = 0;
       
   167             array2[73] = 0;
       
   168             array2[74] = 0;
       
   169             array2[75] = 0;
       
   170             array2[76] = 0;
       
   171             array2[77] = 0;
       
   172             array2[78] = 0;
       
   173             array2[79] = 0;
       
   174             array2[80] = 0;
       
   175             array2[81] = 0;
       
   176             array2[82] = 0;
       
   177             array2[83] = 0;
       
   178             array2[84] = 0;
       
   179             array2[85] = 0;
       
   180             array2[86] = 0;
       
   181             array2[87] = 0;
       
   182             array2[88] = 0;
       
   183             array2[89] = 0;
       
   184             array2[90] = 0;
       
   185             array2[91] = 0;
       
   186             array2[92] = 0;
       
   187             array2[93] = 0;
       
   188             array2[94] = 0;
       
   189             array2[95] = 0;
       
   190             array2[96] = 0;
       
   191             array2[97] = 0;
       
   192             array2[98] = 0;
       
   193             array2[99] = 0;
       
   194 
       
   195             array2[100] = 0;
       
   196             array2[101] = 0;
       
   197             array2[102] = 0;
       
   198             array2[103] = 0;
       
   199             array2[104] = 0;
       
   200             array2[105] = 0;
       
   201             array2[106] = 0;
       
   202             array2[107] = 0;
       
   203             array2[108] = 0;
       
   204             array2[109] = 0;
       
   205             array2[110] = 0;
       
   206             array2[111] = 0;
       
   207             array2[112] = 0;
       
   208             array2[113] = 0;
       
   209             array2[114] = 0;
       
   210             array2[115] = 0;
       
   211             array2[116] = 0;
       
   212             array2[117] = 0;
       
   213             array2[118] = 0;
       
   214             array2[119] = 0;
       
   215             array2[120] = 0;
       
   216             array2[121] = 0;
       
   217             array2[122] = 0;
       
   218             array2[123] = 0;
       
   219             array2[124] = 0;
       
   220             array2[125] = 0;
       
   221             array2[126] = 0;
       
   222             array2[127] = 0;
       
   223             array2[128] = 0;
       
   224             array2[129] = 0;
       
   225             array2[130] = 0;
       
   226             array2[131] = 0;
       
   227             array2[132] = 0;
       
   228             array2[133] = 0;
       
   229             array2[134] = 0;
       
   230             array2[135] = 0;
       
   231             array2[136] = 0;
       
   232             array2[137] = 0;
       
   233             array2[138] = 0;
       
   234             array2[139] = 0;
       
   235             array2[140] = 0;
       
   236             array2[141] = 0;
       
   237             array2[142] = 0;
       
   238             array2[143] = 0;
       
   239             array2[144] = 0;
       
   240             array2[145] = 0;
       
   241             array2[146] = 0;
       
   242             array2[147] = 0;
       
   243             array2[148] = 0;
       
   244             array2[149] = 0;
       
   245             array2[150] = 0;
       
   246             array2[151] = 0;
       
   247             array2[152] = 0;
       
   248             array2[153] = 0;
       
   249             array2[154] = 0;
       
   250             array2[155] = 0;
       
   251             array2[156] = 0;
       
   252             array2[157] = 0;
       
   253             array2[158] = 0;
       
   254             array2[159] = 0;
       
   255             array2[160] = 0;
       
   256             array2[161] = 0;
       
   257             array2[162] = 0;
       
   258             array2[163] = 0;
       
   259             array2[164] = 0;
       
   260             array2[165] = 0;
       
   261             array2[166] = 0;
       
   262             array2[167] = 0;
       
   263             array2[168] = 0;
       
   264             array2[169] = 0;
       
   265             array2[170] = 0;
       
   266             array2[171] = 0;
       
   267             array2[172] = 0;
       
   268             array2[173] = 0;
       
   269             array2[174] = 0;
       
   270             array2[175] = 0;
       
   271             array2[176] = 0;
       
   272             array2[177] = 0;
       
   273             array2[178] = 0;
       
   274             array2[179] = 0;
       
   275             array2[180] = 0;
       
   276             array2[181] = 0;
       
   277             array2[182] = 0;
       
   278             array2[183] = 0;
       
   279             array2[184] = 0;
       
   280             array2[185] = 0;
       
   281             array2[186] = 0;
       
   282             array2[187] = 0;
       
   283             array2[188] = 0;
       
   284             array2[189] = 0;
       
   285             array2[190] = 0;
       
   286             array2[191] = 0;
       
   287             array2[192] = 0;
       
   288             array2[193] = 0;
       
   289             array2[194] = 0;
       
   290             array2[195] = 0;
       
   291             array2[196] = 0;
       
   292             array2[197] = 0;
       
   293             array2[198] = 0;
       
   294             array2[199] = 0;
       
   295             if (o1.j >= 20) {
       
   296                 break;
       
   297             }
       
   298             o1.j++;
       
   299         } while(true);
       
   300         not_inlined4();
       
   301     }
       
   302 
       
   303     static public void main(String[] args) {
       
   304         BadPredicateAfterPartialPeel o1 = new BadPredicateAfterPartialPeel();
       
   305         BadPredicateAfterPartialPeel o2 = new BadPredicateAfterPartialPeel();
       
   306         for (int i = 0; i < 20000; i++) {
       
   307             o1.j = 0;
       
   308             m(o1, o2, o2, 0);
       
   309             m_helper(i, 2, i); // pollute profile
       
   310         }
       
   311     }
       
   312 }