hotspot/test/compiler/loopopts/TestPredicateLostDependency.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 30300 4b12a5b40064
child 40059 c2304140ed64
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30300
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     1
/*
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     4
 *
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     8
 *
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    13
 * accompanied this code).
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    14
 *
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    18
 *
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    21
 * questions.
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    22
 *
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    23
 */
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    24
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    25
/**
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    26
 * @test
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    27
 * @bug 8069191
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    28
 * @summary predicate moved out of loops and CastPP removal causes dependency to be lost
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    29
 * @run main/othervm -Xcomp -XX:CompileOnly=TestPredicateLostDependency.m1 -XX:+IgnoreUnrecognizedVMOptions -XX:+StressGCM TestPredicateLostDependency
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    30
 *
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    31
 */
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    32
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    33
public class TestPredicateLostDependency {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    34
    static class A {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    35
        int i;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    36
    }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    37
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    38
    static class B extends A {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    39
    }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    40
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    41
    static boolean crash = false;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    42
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    43
    static boolean m2() {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    44
        return crash;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    45
    }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    46
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    47
    static int m3(float[] arr) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    48
        return 0;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    49
    }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    50
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    51
    static float m1(A aa) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    52
        float res = 0;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    53
        float[] arr = new float[10];
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    54
        for (int i = 0; i < 10; i++) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    55
            if (m2()) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    56
                arr = null;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    57
            }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    58
            m3(arr);
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    59
            int j = arr.length;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    60
            int k = 0;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    61
            for (k = 9; k < j; k++) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    62
            }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    63
            if (k == 10) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    64
                if (aa instanceof B) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    65
                }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    66
            }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    67
            res += arr[0];
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    68
            res += arr[1];
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    69
        }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    70
        return res;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    71
    }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    72
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    73
    static public void main(String args[]) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    74
        A a = new A();
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    75
        B b = new B();
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    76
        for (int i = 0; i < 20000; i++) {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    77
            m1(a);
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    78
        }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    79
        crash = true;
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    80
        try {
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    81
            m1(a);
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    82
        } catch (NullPointerException npe) {}
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    83
    }
4b12a5b40064 8069191: moving predicate out of loops may cause array accesses to bypass null check
roland
parents:
diff changeset
    84
}