test/hotspot/jtreg/compiler/rangechecks/TestExplicitRangeChecks.java
author jiangli
Fri, 02 Nov 2018 19:30:31 -0400
changeset 52397 1322829d1501
parent 47216 71c04702a3d5
permissions -rw-r--r--
8209564: runtime/appcds/CDSandJFR.java timeout on tier6 on sparc Summary: Set timeout 500 in CDSandJFR.java Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     1
/*
38036
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     4
 *
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     8
 *
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    13
 * accompanied this code).
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    14
 *
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    18
 *
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    21
 * questions.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    22
 */
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    23
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    24
/*
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    25
 * @test
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    26
 * @bug 8073480
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    27
 * @summary explicit range checks should be recognized by C2
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    28
 * @library /test/lib /
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40631
diff changeset
    29
 * @modules java.base/jdk.internal.misc:+open
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    30
 * @build sun.hotspot.WhiteBox
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 38152
diff changeset
    31
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    32
 * @run main/othervm -ea -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    33
 *                   -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    34
 *                   -XX:CompileCommand=compileonly,compiler.rangechecks.TestExplicitRangeChecks::test*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    35
 *                   compiler.rangechecks.TestExplicitRangeChecks
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    36
 *
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    37
 */
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    38
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    39
package compiler.rangechecks;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    40
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    41
import compiler.whitebox.CompilerWhiteBoxTest;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    42
import jdk.internal.misc.Unsafe;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    43
import jdk.test.lib.Platform;
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    44
import sun.hotspot.WhiteBox;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    45
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    46
import java.lang.annotation.Retention;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    47
import java.lang.annotation.RetentionPolicy;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    48
import java.lang.reflect.Field;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    49
import java.lang.reflect.Method;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    50
import java.lang.reflect.Modifier;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    51
import java.util.HashMap;
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    52
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    53
public class TestExplicitRangeChecks {
38036
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
    54
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
    55
    private static final int TIERED_STOP_AT_LEVEL = WHITE_BOX.getIntxVMFlag("TieredStopAtLevel").intValue();
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
    56
    private static int[] array = new int[10];
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
    57
    private static boolean success = true;
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    58
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    59
    @Retention(RetentionPolicy.RUNTIME)
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    60
    @interface Args {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    61
        int[] compile();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    62
        int[] good();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    63
        int[] bad();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    64
        boolean deoptimize() default true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    65
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    66
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    67
    // Should be compiled as a single unsigned comparison
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    68
    // 0 <= index < array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    69
    @Args(compile = {5,}, good = {0, 9}, bad = {-1, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    70
    static boolean test1_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    71
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    72
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    73
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    74
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    75
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    76
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    77
    // same test but so we can compile with same optimization after trap in test1_1
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    78
    static boolean test1_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    79
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    80
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    81
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    82
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    83
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    84
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    85
    // Shouldn't matter whether first or second test is the one
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    86
    // against a constants
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    87
    // 0 <= index < array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    88
    @Args(compile = {5,}, good = {0, 9}, bad = {-1, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    89
    static boolean test2_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    90
        if (index >= array.length || index < 0) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    91
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    92
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    93
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    94
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    95
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    96
    static boolean test2_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    97
        if (index >= array.length || index < 0) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    98
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
    99
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   100
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   101
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   102
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   103
    // 0 <= index <= array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   104
    @Args(compile = {5,}, good = {0, 10}, bad = {-1, 11})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   105
    static boolean test3_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   106
        if (index < 0 || index > array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   107
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   108
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   109
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   110
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   111
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   112
    static boolean test3_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   113
        if (index < 0 || index > array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   114
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   115
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   116
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   117
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   118
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   119
    // 0 <= index <= array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   120
    @Args(compile = {5,}, good = {0, 10}, bad = {-1, 11})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   121
    static boolean test4_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   122
        if (index > array.length || index < 0 ) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   123
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   124
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   125
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   126
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   127
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   128
    static boolean test4_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   129
        if (index > array.length || index < 0) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   130
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   131
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   132
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   133
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   134
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   135
    static int[] test5_helper(int i) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   136
        return (i < 100) ? new int[10] : new int[5];
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   137
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   138
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   139
    // 0 < index < array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   140
    @Args(compile = {5,}, good = {1, 9}, bad = {0, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   141
    static boolean test5_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   142
        array = test5_helper(index); // array.length must be not constant greater than 1
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   143
        if (index <= 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   144
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   145
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   146
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   147
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   148
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   149
    static boolean test5_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   150
        array = test5_helper(index); // array.length must be not constant greater than 1
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   151
        if (index <= 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   152
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   153
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   154
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   155
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   156
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   157
    // 0 < index < array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   158
    @Args(compile = {5,}, good = {1, 9}, bad = {0, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   159
    static boolean test6_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   160
        array = test5_helper(index); // array.length must be not constant greater than 1
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   161
        if (index >= array.length || index <= 0 ) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   162
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   163
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   164
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   165
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   166
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   167
    static boolean test6_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   168
        array = test5_helper(index); // array.length must be not constant greater than 1
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   169
        if (index >= array.length || index <= 0) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   170
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   171
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   172
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   173
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   174
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   175
    // 0 < index <= array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   176
    @Args(compile = {5,}, good = {1, 10}, bad = {0, 11})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   177
    static boolean test7_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   178
        if (index <= 0 || index > array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   179
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   180
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   181
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   182
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   184
    static boolean test7_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   185
        if (index <= 0 || index > array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   186
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   187
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   188
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   189
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   190
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   191
    // 0 < index <= array.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   192
    @Args(compile = {5,}, good = {1, 10}, bad = {0, 11})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   193
    static boolean test8_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   194
        if (index > array.length || index <= 0 ) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   195
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   196
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   197
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   198
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   199
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   200
    static boolean test8_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   201
        if (index > array.length || index <= 0) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   202
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   203
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   204
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   205
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   206
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   207
    static int[] test9_helper1(int i) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   208
        return (i < 100) ? new int[1] : new int[2];
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   209
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   210
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   211
    static int[] test9_helper2(int i) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   212
        return (i < 100) ? new int[10] : new int[11];
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   213
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   214
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   215
    // array1.length <= index < array2.length
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   216
    @Args(compile = {5,}, good = {1, 9}, bad = {0, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   217
    static boolean test9_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   218
        int[] array1 = test9_helper1(index);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   219
        int[] array2 = test9_helper2(index);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   220
        if (index < array1.length || index >= array2.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   221
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   222
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   223
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   224
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   225
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   226
    static boolean test9_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   227
        int[] array1 = test9_helper1(index);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   228
        int[] array2 = test9_helper2(index);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   229
        if (index < array1.length || index >= array2.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   230
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   231
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   232
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   233
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   234
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   235
    // Previously supported pattern
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   236
    @Args(compile = {-5,5,15}, good = {0, 9}, bad = {-1, 10}, deoptimize=false)
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   237
    static boolean test10_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   238
        if (index < 0 || index >= 10) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   239
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   240
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   241
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   242
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   243
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   244
    static int[] array11 = new int[10];
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   245
    @Args(compile = {5,}, good = {0, 9}, bad = {-1,})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   246
    static boolean test11_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   247
        if (index < 0) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   248
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   249
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   250
        int unused = array11[index];
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   251
        // If this one is folded with the first test then we allow
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   252
        // array access above to proceed even for out of bound array
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   253
        // index and the method throws an
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   254
        // ArrayIndexOutOfBoundsException.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   255
        if (index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   256
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   257
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   258
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   259
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   260
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   261
    static int[] array12 = {10, 10, 10, 10, 10, 10, 10, 10, 10, 10};
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   262
    @Args(compile = {5,}, good = {0, 9}, bad = {-1,})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   263
    static boolean test12_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   264
        // Cannot be folded otherwise would cause incorrect array
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   265
        // access if the array12 range check is executed before the
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   266
        // folded test.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   267
        if (index < 0 || index >= array12[index]) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   268
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   269
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   270
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   271
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   272
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   273
    // Same as test1_1 but pass null array when index < 0: shouldn't
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   274
    // cause NPE.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   275
    @Args(compile = {5,}, good = {0, 9}, bad = {})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   276
    static boolean test13_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   277
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   278
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   279
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   280
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   281
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   282
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   283
    // Same as test10 but with uncommon traps
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   284
    @Args(compile = {5}, good = {0, 9}, bad = {-1, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   285
    static boolean test14_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   286
        if (index < 0 || index >= 10) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   287
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   288
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   289
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   290
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   291
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   292
    static boolean test14_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   293
        if (index < 0 || index >= 10) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   294
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   295
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   296
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   297
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   298
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   299
    // Same as test13_1 but pass null array: null trap should be reported on first if
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   300
    @Args(compile = {5,}, good = {0, 9}, bad = {})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   301
    static boolean test15_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   302
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   303
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   304
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   305
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   306
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   307
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   308
    // Same as test1 but with no null check between the integer comparisons
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   309
    @Args(compile = {5,}, good = {0, 9}, bad = {-1, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   310
    static boolean test16_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   311
        int l = array.length;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   312
        if (index < 0 || index >= l) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   313
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   314
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   315
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   316
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   317
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   318
    static boolean test16_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   319
        int l = array.length;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   320
        if (index < 0 || index >= l) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   321
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   322
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   323
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   324
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   325
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   326
    // Same as test1 but bound check on array access should optimize
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   327
    // out.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   328
    @Args(compile = {5,}, good = {0, 9}, bad = {-1, 10})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   329
    static boolean test17_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   330
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   331
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   332
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   333
        array[index] = 0;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   334
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   335
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   336
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   337
    static boolean test17_2(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   338
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   339
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   340
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   341
        array[index] = 0;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   342
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   343
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   344
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   345
    // Same as test1 but range check smearing should optimize
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   346
    // 3rd range check out.
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   347
    @Args(compile = {5,}, good = {}, bad = {})
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   348
    static boolean test18_1(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   349
        if (index < 0 || index >= array.length) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   350
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   351
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   352
        array[index+2] = 0;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   353
        array[index+1] = 0;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   354
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   355
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   356
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   357
    static boolean test19_helper1(int index) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   358
        if (index < 12) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   359
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   360
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   361
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   362
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   363
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   364
    static boolean test19_helper2(int index) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   365
        if (index > 8) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   366
            return false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   367
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   368
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   369
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   370
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   371
    // Second test should be optimized out
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   372
    static boolean test19(int index, int[] array) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   373
        test19_helper1(index);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   374
        test19_helper2(index);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   375
        return true;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   376
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   377
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   378
    final HashMap<String,Method> tests = new HashMap<>();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   379
    {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   380
        for (Method m : this.getClass().getDeclaredMethods()) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   381
            if (m.getName().matches("test[0-9]+(_[0-9])?")) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   382
                assert(Modifier.isStatic(m.getModifiers())) : m;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   383
                tests.put(m.getName(), m);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   384
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   385
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   386
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   387
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   388
    void doTest(String name) throws Exception {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   389
        Method m = tests.get(name + "_1");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   390
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   391
        Args anno =  m.getAnnotation(Args.class);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   392
        int[] compile = anno.compile();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   393
        int[] good = anno.good();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   394
        int[] bad = anno.bad();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   395
        boolean deoptimize = anno.deoptimize();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   396
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   397
        // Get compiled
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   398
        for (int i = 0; i < 20000;) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   399
            for (int j = 0; j < compile.length; j++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   400
                m.invoke(null, compile[j], array);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   401
                i++;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   402
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   403
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   404
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   405
        if (!WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   406
            System.out.println(name + "_1 not compiled");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   407
            success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   408
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   409
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   410
        // check that good values don't trigger exception or
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   411
        // deoptimization
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   412
        for (int i = 0; i < good.length; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   413
            boolean res = (boolean)m.invoke(null, good[i], array);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   414
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   415
            if (!res) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   416
                System.out.println(name + " bad result for good input " + good[i]);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   417
                success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   418
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   419
            if (!WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   420
                System.out.println(name + " deoptimized on valid access");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   421
                success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   422
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   423
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   424
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   425
        // check that bad values trigger exception and deoptimization
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   426
        for (int i = 0; i < bad.length; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   427
            if (i > 0 && deoptimize) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   428
                m = tests.get(name + "_" + (i+1));
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   429
                for (int k = 0; k < 20000;) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   430
                    for (int j = 0; j < compile.length; j++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   431
                        m.invoke(null, compile[j], array);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   432
                        k++;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   433
                    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   434
                }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   435
                if (!WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   436
                    System.out.println(name + ("_" + (i+1)) + " not compiled");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   437
                    success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   438
                }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   439
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   440
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   441
            boolean res = (boolean)m.invoke(null, bad[i], array);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   442
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   443
            if (res) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   444
                System.out.println(name + " bad result for bad input " + bad[i]);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   445
                success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   446
            }
38036
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
   447
            // Only perform these additional checks if C2 is available
43455
96560cffef4d 8166002: Emulate client build on platforms with reduced virtual address space
jcm
parents: 42307
diff changeset
   448
            if (Platform.isServer() && !Platform.isEmulatedClient() &&
38036
f51b942d970c 8154073: Several compiler tests fail when are executed with C1 only
thartmann
parents: 34185
diff changeset
   449
                TIERED_STOP_AT_LEVEL == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION) {
30183
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   450
                if (deoptimize && WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   451
                    System.out.println(name + " not deoptimized on invalid access");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   452
                    success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   453
                } else if (!deoptimize && !WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   454
                    System.out.println(name + " deoptimized on invalid access");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   455
                    success = false;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   456
                }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   457
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   458
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   459
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   460
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   461
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   462
    private static final Unsafe UNSAFE;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   463
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   464
    static {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   465
        try {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   466
            Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   467
            unsafeField.setAccessible(true);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   468
            UNSAFE = (Unsafe) unsafeField.get(null);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   469
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   470
        catch (Exception e) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   471
            throw new AssertionError(e);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   472
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   473
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   474
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   475
    // On x64, int to long conversion should optimize away in address computation
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   476
    static int test20(int[] a) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   477
        int sum = 0;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   478
        for (int i = 0; i < a.length; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   479
            sum += test20_helper(a, i);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   480
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   481
        return sum;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   482
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   483
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   484
    static int test20_helper(int[] a, int i) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   485
        if (i < 0 || i >= a.length)
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   486
            throw new ArrayIndexOutOfBoundsException();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   487
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   488
        long address = (((long) i) << 2) + UNSAFE.ARRAY_INT_BASE_OFFSET;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   489
        return UNSAFE.getInt(a, address);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   490
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   491
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   492
    static int test21(int[] a) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   493
        int sum = 0;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   494
        for (int i = 0; i < a.length; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   495
            sum += test20_helper(a, i);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   496
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   497
        return sum;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   498
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   499
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   500
    static int test21_helper(int[] a, int i) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   501
        if (i < 0 || i >= a.length)
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   502
            throw new ArrayIndexOutOfBoundsException();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   503
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   504
        long address = (((long) i) << 2) + UNSAFE.ARRAY_INT_BASE_OFFSET;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   505
        return UNSAFE.getIntVolatile(a, address);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   506
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   507
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   508
    static public void main(String[] args) throws Exception {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   509
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   510
        if (WHITE_BOX.getBooleanVMFlag("BackgroundCompilation")) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   511
            throw new AssertionError("Background compilation enabled");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   512
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   513
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   514
        TestExplicitRangeChecks test = new TestExplicitRangeChecks();
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   515
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   516
        test.doTest("test1");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   517
        test.doTest("test2");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   518
        test.doTest("test3");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   519
        test.doTest("test4");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   520
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   521
        // pollute branch profile
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   522
        for (int i = 0; i < 10000; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   523
            test5_helper((i%2 == 0) ? 0 : 1000);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   524
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   525
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   526
        test.doTest("test5");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   527
        test.doTest("test6");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   528
        test.doTest("test7");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   529
        test.doTest("test8");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   530
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   531
        // pollute branch profile
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   532
        for (int i = 0; i < 10000; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   533
            test9_helper1((i%2 == 0) ? 0 : 1000);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   534
            test9_helper2((i%2 == 0) ? 0 : 1000);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   535
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   536
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   537
        test.doTest("test9");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   538
        test.doTest("test10");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   539
        test.doTest("test11");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   540
        test.doTest("test12");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   541
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   542
        test.doTest("test13");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   543
        {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   544
            Method m = test.tests.get("test13_1");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   545
            for (int i = 0; i < 1; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   546
                test13_1(-1, null);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   547
                if (!WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   548
                    break;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   549
                }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   550
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   551
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   552
        test.doTest("test13");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   553
        {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   554
            Method m = test.tests.get("test13_1");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   555
            for (int i = 0; i < 10; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   556
                test13_1(-1, null);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   557
                if (!WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   558
                    break;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   559
                }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   560
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   561
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   562
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   563
        test.doTest("test14");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   564
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   565
        test.doTest("test15");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   566
        {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   567
            Method m = test.tests.get("test15_1");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   568
            for (int i = 0; i < 10; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   569
                try {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   570
                    test15_1(5, null);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   571
                } catch(NullPointerException npe) {}
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   572
                if (!WHITE_BOX.isMethodCompiled(m)) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   573
                    break;
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   574
                }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   575
            }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   576
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   577
        test.doTest("test15");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   578
        test.doTest("test16");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   579
        test.doTest("test17");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   580
        test.doTest("test18");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   581
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   582
        for (int i = 0; i < 20000; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   583
            test19_helper1(20);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   584
            test19_helper2(5);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   585
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   586
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   587
        {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   588
            Method m = test.tests.get("test19");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   589
            WHITE_BOX.enqueueMethodForCompilation(m, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   590
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   591
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   592
        for (int i = 0; i < 20000; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   593
            test20(array);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   594
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   595
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   596
        for (int i = 0; i < 20000; i++) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   597
            test21(array);
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   598
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   599
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   600
        if (!success) {
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   601
            throw new RuntimeException("some tests failed");
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   602
        }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   603
    }
a6588c0a3259 8073480: C2 should optimize explicit range checks
roland
parents:
diff changeset
   604
}