author | adinn |
Fri, 29 Nov 2019 15:37:13 +0000 | |
changeset 59326 | 851a389fc54d |
parent 52220 | 9c260a6b6471 |
permissions | -rw-r--r-- |
50874
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
1 |
/* |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Red Hat, Inc. All rights reserved. |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
4 |
* |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
8 |
* |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
13 |
* accompanied this code). |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
14 |
* |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
18 |
* |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
21 |
* questions. |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
22 |
*/ |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
23 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
24 |
package compiler.c2.aarch64; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
25 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
26 |
import java.lang.reflect.Field; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
27 |
import jdk.internal.misc.Unsafe; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
28 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
29 |
class TestUnsafeVolatileStore |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
30 |
{ |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
31 |
public volatile int f_int = 0; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
32 |
public volatile Integer f_obj = Integer.valueOf(0); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
33 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
34 |
public static Unsafe unsafe = Unsafe.getUnsafe(); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
35 |
public static Field f_int_field; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
36 |
public static Field f_obj_field; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
37 |
public static long f_int_off; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
38 |
public static long f_obj_off; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
39 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
40 |
static { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
41 |
try { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
42 |
f_int_field = TestUnsafeVolatileStore.class.getField("f_int"); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
43 |
f_obj_field = TestUnsafeVolatileStore.class.getField("f_obj"); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
44 |
f_int_off = unsafe.objectFieldOffset(f_int_field); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
45 |
f_obj_off = unsafe.objectFieldOffset(f_obj_field); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
46 |
} catch (Exception e) { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
47 |
System.out.println("reflection failed " + e); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
48 |
e.printStackTrace(); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
49 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
50 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
51 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
52 |
public static void main(String[] args) |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
53 |
{ |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
54 |
final TestUnsafeVolatileStore t = new TestUnsafeVolatileStore(); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
55 |
for (int i = 0; i < 100_000; i++) { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
56 |
t.f_int = -1; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
57 |
t.testInt(i); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
58 |
if (t.f_int != i) { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
59 |
throw new RuntimeException("bad result!"); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
60 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
61 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
62 |
for (int i = 0; i < 100_000; i++) { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
63 |
t.f_obj = null; |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
64 |
t.testObj(Integer.valueOf(i)); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
65 |
if (t.f_obj != i) { |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
66 |
throw new RuntimeException("bad result!"); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
67 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
68 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
69 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
70 |
public void testInt(int i) |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
71 |
{ |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
72 |
unsafe.putIntVolatile(this, f_int_off, i); |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
73 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
74 |
|
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
75 |
public void testObj(Object o) |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
76 |
{ |
52220
9c260a6b6471
8207146: Rename jdk.internal.misc.Unsafe::xxxObject to xxxReference
mchung
parents:
50874
diff
changeset
|
77 |
unsafe.putReferenceVolatile(this, f_obj_off, o); |
50874
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
78 |
} |
551c340ca01a
8205694: AArch64: Add test to validate volatile load, store and CAS code generation
adinn
parents:
diff
changeset
|
79 |
} |