33
package compiler.arraycopy;
35
public class TestArrayCopyNoInit {
37
static int[] m1(int[] src) {
38
int[] dest = new int[10];
40
System.arraycopy(src, 0, dest, 0, 10);
41
} catch (NullPointerException npe) {
46
static int[] m2(Object src, boolean flag) {
47
Class tmp = src.getClass();
51
int[] dest = new int[10];
53
System.arraycopy(src, 0, dest, 0, 10);
54
} catch (ArrayStoreException npe) {
59
static int[] m3(int[] src, int src_offset) {
61
int[] dest = new int[10];
63
System.arraycopy(src, src_offset, dest, 0, 10);
64
} catch (IndexOutOfBoundsException npe) {
69
static int[] m4(int[] src, int length) {
71
int[] dest = new int[10];
73
System.arraycopy(src, 0, dest, 0, length);
74
} catch (IndexOutOfBoundsException npe) {
79
static TestArrayCopyNoInit[] m5(Object[] src) {
81
TestArrayCopyNoInit[] dest = new TestArrayCopyNoInit[10];
82
System.arraycopy(src, 0, dest, 0, 10);
89
static class B extends A {
92
static class C extends B {
95
static class D extends C {
98
static class E extends D {
101
static class F extends E {
104
static class G extends F {
107
static class H extends G {
110
static class I extends H {
113
static H[] m6(Object[] src) {
115
H[] dest = new H[10];
116
System.arraycopy(src, 0, dest, 0, 10);
120
static Object m7_src(Object src) {
124
static int[] m7(Object src, boolean flag) {
125
Class tmp = src.getClass();
130
int[] dest = new int[10];
132
System.arraycopy(src, 0, dest, 0, 10);
133
} catch (ArrayStoreException npe) {
138
static public void main(String[] args) {
139
boolean success = true;
140
int[] src = new int[10];
141
TestArrayCopyNoInit[] src2 = new TestArrayCopyNoInit[10];
143
TestArrayCopyNoInit[] res2 = null;
144
Object src_obj = new Object();
146
for (int i = 0; i < 20000; i++) {
151
for (int i = 0; i < res.length; i++) {
154
System.out.println("Uninitialized array following NPE");
159
for (int i = 0; i < 20000; i++) {
166
res = m2(src_obj, false);
167
for (int i = 0; i < res.length; i++) {
170
System.out.println("Uninitialized array following failed array check");
175
for (int i = 0; i < 20000; i++) {
179
for (int i = 0; i < res.length; i++) {
182
System.out.println("Uninitialized array following failed src offset check");
187
for (int i = 0; i < 20000; i++) {
191
for (int i = 0; i < res.length; i++) {
194
System.out.println("Uninitialized array following failed length check");
199
for (int i = 0; i < 20000; i++) {
202
res2 = m5(new Object[10]);
203
for (int i = 0; i < res2.length; i++) {
204
if (res2[i] != null) {
206
System.out.println("Uninitialized array following failed type check");
211
H[] src3 = new H[10];
213
for (int i = 0; i < 20000; i++) {
216
H[] res3 = m6(new Object[10]);
217
for (int i = 0; i < res3.length; i++) {
218
if (res3[i] != null) {
220
System.out.println("Uninitialized array following failed full type check");
225
for (int i = 0; i < 20000; i++) {
232
res = m7(src_obj, false);
233
for (int i = 0; i < res.length; i++) {
236
System.out.println("Uninitialized array following failed type check with return value profiling");
242
throw new RuntimeException("Some tests failed");