aoqi@0: /* aoqi@0: * Copyright 2010 Google, Inc. All Rights Reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 6946040 aoqi@0: * @summary Tests Character/Short.reverseBytes and their intrinsics implementation in the server compiler aoqi@0: * @run main/othervm -Xbatch -XX:CompileOnly=.testChar,.testShort TestCharShortByteSwap aoqi@0: */ aoqi@0: aoqi@0: // This test must run without any command line arguments. aoqi@0: aoqi@0: public class TestCharShortByteSwap { aoqi@0: aoqi@0: private static short initShort(String[] args, short v) { aoqi@0: if (args.length > 0) { aoqi@0: try { aoqi@0: return (short) Integer.valueOf(args[0]).intValue(); aoqi@0: } catch (NumberFormatException e) { } aoqi@0: } aoqi@0: return v; aoqi@0: } aoqi@0: aoqi@0: private static char initChar(String[] args, char v) { aoqi@0: if (args.length > 0) { aoqi@0: try { aoqi@0: return (char) Integer.valueOf(args[0]).intValue(); aoqi@0: } catch (NumberFormatException e) { } aoqi@0: } aoqi@0: return v; aoqi@0: } aoqi@0: aoqi@0: private static void testChar(char a, char b) { aoqi@0: if (a != Character.reverseBytes(b)) { aoqi@0: throw new RuntimeException("FAIL: " + (int)a + " != Character.reverseBytes(" + (int)b + ")"); aoqi@0: } aoqi@0: if (b != Character.reverseBytes(a)) { aoqi@0: throw new RuntimeException("FAIL: " + (int)b + " != Character.reverseBytes(" + (int)a + ")"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: private static void testShort(short a, short b) { aoqi@0: if (a != Short.reverseBytes(b)) { aoqi@0: throw new RuntimeException("FAIL: " + (int)a + " != Short.reverseBytes(" + (int)b + ")"); aoqi@0: } aoqi@0: if (b != Short.reverseBytes(a)) { aoqi@0: throw new RuntimeException("FAIL: " + (int)b + " != Short.reverseBytes(" + (int)a + ")"); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public static void main(String[] args) { aoqi@0: for (int i = 0; i < 100000; ++i) { // Trigger compilation aoqi@0: char c1 = initChar(args, (char) 0x0123); aoqi@0: char c2 = initChar(args, (char) 0x2301); aoqi@0: char c3 = initChar(args, (char) 0xaabb); aoqi@0: char c4 = initChar(args, (char) 0xbbaa); aoqi@0: short s1 = initShort(args, (short) 0x0123); aoqi@0: short s2 = initShort(args, (short) 0x2301); aoqi@0: short s3 = initShort(args, (short) 0xaabb); aoqi@0: short s4 = initShort(args, (short) 0xbbaa); aoqi@0: testChar(c1, c2); aoqi@0: testChar(c3, c4); aoqi@0: testShort(s1, s2); aoqi@0: testShort(s3, s4); aoqi@0: } aoqi@0: } aoqi@0: }