1 /*
   2  * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @bug 6431242
  28  *
  29  * @run main compiler.codegen.Test6431242
  30  */
  31 
  32 package compiler.codegen;
  33 
  34 public class Test6431242 {
  35 
  36     int _len = 8;
  37     int[] _arr_i = new int[_len];
  38     long[] _arr_l = new long[_len];
  39 
  40     int[] _arr_i_cp = new int[_len];
  41     long[] _arr_l_cp = new long[_len];
  42 
  43     int _k = 0x12345678;
  44     int _j = 0;
  45     int _ir = 0x78563412;
  46     int _ir1 = 0x78563413;
  47     int _ir2 = 0x79563412;
  48 
  49     long _m = 0x123456789abcdef0L;
  50     long _l = 0L;
  51     long _lr = 0xf0debc9a78563412L;
  52     long _lr1 = 0xf0debc9a78563413L;
  53     long _lr2 = 0xf1debc9a78563412L;
  54 
  55     void init() {
  56         for (int i = 0; i < _arr_i.length; i++) {
  57             _arr_i[i] = _k;
  58             _arr_l[i] = _m;
  59         }
  60     }
  61 
  62     public int test_int_reversed(int i) {
  63         return Integer.reverseBytes(i);
  64     }
  65 
  66     public long test_long_reversed(long i) {
  67         return Long.reverseBytes(i);
  68     }
  69 
  70     public void test_copy_ints(int[] dst, int[] src) {
  71         for (int i = 0; i < src.length; i++) {
  72             dst[i] = Integer.reverseBytes(src[i]);
  73         }
  74     }
  75 
  76     public void test_copy_ints_reversed(int[] dst, int[] src) {
  77         for (int i = 0; i < src.length; i++) {
  78             dst[i] = 1 + Integer.reverseBytes(src[i]);
  79         }
  80     }
  81 
  82     public void test_copy_ints_store_reversed(int[] dst, int[] src) {
  83         for (int i = 0; i < src.length; i++) {
  84             dst[i] = Integer.reverseBytes(1 + src[i]);
  85         }
  86     }
  87 
  88     public void test_copy_longs(long[] dst, long[] src) {
  89         for (int i = 0; i < src.length; i++) {
  90             dst[i] = Long.reverseBytes(src[i]);
  91         }
  92     }
  93 
  94     public void test_copy_longs_reversed(long[] dst, long[] src) {
  95         for (int i = 0; i < src.length; i++) {
  96             dst[i] = 1 + Long.reverseBytes(src[i]);
  97         }
  98     }
  99 
 100     public void test_copy_longs_store_reversed(long[] dst, long[] src) {
 101         for (int i = 0; i < src.length; i++) {
 102             dst[i] = Long.reverseBytes(1 + src[i]);
 103         }
 104     }
 105 
 106     public void test() throws Exception {
 107         int up_limit = 90000;
 108 
 109 
 110         //test single
 111 
 112         for (int loop = 0; loop < up_limit; loop++) {
 113             _j = test_int_reversed(_k);
 114             if (_j != _ir) {
 115                 throw new Exception("Interger.reverseBytes failed " + _j + " iter " + loop);
 116             }
 117             _l = test_long_reversed(_m);
 118             if (_l != _lr) {
 119                 throw new Exception("Long.reverseBytes failed " + _l + " iter " + loop);
 120             }
 121         }
 122 
 123         // test scalar load/store
 124         for (int loop = 0; loop < up_limit; loop++) {
 125 
 126             test_copy_ints(_arr_i_cp, _arr_i);
 127             for (int j = 0; j < _arr_i.length; j++) {
 128                 if (_arr_i_cp[j] != _ir) {
 129                     throw new Exception("Interger.reverseBytes failed test_copy_ints iter " + loop);
 130                 }
 131             }
 132 
 133             test_copy_ints_reversed(_arr_i_cp, _arr_i);
 134             for (int j = 0; j < _arr_i.length; j++) {
 135                 if (_arr_i_cp[j] != _ir1) {
 136                     throw new Exception("Interger.reverseBytes failed test_copy_ints_reversed iter " + loop);
 137                 }
 138             }
 139             test_copy_ints_store_reversed(_arr_i_cp, _arr_i);
 140             for (int j = 0; j < _arr_i.length; j++) {
 141                 if (_arr_i_cp[j] != _ir2) {
 142                     throw new Exception("Interger.reverseBytes failed test_copy_ints_store_reversed iter " + loop);
 143                 }
 144             }
 145 
 146             test_copy_longs(_arr_l_cp, _arr_l);
 147             for (int j = 0; j < _arr_i.length; j++) {
 148                 if (_arr_l_cp[j] != _lr) {
 149                     throw new Exception("Long.reverseBytes failed test_copy_longs iter " + loop);
 150                 }
 151             }
 152             test_copy_longs_reversed(_arr_l_cp, _arr_l);
 153             for (int j = 0; j < _arr_i.length; j++) {
 154                 if (_arr_l_cp[j] != _lr1) {
 155                     throw new Exception("Long.reverseBytes failed test_copy_longs_reversed iter " + loop);
 156                 }
 157             }
 158             test_copy_longs_store_reversed(_arr_l_cp, _arr_l);
 159             for (int j = 0; j < _arr_i.length; j++) {
 160                 if (_arr_l_cp[j] != _lr2) {
 161                     throw new Exception("Long.reverseBytes failed test_copy_longs_store_reversed iter " + loop);
 162                 }
 163             }
 164 
 165         }
 166     }
 167 
 168     public static void main(String args[]) {
 169         try {
 170             Test6431242 t = new Test6431242();
 171             t.init();
 172             t.test();
 173             System.out.println("Passed");
 174         } catch (Exception e) {
 175             e.printStackTrace();
 176             System.out.println("Failed");
 177         }
 178     }
 179 }