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