test/compiler/6946040/TestCharShortByteSwap.java

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 4684
7369298bec7e
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright 2010 Google, Inc. All Rights Reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 /*
aoqi@0 26 * @test
aoqi@0 27 * @bug 6946040
aoqi@0 28 * @summary Tests Character/Short.reverseBytes and their intrinsics implementation in the server compiler
aoqi@0 29 * @run main/othervm -Xbatch -XX:CompileOnly=.testChar,.testShort TestCharShortByteSwap
aoqi@0 30 */
aoqi@0 31
aoqi@0 32 // This test must run without any command line arguments.
aoqi@0 33
aoqi@0 34 public class TestCharShortByteSwap {
aoqi@0 35
aoqi@0 36 private static short initShort(String[] args, short v) {
aoqi@0 37 if (args.length > 0) {
aoqi@0 38 try {
aoqi@0 39 return (short) Integer.valueOf(args[0]).intValue();
aoqi@0 40 } catch (NumberFormatException e) { }
aoqi@0 41 }
aoqi@0 42 return v;
aoqi@0 43 }
aoqi@0 44
aoqi@0 45 private static char initChar(String[] args, char v) {
aoqi@0 46 if (args.length > 0) {
aoqi@0 47 try {
aoqi@0 48 return (char) Integer.valueOf(args[0]).intValue();
aoqi@0 49 } catch (NumberFormatException e) { }
aoqi@0 50 }
aoqi@0 51 return v;
aoqi@0 52 }
aoqi@0 53
aoqi@0 54 private static void testChar(char a, char b) {
aoqi@0 55 if (a != Character.reverseBytes(b)) {
aoqi@0 56 throw new RuntimeException("FAIL: " + (int)a + " != Character.reverseBytes(" + (int)b + ")");
aoqi@0 57 }
aoqi@0 58 if (b != Character.reverseBytes(a)) {
aoqi@0 59 throw new RuntimeException("FAIL: " + (int)b + " != Character.reverseBytes(" + (int)a + ")");
aoqi@0 60 }
aoqi@0 61 }
aoqi@0 62
aoqi@0 63 private static void testShort(short a, short b) {
aoqi@0 64 if (a != Short.reverseBytes(b)) {
aoqi@0 65 throw new RuntimeException("FAIL: " + (int)a + " != Short.reverseBytes(" + (int)b + ")");
aoqi@0 66 }
aoqi@0 67 if (b != Short.reverseBytes(a)) {
aoqi@0 68 throw new RuntimeException("FAIL: " + (int)b + " != Short.reverseBytes(" + (int)a + ")");
aoqi@0 69 }
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 public static void main(String[] args) {
aoqi@0 73 for (int i = 0; i < 100000; ++i) { // Trigger compilation
aoqi@0 74 char c1 = initChar(args, (char) 0x0123);
aoqi@0 75 char c2 = initChar(args, (char) 0x2301);
aoqi@0 76 char c3 = initChar(args, (char) 0xaabb);
aoqi@0 77 char c4 = initChar(args, (char) 0xbbaa);
aoqi@0 78 short s1 = initShort(args, (short) 0x0123);
aoqi@0 79 short s2 = initShort(args, (short) 0x2301);
aoqi@0 80 short s3 = initShort(args, (short) 0xaabb);
aoqi@0 81 short s4 = initShort(args, (short) 0xbbaa);
aoqi@0 82 testChar(c1, c2);
aoqi@0 83 testChar(c3, c4);
aoqi@0 84 testShort(s1, s2);
aoqi@0 85 testShort(s3, s4);
aoqi@0 86 }
aoqi@0 87 }
aoqi@0 88 }

mercurial