1 /* 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 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 6814842 27 * @summary Load shortening optimizations 28 * 29 * @run main/othervm -Xcomp 30 * -XX:CompileCommand=compileonly,compiler.codegen.Test6814842::load* 31 * compiler.codegen.Test6814842 32 */ 33 34 package compiler.codegen; 35 36 public class Test6814842 { 37 static final short[] sa = new short[] { (short) 0xF1F2 }; 38 static final char[] ca = new char[] { (char) 0xF3F4 }; 39 static final int[] ia = new int[] { 0xF1F2F3F4 }; 40 41 public static void main(String[] args) 42 { 43 byte s2b = loadS2B(sa); 44 if (s2b != (byte) 0xF2) 45 throw new InternalError("loadS2B failed: " + s2b + " != " + (byte) 0xF2); 46 47 byte s2bmask255 = loadS2Bmask255(sa); 48 if (s2bmask255 != (byte) 0xF2) 49 throw new InternalError("loadS2Bmask255 failed: " + s2bmask255 + " != " + (byte) 0xF2); 50 51 byte us2b = loadUS2B(ca); 52 if (us2b != (byte) 0xF4) 53 throw new InternalError("loadUS2B failed: " + us2b + " != " + (byte) 0xF4); 54 55 byte us2bmask255 = loadUS2Bmask255(ca); 56 if (us2bmask255 != (byte) 0xF4) 57 throw new InternalError("loadUS2Bmask255 failed: " + us2bmask255 + " != " + (byte) 0xF4); 58 59 byte i2b = loadI2B(ia); 60 if (i2b != (byte) 0xF4) 61 throw new InternalError("loadI2B failed: " + i2b + " != " + (byte) 0xF4); 62 63 byte i2bmask255 = loadI2Bmask255(ia); 64 if (i2bmask255 != (byte) 0xF4) 65 throw new InternalError("loadI2Bmask255 failed: " + i2bmask255 + " != " + (byte) 0xF4); 66 67 short i2s = loadI2S(ia); 68 if (i2s != (short) 0xF3F4) 69 throw new InternalError("loadI2S failed: " + i2s + " != " + (short) 0xF3F4); 70 71 short i2smask255 = loadI2Smask255(ia); 72 if (i2smask255 != (short) 0xF4) 73 throw new InternalError("loadI2Smask255 failed: " + i2smask255 + " != " + (short) 0xF4); 74 75 short i2smask65535 = loadI2Smask65535(ia); 76 if (i2smask65535 != (short) 0xF3F4) 77 throw new InternalError("loadI2Smask65535 failed: " + i2smask65535 + " != " + (short) 0xF3F4); 78 79 char i2us = loadI2US(ia); 80 if (i2us != (char) 0xF3F4) 81 throw new InternalError("loadI2US failed: " + (int) i2us + " != " + (char) 0xF3F4); 82 83 char i2usmask255 = loadI2USmask255(ia); 84 if (i2usmask255 != (char) 0xF4) 85 throw new InternalError("loadI2USmask255 failed: " + (int) i2usmask255 + " != " + (char) 0xF4); 86 87 char i2usmask65535 = loadI2USmask65535(ia); 88 if (i2usmask65535 != (char) 0xF3F4) 89 throw new InternalError("loadI2USmask65535 failed: " + (int) i2usmask65535 + " != " + (char) 0xF3F4); 90 } 91 92 static byte loadS2B (short[] sa) { return (byte) (sa[0] ); } 93 static byte loadS2Bmask255 (short[] sa) { return (byte) (sa[0] & 0xFF ); } 94 95 static byte loadUS2B (char[] ca) { return (byte) (ca[0] ); } 96 static byte loadUS2Bmask255 (char[] ca) { return (byte) (ca[0] & 0xFF ); } 97 98 static byte loadI2B (int[] ia) { return (byte) (ia[0] ); } 99 static byte loadI2Bmask255 (int[] ia) { return (byte) (ia[0] & 0xFF ); } 100 101 static short loadI2S (int[] ia) { return (short) (ia[0] ); } 102 static short loadI2Smask255 (int[] ia) { return (short) (ia[0] & 0xFF ); } 103 static short loadI2Smask65535 (int[] ia) { return (short) (ia[0] & 0xFFFF); } 104 105 static char loadI2US (int[] ia) { return (char) (ia[0] ); } 106 static char loadI2USmask255 (int[] ia) { return (char) (ia[0] & 0xFF ); } 107 static char loadI2USmask65535(int[] ia) { return (char) (ia[0] & 0xFFFF); } 108 }