author | gtriantafill |
Wed, 14 Sep 2016 08:17:50 -0400 | |
changeset 41092 | c388d897472d |
parent 40855 | 3c4c913195e3 |
permissions | -rw-r--r-- |
26820 | 1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
26820 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
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 8058744 |
|
27 |
* @summary Invalid pattern-matching of address computations in raw unsafe |
|
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
28 |
* @library /test/lib |
36851 | 29 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
27453
diff
changeset
|
30 |
* java.management |
40059 | 31 |
* @run main/othervm -Xbatch compiler.unsafe.UnsafeRaw |
26820 | 32 |
*/ |
33 |
||
40059 | 34 |
package compiler.unsafe; |
35 |
||
36 |
import jdk.internal.misc.Unsafe; |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
37 |
import jdk.test.lib.Utils; |
40059 | 38 |
|
26820 | 39 |
import java.util.Random; |
40 |
||
41 |
public class UnsafeRaw { |
|
42 |
public static class Tests { |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
43 |
public static int int_index(Unsafe unsafe, long base, int index) throws Exception { |
26820 | 44 |
return unsafe.getInt(base + (index << 2)); |
45 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
46 |
public static int long_index(Unsafe unsafe, long base, long index) throws Exception { |
26820 | 47 |
return unsafe.getInt(base + (index << 2)); |
48 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
49 |
public static int int_index_back_ashift(Unsafe unsafe, long base, int index) throws Exception { |
26820 | 50 |
return unsafe.getInt(base + (index >> 2)); |
51 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
52 |
public static int int_index_back_lshift(Unsafe unsafe, long base, int index) throws Exception { |
26820 | 53 |
return unsafe.getInt(base + (index >>> 2)); |
54 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
55 |
public static int long_index_back_ashift(Unsafe unsafe, long base, long index) throws Exception { |
26820 | 56 |
return unsafe.getInt(base + (index >> 2)); |
57 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
58 |
public static int long_index_back_lshift(Unsafe unsafe, long base, long index) throws Exception { |
26820 | 59 |
return unsafe.getInt(base + (index >>> 2)); |
60 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
61 |
public static int int_const_12345678_index(Unsafe unsafe, long base) throws Exception { |
26820 | 62 |
int idx4 = 0x12345678; |
63 |
return unsafe.getInt(base + idx4); |
|
64 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
65 |
public static int long_const_1234567890abcdef_index(Unsafe unsafe, long base) throws Exception { |
26820 | 66 |
long idx5 = 0x1234567890abcdefL; |
67 |
return unsafe.getInt(base + idx5); |
|
68 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
69 |
public static int int_index_mul(Unsafe unsafe, long base, int index) throws Exception { |
26820 | 70 |
return unsafe.getInt(base + (index * 4)); |
71 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
72 |
public static int long_index_mul(Unsafe unsafe, long base, long index) throws Exception { |
26820 | 73 |
return unsafe.getInt(base + (index * 4)); |
74 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
75 |
public static int int_index_mul_scale_16(Unsafe unsafe, long base, int index) throws Exception { |
26820 | 76 |
return unsafe.getInt(base + (index * 16)); |
77 |
} |
|
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36851
diff
changeset
|
78 |
public static int long_index_mul_scale_16(Unsafe unsafe, long base, long index) throws Exception { |
26820 | 79 |
return unsafe.getInt(base + (index * 16)); |
80 |
} |
|
81 |
} |
|
82 |
||
83 |
public static void main(String[] args) throws Exception { |
|
41092
c388d897472d
8165889: Remove jdk.test.lib.unsafe.UnsafeHelper
gtriantafill
parents:
40855
diff
changeset
|
84 |
Unsafe unsafe = Unsafe.getUnsafe(); |
26820 | 85 |
final int array_size = 128; |
86 |
final int element_size = 4; |
|
87 |
final int magic = 0x12345678; |
|
88 |
||
27453
9aeb9b97bef6
8044186: Introduce a reproducible random generator
iignatyev
parents:
26820
diff
changeset
|
89 |
Random rnd = Utils.getRandomInstance(); |
26820 | 90 |
|
91 |
long array = unsafe.allocateMemory(array_size * element_size); // 128 ints |
|
92 |
long addr = array + array_size * element_size / 2; // something in the middle to work with |
|
93 |
unsafe.putInt(addr, magic); |
|
94 |
for (int j = 0; j < 100000; j++) { |
|
95 |
if (Tests.int_index(unsafe, addr, 0) != magic) throw new Exception(); |
|
96 |
if (Tests.long_index(unsafe, addr, 0) != magic) throw new Exception(); |
|
97 |
if (Tests.int_index_mul(unsafe, addr, 0) != magic) throw new Exception(); |
|
98 |
if (Tests.long_index_mul(unsafe, addr, 0) != magic) throw new Exception(); |
|
99 |
{ |
|
100 |
long idx1 = rnd.nextLong(); |
|
101 |
long addr1 = addr - (idx1 << 2); |
|
102 |
if (Tests.long_index(unsafe, addr1, idx1) != magic) throw new Exception(); |
|
103 |
} |
|
104 |
{ |
|
105 |
long idx2 = rnd.nextLong(); |
|
106 |
long addr2 = addr - (idx2 >> 2); |
|
107 |
if (Tests.long_index_back_ashift(unsafe, addr2, idx2) != magic) throw new Exception(); |
|
108 |
} |
|
109 |
{ |
|
110 |
long idx3 = rnd.nextLong(); |
|
111 |
long addr3 = addr - (idx3 >>> 2); |
|
112 |
if (Tests.long_index_back_lshift(unsafe, addr3, idx3) != magic) throw new Exception(); |
|
113 |
} |
|
114 |
{ |
|
115 |
long idx4 = 0x12345678; |
|
116 |
long addr4 = addr - idx4; |
|
117 |
if (Tests.int_const_12345678_index(unsafe, addr4) != magic) throw new Exception(); |
|
118 |
} |
|
119 |
{ |
|
120 |
long idx5 = 0x1234567890abcdefL; |
|
121 |
long addr5 = addr - idx5; |
|
122 |
if (Tests.long_const_1234567890abcdef_index(unsafe, addr5) != magic) throw new Exception(); |
|
123 |
} |
|
124 |
{ |
|
125 |
int idx6 = rnd.nextInt(); |
|
126 |
long addr6 = addr - (idx6 >> 2); |
|
127 |
if (Tests.int_index_back_ashift(unsafe, addr6, idx6) != magic) throw new Exception(); |
|
128 |
} |
|
129 |
{ |
|
130 |
int idx7 = rnd.nextInt(); |
|
131 |
long addr7 = addr - (idx7 >>> 2); |
|
132 |
if (Tests.int_index_back_lshift(unsafe, addr7, idx7) != magic) throw new Exception(); |
|
133 |
} |
|
134 |
{ |
|
135 |
int idx8 = rnd.nextInt(); |
|
136 |
long addr8 = addr - (idx8 * 16); |
|
137 |
if (Tests.int_index_mul_scale_16(unsafe, addr8, idx8) != magic) throw new Exception(); |
|
138 |
} |
|
139 |
{ |
|
140 |
long idx9 = rnd.nextLong(); |
|
141 |
long addr9 = addr - (idx9 * 16); |
|
142 |
if (Tests.long_index_mul_scale_16(unsafe, addr9, idx9) != magic) throw new Exception(); |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
} |