annotate test/compiler/unsafe/UnsafeRaw.java @ 20492:50d3433155d9

8059002: 8058744 needs a test case Summary: Added a test case the UnsafeRawOp intrinsics Reviewed-by: kvn
author iveresov
date Tue, 23 Sep 2014 17:24:34 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20492
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
1 /*
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
4 *
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
7 * published by the Free Software Foundation.
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
8 *
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
13 * accompanied this code).
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
14 *
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
18 *
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
21 * questions.
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
22 */
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
23
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
24 /*
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
25 * @test
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
26 * @bug 8058744
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
27 * @summary Invalid pattern-matching of address computations in raw unsafe
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
28 * @library /testlibrary
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
29 * @run main/othervm -Xbatch UnsafeRaw
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
30 */
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
31
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
32 import com.oracle.java.testlibrary.Utils;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
33 import java.util.Random;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
34
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
35 public class UnsafeRaw {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
36 public static class Tests {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
37 public static int int_index(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
38 return unsafe.getInt(base + (index << 2));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
39 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
40 public static int long_index(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
41 return unsafe.getInt(base + (index << 2));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
42 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
43 public static int int_index_back_ashift(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
44 return unsafe.getInt(base + (index >> 2));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
45 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
46 public static int int_index_back_lshift(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
47 return unsafe.getInt(base + (index >>> 2));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
48 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
49 public static int long_index_back_ashift(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
50 return unsafe.getInt(base + (index >> 2));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
51 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
52 public static int long_index_back_lshift(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
53 return unsafe.getInt(base + (index >>> 2));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
54 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
55 public static int int_const_12345678_index(sun.misc.Unsafe unsafe, long base) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
56 int idx4 = 0x12345678;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
57 return unsafe.getInt(base + idx4);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
58 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
59 public static int long_const_1234567890abcdef_index(sun.misc.Unsafe unsafe, long base) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
60 long idx5 = 0x1234567890abcdefL;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
61 return unsafe.getInt(base + idx5);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
62 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
63 public static int int_index_mul(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
64 return unsafe.getInt(base + (index * 4));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
65 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
66 public static int long_index_mul(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
67 return unsafe.getInt(base + (index * 4));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
68 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
69 public static int int_index_mul_scale_16(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
70 return unsafe.getInt(base + (index * 16));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
71 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
72 public static int long_index_mul_scale_16(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
73 return unsafe.getInt(base + (index * 16));
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
74 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
75 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
76
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
77 public static void main(String[] args) throws Exception {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
78 sun.misc.Unsafe unsafe = Utils.getUnsafe();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
79 final int array_size = 128;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
80 final int element_size = 4;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
81 final int magic = 0x12345678;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
82
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
83 Random rnd = new Random();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
84
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
85 long array = unsafe.allocateMemory(array_size * element_size); // 128 ints
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
86 long addr = array + array_size * element_size / 2; // something in the middle to work with
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
87 unsafe.putInt(addr, magic);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
88 for (int j = 0; j < 100000; j++) {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
89 if (Tests.int_index(unsafe, addr, 0) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
90 if (Tests.long_index(unsafe, addr, 0) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
91 if (Tests.int_index_mul(unsafe, addr, 0) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
92 if (Tests.long_index_mul(unsafe, addr, 0) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
93 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
94 long idx1 = rnd.nextLong();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
95 long addr1 = addr - (idx1 << 2);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
96 if (Tests.long_index(unsafe, addr1, idx1) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
97 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
98 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
99 long idx2 = rnd.nextLong();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
100 long addr2 = addr - (idx2 >> 2);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
101 if (Tests.long_index_back_ashift(unsafe, addr2, idx2) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
102 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
103 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
104 long idx3 = rnd.nextLong();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
105 long addr3 = addr - (idx3 >>> 2);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
106 if (Tests.long_index_back_lshift(unsafe, addr3, idx3) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
107 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
108 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
109 long idx4 = 0x12345678;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
110 long addr4 = addr - idx4;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
111 if (Tests.int_const_12345678_index(unsafe, addr4) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
112 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
113 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
114 long idx5 = 0x1234567890abcdefL;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
115 long addr5 = addr - idx5;
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
116 if (Tests.long_const_1234567890abcdef_index(unsafe, addr5) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
117 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
118 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
119 int idx6 = rnd.nextInt();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
120 long addr6 = addr - (idx6 >> 2);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
121 if (Tests.int_index_back_ashift(unsafe, addr6, idx6) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
122 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
123 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
124 int idx7 = rnd.nextInt();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
125 long addr7 = addr - (idx7 >>> 2);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
126 if (Tests.int_index_back_lshift(unsafe, addr7, idx7) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
127 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
128 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
129 int idx8 = rnd.nextInt();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
130 long addr8 = addr - (idx8 * 16);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
131 if (Tests.int_index_mul_scale_16(unsafe, addr8, idx8) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
132 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
133 {
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
134 long idx9 = rnd.nextLong();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
135 long addr9 = addr - (idx9 * 16);
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
136 if (Tests.long_index_mul_scale_16(unsafe, addr9, idx9) != magic) throw new Exception();
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
137 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
138 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
139 }
50d3433155d9 8059002: 8058744 needs a test case
iveresov
parents:
diff changeset
140 }