11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8066103
27 * @summary C2's range check smearing allows out of bound array accesses
28 * @library /testlibrary /test/lib /
29 * @modules java.base/jdk.internal.misc
30 * java.management
31 * @build TestRangeCheckSmearing
32 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
33 * jdk.test.lib.Platform
34 * @run main/othervm -ea -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
35 * -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestRangeCheckSmearing
36 *
37 */
38
39 import java.lang.annotation.*;
40 import java.lang.reflect.*;
41 import java.util.*;
42 import sun.hotspot.WhiteBox;
43 import sun.hotspot.code.NMethod;
44 import jdk.test.lib.Platform;
45 import compiler.whitebox.CompilerWhiteBoxTest;
46
47 public class TestRangeCheckSmearing {
48 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
49
50 @Retention(RetentionPolicy.RUNTIME)
51 @interface Args { int[] value(); }
52
53 // first range check is i + max of all constants
54 @Args({0, 8})
55 static int m1(int[] array, int i, boolean allaccesses) {
56 int res = 0;
57 res += array[i+9];
58 if (allaccesses) {
59 res += array[i+8];
60 res += array[i+7];
61 res += array[i+6];
62 res += array[i+5];
63 res += array[i+4];
64 res += array[i+3];
65 res += array[i+2];
66 res += array[i+1];
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8066103
27 * @summary C2's range check smearing allows out of bound array accesses
28 * @library /testlibrary /test/lib /
29 * @modules java.base/jdk.internal.misc
30 * java.management
31 * @build compiler.rangechecks.TestRangeCheckSmearing
32 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
33 * jdk.test.lib.Platform
34 * @run main/othervm -ea -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
35 * -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
36 * compiler.rangechecks.TestRangeCheckSmearing
37 *
38 */
39
40 package compiler.rangechecks;
41
42 import compiler.whitebox.CompilerWhiteBoxTest;
43 import jdk.test.lib.Platform;
44 import sun.hotspot.WhiteBox;
45
46 import java.lang.annotation.Retention;
47 import java.lang.annotation.RetentionPolicy;
48 import java.lang.reflect.Method;
49 import java.lang.reflect.Modifier;
50 import java.util.Arrays;
51 import java.util.HashMap;
52
53 public class TestRangeCheckSmearing {
54 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
55
56 @Retention(RetentionPolicy.RUNTIME)
57 @interface Args { int[] value(); }
58
59 // first range check is i + max of all constants
60 @Args({0, 8})
61 static int m1(int[] array, int i, boolean allaccesses) {
62 int res = 0;
63 res += array[i+9];
64 if (allaccesses) {
65 res += array[i+8];
66 res += array[i+7];
67 res += array[i+6];
68 res += array[i+5];
69 res += array[i+4];
70 res += array[i+3];
71 res += array[i+2];
72 res += array[i+1];
|