1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/8000805/Test8000805.java Mon Oct 22 11:44:30 2012 -0700 1.3 @@ -0,0 +1,85 @@ 1.4 +/* 1.5 + * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/** 1.28 + * @test 1.29 + * @bug 8000805 1.30 + * @summary JMM issue: short loads are non-atomic 1.31 + * 1.32 + * @run main/othervm -server -XX:-TieredCompilation -Xcomp -XX:+PrintCompilation -XX:CompileOnly=Test8000805.loadS2LmaskFF,Test8000805.loadS2Lmask16,Test8000805.loadS2Lmask13,Test8000805.loadUS_signExt,Test8000805.loadB2L_mask8 Test8000805 1.33 + */ 1.34 + 1.35 +public class Test8000805 { 1.36 + static long loadS2LmaskFF (short[] sa) { return sa[0] & 0xFF; } 1.37 + static long loadS2LmaskFF_1 (short[] sa) { return sa[0] & 0xFF; } 1.38 + 1.39 + static long loadS2Lmask16 (short[] sa) { return sa[0] & 0xFFFE; } 1.40 + static long loadS2Lmask16_1 (short[] sa) { return sa[0] & 0xFFFE; } 1.41 + 1.42 + static long loadS2Lmask13 (short[] sa) { return sa[0] & 0x0FFF; } 1.43 + static long loadS2Lmask13_1 (short[] sa) { return sa[0] & 0x0FFF; } 1.44 + 1.45 + static int loadUS_signExt (char[] ca) { return (ca[0] << 16) >> 16; } 1.46 + static int loadUS_signExt_1 (char[] ca) { return (ca[0] << 16) >> 16; } 1.47 + 1.48 + static long loadB2L_mask8 (byte[] ba) { return ba[0] & 0x55; } 1.49 + static long loadB2L_mask8_1 (byte[] ba) { return ba[0] & 0x55; } 1.50 + 1.51 + public static void main(String[] args) { 1.52 + for (int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) { 1.53 + byte[] ba = new byte[] { (byte) i}; 1.54 + 1.55 + { long v1 = loadB2L_mask8(ba); 1.56 + long v2 = loadB2L_mask8_1(ba); 1.57 + if (v1 != v2) 1.58 + throw new InternalError(String.format("loadB2L_mask8 failed: %x != %x", v1, v2)); } 1.59 + } 1.60 + 1.61 + for (int i = Short.MIN_VALUE; i < Short.MAX_VALUE; i++) { 1.62 + short[] sa = new short[] { (short)i }; 1.63 + char[] ca = new char[] { (char)i }; 1.64 + 1.65 + { long v1 = loadS2LmaskFF(sa); 1.66 + long v2 = loadS2LmaskFF_1(sa); 1.67 + if (v1 != v2) 1.68 + throw new InternalError(String.format("loadS2LmaskFF failed: %x != %x", v1, v2)); } 1.69 + 1.70 + { long v1 = loadS2Lmask16(sa); 1.71 + long v2 = loadS2Lmask16_1(sa); 1.72 + if (v1 != v2) 1.73 + throw new InternalError(String.format("loadS2Lmask16 failed: %x != %x", v1, v2)); } 1.74 + 1.75 + { long v1 = loadS2Lmask13(sa); 1.76 + long v2 = loadS2Lmask13_1(sa); 1.77 + if (v1 != v2) 1.78 + throw new InternalError(String.format("loadS2Lmask13 failed: %x != %x", v1, v2)); } 1.79 + 1.80 + { int v1 = loadUS_signExt(ca); 1.81 + int v2 = loadUS_signExt_1(ca); 1.82 + if (v1 != v2) 1.83 + throw new InternalError(String.format("loadUS_signExt failed: %x != %x", v1, v2)); } 1.84 + } 1.85 + 1.86 + System.out.println("TEST PASSED."); 1.87 + } 1.88 +}