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.reflect.Field; |
|
27 |
import java.lang.reflect.Method; |
|
28 |
import java.lang.reflect.Modifier; |
|
29 |
import java.util.HashMap; |
|
30629
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
30 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
31 |
abstract class TestInstanceCloneUtils { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
32 |
static class Base implements Cloneable { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
33 |
void initialize(Class c, int i) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
34 |
for (Field f : c.getDeclaredFields()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
35 |
setVal(f, i); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
36 |
i++; |
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 |
if (c != Base.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
39 |
initialize(c.getSuperclass(), i); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
40 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
41 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
42 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
43 |
Base(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
44 |
if (initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
45 |
initialize(getClass(), 0); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
49 |
void setVal(Field f, int i) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
50 |
try { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
51 |
if (f.getType() == int.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
52 |
f.setInt(this, i); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
53 |
return; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
54 |
} else if (f.getType() == short.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
55 |
f.setShort(this, (short)i); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
56 |
return; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
57 |
} else if (f.getType() == byte.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
58 |
f.setByte(this, (byte)i); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
59 |
return; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
60 |
} else if (f.getType() == long.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
61 |
f.setLong(this, i); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
62 |
return; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
63 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
64 |
} catch(IllegalAccessException iae) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
65 |
throw new RuntimeException("Getting fields failed"); |
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 |
throw new RuntimeException("unexpected field type"); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
70 |
int getVal(Field f) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
71 |
try { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
72 |
if (f.getType() == int.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
73 |
return f.getInt(this); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
74 |
} else if (f.getType() == short.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
75 |
return (int)f.getShort(this); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
76 |
} else if (f.getType() == byte.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
77 |
return (int)f.getByte(this); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
78 |
} else if (f.getType() == long.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
79 |
return (int)f.getLong(this); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
80 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
81 |
} catch(IllegalAccessException iae) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
82 |
throw new RuntimeException("Setting fields failed"); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
83 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
84 |
throw new RuntimeException("unexpected field type"); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
85 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
86 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
87 |
boolean fields_equal(Class c, Base o) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
88 |
for (Field f : c.getDeclaredFields()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
89 |
if (getVal(f) != o.getVal(f)) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
90 |
return false; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
91 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
92 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
93 |
if (c != Base.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
94 |
return fields_equal(c.getSuperclass(), o); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
95 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
96 |
return true; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
97 |
} |
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 |
public boolean equals(Object obj) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
100 |
return fields_equal(getClass(), (Base)obj); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
101 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
102 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
103 |
String print_fields(Class c, String s) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
104 |
for (Field f : c.getDeclaredFields()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
105 |
if (s != "") { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
106 |
s += "\n"; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
107 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
108 |
s = s + f + " = " + getVal(f); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
109 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
110 |
if (c != Base.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
111 |
return print_fields(c.getSuperclass(), s); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
112 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
113 |
return s; |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
116 |
public String toString() { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
117 |
return print_fields(getClass(), ""); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
120 |
int fields_sum(Class c, int s) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
121 |
for (Field f : c.getDeclaredFields()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
122 |
s += getVal(f); |
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 (c != Base.class) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
125 |
return fields_sum(c.getSuperclass(), s); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
126 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
127 |
return s; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
128 |
} |
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 |
public int sum() { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
131 |
return fields_sum(getClass(), 0); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
134 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
135 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
136 |
static class A extends Base { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
137 |
int i1; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
138 |
int i2; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
139 |
int i3; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
140 |
int i4; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
141 |
int i5; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
142 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
143 |
A(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
144 |
super(initialize); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
145 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
146 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
147 |
public Object clone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
148 |
return super.clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
149 |
} |
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 |
static class B extends A { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
153 |
int i6; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
154 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
155 |
B(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
156 |
super(initialize); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
157 |
} |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
160 |
static final class D extends Base { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
161 |
byte i1; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
162 |
short i2; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
163 |
long i3; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
164 |
int i4; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
165 |
int i5; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
166 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
167 |
D(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
168 |
super(initialize); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
171 |
public Object clone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
172 |
return super.clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
173 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
174 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
175 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
176 |
static final class E extends Base { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
177 |
int i1; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
178 |
int i2; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
179 |
int i3; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
180 |
int i4; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
181 |
int i5; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
182 |
int i6; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
183 |
int i7; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
184 |
int i8; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
185 |
int i9; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
186 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
187 |
E(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
188 |
super(initialize); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
191 |
public Object clone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
192 |
return super.clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
193 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
194 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
195 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
196 |
static final class F extends Base { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
197 |
F(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
198 |
super(initialize); |
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 |
public Object clone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
202 |
return super.clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
203 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
204 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
205 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
206 |
static class G extends Base { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
207 |
int i1; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
208 |
int i2; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
209 |
int i3; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
210 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
211 |
G(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
212 |
super(initialize); |
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 |
public Object myclone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
216 |
return clone(); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
220 |
static class H extends G { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
221 |
int i4; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
222 |
int i5; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
223 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
224 |
H(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
225 |
super(initialize); |
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 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
228 |
public Object clone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
229 |
return super.clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
230 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
231 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
232 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
233 |
static class J extends Base { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
234 |
int i1; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
235 |
int i2; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
236 |
int i3; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
237 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
238 |
J(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
239 |
super(initialize); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
240 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
241 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
242 |
public Object myclone() throws CloneNotSupportedException { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
243 |
return clone(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
244 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
245 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
246 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
247 |
static class K extends J { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
248 |
int i4; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
249 |
int i5; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
250 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
251 |
K(boolean initialize) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
252 |
super(initialize); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
253 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
254 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
255 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
256 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
257 |
static final A a = new A(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
258 |
static final B b = new B(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
259 |
static final D d = new D(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
260 |
static final E e = new E(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
261 |
static final F f = new F(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
262 |
static final G g = new G(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
263 |
static final H h = new H(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
264 |
static final J j = new J(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
265 |
static final K k = new K(true); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
266 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
267 |
final HashMap<String,Method> tests = new HashMap<>(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
268 |
{ |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
269 |
for (Method m : this.getClass().getDeclaredMethods()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
270 |
if (m.getName().matches("m[0-9]+")) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
271 |
assert(Modifier.isStatic(m.getModifiers())) : m; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
272 |
tests.put(m.getName(), m); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
273 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
274 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
275 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
276 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
277 |
boolean success = true; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
278 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
279 |
void doTest(Base src, String name) throws Exception { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
280 |
Method m = tests.get(name); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
281 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
282 |
for (int i = 0; i < 20000; i++) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
283 |
boolean failure = false; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
284 |
Base res = null; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
285 |
int s = 0; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
286 |
Class retType = m.getReturnType(); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
287 |
if (retType.isPrimitive()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
288 |
if (!retType.equals(Void.TYPE)) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
289 |
s = (int)m.invoke(null, src); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
290 |
failure = (s != src.sum()); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
291 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
292 |
m.invoke(null, src); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
293 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
294 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
295 |
res = (Base)m.invoke(null, src); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
296 |
failure = !res.equals(src); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
297 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
298 |
if (failure) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
299 |
System.out.println("Test " + name + " failed"); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
300 |
System.out.println("source: "); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
301 |
System.out.println(src); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
302 |
System.out.println("result: "); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
303 |
if (m.getReturnType().isPrimitive()) { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
304 |
System.out.println(s); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
305 |
} else { |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
306 |
System.out.println(res); |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
307 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
308 |
success = false; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
309 |
break; |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
310 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
311 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
312 |
} |
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
313 |
|
b6e5ad2f18d5
8076188: Optimize arraycopy out for non escaping destination
roland
parents:
diff
changeset
|
314 |
} |