author | alanb |
Thu, 01 Dec 2016 15:54:39 +0000 | |
changeset 42309 | 21f9f3fbc302 |
parent 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
29337
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
1 |
/* |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
4 |
* |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
8 |
* |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
13 |
* accompanied this code). |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
14 |
* |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
18 |
* |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
21 |
* questions. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
22 |
*/ |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
23 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
24 |
/* |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
25 |
* @test |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
26 |
* @bug 6912521 |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
27 |
* @summary small array copy as loads/stores |
40059 | 28 |
* @library / |
29337
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
29 |
* |
40059 | 30 |
* @run main/othervm -ea -XX:-BackgroundCompilation -XX:-UseOnStackReplacement |
31 |
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestArrayCopyAsLoadsStores::m* |
|
32 |
* -XX:TypeProfileLevel=200 |
|
33 |
* compiler.arraycopy.TestArrayCopyAsLoadsStores |
|
34 |
* @run main/othervm -ea -XX:-BackgroundCompilation -XX:-UseOnStackReplacement |
|
35 |
* -XX:CompileCommand=dontinline,compiler.arraycopy.TestArrayCopyAsLoadsStores::m* |
|
36 |
* -XX:TypeProfileLevel=200 |
|
37 |
* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressArrayCopyMacroNode |
|
38 |
* compiler.arraycopy.TestArrayCopyAsLoadsStores |
|
29337
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
39 |
*/ |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
40 |
|
40059 | 41 |
package compiler.arraycopy; |
42 |
||
43 |
import java.util.Arrays; |
|
29337
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
44 |
|
30629
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
29345
diff
changeset
|
45 |
public class TestArrayCopyAsLoadsStores extends TestArrayCopyUtils { |
29337
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
46 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
47 |
// array clone should be compiled as loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
48 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
49 |
static A[] m1() throws CloneNotSupportedException { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
50 |
return (A[])small_a_src.clone(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
51 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
52 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
53 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
54 |
static int[] m2() throws CloneNotSupportedException { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
55 |
return (int[])small_int_src.clone(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
56 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
57 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
58 |
// new array allocation should be optimized out |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
59 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
60 |
static int m3() throws CloneNotSupportedException { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
61 |
int[] array_clone = (int[])small_int_src.clone(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
62 |
return array_clone[0] + array_clone[1] + array_clone[2] + |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
63 |
array_clone[3] + array_clone[4]; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
64 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
65 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
66 |
// should not be compiled as loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
67 |
@Args(src=ArraySrc.LARGE) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
68 |
static int[] m4() throws CloneNotSupportedException { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
69 |
return (int[])large_int_src.clone(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
70 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
71 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
72 |
// check that array of length 0 is handled correctly |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
73 |
@Args(src=ArraySrc.ZERO) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
74 |
static int[] m5() throws CloneNotSupportedException { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
75 |
return (int[])zero_int_src.clone(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
76 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
77 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
78 |
// array copy should be compiled as loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
79 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NEW) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
80 |
static void m6(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
81 |
System.arraycopy(src, 0, dest, 0, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
82 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
83 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
84 |
// array copy should not be compiled as loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
85 |
@Args(src=ArraySrc.LARGE, dst=ArrayDst.NEW) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
86 |
static void m7(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
87 |
System.arraycopy(src, 0, dest, 0, 10); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
88 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
89 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
90 |
// array copy should be compiled as loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
91 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
92 |
static A[] m8(A[] src) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
93 |
src[0] = src[0]; // force null check |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
94 |
A[] dest = new A[5]; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
95 |
System.arraycopy(src, 0, dest, 0, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
96 |
return dest; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
97 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
98 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
99 |
// array copy should not be compiled as loads/stores: we would |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
100 |
// need to emit GC barriers |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
101 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NEW) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
102 |
static void m9(A[] src, A[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
103 |
System.arraycopy(src, 0, dest, 0, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
104 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
105 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
106 |
// overlapping array regions: copy backward |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
107 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.SRC) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
108 |
static void m10(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
109 |
System.arraycopy(src, 0, dest, 1, 4); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
110 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
111 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
112 |
static boolean m10_check(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
113 |
boolean failure = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
114 |
for (int i = 0; i < 5; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
115 |
int j = Math.max(i - 1, 0); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
116 |
if (dest[i] != src[j]) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
117 |
System.out.println("Test m10 failed for " + i + " src[" + j +"]=" + src[j] + ", dest[" + i + "]=" + dest[i]); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
118 |
failure = true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
119 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
120 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
121 |
return failure; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
122 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
123 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
124 |
// overlapping array regions: copy forward |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
125 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.SRC) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
126 |
static void m11(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
127 |
System.arraycopy(src, 1, dest, 0, 4); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
128 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
129 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
130 |
static boolean m11_check(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
131 |
boolean failure = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
132 |
for (int i = 0; i < 5; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
133 |
int j = Math.min(i + 1, 4); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
134 |
if (dest[i] != src[j]) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
135 |
System.out.println("Test m11 failed for " + i + " src[" + j +"]=" + src[j] + ", dest[" + i + "]=" + dest[i]); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
136 |
failure = true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
137 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
138 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
139 |
return failure; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
140 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
141 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
142 |
// overlapping array region with unknown src/dest offsets: compiled code must include both forward and backward copies |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
143 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.SRC, extra_args={0,1}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
144 |
static void m12(int[] src, int[] dest, int srcPos, int destPos) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
145 |
System.arraycopy(src, srcPos, dest, destPos, 4); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
146 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
147 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
148 |
static boolean m12_check(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
149 |
boolean failure = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
150 |
for (int i = 0; i < 5; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
151 |
int j = Math.max(i - 1, 0); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
152 |
if (dest[i] != src[j]) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
153 |
System.out.println("Test m10 failed for " + i + " src[" + j +"]=" + src[j] + ", dest[" + i + "]=" + dest[i]); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
154 |
failure = true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
155 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
156 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
157 |
return failure; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
158 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
159 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
160 |
// Array allocation and copy should optimize out |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
161 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
162 |
static int m13(int[] src) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
163 |
int[] dest = new int[5]; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
164 |
System.arraycopy(src, 0, dest, 0, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
165 |
return dest[0] + dest[1] + dest[2] + dest[3] + dest[4]; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
166 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
167 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
168 |
// Check that copy of length 0 is handled correctly |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
169 |
@Args(src=ArraySrc.ZERO, dst=ArrayDst.NEW) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
170 |
static void m14(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
171 |
System.arraycopy(src, 0, dest, 0, 0); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
172 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
173 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
174 |
// copyOf should compile to loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
175 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
176 |
static A[] m15() { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
177 |
return Arrays.copyOf(small_a_src, 5, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
178 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
179 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
180 |
static Object[] helper16(int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
181 |
Object[] arr = null; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
182 |
if ((i%2) == 0) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
183 |
arr = small_a_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
184 |
} else { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
185 |
arr = small_object_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
186 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
187 |
return arr; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
188 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
189 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
190 |
// CopyOf may need subtype check |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
191 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NONE, extra_args={0}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
192 |
static A[] m16(A[] unused_src, int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
193 |
Object[] arr = helper16(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
194 |
return Arrays.copyOf(arr, 5, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
195 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
196 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
197 |
static Object[] helper17_1(int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
198 |
Object[] arr = null; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
199 |
if ((i%2) == 0) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
200 |
arr = small_a_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
201 |
} else { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
202 |
arr = small_object_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
203 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
204 |
return arr; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
205 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
206 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
207 |
static A[] helper17_2(Object[] arr) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
208 |
return Arrays.copyOf(arr, 5, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
209 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
210 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
211 |
// CopyOf may leverage type speculation |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
212 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NONE, extra_args={0}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
213 |
static A[] m17(A[] unused_src, int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
214 |
Object[] arr = helper17_1(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
215 |
return helper17_2(arr); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
216 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
217 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
218 |
static Object[] helper18_1(int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
219 |
Object[] arr = null; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
220 |
if ((i%2) == 0) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
221 |
arr = small_a_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
222 |
} else { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
223 |
arr = small_object_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
224 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
225 |
return arr; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
226 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
227 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
228 |
static Object[] helper18_2(Object[] arr) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
229 |
return Arrays.copyOf(arr, 5, Object[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
230 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
231 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
232 |
// CopyOf should not attempt to use type speculation if it's not needed |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
233 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NONE, extra_args={0}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
234 |
static Object[] m18(A[] unused_src, int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
235 |
Object[] arr = helper18_1(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
236 |
return helper18_2(arr); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
237 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
238 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
239 |
static Object[] helper19(int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
240 |
Object[] arr = null; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
241 |
if ((i%2) == 0) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
242 |
arr = small_a_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
243 |
} else { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
244 |
arr = small_object_src; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
245 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
246 |
return arr; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
247 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
248 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
249 |
// CopyOf may need subtype check. Test is run to make type check |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
250 |
// fail and cause deoptimization. Next compilation should not |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
251 |
// compile as loads/stores because the first compilation |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
252 |
// deoptimized. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
253 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NONE, extra_args={0}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
254 |
static A[] m19(A[] unused_src, int i) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
255 |
Object[] arr = helper19(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
256 |
return Arrays.copyOf(arr, 5, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
257 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
258 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
259 |
// copyOf for large array should not compile to loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
260 |
@Args(src=ArraySrc.LARGE) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
261 |
static A[] m20() { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
262 |
return Arrays.copyOf(large_a_src, 10, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
263 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
264 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
265 |
// check zero length copyOf is handled correctly |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
266 |
@Args(src=ArraySrc.ZERO) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
267 |
static A[] m21() { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
268 |
return Arrays.copyOf(zero_a_src, 0, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
269 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
270 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
271 |
// Run with srcPos=0 for a 1st compile, then with incorrect value |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
272 |
// of srcPos to cause deoptimization, then with srcPos=0 for a 2nd |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
273 |
// compile. The 2nd compile shouldn't turn arraycopy into |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
274 |
// loads/stores because input arguments are no longer known to be |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
275 |
// valid. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
276 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.NEW, extra_args={0}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
277 |
static void m22(int[] src, int[] dest, int srcPos) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
278 |
System.arraycopy(src, srcPos, dest, 0, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
279 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
280 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
281 |
// copyOfRange should compile to loads/stores |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
282 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
283 |
static A[] m23() { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
284 |
return Arrays.copyOfRange(small_a_src, 1, 4, A[].class); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
285 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
286 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
287 |
static boolean m23_check(A[] src, A[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
288 |
boolean failure = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
289 |
for (int i = 0; i < 3; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
290 |
if (src[i+1] != dest[i]) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
291 |
System.out.println("Test m23 failed for " + i + " src[" + (i+1) +"]=" + dest[i] + ", dest[" + i + "]=" + dest[i]); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
292 |
failure = true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
293 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
294 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
295 |
return failure; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
296 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
297 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
298 |
// array copy should be compiled as loads/stores. Invoke then with |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
299 |
// incompatible array type to verify we don't allow a forbidden |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
300 |
// arraycopy to happen. |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
301 |
@Args(src=ArraySrc.SMALL) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
302 |
static A[] m24(Object[] src) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
303 |
src[0] = src[0]; // force null check |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
304 |
A[] dest = new A[5]; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
305 |
System.arraycopy(src, 0, dest, 0, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
306 |
return dest; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
307 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
308 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
309 |
// overlapping array region with unknown src/dest offsets but |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
310 |
// length 1: compiled code doesn't need both forward and backward |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
311 |
// copies |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
312 |
@Args(src=ArraySrc.SMALL, dst=ArrayDst.SRC, extra_args={0,1}) |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
313 |
static void m25(int[] src, int[] dest, int srcPos, int destPos) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
314 |
System.arraycopy(src, srcPos, dest, destPos, 1); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
315 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
316 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
317 |
static boolean m25_check(int[] src, int[] dest) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
318 |
boolean failure = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
319 |
if (dest[1] != src[0]) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
320 |
System.out.println("Test m10 failed for src[0]=" + src[0] + ", dest[1]=" + dest[1]); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
321 |
return true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
322 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
323 |
return false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
324 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
325 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
326 |
public static void main(String[] args) throws Exception { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
327 |
TestArrayCopyAsLoadsStores test = new TestArrayCopyAsLoadsStores(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
328 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
329 |
test.doTest("m1"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
330 |
test.doTest("m2"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
331 |
test.doTest("m3"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
332 |
test.doTest("m4"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
333 |
test.doTest("m5"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
334 |
test.doTest("m6"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
335 |
test.doTest("m7"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
336 |
test.doTest("m8"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
337 |
test.doTest("m9"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
338 |
test.doTest("m10"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
339 |
test.doTest("m11"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
340 |
test.doTest("m12"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
341 |
test.doTest("m13"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
342 |
test.doTest("m14"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
343 |
test.doTest("m15"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
344 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
345 |
// make both branches of the If appear taken |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
346 |
for (int i = 0; i < 20000; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
347 |
helper16(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
348 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
349 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
350 |
test.doTest("m16"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
351 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
352 |
// load class B so type check in m17 would not be simple comparison |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
353 |
B b = new B(); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
354 |
// make both branches of the If appear taken |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
355 |
for (int i = 0; i < 20000; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
356 |
helper17_1(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
357 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
358 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
359 |
test.doTest("m17"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
360 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
361 |
// make both branches of the If appear taken |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
362 |
for (int i = 0; i < 20000; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
363 |
helper18_1(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
364 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
365 |
test.doTest("m18"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
366 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
367 |
// make both branches of the If appear taken |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
368 |
for (int i = 0; i < 20000; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
369 |
helper19(i); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
370 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
371 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
372 |
// Compile |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
373 |
for (int i = 0; i < 20000; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
374 |
m19(null, 0); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
375 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
376 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
377 |
// force deopt |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
378 |
boolean m19_exception = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
379 |
for (int i = 0; i < 10; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
380 |
try { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
381 |
m19(null, 1); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
382 |
} catch(ArrayStoreException ase) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
383 |
m19_exception = true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
384 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
385 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
386 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
387 |
if (!m19_exception) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
388 |
System.out.println("Test m19: exception wasn't thrown"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
389 |
test.success = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
390 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
391 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
392 |
test.doTest("m19"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
393 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
394 |
test.doTest("m20"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
395 |
test.doTest("m21"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
396 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
397 |
// Compile |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
398 |
int[] dst = new int[small_int_src.length]; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
399 |
for (int i = 0; i < 20000; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
400 |
m22(small_int_src, dst, 0); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
401 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
402 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
403 |
// force deopt |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
404 |
for (int i = 0; i < 10; i++) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
405 |
try { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
406 |
m22(small_int_src, dst, 5); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
407 |
} catch(ArrayIndexOutOfBoundsException aioobe) {} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
408 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
409 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
410 |
test.doTest("m22"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
411 |
test.doTest("m23"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
412 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
413 |
test.doTest("m24"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
414 |
boolean m24_exception = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
415 |
try { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
416 |
m24(small_object_src); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
417 |
} catch(ArrayStoreException ase) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
418 |
m24_exception = true; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
419 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
420 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
421 |
if (!m24_exception) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
422 |
System.out.println("Test m24: exception wasn't thrown"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
423 |
test.success = false; |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
424 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
425 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
426 |
test.doTest("m25"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
427 |
|
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
428 |
if (!test.success) { |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
429 |
throw new RuntimeException("some tests failed"); |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
430 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
431 |
} |
ef2be52deeaf
6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff
changeset
|
432 |
} |