aboutsummaryrefslogtreecommitdiff
path: root/test/compiler/6431242/Test.java
blob: a5d6cea53ca0dc5a0c8326940da7354c0514b352 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

/*
 * @test
 * @bug 6431242
 * @run main/othervm -server -XX:+PrintCompilation Test
 */

public class Test{

  int    _len      = 8;
  int[]  _arr_i    = new int[_len];
  long[] _arr_l    = new long[_len];

  int[]  _arr_i_cp = new int [_len];
  long[] _arr_l_cp = new long [_len];

  int _k     = 0x12345678;
  int _j     = 0;
  int _ir    = 0x78563412;
  int _ir1   = 0x78563413;
  int _ir2   = 0x79563412;

  long _m    = 0x123456789abcdef0L;
  long _l    = 0L;
  long _lr   = 0xf0debc9a78563412L;
  long _lr1  = 0xf0debc9a78563413L;
  long _lr2  = 0xf1debc9a78563412L;

  void init() {
    for (int i=0; i<_arr_i.length; i++) {
      _arr_i[i] = _k;
      _arr_l[i] = _m;
    }
  }

  public int test_int_reversed(int i) {
    return Integer.reverseBytes(i);
  }

  public long test_long_reversed(long i) {
    return Long.reverseBytes(i);
  }

  public void test_copy_ints(int[] dst, int[] src) {
    for(int i=0; i<src.length; i++) {
      dst[i] = Integer.reverseBytes(src[i]);
    }
  }

  public void test_copy_ints_reversed(int[] dst, int[] src) {
    for (int i=0; i<src.length; i++) {
      dst[i] = 1 + Integer.reverseBytes(src[i]);
    }
  }

  public void test_copy_ints_store_reversed(int[] dst, int[] src) {
    for(int i=0; i<src.length; i++) {
      dst[i] = Integer.reverseBytes(1 + src[i]);
    }
  }

  public void test_copy_longs(long[] dst, long[] src) {
    for(int i=0; i<src.length; i++) {
      dst[i] = Long.reverseBytes(src[i]);
    }
  }

  public void test_copy_longs_reversed(long[] dst, long[] src) {
    for (int i=0; i<src.length; i++) {
      dst[i] = 1 + Long.reverseBytes(src[i]);
    }
  }

  public void test_copy_longs_store_reversed(long[] dst, long[] src) {
    for(int i=0; i<src.length; i++) {
      dst[i] = Long.reverseBytes(1 + src[i]);
    }
  }

  public void test() throws Exception {
    int up_limit=90000;


    //test single

    for (int loop=0; loop<up_limit; loop++) {
      _j = test_int_reversed(_k);
      if (_j != _ir ) {
        throw new Exception("Interger.reverseBytes failed " + _j + " iter " + loop);
      }
      _l = test_long_reversed(_m);
      if (_l != _lr ) {
        throw new Exception("Long.reverseBytes failed " + _l + " iter " + loop);
      }
    }

    // test scalar load/store
    for (int loop=0; loop<up_limit; loop++) {

      test_copy_ints(_arr_i_cp, _arr_i);
      for (int j=0; j< _arr_i.length; j++) {
        if (_arr_i_cp[j] != _ir) {
          throw new Exception("Interger.reverseBytes failed test_copy_ints iter " + loop);
        }
      }

      test_copy_ints_reversed(_arr_i_cp, _arr_i);
      for (int j=0; j< _arr_i.length; j++) {
        if (_arr_i_cp[j] != _ir1) {
          throw new Exception("Interger.reverseBytes failed test_copy_ints_reversed iter " + loop);
        }
      }
      test_copy_ints_store_reversed(_arr_i_cp, _arr_i);
      for (int j=0; j< _arr_i.length; j++) {
        if (_arr_i_cp[j] != _ir2) {
          throw new Exception("Interger.reverseBytes failed test_copy_ints_store_reversed iter " + loop);
        }
      }

      test_copy_longs(_arr_l_cp, _arr_l);
      for (int j=0; j< _arr_i.length; j++) {
        if (_arr_l_cp[j] != _lr) {
          throw new Exception("Long.reverseBytes failed test_copy_longs iter " + loop);
        }
      }
      test_copy_longs_reversed(_arr_l_cp, _arr_l);
      for (int j=0; j< _arr_i.length; j++) {
        if (_arr_l_cp[j] != _lr1) {
          throw new Exception("Long.reverseBytes failed test_copy_longs_reversed iter " + loop);
        }
      }
      test_copy_longs_store_reversed(_arr_l_cp, _arr_l);
      for (int j=0; j< _arr_i.length; j++) {
        if (_arr_l_cp[j] != _lr2) {
          throw new Exception("Long.reverseBytes failed test_copy_longs_store_reversed iter " + loop);
        }
      }

    }
  }

  public static void main(String args[]) {
    try {
      Test t = new Test();
      t.init();
      t.test();
      System.out.println("Passed");
    }catch (Exception e) {
      e.printStackTrace();
      System.out.println("Failed");
    }
  }
}