author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45514 | hotspot/test/compiler/profiling/UnsafeAccess.java@0fc9cc73ce45 |
child 52220 | 9c260a6b6471 |
permissions | -rw-r--r-- |
38131
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
1 |
/* |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
4 |
* |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
8 |
* |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
13 |
* accompanied this code). |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
14 |
* |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
18 |
* |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
21 |
* questions. |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
22 |
*/ |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
23 |
/* |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
24 |
* @test |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
25 |
* @bug 8134918 |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
26 |
* @modules java.base/jdk.internal.misc |
40059 | 27 |
* |
38188
e76af590ea2f
8155751: Some tests miss othervm for main/bootclasspath mode
vlivanov
parents:
38131
diff
changeset
|
28 |
* @run main/bootclasspath/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:TypeProfileLevel=222 -XX:+UseTypeSpeculation -Xbatch |
40059 | 29 |
* -XX:CompileCommand=dontinline,compiler.profiling.UnsafeAccess::test* |
30 |
* compiler.profiling.UnsafeAccess |
|
38131
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
31 |
*/ |
40059 | 32 |
|
33 |
package compiler.profiling; |
|
34 |
||
38131
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
35 |
import jdk.internal.misc.Unsafe; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
36 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
37 |
public class UnsafeAccess { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
38 |
private static final Unsafe U = Unsafe.getUnsafe(); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
39 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
40 |
static Class cls = Object.class; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
41 |
static long off = U.ARRAY_OBJECT_BASE_OFFSET; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
42 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
43 |
static Object testUnsafeAccess(Object o, boolean isObjArray) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
44 |
if (o != null && cls.isInstance(o)) { // speculates "o" type to int[] |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
45 |
return helperUnsafeAccess(o, isObjArray); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
46 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
47 |
return null; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
48 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
49 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
50 |
static Object helperUnsafeAccess(Object o, boolean isObjArray) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
51 |
if (isObjArray) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
52 |
U.putObject(o, off, new Object()); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
53 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
54 |
return o; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
55 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
56 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
57 |
static Object testUnsafeLoadStore(Object o, boolean isObjArray) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
58 |
if (o != null && cls.isInstance(o)) { // speculates "o" type to int[] |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
59 |
return helperUnsafeLoadStore(o, isObjArray); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
60 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
61 |
return null; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
62 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
63 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
64 |
static Object helperUnsafeLoadStore(Object o, boolean isObjArray) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
65 |
if (isObjArray) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
66 |
Object o1 = U.getObject(o, off); |
45514
0fc9cc73ce45
8181292: Backport Rename internal Unsafe.compare methods from 10 to 9
psandoz
parents:
40059
diff
changeset
|
67 |
U.compareAndSetObject(o, off, o1, new Object()); |
38131
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
68 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
69 |
return o; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
70 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
71 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
72 |
public static void main(String[] args) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
73 |
Object[] objArray = new Object[10]; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
74 |
int[] intArray = new int[10]; |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
75 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
76 |
for (int i = 0; i < 20_000; i++) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
77 |
helperUnsafeAccess(objArray, true); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
78 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
79 |
for (int i = 0; i < 20_000; i++) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
80 |
testUnsafeAccess(intArray, false); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
81 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
82 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
83 |
for (int i = 0; i < 20_000; i++) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
84 |
helperUnsafeLoadStore(objArray, true); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
85 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
86 |
for (int i = 0; i < 20_000; i++) { |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
87 |
testUnsafeLoadStore(intArray, false); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
88 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
89 |
|
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
90 |
System.out.println("TEST PASSED"); |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
91 |
} |
7bb27ec1a3d8
8134918: C2: Type speculation produces mismatched unsafe accesses
vlivanov
parents:
diff
changeset
|
92 |
} |