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