author | alanb |
Wed, 11 Nov 2009 14:38:01 +0000 | |
changeset 4233 | 9b594a48d0f4 |
parent 4177 | 208f8c11e7ba |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
1 |
/* |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
2 |
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
4 |
* |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
8 |
* |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
14 |
* |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
18 |
* |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
21 |
* have any questions. |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
22 |
*/ |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
23 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
24 |
/* |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
25 |
* @test |
4233 | 26 |
* @bug 6880672 6896573 6899694 |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
27 |
* @summary Exercise Arrays.sort |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
28 |
* @build Sorting |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
29 |
* @run main Sorting -shortrun |
4233 | 30 |
* |
31 |
* @author Vladimir Yaroslavskiy |
|
32 |
* @author Jon Bentley |
|
33 |
* @author Josh Bloch |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
34 |
*/ |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
35 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
37 |
import java.util.Random; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
38 |
import java.io.PrintStream; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
39 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
40 |
public class Sorting { |
4233 | 41 |
private static final PrintStream out = System.out; |
42 |
private static final PrintStream err = System.err; |
|
43 |
||
44 |
// Array lengths used in a long run (default) |
|
45 |
private static final int[] LONG_RUN_LENGTHS = { |
|
46 |
1, 2, 3, 5, 8, 13, 21, 34, 55, 100, 1000, 10000, 100000, 1000000}; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
47 |
|
4233 | 48 |
// Array lengths used in a short run |
49 |
private static final int[] SHORT_RUN_LENGTHS = { 1, 2, 3, 21, 55, 1000, 10000 }; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
50 |
|
4233 | 51 |
// Random initial values used in a long run (default) |
52 |
private static final long[] LONG_RUN_RANDOMS = {666, 0xC0FFEE, 999}; |
|
53 |
||
54 |
// Random initial values used in a short run |
|
55 |
private static final long[] SHORT_RUN_RANDOMS = {666}; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
56 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
57 |
public static void main(String[] args) { |
4233 | 58 |
boolean shortRun = args.length > 0 && args[0].equals("-shortrun"); |
59 |
long start = System.currentTimeMillis(); |
|
60 |
||
61 |
if (shortRun) { |
|
62 |
testAndCheck(SHORT_RUN_LENGTHS, SHORT_RUN_RANDOMS); |
|
63 |
} else { |
|
64 |
testAndCheck(LONG_RUN_LENGTHS, LONG_RUN_RANDOMS); |
|
65 |
} |
|
66 |
long end = System.currentTimeMillis(); |
|
67 |
||
68 |
out.format("PASS in %d sec.\n", Math.round((end - start) / 1E3)); |
|
69 |
} |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
70 |
|
4233 | 71 |
private static void testAndCheck(int[] lengths, long[] randoms) { |
72 |
for (long random : randoms) { |
|
73 |
reset(random); |
|
74 |
||
75 |
for (int len : lengths) { |
|
76 |
testAndCheckWithCheckSum(len, random); |
|
77 |
} |
|
78 |
reset(random); |
|
79 |
||
80 |
for (int len : lengths) { |
|
81 |
testAndCheckWithScrambling(len, random); |
|
82 |
} |
|
83 |
reset(random); |
|
84 |
||
85 |
for (int len : lengths) { |
|
86 |
testAndCheckFloat(len, random); |
|
87 |
} |
|
88 |
reset(random); |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
89 |
|
4233 | 90 |
for (int len : lengths) { |
91 |
testAndCheckDouble(len, random); |
|
92 |
} |
|
93 |
reset(random); |
|
94 |
||
95 |
for (int len : lengths) { |
|
96 |
testAndCheckRange(len, random); |
|
97 |
} |
|
98 |
reset(random); |
|
99 |
||
100 |
for (int len : lengths) { |
|
101 |
testAndCheckSubArray(len, random); |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
private static void testAndCheckSubArray(int len, long random) { |
|
107 |
int[] golden = new int[len]; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
108 |
|
4233 | 109 |
for (int m = 1; m < len / 2; m *= 2) { |
110 |
int fromIndex = m; |
|
111 |
int toIndex = len - m; |
|
112 |
||
113 |
prepareSubArray(golden, fromIndex, toIndex, m); |
|
114 |
int[] test = golden.clone(); |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
115 |
|
4233 | 116 |
for (TypeConverter converter : TypeConverter.values()) { |
117 |
out.println("Test #6: " + converter + |
|
118 |
" len = " + len + ", m = " + m); |
|
119 |
Object convertedGolden = converter.convert(golden); |
|
120 |
Object convertedTest = converter.convert(test); |
|
121 |
||
122 |
// outArr(test); |
|
123 |
sortSubArray(convertedTest, fromIndex, toIndex); |
|
124 |
// outArr(test); |
|
125 |
checkSubArray(convertedTest, fromIndex, toIndex, m); |
|
126 |
} |
|
127 |
} |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
128 |
out.println(); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
129 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
130 |
|
4233 | 131 |
private static void testAndCheckRange(int len, long random) { |
132 |
int[] golden = new int[len]; |
|
133 |
||
134 |
for (int m = 1; m < 2 * len; m *= 2) { |
|
135 |
for (int i = 1; i <= len; i++) { |
|
136 |
golden[i - 1] = i % m + m % i; |
|
137 |
} |
|
138 |
for (TypeConverter converter : TypeConverter.values()) { |
|
139 |
out.println("Test #5: " + converter + |
|
140 |
", len = " + len + ", m = " + m); |
|
141 |
Object convertedGolden = converter.convert(golden); |
|
142 |
sortRange(convertedGolden, m); |
|
143 |
sortEmpty(convertedGolden); |
|
144 |
} |
|
145 |
} |
|
146 |
out.println(); |
|
147 |
} |
|
148 |
||
149 |
private static void testAndCheckWithCheckSum(int len, long random) { |
|
150 |
int[] golden = new int[len]; |
|
151 |
||
152 |
for (int m = 1; m < 2 * len; m *= 2) { |
|
153 |
for (UnsortedBuilder builder : UnsortedBuilder.values()) { |
|
154 |
builder.build(golden, m); |
|
155 |
int[] test = golden.clone(); |
|
156 |
||
157 |
for (TypeConverter converter : TypeConverter.values()) { |
|
158 |
out.println("Test #1: " + converter + " " + builder + |
|
159 |
"random = " + random + ", len = " + len + |
|
160 |
", m = " + m); |
|
161 |
Object convertedGolden = converter.convert(golden); |
|
162 |
Object convertedTest = converter.convert(test); |
|
163 |
sort(convertedTest); |
|
164 |
checkWithCheckSum(convertedTest, convertedGolden); |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
out.println(); |
|
169 |
} |
|
170 |
||
171 |
private static void testAndCheckWithScrambling(int len, long random) { |
|
172 |
int[] golden = new int[len]; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
173 |
|
4233 | 174 |
for (int m = 1; m <= 7; m++) { |
175 |
if (m > len) { |
|
176 |
break; |
|
177 |
} |
|
178 |
for (SortedBuilder builder : SortedBuilder.values()) { |
|
179 |
builder.build(golden, m); |
|
180 |
int[] test = golden.clone(); |
|
181 |
scramble(test); |
|
182 |
||
183 |
for (TypeConverter converter : TypeConverter.values()) { |
|
184 |
out.println("Test #2: " + converter + " " + builder + |
|
185 |
"random = " + random + ", len = " + len + |
|
186 |
", m = " + m); |
|
187 |
Object convertedGolden = converter.convert(golden); |
|
188 |
Object convertedTest = converter.convert(test); |
|
189 |
sort(convertedTest); |
|
190 |
compare(convertedTest, convertedGolden); |
|
191 |
} |
|
192 |
} |
|
193 |
} |
|
194 |
out.println(); |
|
195 |
} |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
196 |
|
4233 | 197 |
private static void testAndCheckFloat(int len, long random) { |
198 |
float[] golden = new float[len]; |
|
199 |
final int MAX = 10; |
|
200 |
boolean newLine = false; |
|
201 |
||
202 |
for (int a = 0; a <= MAX; a++) { |
|
203 |
for (int g = 0; g <= MAX; g++) { |
|
204 |
for (int z = 0; z <= MAX; z++) { |
|
205 |
for (int n = 0; n <= MAX; n++) { |
|
206 |
for (int p = 0; p <= MAX; p++) { |
|
207 |
if (a + g + z + n + p > len) { |
|
208 |
continue; |
|
209 |
} |
|
210 |
if (a + g + z + n + p < len) { |
|
211 |
continue; |
|
212 |
} |
|
213 |
for (FloatBuilder builder : FloatBuilder.values()) { |
|
214 |
out.println("Test #3: random = " + random + |
|
215 |
", len = " + len + ", a = " + a + ", g = " + g + |
|
216 |
", z = " + z + ", n = " + n + ", p = " + p); |
|
217 |
builder.build(golden, a, g, z, n, p); |
|
218 |
float[] test = golden.clone(); |
|
219 |
scramble(test); |
|
220 |
// outArr(test); |
|
221 |
sort(test); |
|
222 |
// outArr(test); |
|
223 |
compare(test, golden, a, n, g); |
|
224 |
} |
|
225 |
newLine = true; |
|
226 |
} |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
227 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
228 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
229 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
230 |
} |
4233 | 231 |
if (newLine) { |
232 |
out.println(); |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
private static void testAndCheckDouble(int len, long random) { |
|
237 |
double[] golden = new double[len]; |
|
238 |
final int MAX = 10; |
|
239 |
boolean newLine = false; |
|
240 |
||
241 |
for (int a = 0; a <= MAX; a++) { |
|
242 |
for (int g = 0; g <= MAX; g++) { |
|
243 |
for (int z = 0; z <= MAX; z++) { |
|
244 |
for (int n = 0; n <= MAX; n++) { |
|
245 |
for (int p = 0; p <= MAX; p++) { |
|
246 |
if (a + g + z + n + p > len) { |
|
247 |
continue; |
|
248 |
} |
|
249 |
if (a + g + z + n + p < len) { |
|
250 |
continue; |
|
251 |
} |
|
252 |
for (DoubleBuilder builder : DoubleBuilder.values()) { |
|
253 |
out.println("Test #4: random = " + random + |
|
254 |
", len = " + len + ", a = " + a + ", g = " + g + |
|
255 |
", z = " + z + ", n = " + n + ", p = " + p); |
|
256 |
builder.build(golden, a, g, z, n, p); |
|
257 |
double[] test = golden.clone(); |
|
258 |
scramble(test); |
|
259 |
// outArr(test); |
|
260 |
sort(test); |
|
261 |
// outArr(test); |
|
262 |
compare(test, golden, a, n, g); |
|
263 |
} |
|
264 |
newLine = true; |
|
265 |
} |
|
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
} |
|
270 |
if (newLine) { |
|
271 |
out.println(); |
|
272 |
} |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
273 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
274 |
|
4233 | 275 |
private static void prepareSubArray(int[] a, int fromIndex, int toIndex, int m) { |
276 |
for (int i = 0; i < fromIndex; i++) { |
|
277 |
a[i] = 0xBABA; |
|
278 |
} |
|
279 |
||
280 |
for (int i = fromIndex; i < toIndex; i++) { |
|
281 |
a[i] = -i + m; |
|
282 |
} |
|
283 |
||
284 |
for (int i = toIndex; i < a.length; i++) { |
|
285 |
a[i] = 0xDEDA; |
|
286 |
} |
|
287 |
} |
|
288 |
||
289 |
private static void scramble(int[] a) { |
|
290 |
int length = a.length; |
|
291 |
||
292 |
for (int i = 0; i < length * 7; i++) { |
|
293 |
swap(a, ourRandom.nextInt(length), ourRandom.nextInt(length)); |
|
294 |
} |
|
295 |
} |
|
296 |
||
297 |
private static void scramble(float[] a) { |
|
298 |
int length = a.length; |
|
299 |
||
300 |
for (int i = 0; i < length * 7; i++) { |
|
301 |
swap(a, ourRandom.nextInt(length), ourRandom.nextInt(length)); |
|
302 |
} |
|
303 |
} |
|
304 |
||
305 |
private static void scramble(double[] a) { |
|
306 |
int length = a.length; |
|
307 |
||
308 |
for (int i = 0; i < length * 7; i++) { |
|
309 |
swap(a, ourRandom.nextInt(length), ourRandom.nextInt(length)); |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
private static void swap(int[] a, int i, int j) { |
|
314 |
int t = a[i]; |
|
315 |
a[i] = a[j]; |
|
316 |
a[j] = t; |
|
317 |
} |
|
318 |
||
319 |
private static void swap(float[] a, int i, int j) { |
|
320 |
float t = a[i]; |
|
321 |
a[i] = a[j]; |
|
322 |
a[j] = t; |
|
323 |
} |
|
324 |
||
325 |
private static void swap(double[] a, int i, int j) { |
|
326 |
double t = a[i]; |
|
327 |
a[i] = a[j]; |
|
328 |
a[j] = t; |
|
329 |
} |
|
330 |
||
331 |
private static enum TypeConverter { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
332 |
INT { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
333 |
Object convert(int[] a) { |
4233 | 334 |
return a.clone(); |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
335 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
336 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
337 |
LONG { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
338 |
Object convert(int[] a) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
339 |
long[] b = new long[a.length]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
340 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
341 |
for (int i = 0; i < a.length; i++) { |
4233 | 342 |
b[i] = (long) a[i]; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
343 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
344 |
return b; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
345 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
346 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
347 |
BYTE { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
348 |
Object convert(int[] a) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
349 |
byte[] b = new byte[a.length]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
350 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
351 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
352 |
b[i] = (byte) a[i]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
353 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
354 |
return b; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
355 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
356 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
357 |
SHORT { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
358 |
Object convert(int[] a) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
359 |
short[] b = new short[a.length]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
360 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
361 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
362 |
b[i] = (short) a[i]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
363 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
364 |
return b; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
365 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
366 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
367 |
CHAR { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
368 |
Object convert(int[] a) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
369 |
char[] b = new char[a.length]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
370 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
371 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
372 |
b[i] = (char) a[i]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
373 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
374 |
return b; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
375 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
376 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
377 |
FLOAT { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
378 |
Object convert(int[] a) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
379 |
float[] b = new float[a.length]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
380 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
381 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
382 |
b[i] = (float) a[i]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
383 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
384 |
return b; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
385 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
386 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
387 |
DOUBLE { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
388 |
Object convert(int[] a) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
389 |
double[] b = new double[a.length]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
390 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
391 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
392 |
b[i] = (double) a[i]; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
393 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
394 |
return b; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
395 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
396 |
}; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
397 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
398 |
abstract Object convert(int[] a); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
399 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
400 |
@Override public String toString() { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
401 |
String name = name(); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
402 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
403 |
for (int i = name.length(); i < 9; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
404 |
name += " "; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
405 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
406 |
return name; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
407 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
408 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
409 |
|
4233 | 410 |
private static enum FloatBuilder { |
411 |
SIMPLE { |
|
412 |
void build(float[] x, int a, int g, int z, int n, int p) { |
|
413 |
int fromIndex = 0; |
|
414 |
float negativeValue = -ourRandom.nextFloat(); |
|
415 |
float positiveValue = ourRandom.nextFloat(); |
|
416 |
||
417 |
writeValue(x, negativeValue, fromIndex, n); |
|
418 |
fromIndex += n; |
|
419 |
||
420 |
writeValue(x, -0.0f, fromIndex, g); |
|
421 |
fromIndex += g; |
|
422 |
||
423 |
writeValue(x, 0.0f, fromIndex, z); |
|
424 |
fromIndex += z; |
|
425 |
||
426 |
writeValue(x, positiveValue, fromIndex, p); |
|
427 |
fromIndex += p; |
|
428 |
||
429 |
writeValue(x, Float.NaN, fromIndex, a); |
|
430 |
} |
|
431 |
}; |
|
432 |
||
433 |
abstract void build(float[] x, int a, int g, int z, int n, int p); |
|
434 |
} |
|
435 |
||
436 |
private static enum DoubleBuilder { |
|
437 |
SIMPLE { |
|
438 |
void build(double[] x, int a, int g, int z, int n, int p) { |
|
439 |
int fromIndex = 0; |
|
440 |
double negativeValue = -ourRandom.nextFloat(); |
|
441 |
double positiveValue = ourRandom.nextFloat(); |
|
442 |
||
443 |
writeValue(x, negativeValue, fromIndex, n); |
|
444 |
fromIndex += n; |
|
445 |
||
446 |
writeValue(x, -0.0d, fromIndex, g); |
|
447 |
fromIndex += g; |
|
448 |
||
449 |
writeValue(x, 0.0d, fromIndex, z); |
|
450 |
fromIndex += z; |
|
451 |
||
452 |
writeValue(x, positiveValue, fromIndex, p); |
|
453 |
fromIndex += p; |
|
454 |
||
455 |
writeValue(x, Double.NaN, fromIndex, a); |
|
456 |
} |
|
457 |
}; |
|
458 |
||
459 |
abstract void build(double[] x, int a, int g, int z, int n, int p); |
|
460 |
} |
|
461 |
||
462 |
private static void writeValue(float[] a, float value, int fromIndex, int count) { |
|
463 |
for (int i = fromIndex; i < fromIndex + count; i++) { |
|
464 |
a[i] = value; |
|
465 |
} |
|
466 |
} |
|
467 |
||
468 |
private static void compare(float[] a, float[] b, int numNaN, int numNeg, int numNegZero) { |
|
469 |
for (int i = a.length - numNaN; i < a.length; i++) { |
|
470 |
if (a[i] == a[i]) { |
|
471 |
failed("On position " + i + " must be NaN instead of " + a[i]); |
|
472 |
} |
|
473 |
} |
|
474 |
final int NEGATIVE_ZERO = Float.floatToIntBits(-0.0f); |
|
475 |
||
476 |
for (int i = numNeg; i < numNeg + numNegZero; i++) { |
|
477 |
if (NEGATIVE_ZERO != Float.floatToIntBits(a[i])) { |
|
478 |
failed("On position " + i + " must be -0.0f instead of " + a[i]); |
|
479 |
} |
|
480 |
} |
|
481 |
for (int i = 0; i < a.length - numNaN; i++) { |
|
482 |
if (a[i] != b[i]) { |
|
483 |
failed(i, "" + a[i], "" + b[i]); |
|
484 |
} |
|
485 |
} |
|
486 |
} |
|
487 |
||
488 |
private static void writeValue(double[] a, double value, int fromIndex, int count) { |
|
489 |
for (int i = fromIndex; i < fromIndex + count; i++) { |
|
490 |
a[i] = value; |
|
491 |
} |
|
492 |
} |
|
493 |
||
494 |
private static void compare(double[] a, double[] b, int numNaN, int numNeg, int numNegZero) { |
|
495 |
for (int i = a.length - numNaN; i < a.length; i++) { |
|
496 |
if (a[i] == a[i]) { |
|
497 |
failed("On position " + i + " must be NaN instead of " + a[i]); |
|
498 |
} |
|
499 |
} |
|
500 |
final long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0d); |
|
501 |
||
502 |
for (int i = numNeg; i < numNeg + numNegZero; i++) { |
|
503 |
if (NEGATIVE_ZERO != Double.doubleToLongBits(a[i])) { |
|
504 |
failed("On position " + i + " must be -0.0d instead of " + a[i]); |
|
505 |
} |
|
506 |
} |
|
507 |
for (int i = 0; i < a.length - numNaN; i++) { |
|
508 |
if (a[i] != b[i]) { |
|
509 |
failed(i, "" + a[i], "" + b[i]); |
|
510 |
} |
|
511 |
} |
|
512 |
} |
|
513 |
||
514 |
private static enum SortedBuilder { |
|
515 |
REPEATED { |
|
516 |
void build(int[] a, int m) { |
|
517 |
int period = a.length / m; |
|
518 |
int i = 0; |
|
519 |
int k = 0; |
|
520 |
||
521 |
while (true) { |
|
522 |
for (int t = 1; t <= period; t++) { |
|
523 |
if (i >= a.length) { |
|
524 |
return; |
|
525 |
} |
|
526 |
a[i++] = k; |
|
527 |
} |
|
528 |
if (i >= a.length) { |
|
529 |
return; |
|
530 |
} |
|
531 |
k++; |
|
532 |
} |
|
533 |
} |
|
534 |
}, |
|
535 |
||
536 |
ORGAN_PIPES { |
|
537 |
void build(int[] a, int m) { |
|
538 |
int i = 0; |
|
539 |
int k = m; |
|
540 |
||
541 |
while (true) { |
|
542 |
for (int t = 1; t <= m; t++) { |
|
543 |
if (i >= a.length) { |
|
544 |
return; |
|
545 |
} |
|
546 |
a[i++] = k; |
|
547 |
} |
|
548 |
} |
|
549 |
} |
|
550 |
}; |
|
551 |
||
552 |
abstract void build(int[] a, int m); |
|
553 |
||
554 |
@Override public String toString() { |
|
555 |
String name = name(); |
|
556 |
||
557 |
for (int i = name.length(); i < 12; i++) { |
|
558 |
name += " "; |
|
559 |
} |
|
560 |
return name; |
|
561 |
} |
|
562 |
} |
|
563 |
||
564 |
private static enum UnsortedBuilder { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
565 |
RANDOM { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
566 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
567 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
568 |
a[i] = ourRandom.nextInt(); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
569 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
570 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
571 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
572 |
ASCENDING { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
573 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
574 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
575 |
a[i] = m + i; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
576 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
577 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
578 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
579 |
DESCENDING { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
580 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
581 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
582 |
a[i] = a.length - m - i; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
583 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
584 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
585 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
586 |
ALL_EQUAL { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
587 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
588 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
589 |
a[i] = m; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
590 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
591 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
592 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
593 |
SAW { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
594 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
595 |
int incCount = 1; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
596 |
int decCount = a.length; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
597 |
int i = 0; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
598 |
int period = m; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
599 |
m--; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
600 |
while (true) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
601 |
for (int k = 1; k <= period; k++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
602 |
if (i >= a.length) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
603 |
return; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
604 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
605 |
a[i++] = incCount++; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
606 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
607 |
period += m; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
608 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
609 |
for (int k = 1; k <= period; k++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
610 |
if (i >= a.length) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
611 |
return; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
612 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
613 |
a[i++] = decCount--; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
614 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
615 |
period += m; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
616 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
617 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
618 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
619 |
REPEATED { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
620 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
621 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
622 |
a[i] = i % m; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
623 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
624 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
625 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
626 |
DUPLICATED { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
627 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
628 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
629 |
a[i] = ourRandom.nextInt(m); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
630 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
631 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
632 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
633 |
ORGAN_PIPES { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
634 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
635 |
int middle = a.length / (m + 1); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
636 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
637 |
for (int i = 0; i < middle; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
638 |
a[i] = i; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
639 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
640 |
for (int i = middle; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
641 |
a[i] = a.length - i - 1; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
642 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
643 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
644 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
645 |
STAGGER { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
646 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
647 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
648 |
a[i] = (i * m + i) % a.length; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
649 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
650 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
651 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
652 |
PLATEAU { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
653 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
654 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
655 |
a[i] = Math.min(i, m); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
656 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
657 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
658 |
}, |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
659 |
SHUFFLE { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
660 |
void build(int[] a, int m) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
661 |
for (int i = 0; i < a.length; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
662 |
a[i] = ourRandom.nextBoolean() ? (ourFirst += 2) : (ourSecond += 2); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
663 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
664 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
665 |
}; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
666 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
667 |
abstract void build(int[] a, int m); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
668 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
669 |
@Override public String toString() { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
670 |
String name = name(); |
4233 | 671 |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
672 |
for (int i = name.length(); i < 12; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
673 |
name += " "; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
674 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
675 |
return name; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
676 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
677 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
678 |
|
4233 | 679 |
private static void compare(Object test, Object golden) { |
680 |
if (test instanceof int[]) { |
|
681 |
compare((int[]) test, (int[]) golden); |
|
682 |
} else if (test instanceof long[]) { |
|
683 |
compare((long[]) test, (long[]) golden); |
|
684 |
} else if (test instanceof short[]) { |
|
685 |
compare((short[]) test, (short[]) golden); |
|
686 |
} else if (test instanceof byte[]) { |
|
687 |
compare((byte[]) test, (byte[]) golden); |
|
688 |
} else if (test instanceof char[]) { |
|
689 |
compare((char[]) test, (char[]) golden); |
|
690 |
} else if (test instanceof float[]) { |
|
691 |
compare((float[]) test, (float[]) golden); |
|
692 |
} else if (test instanceof double[]) { |
|
693 |
compare((double[]) test, (double[]) golden); |
|
694 |
} else { |
|
695 |
failed("Unknow type of array: " + test + " of class " + |
|
696 |
test.getClass().getName()); |
|
697 |
} |
|
698 |
} |
|
699 |
||
700 |
private static void checkWithCheckSum(Object test, Object golden) { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
701 |
checkSorted(test); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
702 |
checkCheckSum(test, golden); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
703 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
704 |
|
4233 | 705 |
private static void failed(String message) { |
706 |
err.format("\n*** FAILED: %s\n\n", message); |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
707 |
throw new RuntimeException("Test failed - see log file for details"); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
708 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
709 |
|
4233 | 710 |
private static void failed(int index, String value1, String value2) { |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
711 |
failed("Array is not sorted at " + index + "-th position: " + value1 + |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
712 |
" and " + value2); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
713 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
714 |
|
4233 | 715 |
private static void checkSorted(Object object) { |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
716 |
if (object instanceof int[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
717 |
checkSorted((int[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
718 |
} else if (object instanceof long[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
719 |
checkSorted((long[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
720 |
} else if (object instanceof short[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
721 |
checkSorted((short[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
722 |
} else if (object instanceof byte[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
723 |
checkSorted((byte[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
724 |
} else if (object instanceof char[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
725 |
checkSorted((char[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
726 |
} else if (object instanceof float[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
727 |
checkSorted((float[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
728 |
} else if (object instanceof double[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
729 |
checkSorted((double[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
730 |
} else { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
731 |
failed("Unknow type of array: " + object + " of class " + |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
732 |
object.getClass().getName()); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
733 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
734 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
735 |
|
4233 | 736 |
private static void compare(int[] a, int[] b) { |
737 |
for (int i = 0; i < a.length; i++) { |
|
738 |
if (a[i] != b[i]) { |
|
739 |
failed(i, "" + a[i], "" + b[i]); |
|
740 |
} |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
private static void compare(long[] a, long[] b) { |
|
745 |
for (int i = 0; i < a.length; i++) { |
|
746 |
if (a[i] != b[i]) { |
|
747 |
failed(i, "" + a[i], "" + b[i]); |
|
748 |
} |
|
749 |
} |
|
750 |
} |
|
751 |
||
752 |
private static void compare(short[] a, short[] b) { |
|
753 |
for (int i = 0; i < a.length; i++) { |
|
754 |
if (a[i] != b[i]) { |
|
755 |
failed(i, "" + a[i], "" + b[i]); |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
756 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
757 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
758 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
759 |
|
4233 | 760 |
private static void compare(byte[] a, byte[] b) { |
761 |
for (int i = 0; i < a.length; i++) { |
|
762 |
if (a[i] != b[i]) { |
|
763 |
failed(i, "" + a[i], "" + b[i]); |
|
764 |
} |
|
765 |
} |
|
766 |
} |
|
767 |
||
768 |
private static void compare(char[] a, char[] b) { |
|
769 |
for (int i = 0; i < a.length; i++) { |
|
770 |
if (a[i] != b[i]) { |
|
771 |
failed(i, "" + a[i], "" + b[i]); |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
772 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
773 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
774 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
775 |
|
4233 | 776 |
private static void compare(float[] a, float[] b) { |
777 |
for (int i = 0; i < a.length; i++) { |
|
778 |
if (a[i] != b[i]) { |
|
779 |
failed(i, "" + a[i], "" + b[i]); |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
780 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
781 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
782 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
783 |
|
4233 | 784 |
private static void compare(double[] a, double[] b) { |
785 |
for (int i = 0; i < a.length; i++) { |
|
786 |
if (a[i] != b[i]) { |
|
787 |
failed(i, "" + a[i], "" + b[i]); |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
||
792 |
private static void checkSorted(int[] a) { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
793 |
for (int i = 0; i < a.length - 1; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
794 |
if (a[i] > a[i + 1]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
795 |
failed(i, "" + a[i], "" + a[i + 1]); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
796 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
797 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
798 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
799 |
|
4233 | 800 |
private static void checkSorted(long[] a) { |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
801 |
for (int i = 0; i < a.length - 1; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
802 |
if (a[i] > a[i + 1]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
803 |
failed(i, "" + a[i], "" + a[i + 1]); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
804 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
805 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
806 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
807 |
|
4233 | 808 |
private static void checkSorted(short[] a) { |
809 |
for (int i = 0; i < a.length - 1; i++) { |
|
810 |
if (a[i] > a[i + 1]) { |
|
811 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
812 |
} |
|
813 |
} |
|
814 |
} |
|
815 |
||
816 |
private static void checkSorted(byte[] a) { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
817 |
for (int i = 0; i < a.length - 1; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
818 |
if (a[i] > a[i + 1]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
819 |
failed(i, "" + a[i], "" + a[i + 1]); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
820 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
821 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
822 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
823 |
|
4233 | 824 |
private static void checkSorted(char[] a) { |
825 |
for (int i = 0; i < a.length - 1; i++) { |
|
826 |
if (a[i] > a[i + 1]) { |
|
827 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
828 |
} |
|
829 |
} |
|
830 |
} |
|
831 |
||
832 |
private static void checkSorted(float[] a) { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
833 |
for (int i = 0; i < a.length - 1; i++) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
834 |
if (a[i] > a[i + 1]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
835 |
failed(i, "" + a[i], "" + a[i + 1]); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
836 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
837 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
838 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
839 |
|
4233 | 840 |
private static void checkSorted(double[] a) { |
841 |
for (int i = 0; i < a.length - 1; i++) { |
|
842 |
if (a[i] > a[i + 1]) { |
|
843 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
844 |
} |
|
845 |
} |
|
846 |
} |
|
847 |
||
848 |
private static void checkCheckSum(Object test, Object golden) { |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
849 |
if (checkSum(test) != checkSum(golden)) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
850 |
failed("Original and sorted arrays seems not identical"); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
851 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
852 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
853 |
|
4233 | 854 |
private static int checkSum(Object object) { |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
855 |
if (object instanceof int[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
856 |
return checkSum((int[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
857 |
} else if (object instanceof long[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
858 |
return checkSum((long[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
859 |
} else if (object instanceof short[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
860 |
return checkSum((short[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
861 |
} else if (object instanceof byte[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
862 |
return checkSum((byte[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
863 |
} else if (object instanceof char[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
864 |
return checkSum((char[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
865 |
} else if (object instanceof float[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
866 |
return checkSum((float[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
867 |
} else if (object instanceof double[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
868 |
return checkSum((double[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
869 |
} else { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
870 |
failed("Unknow type of array: " + object + " of class " + |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
871 |
object.getClass().getName()); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
872 |
return -1; |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
873 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
874 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
875 |
|
4233 | 876 |
private static int checkSum(int[] a) { |
877 |
int checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
878 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
879 |
for (int e : a) { |
4233 | 880 |
checkXorSum ^= e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
881 |
} |
4233 | 882 |
return checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
883 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
884 |
|
4233 | 885 |
private static int checkSum(long[] a) { |
886 |
long checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
887 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
888 |
for (long e : a) { |
4233 | 889 |
checkXorSum ^= e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
890 |
} |
4233 | 891 |
return (int) checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
892 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
893 |
|
4233 | 894 |
private static int checkSum(short[] a) { |
895 |
short checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
896 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
897 |
for (short e : a) { |
4233 | 898 |
checkXorSum ^= e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
899 |
} |
4233 | 900 |
return (int) checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
901 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
902 |
|
4233 | 903 |
private static int checkSum(byte[] a) { |
904 |
byte checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
905 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
906 |
for (byte e : a) { |
4233 | 907 |
checkXorSum ^= e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
908 |
} |
4233 | 909 |
return (int) checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
910 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
911 |
|
4233 | 912 |
private static int checkSum(char[] a) { |
913 |
char checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
914 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
915 |
for (char e : a) { |
4233 | 916 |
checkXorSum ^= e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
917 |
} |
4233 | 918 |
return (int) checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
919 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
920 |
|
4233 | 921 |
private static int checkSum(float[] a) { |
922 |
int checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
923 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
924 |
for (float e : a) { |
4233 | 925 |
checkXorSum ^= (int) e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
926 |
} |
4233 | 927 |
return checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
928 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
929 |
|
4233 | 930 |
private static int checkSum(double[] a) { |
931 |
int checkXorSum = 0; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
932 |
|
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
933 |
for (double e : a) { |
4233 | 934 |
checkXorSum ^= (int) e; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
935 |
} |
4233 | 936 |
return checkXorSum; |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
937 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
938 |
|
4233 | 939 |
private static void sort(Object object) { |
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
940 |
if (object instanceof int[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
941 |
Arrays.sort((int[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
942 |
} else if (object instanceof long[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
943 |
Arrays.sort((long[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
944 |
} else if (object instanceof short[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
945 |
Arrays.sort((short[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
946 |
} else if (object instanceof byte[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
947 |
Arrays.sort((byte[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
948 |
} else if (object instanceof char[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
949 |
Arrays.sort((char[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
950 |
} else if (object instanceof float[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
951 |
Arrays.sort((float[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
952 |
} else if (object instanceof double[]) { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
953 |
Arrays.sort((double[]) object); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
954 |
} else { |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
955 |
failed("Unknow type of array: " + object + " of class " + |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
956 |
object.getClass().getName()); |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
957 |
} |
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
958 |
} |
4233 | 959 |
|
960 |
private static void sortSubArray(Object object, int fromIndex, int toIndex) { |
|
961 |
if (object instanceof int[]) { |
|
962 |
Arrays.sort((int[]) object, fromIndex, toIndex); |
|
963 |
} else if (object instanceof long[]) { |
|
964 |
Arrays.sort((long[]) object, fromIndex, toIndex); |
|
965 |
} else if (object instanceof short[]) { |
|
966 |
Arrays.sort((short[]) object, fromIndex, toIndex); |
|
967 |
} else if (object instanceof byte[]) { |
|
968 |
Arrays.sort((byte[]) object, fromIndex, toIndex); |
|
969 |
} else if (object instanceof char[]) { |
|
970 |
Arrays.sort((char[]) object, fromIndex, toIndex); |
|
971 |
} else if (object instanceof float[]) { |
|
972 |
Arrays.sort((float[]) object, fromIndex, toIndex); |
|
973 |
} else if (object instanceof double[]) { |
|
974 |
Arrays.sort((double[]) object, fromIndex, toIndex); |
|
975 |
} else { |
|
976 |
failed("Unknow type of array: " + object + " of class " + |
|
977 |
object.getClass().getName()); |
|
978 |
} |
|
979 |
} |
|
980 |
||
981 |
private static void checkSubArray(Object object, int fromIndex, int toIndex, int m) { |
|
982 |
if (object instanceof int[]) { |
|
983 |
checkSubArray((int[]) object, fromIndex, toIndex, m); |
|
984 |
} else if (object instanceof long[]) { |
|
985 |
checkSubArray((long[]) object, fromIndex, toIndex, m); |
|
986 |
} else if (object instanceof short[]) { |
|
987 |
checkSubArray((short[]) object, fromIndex, toIndex, m); |
|
988 |
} else if (object instanceof byte[]) { |
|
989 |
checkSubArray((byte[]) object, fromIndex, toIndex, m); |
|
990 |
} else if (object instanceof char[]) { |
|
991 |
checkSubArray((char[]) object, fromIndex, toIndex, m); |
|
992 |
} else if (object instanceof float[]) { |
|
993 |
checkSubArray((float[]) object, fromIndex, toIndex, m); |
|
994 |
} else if (object instanceof double[]) { |
|
995 |
checkSubArray((double[]) object, fromIndex, toIndex, m); |
|
996 |
} else { |
|
997 |
failed("Unknow type of array: " + object + " of class " + |
|
998 |
object.getClass().getName()); |
|
999 |
} |
|
1000 |
} |
|
1001 |
||
1002 |
private static void checkSubArray(int[] a, int fromIndex, int toIndex, int m) { |
|
1003 |
for (int i = 0; i < fromIndex; i++) { |
|
1004 |
if (a[i] != 0xBABA) { |
|
1005 |
failed("Range sort changes left element on position " + i + |
|
1006 |
": " + a[i] + ", must be " + 0xBABA); |
|
1007 |
} |
|
1008 |
} |
|
1009 |
||
1010 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1011 |
if (a[i] > a[i + 1]) { |
|
1012 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
for (int i = toIndex; i < a.length; i++) { |
|
1017 |
if (a[i] != 0xDEDA) { |
|
1018 |
failed("Range sort changes right element on position " + i + |
|
1019 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1020 |
} |
|
1021 |
} |
|
1022 |
} |
|
1023 |
||
1024 |
private static void checkSubArray(byte[] a, int fromIndex, int toIndex, int m) { |
|
1025 |
for (int i = 0; i < fromIndex; i++) { |
|
1026 |
if (a[i] != (byte) 0xBABA) { |
|
1027 |
failed("Range sort changes left element on position " + i + |
|
1028 |
": " + a[i] + ", must be " + 0xBABA); |
|
1029 |
} |
|
1030 |
} |
|
1031 |
||
1032 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1033 |
if (a[i] > a[i + 1]) { |
|
1034 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1035 |
} |
|
1036 |
} |
|
1037 |
||
1038 |
for (int i = toIndex; i < a.length; i++) { |
|
1039 |
if (a[i] != (byte) 0xDEDA) { |
|
1040 |
failed("Range sort changes right element on position " + i + |
|
1041 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1042 |
} |
|
1043 |
} |
|
1044 |
} |
|
1045 |
||
1046 |
private static void checkSubArray(long[] a, int fromIndex, int toIndex, int m) { |
|
1047 |
for (int i = 0; i < fromIndex; i++) { |
|
1048 |
if (a[i] != (long) 0xBABA) { |
|
1049 |
failed("Range sort changes left element on position " + i + |
|
1050 |
": " + a[i] + ", must be " + 0xBABA); |
|
1051 |
} |
|
1052 |
} |
|
1053 |
||
1054 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1055 |
if (a[i] > a[i + 1]) { |
|
1056 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1057 |
} |
|
1058 |
} |
|
1059 |
||
1060 |
for (int i = toIndex; i < a.length; i++) { |
|
1061 |
if (a[i] != (long) 0xDEDA) { |
|
1062 |
failed("Range sort changes right element on position " + i + |
|
1063 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
} |
|
1067 |
||
1068 |
private static void checkSubArray(char[] a, int fromIndex, int toIndex, int m) { |
|
1069 |
for (int i = 0; i < fromIndex; i++) { |
|
1070 |
if (a[i] != (char) 0xBABA) { |
|
1071 |
failed("Range sort changes left element on position " + i + |
|
1072 |
": " + a[i] + ", must be " + 0xBABA); |
|
1073 |
} |
|
1074 |
} |
|
1075 |
||
1076 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1077 |
if (a[i] > a[i + 1]) { |
|
1078 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1079 |
} |
|
1080 |
} |
|
1081 |
||
1082 |
for (int i = toIndex; i < a.length; i++) { |
|
1083 |
if (a[i] != (char) 0xDEDA) { |
|
1084 |
failed("Range sort changes right element on position " + i + |
|
1085 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1086 |
} |
|
1087 |
} |
|
1088 |
} |
|
1089 |
||
1090 |
private static void checkSubArray(short[] a, int fromIndex, int toIndex, int m) { |
|
1091 |
for (int i = 0; i < fromIndex; i++) { |
|
1092 |
if (a[i] != (short) 0xBABA) { |
|
1093 |
failed("Range sort changes left element on position " + i + |
|
1094 |
": " + a[i] + ", must be " + 0xBABA); |
|
1095 |
} |
|
1096 |
} |
|
1097 |
||
1098 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1099 |
if (a[i] > a[i + 1]) { |
|
1100 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1101 |
} |
|
1102 |
} |
|
1103 |
||
1104 |
for (int i = toIndex; i < a.length; i++) { |
|
1105 |
if (a[i] != (short) 0xDEDA) { |
|
1106 |
failed("Range sort changes right element on position " + i + |
|
1107 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1108 |
} |
|
1109 |
} |
|
1110 |
} |
|
1111 |
||
1112 |
private static void checkSubArray(float[] a, int fromIndex, int toIndex, int m) { |
|
1113 |
for (int i = 0; i < fromIndex; i++) { |
|
1114 |
if (a[i] != (float) 0xBABA) { |
|
1115 |
failed("Range sort changes left element on position " + i + |
|
1116 |
": " + a[i] + ", must be " + 0xBABA); |
|
1117 |
} |
|
1118 |
} |
|
1119 |
||
1120 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1121 |
if (a[i] > a[i + 1]) { |
|
1122 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1123 |
} |
|
1124 |
} |
|
1125 |
||
1126 |
for (int i = toIndex; i < a.length; i++) { |
|
1127 |
if (a[i] != (float) 0xDEDA) { |
|
1128 |
failed("Range sort changes right element on position " + i + |
|
1129 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1130 |
} |
|
1131 |
} |
|
1132 |
} |
|
1133 |
||
1134 |
private static void checkSubArray(double[] a, int fromIndex, int toIndex, int m) { |
|
1135 |
for (int i = 0; i < fromIndex; i++) { |
|
1136 |
if (a[i] != (double) 0xBABA) { |
|
1137 |
failed("Range sort changes left element on position " + i + |
|
1138 |
": " + a[i] + ", must be " + 0xBABA); |
|
1139 |
} |
|
1140 |
} |
|
1141 |
||
1142 |
for (int i = fromIndex; i < toIndex - 1; i++) { |
|
1143 |
if (a[i] > a[i + 1]) { |
|
1144 |
failed(i, "" + a[i], "" + a[i + 1]); |
|
1145 |
} |
|
1146 |
} |
|
1147 |
||
1148 |
for (int i = toIndex; i < a.length; i++) { |
|
1149 |
if (a[i] != (double) 0xDEDA) { |
|
1150 |
failed("Range sort changes right element on position " + i + |
|
1151 |
": " + a[i] + ", must be " + 0xDEDA); |
|
1152 |
} |
|
1153 |
} |
|
1154 |
} |
|
1155 |
||
1156 |
private static void sortRange(Object object, int m) { |
|
1157 |
if (object instanceof int[]) { |
|
1158 |
sortRange((int[]) object, m); |
|
1159 |
} else if (object instanceof long[]) { |
|
1160 |
sortRange((long[]) object, m); |
|
1161 |
} else if (object instanceof short[]) { |
|
1162 |
sortRange((short[]) object, m); |
|
1163 |
} else if (object instanceof byte[]) { |
|
1164 |
sortRange((byte[]) object, m); |
|
1165 |
} else if (object instanceof char[]) { |
|
1166 |
sortRange((char[]) object, m); |
|
1167 |
} else if (object instanceof float[]) { |
|
1168 |
sortRange((float[]) object, m); |
|
1169 |
} else if (object instanceof double[]) { |
|
1170 |
sortRange((double[]) object, m); |
|
1171 |
} else { |
|
1172 |
failed("Unknow type of array: " + object + " of class " + |
|
1173 |
object.getClass().getName()); |
|
1174 |
} |
|
1175 |
} |
|
1176 |
||
1177 |
private static void sortEmpty(Object object) { |
|
1178 |
if (object instanceof int[]) { |
|
1179 |
Arrays.sort(new int [] {}); |
|
1180 |
} else if (object instanceof long[]) { |
|
1181 |
Arrays.sort(new long [] {}); |
|
1182 |
} else if (object instanceof short[]) { |
|
1183 |
Arrays.sort(new short [] {}); |
|
1184 |
} else if (object instanceof byte[]) { |
|
1185 |
Arrays.sort(new byte [] {}); |
|
1186 |
} else if (object instanceof char[]) { |
|
1187 |
Arrays.sort(new char [] {}); |
|
1188 |
} else if (object instanceof float[]) { |
|
1189 |
Arrays.sort(new float [] {}); |
|
1190 |
} else if (object instanceof double[]) { |
|
1191 |
Arrays.sort(new double [] {}); |
|
1192 |
} else { |
|
1193 |
failed("Unknow type of array: " + object + " of class " + |
|
1194 |
object.getClass().getName()); |
|
1195 |
} |
|
1196 |
} |
|
1197 |
||
1198 |
private static void sortRange(int[] a, int m) { |
|
1199 |
try { |
|
1200 |
Arrays.sort(a, m + 1, m); |
|
1201 |
||
1202 |
failed("Sort does not throw IllegalArgumentException " + |
|
1203 |
" as expected: fromIndex = " + (m + 1) + |
|
1204 |
" toIndex = " + m); |
|
1205 |
} |
|
1206 |
catch (IllegalArgumentException iae) { |
|
1207 |
try { |
|
1208 |
Arrays.sort(a, -m, a.length); |
|
1209 |
||
1210 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1211 |
" as expected: fromIndex = " + (-m)); |
|
1212 |
} |
|
1213 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1214 |
try { |
|
1215 |
Arrays.sort(a, 0, a.length + m); |
|
1216 |
||
1217 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1218 |
" as expected: toIndex = " + (a.length + m)); |
|
1219 |
} |
|
1220 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1221 |
return; |
|
1222 |
} |
|
1223 |
} |
|
1224 |
} |
|
1225 |
} |
|
1226 |
||
1227 |
private static void sortRange(long[] a, int m) { |
|
1228 |
try { |
|
1229 |
Arrays.sort(a, m + 1, m); |
|
1230 |
||
1231 |
failed("Sort does not throw IllegalArgumentException " + |
|
1232 |
" as expected: fromIndex = " + (m + 1) + |
|
1233 |
" toIndex = " + m); |
|
1234 |
} |
|
1235 |
catch (IllegalArgumentException iae) { |
|
1236 |
try { |
|
1237 |
Arrays.sort(a, -m, a.length); |
|
1238 |
||
1239 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1240 |
" as expected: fromIndex = " + (-m)); |
|
1241 |
} |
|
1242 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1243 |
try { |
|
1244 |
Arrays.sort(a, 0, a.length + m); |
|
1245 |
||
1246 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1247 |
" as expected: toIndex = " + (a.length + m)); |
|
1248 |
} |
|
1249 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1250 |
return; |
|
1251 |
} |
|
1252 |
} |
|
1253 |
} |
|
1254 |
} |
|
1255 |
||
1256 |
private static void sortRange(byte[] a, int m) { |
|
1257 |
try { |
|
1258 |
Arrays.sort(a, m + 1, m); |
|
1259 |
||
1260 |
failed("Sort does not throw IllegalArgumentException " + |
|
1261 |
" as expected: fromIndex = " + (m + 1) + |
|
1262 |
" toIndex = " + m); |
|
1263 |
} |
|
1264 |
catch (IllegalArgumentException iae) { |
|
1265 |
try { |
|
1266 |
Arrays.sort(a, -m, a.length); |
|
1267 |
||
1268 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1269 |
" as expected: fromIndex = " + (-m)); |
|
1270 |
} |
|
1271 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1272 |
try { |
|
1273 |
Arrays.sort(a, 0, a.length + m); |
|
1274 |
||
1275 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1276 |
" as expected: toIndex = " + (a.length + m)); |
|
1277 |
} |
|
1278 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1279 |
return; |
|
1280 |
} |
|
1281 |
} |
|
1282 |
} |
|
1283 |
} |
|
1284 |
||
1285 |
private static void sortRange(short[] a, int m) { |
|
1286 |
try { |
|
1287 |
Arrays.sort(a, m + 1, m); |
|
1288 |
||
1289 |
failed("Sort does not throw IllegalArgumentException " + |
|
1290 |
" as expected: fromIndex = " + (m + 1) + |
|
1291 |
" toIndex = " + m); |
|
1292 |
} |
|
1293 |
catch (IllegalArgumentException iae) { |
|
1294 |
try { |
|
1295 |
Arrays.sort(a, -m, a.length); |
|
1296 |
||
1297 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1298 |
" as expected: fromIndex = " + (-m)); |
|
1299 |
} |
|
1300 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1301 |
try { |
|
1302 |
Arrays.sort(a, 0, a.length + m); |
|
1303 |
||
1304 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1305 |
" as expected: toIndex = " + (a.length + m)); |
|
1306 |
} |
|
1307 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1308 |
return; |
|
1309 |
} |
|
1310 |
} |
|
1311 |
} |
|
1312 |
} |
|
1313 |
||
1314 |
private static void sortRange(char[] a, int m) { |
|
1315 |
try { |
|
1316 |
Arrays.sort(a, m + 1, m); |
|
1317 |
||
1318 |
failed("Sort does not throw IllegalArgumentException " + |
|
1319 |
" as expected: fromIndex = " + (m + 1) + |
|
1320 |
" toIndex = " + m); |
|
1321 |
} |
|
1322 |
catch (IllegalArgumentException iae) { |
|
1323 |
try { |
|
1324 |
Arrays.sort(a, -m, a.length); |
|
1325 |
||
1326 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1327 |
" as expected: fromIndex = " + (-m)); |
|
1328 |
} |
|
1329 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1330 |
try { |
|
1331 |
Arrays.sort(a, 0, a.length + m); |
|
1332 |
||
1333 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1334 |
" as expected: toIndex = " + (a.length + m)); |
|
1335 |
} |
|
1336 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1337 |
return; |
|
1338 |
} |
|
1339 |
} |
|
1340 |
} |
|
1341 |
} |
|
1342 |
||
1343 |
private static void sortRange(float[] a, int m) { |
|
1344 |
try { |
|
1345 |
Arrays.sort(a, m + 1, m); |
|
1346 |
||
1347 |
failed("Sort does not throw IllegalArgumentException " + |
|
1348 |
" as expected: fromIndex = " + (m + 1) + |
|
1349 |
" toIndex = " + m); |
|
1350 |
} |
|
1351 |
catch (IllegalArgumentException iae) { |
|
1352 |
try { |
|
1353 |
Arrays.sort(a, -m, a.length); |
|
1354 |
||
1355 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1356 |
" as expected: fromIndex = " + (-m)); |
|
1357 |
} |
|
1358 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1359 |
try { |
|
1360 |
Arrays.sort(a, 0, a.length + m); |
|
1361 |
||
1362 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1363 |
" as expected: toIndex = " + (a.length + m)); |
|
1364 |
} |
|
1365 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1366 |
return; |
|
1367 |
} |
|
1368 |
} |
|
1369 |
} |
|
1370 |
} |
|
1371 |
||
1372 |
private static void sortRange(double[] a, int m) { |
|
1373 |
try { |
|
1374 |
Arrays.sort(a, m + 1, m); |
|
1375 |
||
1376 |
failed("Sort does not throw IllegalArgumentException " + |
|
1377 |
" as expected: fromIndex = " + (m + 1) + |
|
1378 |
" toIndex = " + m); |
|
1379 |
} |
|
1380 |
catch (IllegalArgumentException iae) { |
|
1381 |
try { |
|
1382 |
Arrays.sort(a, -m, a.length); |
|
1383 |
||
1384 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1385 |
" as expected: fromIndex = " + (-m)); |
|
1386 |
} |
|
1387 |
catch (ArrayIndexOutOfBoundsException aoe) { |
|
1388 |
try { |
|
1389 |
Arrays.sort(a, 0, a.length + m); |
|
1390 |
||
1391 |
failed("Sort does not throw ArrayIndexOutOfBoundsException " + |
|
1392 |
" as expected: toIndex = " + (a.length + m)); |
|
1393 |
} |
|
1394 |
catch (ArrayIndexOutOfBoundsException aie) { |
|
1395 |
return; |
|
1396 |
} |
|
1397 |
} |
|
1398 |
} |
|
1399 |
} |
|
1400 |
||
1401 |
private static void prepareRandom(int[] a) { |
|
1402 |
for (int i = 0; i < a.length; i++) { |
|
1403 |
a[i] = ourRandom.nextInt(); |
|
1404 |
} |
|
1405 |
} |
|
1406 |
||
1407 |
private static void reset(long seed) { |
|
1408 |
ourRandom = new Random(seed); |
|
1409 |
ourFirst = 0; |
|
1410 |
ourSecond = 0; |
|
1411 |
} |
|
1412 |
||
1413 |
private static void outArr(int[] a) { |
|
1414 |
for (int i = 0; i < a.length; i++) { |
|
1415 |
out.print(a[i] + " "); |
|
1416 |
} |
|
1417 |
out.println(); |
|
1418 |
out.println(); |
|
1419 |
} |
|
1420 |
||
1421 |
private static void outArr(float[] a) { |
|
1422 |
for (int i = 0; i < a.length; i++) { |
|
1423 |
out.print(a[i] + " "); |
|
1424 |
} |
|
1425 |
out.println(); |
|
1426 |
out.println(); |
|
1427 |
} |
|
1428 |
||
1429 |
private static void outArr(double[] a) { |
|
1430 |
for (int i = 0; i < a.length; i++) { |
|
1431 |
out.print(a[i] + " "); |
|
1432 |
} |
|
1433 |
out.println(); |
|
1434 |
out.println(); |
|
1435 |
} |
|
1436 |
||
1437 |
private static int ourFirst; |
|
1438 |
private static int ourSecond; |
|
1439 |
private static Random ourRandom; |
|
4177
208f8c11e7ba
6896573: Arrays.sort(long[]) fails with StackOverflowError
alanb
parents:
diff
changeset
|
1440 |
} |