blob: 4e0c6523985e6992bd7ce0e4a134dbfd3815385d [file] [log] [blame]
Mads Ager418d1ca2017-05-22 09:35:49 +02001// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4package filledarray;
5
6import java.util.Arrays;
7
8public class FilledArray {
9 private static boolean[] booleans = new boolean[] { true, true, false, false };
10 private static byte[] bytes = new byte[] {
11 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, -19, -20, -96,
12 Byte.MAX_VALUE, Byte.MIN_VALUE };
Jean-Marie Henaffce162f32017-10-04 10:39:27 +020013 private static char[] chars = new char[] {'a', 'b', 'c', 'd'};
Mads Ager418d1ca2017-05-22 09:35:49 +020014 private static int[] ints = new int[] { Integer.MAX_VALUE, 0, -42, 42, Integer.MIN_VALUE };
15 private static short[] shorts = new short[] { Short.MAX_VALUE, 0, -42, 42, Short.MIN_VALUE };
16 private static long[] longs = new long[] {
17 Long.MAX_VALUE, 0x1234123412341234L, -0x1234123412341234L, Long.MIN_VALUE };
18 private static float[] floats = new float[] {
19 Float.MAX_VALUE, 23.23F, -43.123F, Float.MIN_VALUE, Float.MIN_NORMAL };
20 private static double[] doubles = new double[] {
21 Double.MAX_VALUE, 123123123.123, -43333.123, Double.MIN_VALUE, Double.MIN_NORMAL };
22
23
24 public static void filledArrays() {
25 boolean[] localBooleans = new boolean[] { true, true, false, false };
26 localBooleans[0] = false;
27 byte[] localBytes = new byte[] { 21, 22, -23 };
28 char[] localChars = new char[] { 'a', 'b', 'c', 'd' };
29 int[] localInts = new int[] { Integer.MAX_VALUE, 0, -42, 42, Integer.MIN_VALUE };
30 short[] localShorts = new short[] { Short.MAX_VALUE, 0, -42, 42, Short.MIN_VALUE };
31 long[] localLongs= new long[] { 0x1234432112341234L, -0x1234123412344321L };
32 localLongs[1] = localLongs[1] + 2;
33 float[] localFloats = new float[] { 23.23F, -43.123F };
34 double[] localDoubles = new double[] { 123123123.123, -43333.123 };
35 System.out.println("booleans");
36 for (int i = 0; i < booleans.length; i++) {
37 System.out.println(booleans[i]);
38 }
39 for (int i = 0; i < localBooleans.length; i++) {
40 System.out.println(localBooleans[i]);
41 }
42 System.out.println("bytes");
43 for (int i = 0; i < bytes.length; i++) {
44 System.out.println(bytes[i]);
45 }
46 for (int i = 0; i < localBytes.length; i++) {
47 System.out.println(localBytes[i]);
48 }
49 System.out.println("chars");
50 for (int i = 0; i < chars.length; i++) {
51 System.out.println(chars[i]);
52 }
53 for (int i = 0; i < localChars.length; i++) {
54 System.out.println(localChars[i]);
55 }
56 System.out.println("ints");
57 for (int i = 0; i < ints.length; i++) {
58 System.out.println(ints[i]);
59 }
60 for (int i = 0; i < localInts.length; i++) {
61 System.out.println(localInts[i]);
62 }
63 System.out.println("shorts");
64 for (int i = 0; i < shorts.length; i++) {
65 System.out.println(shorts[i]);
66 }
67 for (int i = 0; i < localShorts.length; i++) {
68 System.out.println(localShorts[i]);
69 }
70 System.out.println("longs");
71 for (int i = 0; i < longs.length; i++) {
72 System.out.println(longs[i]);
73 }
74 for (int i = 0; i < localLongs.length; i++) {
75 System.out.println(localLongs[i]);
76 }
77 System.out.println("floats");
78 for (int i = 0; i < floats.length; i++) {
79 System.out.println(floats[i]);
80 }
81 for (int i = 0; i < localFloats.length; i++) {
82 System.out.println(localFloats[i]);
83 }
84 System.out.println("doubles");
85 for (int i = 0; i < doubles.length; i++) {
86 System.out.println(doubles[i]);
87 }
88 for (int i = 0; i < localDoubles.length; i++) {
89 System.out.println(localDoubles[i]);
90 }
91 }
92
93 public static void filledArraysExceptions(int divisor) {
94 try {
95 // Array creations that can be turned into fill-array-data.
96 int[] ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
97 int[] ints2 = new int[5];
98 ints2[0] = 0;
99 ints2[1] = 1;
100 ints2[2] = 2;
101 ints2[3] = 3;
102 ints2[4] = 4;
103 int i = ints[1] / divisor;
104 System.out.println("i = " + i);
105 System.out.println("ints = " + Arrays.toString(ints));
106 System.out.println("ints2 = " + Arrays.toString(ints2));
107 } catch (Throwable t) {
Mads Ager5577ce02017-06-07 12:42:03 +0200108 System.out.println("Exception: " + t.getClass().toString());
Mads Ager418d1ca2017-05-22 09:35:49 +0200109 }
110
111 try {
112 // Array creation that cannot be turned into fill-array-data because an exception would
113 // cause the initialization sequence to be interrupted.
114 int[] ints = new int[5];
115 ints[0] = 0;
116 ints[1] = 1;
117 ints[2] = 2;
118 ints[3] = 3;
119 int i = 7 / divisor;
120 ints[4] = 4;
121 System.out.println("i = " + i);
122 System.out.println("ints = " + Arrays.toString(ints));
123 } catch (Throwable t) {
Mads Ager5577ce02017-06-07 12:42:03 +0200124 System.out.println("Exception: " + t.getClass().toString());
Mads Ager418d1ca2017-05-22 09:35:49 +0200125 }
126 }
127
128 public static void main(String[] args) {
129 filledArrays();
130 filledArraysExceptions(1);
131 filledArraysExceptions(0);
132 }
133}