test/hotspot/jtreg/compiler/loopstripmining/TestConservativeAntiDep.java
changeset 58471 bada0782842a
equal deleted inserted replaced
58470:8991796c17d4 58471:bada0782842a
       
     1 /*
       
     2  * Copyright (c) 2019, Red Hat, Inc. 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 8231550
       
    27  * @summary C2: ShouldNotReachHere() in verify_strip_mined_scheduling
       
    28  *
       
    29  * @run main/othervm -XX:-BackgroundCompilation -XX:LoopMaxUnroll=0 TestConservativeAntiDep
       
    30  *
       
    31  */
       
    32 
       
    33 import java.lang.reflect.Array;
       
    34 import java.util.Arrays;
       
    35 
       
    36 public class TestConservativeAntiDep {
       
    37     private static long longField;
       
    38 
       
    39     public static void main(String[] args) throws InstantiationException, IllegalAccessException {
       
    40         for (int i = 0; i < 20_000; i++) {
       
    41             test1(A.class);
       
    42             test2(B.class);
       
    43         }
       
    44     }
       
    45 
       
    46     private static int test1(Class klass) {
       
    47         Object[] in = (Object[])Array.newInstance(klass, 100);
       
    48 
       
    49         Object[] o = in;
       
    50         int v = 1;
       
    51         // CountedLoop has control dependent CastPP
       
    52         for (int i = 0; i < 100 ; i++) {
       
    53             longField = i; // sunk in outer strip mined loop
       
    54             o = (A[]) o;
       
    55             v *= 2;
       
    56         }
       
    57 
       
    58         // LoadRange cannot float higher than CountedLoop (because of
       
    59         // CastPP) and is found anti-dependent with long store so
       
    60         // scheduled in outer strip mined loop
       
    61         return v + o.length;
       
    62     }
       
    63 
       
    64     private static int test2(Class klass) throws IllegalAccessException, InstantiationException {
       
    65         A in = (A)klass.newInstance();
       
    66 
       
    67         A o = in;
       
    68         int v = 1;
       
    69         // CountedLoop has control dependent CastPP
       
    70         for (int i = 0; i < 100 ; i++) {
       
    71             longField = i;  // sunk in outer strip mined loop
       
    72             o = (B) o;
       
    73             v *= 2;
       
    74         }
       
    75 
       
    76         // Load cannot float higher than CountedLoop (because of
       
    77         // CastPP) and is found anti-dependent with long store so
       
    78         // scheduled in outer strip mined loop
       
    79         return v + o.intField;
       
    80     }
       
    81 
       
    82     private static class A {
       
    83         int intField;
       
    84         public A() {}
       
    85     }
       
    86 
       
    87     private static class B extends A {
       
    88         public B() {}
       
    89     }
       
    90 }