< prev index next >

test/hotspot/jtreg/compiler/loopopts/TestOverunrolling.java

Print this page


   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  * @test
  26  * @bug 8159016
  27  * @summary Tests correct dominator information after over-unrolling a loop.
  28  * @requires vm.gc == "Parallel" | vm.gc == "null"
  29  *
  30  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -Xcomp -XX:-TieredCompilation
  31  *                   -XX:-UseG1GC -XX:+UseParallelGC
  32  *                   compiler.loopopts.TestOverunrolling
  33  */
  34 
  35 package compiler.loopopts;
  36 
  37 public class TestOverunrolling {
  38 
  39     public static Object test(int arg) {
  40         Object arr[] = new Object[3];
  41         int lim = (arg & 3);
  42         // The pre loop is executed for one iteration, initializing p[0].
  43         // The main loop is unrolled twice, initializing p[1], p[2], p[3] and p[4].
  44         // The p[3] and p[4] stores are always out of bounds and removed. However,
  45         // C2 is unable to remove the "over-unrolled", dead main loop. As a result,
  46         // there is a control path from the main loop to the post loop without a
  47         // memory path (because the last store was replaced by TOP). We crash
  48         // because we use a memory edge from a non-dominating region.
  49         for (int i = 0; i < lim; ++i) {
  50             arr[i] = new Object();
  51         }
  52         // Avoid EA
  53         return arr;
  54     }
  55 





























  56     public static void main(String args[]) {
  57         for (int i = 0; i < 42; ++i) {
  58             test(i);
  59         }

  60     }
  61 }
  62 
   1 /*
   2  * Copyright (c) 2016, 2018, 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 8159016 8202949
  27  * @summary Tests correct dominator information after over-unrolling a loop.
  28  * @requires vm.gc == "Parallel" | vm.gc == "null"
  29  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockExperimentalVMOptions
  30  *                   -Xcomp -XX:-TieredCompilation -XX:-UseSwitchProfiling
  31  *                   -XX:-UseG1GC -XX:+UseParallelGC compiler.loopopts.TestOverunrolling

  32  */
  33 
  34 package compiler.loopopts;
  35 
  36 public class TestOverunrolling {
  37 
  38     public static Object test1(int arg) {
  39         Object arr[] = new Object[3];
  40         int lim = (arg & 3);
  41         // The pre loop is executed for one iteration, initializing p[0].
  42         // The main loop is unrolled twice, initializing p[1], p[2], p[3] and p[4].
  43         // The p[3] and p[4] stores are always out of bounds and removed. However,
  44         // C2 is unable to remove the "over-unrolled", dead main loop. As a result,
  45         // there is a control path from the main loop to the post loop without a
  46         // memory path (because the last store was replaced by TOP). We crash
  47         // because we use a memory edge from a non-dominating region.
  48         for (int i = 0; i < lim; ++i) {
  49             arr[i] = new Object();
  50         }
  51         // Avoid EA
  52         return arr;
  53     }
  54 
  55     public static long lFld = 0;
  56     public static volatile double dFld = 0;
  57 
  58     public static void test2() {
  59         int iArr[] = new int[10];
  60         // The inner for-loop is overunrolled because we fail to determine
  61         // the constant lower and upper bound (6,8]. After unrolling multiple times,
  62         // the range check dependent CastII/ConvI2L emitted for the iArr access become
  63         // TOP because index 'j' is out of bounds. As a result, the memory graph is
  64         // corrupted with memory consuming nodes still being reachable because the dead
  65         // loop is not (yet) removed (Opaque1 nodes are still guarding the bounds).
  66         for (int i = 6; i < 10; i++) {
  67             for (int j = 8; j > i; j--) {
  68                 int k = 1;
  69                 do {
  70                     iArr[j] = 0;
  71                     switch (k) {
  72                     case 1:
  73                         lFld = 0;
  74                         break;
  75                     case 10:
  76                         dFld = 0;
  77                         break;
  78                     }
  79                 } while (++k < 1);
  80             }
  81         }
  82     }
  83 
  84     public static void main(String args[]) {
  85         for (int i = 0; i < 42; ++i) {
  86             test1(i);
  87         }
  88         test2();
  89     }
  90 }
  91 
< prev index next >