author | alanb |
Thu, 01 Dec 2016 15:54:39 +0000 | |
changeset 42309 | 21f9f3fbc302 |
parent 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
30629
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
1 |
/* |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
4 |
* |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
8 |
* |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
13 |
* accompanied this code). |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
14 |
* |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
18 |
* |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
21 |
* questions. |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
22 |
*/ |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
23 |
|
40059 | 24 |
package compiler.arraycopy; |
25 |
||
26 |
import java.lang.annotation.Retention; |
|
27 |
import java.lang.annotation.RetentionPolicy; |
|
28 |
import java.lang.reflect.Method; |
|
29 |
import java.lang.reflect.Modifier; |
|
30 |
import java.util.HashMap; |
|
30629
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
31 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
32 |
abstract class TestArrayCopyUtils { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
33 |
public enum ArraySrc { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
34 |
SMALL, |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
35 |
LARGE, |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
36 |
ZERO |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
37 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
38 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
39 |
public enum ArrayDst { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
40 |
NONE, |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
41 |
NEW, |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
42 |
SRC |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
43 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
44 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
45 |
static class A { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
46 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
47 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
48 |
static class B extends A { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
49 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
50 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
51 |
static final A[] small_a_src = new A[5]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
52 |
static final A[] large_a_src = new A[10]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
53 |
static final A[] zero_a_src = new A[0]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
54 |
static final int[] small_int_src = new int[5]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
55 |
static final int[] large_int_src = new int[10]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
56 |
static final int[] zero_int_src = new int[0]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
57 |
static final Object[] small_object_src = new Object[5]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
58 |
static Object src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
59 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
60 |
@Retention(RetentionPolicy.RUNTIME) |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
61 |
@interface Args { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
62 |
ArraySrc src(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
63 |
ArrayDst dst() default ArrayDst.NONE; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
64 |
int[] extra_args() default {}; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
65 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
66 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
67 |
final HashMap<String,Method> tests = new HashMap<>(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
68 |
{ |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
69 |
for (Method m : this.getClass().getDeclaredMethods()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
70 |
if (m.getName().matches("m[0-9]+(_check)?")) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
71 |
assert(Modifier.isStatic(m.getModifiers())) : m; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
72 |
tests.put(m.getName(), m); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
73 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
74 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
75 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
76 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
77 |
boolean success = true; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
78 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
79 |
void doTest(String name) throws Exception { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
80 |
Method m = tests.get(name); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
81 |
Method m_check = tests.get(name + "_check"); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
82 |
Class[] paramTypes = m.getParameterTypes(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
83 |
Object[] params = new Object[paramTypes.length]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
84 |
Class retType = m.getReturnType(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
85 |
boolean isIntArray = (retType.isPrimitive() && !retType.equals(Void.TYPE)) || |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
86 |
(retType.equals(Void.TYPE) && paramTypes[0].getComponentType().isPrimitive()) || |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
87 |
(retType.isArray() && retType.getComponentType().isPrimitive()); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
88 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
89 |
Args args = m.getAnnotation(Args.class); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
90 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
91 |
Object src = null; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
92 |
switch(args.src()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
93 |
case SMALL: { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
94 |
if (isIntArray) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
95 |
src = small_int_src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
96 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
97 |
src = small_a_src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
98 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
99 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
100 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
101 |
case LARGE: { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
102 |
if (isIntArray) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
103 |
src = large_int_src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
104 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
105 |
src = large_a_src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
106 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
107 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
108 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
109 |
case ZERO: { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
110 |
if (isIntArray) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
111 |
src = zero_int_src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
112 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
113 |
src = zero_a_src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
114 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
115 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
116 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
117 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
118 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
119 |
for (int i = 0; i < 20000; i++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
120 |
boolean failure = false; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
121 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
122 |
int p = 0; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
123 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
124 |
if (params.length > 0) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
125 |
if (isIntArray) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
126 |
params[0] = ((int[])src).clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
127 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
128 |
params[0] = ((A[])src).clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
129 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
130 |
p++; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
131 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
132 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
133 |
if (params.length > 1) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
134 |
switch(args.dst()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
135 |
case NEW: { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
136 |
if (isIntArray) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
137 |
params[1] = new int[((int[])params[0]).length]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
138 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
139 |
params[1] = new A[((A[])params[0]).length]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
140 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
141 |
p++; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
142 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
143 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
144 |
case SRC: { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
145 |
params[1] = params[0]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
146 |
p++; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
147 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
148 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
149 |
case NONE: break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
150 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
151 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
152 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
153 |
for (int j = 0; j < args.extra_args().length; j++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
154 |
params[p+j] = args.extra_args()[j]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
155 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
156 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
157 |
Object res = m.invoke(null, params); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
158 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
159 |
if (retType.isPrimitive() && !retType.equals(Void.TYPE)) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
160 |
int s = (int)res; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
161 |
int sum = 0; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
162 |
int[] int_res = (int[])src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
163 |
for (int j = 0; j < int_res.length; j++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
164 |
sum += int_res[j]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
165 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
166 |
failure = (s != sum); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
167 |
if (failure) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
168 |
System.out.println("Test " + name + " failed: result = " + s + " != " + sum); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
169 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
170 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
171 |
Object dest = null; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
172 |
if (!retType.equals(Void.TYPE)) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
173 |
dest = res; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
174 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
175 |
dest = params[1]; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
176 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
177 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
178 |
if (m_check != null) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
179 |
failure = (boolean)m_check.invoke(null, new Object[] { src, dest }); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
180 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
181 |
if (isIntArray) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
182 |
int[] int_res = (int[])src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
183 |
int[] int_dest = (int[])dest; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
184 |
for (int j = 0; j < int_res.length; j++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
185 |
if (int_res[j] != int_dest[j]) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
186 |
System.out.println("Test " + name + " failed for " + j + " src[" + j +"]=" + int_res[j] + ", dest[" + j + "]=" + int_dest[j]); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
187 |
failure = true; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
188 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
189 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
190 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
191 |
Object[] object_res = (Object[])src; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
192 |
Object[] object_dest = (Object[])dest; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
193 |
for (int j = 0; j < object_res.length; j++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
194 |
if (object_res[j] != object_dest[j]) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
195 |
System.out.println("Test " + name + " failed for " + j + " src[" + j +"]=" + object_res[j] + ", dest[" + j + "]=" + object_dest[j]); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
196 |
failure = true; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
197 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
198 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
199 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
200 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
201 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
202 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
203 |
if (failure) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
204 |
success = false; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
205 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
206 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
207 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
208 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
209 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
210 |
TestArrayCopyUtils() { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
211 |
for (int i = 0; i < small_a_src.length; i++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
212 |
small_a_src[i] = new A(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
213 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
214 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
215 |
for (int i = 0; i < small_int_src.length; i++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
216 |
small_int_src[i] = i; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
217 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
218 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
219 |
for (int i = 0; i < large_int_src.length; i++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
220 |
large_int_src[i] = i; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
221 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
222 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
223 |
for (int i = 0; i < 5; i++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
224 |
small_object_src[i] = new Object(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
225 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
226 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
227 |
} |