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 8000805
27 * @summary JMM issue: short loads are non-atomic
28 *
29 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -Xcomp -XX:+PrintCompilation -XX:CompileOnly=Test8000805.loadS2LmaskFF,Test8000805.loadS2Lmask16,Test8000805.loadS2Lmask13,Test8000805.loadUS_signExt,Test8000805.loadB2L_mask8 Test8000805
30 */
31
32 public class Test8000805 {
33 static long loadS2LmaskFF (short[] sa) { return sa[0] & 0xFF; }
34 static long loadS2LmaskFF_1 (short[] sa) { return sa[0] & 0xFF; }
35
36 static long loadS2Lmask16 (short[] sa) { return sa[0] & 0xFFFE; }
37 static long loadS2Lmask16_1 (short[] sa) { return sa[0] & 0xFFFE; }
38
39 static long loadS2Lmask13 (short[] sa) { return sa[0] & 0x0FFF; }
40 static long loadS2Lmask13_1 (short[] sa) { return sa[0] & 0x0FFF; }
41
42 static int loadUS_signExt (char[] ca) { return (ca[0] << 16) >> 16; }
43 static int loadUS_signExt_1 (char[] ca) { return (ca[0] << 16) >> 16; }
44
45 static long loadB2L_mask8 (byte[] ba) { return ba[0] & 0x55; }
46 static long loadB2L_mask8_1 (byte[] ba) { return ba[0] & 0x55; }
47
48 public static void main(String[] args) {
49 for (int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) {
50 byte[] ba = new byte[] { (byte) i};
51
52 { long v1 = loadB2L_mask8(ba);
53 long v2 = loadB2L_mask8_1(ba);
54 if (v1 != v2)
55 throw new InternalError(String.format("loadB2L_mask8 failed: %x != %x", v1, v2)); }
56 }
57
58 for (int i = Short.MIN_VALUE; i < Short.MAX_VALUE; i++) {
59 short[] sa = new short[] { (short)i };
60 char[] ca = new char[] { (char)i };
61
62 { long v1 = loadS2LmaskFF(sa);
63 long v2 = loadS2LmaskFF_1(sa);
64 if (v1 != v2)
65 throw new InternalError(String.format("loadS2LmaskFF failed: %x != %x", v1, v2)); }
66
67 { long v1 = loadS2Lmask16(sa);
68 long v2 = loadS2Lmask16_1(sa);
69 if (v1 != v2)
70 throw new InternalError(String.format("loadS2Lmask16 failed: %x != %x", v1, v2)); }
71
72 { long v1 = loadS2Lmask13(sa);
73 long v2 = loadS2Lmask13_1(sa);
74 if (v1 != v2)
75 throw new InternalError(String.format("loadS2Lmask13 failed: %x != %x", v1, v2)); }
76
77 { int v1 = loadUS_signExt(ca);
78 int v2 = loadUS_signExt_1(ca);
79 if (v1 != v2)
80 throw new InternalError(String.format("loadUS_signExt failed: %x != %x", v1, v2)); }
81 }
82
83 System.out.println("TEST PASSED.");
84 }
85 }
|
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 8000805
27 * @summary JMM issue: short loads are non-atomic
28 *
29 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -Xcomp
30 * -XX:+PrintCompilation
31 * -XX:CompileCommand=compileonly,compiler.c2.Test8000805::load*
32 * compiler.c2.Test8000805
33 */
34
35 package compiler.c2;
36 public class Test8000805 {
37 static long loadS2LmaskFF (short[] sa) { return sa[0] & 0xFF; }
38 static long _loadS2LmaskFF (short[] sa) { return sa[0] & 0xFF; }
39
40 static long loadS2Lmask16 (short[] sa) { return sa[0] & 0xFFFE; }
41 static long _loadS2Lmask16 (short[] sa) { return sa[0] & 0xFFFE; }
42
43 static long loadS2Lmask13 (short[] sa) { return sa[0] & 0x0FFF; }
44 static long _loadS2Lmask13 (short[] sa) { return sa[0] & 0x0FFF; }
45
46 static int loadUS_signExt (char[] ca) { return (ca[0] << 16) >> 16; }
47 static int _loadUS_signExt (char[] ca) { return (ca[0] << 16) >> 16; }
48
49 static long loadB2L_mask8 (byte[] ba) { return ba[0] & 0x55; }
50 static long _loadB2L_mask8 (byte[] ba) { return ba[0] & 0x55; }
51
52 public static void main(String[] args) {
53 for (int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) {
54 byte[] ba = new byte[] { (byte) i};
55
56 { long v1 = loadB2L_mask8(ba);
57 long v2 = _loadB2L_mask8(ba);
58 if (v1 != v2)
59 throw new InternalError(String.format("loadB2L_mask8 failed: %x != %x", v1, v2)); }
60 }
61
62 for (int i = Short.MIN_VALUE; i < Short.MAX_VALUE; i++) {
63 short[] sa = new short[] { (short)i };
64 char[] ca = new char[] { (char)i };
65
66 { long v1 = loadS2LmaskFF(sa);
67 long v2 = _loadS2LmaskFF(sa);
68 if (v1 != v2)
69 throw new InternalError(String.format("loadS2LmaskFF failed: %x != %x", v1, v2)); }
70
71 { long v1 = loadS2Lmask16(sa);
72 long v2 = _loadS2Lmask16(sa);
73 if (v1 != v2)
74 throw new InternalError(String.format("loadS2Lmask16 failed: %x != %x", v1, v2)); }
75
76 { long v1 = loadS2Lmask13(sa);
77 long v2 = _loadS2Lmask13(sa);
78 if (v1 != v2)
79 throw new InternalError(String.format("loadS2Lmask13 failed: %x != %x", v1, v2)); }
80
81 { int v1 = loadUS_signExt(ca);
82 int v2 = _loadUS_signExt(ca);
83 if (v1 != v2)
84 throw new InternalError(String.format("loadUS_signExt failed: %x != %x", v1, v2)); }
85 }
86
87 System.out.println("TEST PASSED.");
88 }
89 }
|