test/hotspot/jtreg/compiler/c2/TestCharShortByteSwap.java
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.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
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    29
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    30
 * @run main/othervm -Xbatch
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    31
 *      -XX:CompileCommand=compileonly,compiler.c2.TestCharShortByteSwap::testChar
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    32
 *      -XX:CompileCommand=compileonly,compiler.c2.TestCharShortByteSwap::testShort
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    33
 *      compiler.c2.TestCharShortByteSwap
5352
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    34
 */
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    35
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    36
package compiler.c2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    37
5352
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    38
// This test must run without any command line arguments.
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    39
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    40
public class TestCharShortByteSwap {
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
  private static short initShort(String[] args, short v) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    43
    if (args.length > 0) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    44
      try {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    45
        return (short) Integer.valueOf(args[0]).intValue();
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    46
      } catch (NumberFormatException e) { }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    47
    }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    48
    return v;
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    49
  }
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
  private static char initChar(String[] args, char v) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    52
    if (args.length > 0) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    53
      try {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    54
        return (char) Integer.valueOf(args[0]).intValue();
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    55
      } catch (NumberFormatException e) { }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    56
    }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    57
    return v;
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    58
  }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    59
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    60
  private static void testChar(char a, char b) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    61
    if (a != Character.reverseBytes(b)) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    62
      throw new RuntimeException("FAIL: " + (int)a + " != Character.reverseBytes(" + (int)b + ")");
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    63
    }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    64
    if (b != Character.reverseBytes(a)) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    65
      throw new RuntimeException("FAIL: " + (int)b + " != Character.reverseBytes(" + (int)a + ")");
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
  }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    68
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    69
  private static void testShort(short a, short b) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    70
    if (a != Short.reverseBytes(b)) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    71
      throw new RuntimeException("FAIL: " + (int)a + " != Short.reverseBytes(" + (int)b + ")");
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    72
    }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    73
    if (b != Short.reverseBytes(a)) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    74
      throw new RuntimeException("FAIL: " + (int)b + " != Short.reverseBytes(" + (int)a + ")");
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    75
    }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    76
  }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    77
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    78
  public static void main(String[] args) {
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    79
    for (int i = 0; i < 100000; ++i) { // Trigger compilation
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    80
      char c1 = initChar(args, (char) 0x0123);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    81
      char c2 = initChar(args, (char) 0x2301);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    82
      char c3 = initChar(args, (char) 0xaabb);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    83
      char c4 = initChar(args, (char) 0xbbaa);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    84
      short s1 = initShort(args, (short) 0x0123);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    85
      short s2 = initShort(args, (short) 0x2301);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    86
      short s3 = initShort(args, (short) 0xaabb);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    87
      short s4 = initShort(args, (short) 0xbbaa);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    88
      testChar(c1, c2);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    89
      testChar(c3, c4);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    90
      testShort(s1, s2);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    91
      testShort(s3, s4);
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    92
    }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    93
  }
cee8f7acb7bc 6946040: add intrinsic for short and char reverseBytes
never
parents:
diff changeset
    94
}