test/hotspot/jtreg/compiler/rangechecks/RangeCheckEliminationScaleNotOne.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 53169 98580226126d
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53169
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     1
/*
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     2
 * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     4
 *
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     8
 *
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    13
 * accompanied this code).
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    14
 *
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    18
 *
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    21
 * questions.
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    22
 */
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    23
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    24
/*
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    25
 * @test
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    26
 * @bug 8215265
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    27
 * @summary C2: range check elimination may allow illegal out of bound access
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    28
 *
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    29
 * @run main/othervm -XX:-TieredCompilation -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:-UseLoopPredicate RangeCheckEliminationScaleNotOne
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    30
 *
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    31
 */
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    32
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    33
import java.util.Arrays;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    34
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    35
public class RangeCheckEliminationScaleNotOne {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    36
    public static void main(String[] args) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    37
        {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    38
            int[] array = new int[199];
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    39
            boolean[] flags = new boolean[100];
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    40
            Arrays.fill(flags, true);
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    41
            flags[0] = false;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    42
            flags[1] = false;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    43
            for (int i = 0; i < 20_000; i++) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    44
                test1(100, array, 0, flags);
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    45
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    46
            boolean ex = false;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    47
            try {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    48
                test1(100, array, -5, flags);
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    49
            } catch (ArrayIndexOutOfBoundsException aie) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    50
                ex = true;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    51
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    52
            if (!ex) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    53
                throw new RuntimeException("no AIOOB exception");
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    54
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    55
        }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    56
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    57
        {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    58
            int[] array = new int[199];
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    59
            boolean[] flags = new boolean[100];
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    60
            Arrays.fill(flags, true);
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    61
            flags[0] = false;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    62
            flags[1] = false;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    63
            for (int i = 0; i < 20_000; i++) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    64
                test2(100, array, 198, flags);
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    65
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    66
            boolean ex = false;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    67
            try {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    68
                test2(100, array, 203, flags);
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    69
            } catch (ArrayIndexOutOfBoundsException aie) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    70
                ex = true;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    71
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    72
            if (!ex) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    73
                throw new RuntimeException("no AIOOB exception");
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    74
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    75
        }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    76
    }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    77
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    78
    private static int test1(int stop, int[] array, int offset, boolean[] flags) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    79
        if (array == null) {}
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    80
        int res = 0;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    81
        for (int i = 0; i < stop; i++) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    82
            if (flags[i]) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    83
                res += array[2 * i + offset];
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    84
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    85
        }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    86
        return res;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    87
    }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    88
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    89
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    90
    private static int test2(int stop, int[] array, int offset, boolean[] flags) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    91
        if (array == null) {}
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    92
        int res = 0;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    93
        for (int i = 0; i < stop; i++) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    94
            if (flags[i]) {
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    95
                res += array[-2 * i + offset];
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    96
            }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    97
        }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    98
        return res;
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
    99
    }
98580226126d 8215265: C2: range check elimination may allow illegal out of bound access
roland
parents:
diff changeset
   100
}