Mercurial > hg > graal-jvmci-8
annotate test/compiler/unsafe/TestUnsafeLoadControl.java @ 24066:9050d85e2960 jdk8u102-b33
Added tag jdk8u102-b32 for changeset c8988d2e4212
author | asaha |
---|---|
date | Tue, 02 Aug 2016 08:02:27 -0700 |
parents | c1c199dde5c9 |
children |
rev | line source |
---|---|
23055
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
1 /* |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
4 * |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
8 * |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
13 * accompanied this code). |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
14 * |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
18 * |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
21 * questions. |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
22 */ |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
23 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
24 /* |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
25 * @test |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
26 * @bug 8077504 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
27 * @summary Unsafe load can loose control dependency and cause crash |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
28 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestUnsafeLoadControl |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
29 * |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
30 */ |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
31 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
32 import java.lang.reflect.Field; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
33 import sun.misc.Unsafe; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
34 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
35 public class TestUnsafeLoadControl { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
36 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
37 private static final Unsafe UNSAFE; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
38 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
39 static { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
40 try { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
41 Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
42 unsafeField.setAccessible(true); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
43 UNSAFE = (Unsafe) unsafeField.get(null); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
44 } catch(Exception e) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
45 throw new RuntimeException(e); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
46 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
47 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
48 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
49 static int val; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
50 static void test1(int[] a, boolean[] flags, boolean flag, long j) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
51 for (int i = 0; i < 10; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
52 if (flags[i]) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
53 if (flag) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
54 long address = (j << 2) + UNSAFE.ARRAY_INT_BASE_OFFSET; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
55 int v = UNSAFE.getInt(a, address); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
56 val = v; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
57 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
58 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
59 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
60 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
61 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
62 static int test2(int[] a, boolean[] flags, boolean flag, long j) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
63 int sum = 0; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
64 for (int i = 0; i < 10; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
65 if (flags[i]) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
66 if (flag) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
67 long address = (j << 2) + UNSAFE.ARRAY_INT_BASE_OFFSET; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
68 int v = UNSAFE.getInt(a, address); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
69 if (v == 0) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
70 sum++; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
71 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
72 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
73 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
74 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
75 return sum; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
76 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
77 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
78 static public void main(String[] args) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
79 boolean[] flags = new boolean[10]; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
80 for (int i = 0; i < flags.length; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
81 flags[i] = true; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
82 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
83 int[] array = new int[10]; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
84 for (int i = 0; i < 20000; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
85 test1(array, flags, true, 0); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
86 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
87 for (int i = 0; i < flags.length; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
88 flags[i] = false; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
89 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
90 test1(array, flags, true, Long.MAX_VALUE/4); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
91 |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
92 for (int i = 0; i < flags.length; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
93 flags[i] = true; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
94 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
95 for (int i = 0; i < 20000; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
96 test2(array, flags, true, 0); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
97 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
98 for (int i = 0; i < flags.length; i++) { |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
99 flags[i] = false; |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
100 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
101 test2(array, flags, true, Long.MAX_VALUE/4); |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
102 } |
c1c199dde5c9
8077504: Unsafe load can loose control dependency and cause crash
roland
parents:
diff
changeset
|
103 } |