Home | History | Annotate | Download | only in filledarray
      1 // 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.
      4 package filledarray;
      5 
      6 import java.util.Arrays;
      7 
      8 public 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 };
     13   private static char[] chars = new char[] {
     14       Character.MAX_VALUE, 'a', 'b', 'c', 'd', Character.MIN_VALUE };
     15   private static int[] ints = new int[] { Integer.MAX_VALUE, 0, -42, 42, Integer.MIN_VALUE };
     16   private static short[] shorts = new short[] { Short.MAX_VALUE, 0, -42, 42, Short.MIN_VALUE };
     17   private static long[] longs = new long[] {
     18       Long.MAX_VALUE, 0x1234123412341234L, -0x1234123412341234L, Long.MIN_VALUE };
     19   private static float[] floats = new float[] {
     20       Float.MAX_VALUE, 23.23F, -43.123F, Float.MIN_VALUE, Float.MIN_NORMAL };
     21   private static double[] doubles = new double[] {
     22       Double.MAX_VALUE, 123123123.123, -43333.123, Double.MIN_VALUE, Double.MIN_NORMAL };
     23 
     24 
     25   public static void filledArrays() {
     26     boolean[] localBooleans = new boolean[] { true, true, false, false };
     27     localBooleans[0] = false;
     28     byte[] localBytes = new byte[] { 21, 22, -23 };
     29     char[] localChars = new char[] { 'a', 'b', 'c', 'd' };
     30     int[] localInts = new int[] { Integer.MAX_VALUE, 0, -42, 42, Integer.MIN_VALUE };
     31     short[] localShorts = new short[] { Short.MAX_VALUE, 0, -42, 42, Short.MIN_VALUE };
     32     long[] localLongs= new long[] { 0x1234432112341234L, -0x1234123412344321L };
     33     localLongs[1] = localLongs[1] + 2;
     34     float[] localFloats = new float[] { 23.23F, -43.123F };
     35     double[] localDoubles = new double[] { 123123123.123, -43333.123 };
     36     System.out.println("booleans");
     37     for (int i = 0; i < booleans.length; i++) {
     38       System.out.println(booleans[i]);
     39     }
     40     for (int i = 0; i < localBooleans.length; i++) {
     41       System.out.println(localBooleans[i]);
     42     }
     43     System.out.println("bytes");
     44     for (int i = 0; i < bytes.length; i++) {
     45       System.out.println(bytes[i]);
     46     }
     47     for (int i = 0; i < localBytes.length; i++) {
     48       System.out.println(localBytes[i]);
     49     }
     50     System.out.println("chars");
     51     for (int i = 0; i < chars.length; i++) {
     52       System.out.println(chars[i]);
     53     }
     54     for (int i = 0; i < localChars.length; i++) {
     55       System.out.println(localChars[i]);
     56     }
     57     System.out.println("ints");
     58     for (int i = 0; i < ints.length; i++) {
     59       System.out.println(ints[i]);
     60     }
     61     for (int i = 0; i < localInts.length; i++) {
     62       System.out.println(localInts[i]);
     63     }
     64     System.out.println("shorts");
     65     for (int i = 0; i < shorts.length; i++) {
     66       System.out.println(shorts[i]);
     67     }
     68     for (int i = 0; i < localShorts.length; i++) {
     69       System.out.println(localShorts[i]);
     70     }
     71     System.out.println("longs");
     72     for (int i = 0; i < longs.length; i++) {
     73       System.out.println(longs[i]);
     74     }
     75     for (int i = 0; i < localLongs.length; i++) {
     76       System.out.println(localLongs[i]);
     77     }
     78     System.out.println("floats");
     79     for (int i = 0; i < floats.length; i++) {
     80       System.out.println(floats[i]);
     81     }
     82     for (int i = 0; i < localFloats.length; i++) {
     83       System.out.println(localFloats[i]);
     84     }
     85     System.out.println("doubles");
     86     for (int i = 0; i < doubles.length; i++) {
     87       System.out.println(doubles[i]);
     88     }
     89     for (int i = 0; i < localDoubles.length; i++) {
     90       System.out.println(localDoubles[i]);
     91     }
     92   }
     93 
     94   public static void filledArraysExceptions(int divisor) {
     95     try {
     96       // Array creations that can be turned into fill-array-data.
     97       int[] ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     98       int[] ints2 = new int[5];
     99       ints2[0] = 0;
    100       ints2[1] = 1;
    101       ints2[2] = 2;
    102       ints2[3] = 3;
    103       ints2[4] = 4;
    104       int i = ints[1] / divisor;
    105       System.out.println("i = " + i);
    106       System.out.println("ints = " + Arrays.toString(ints));
    107       System.out.println("ints2 = " + Arrays.toString(ints2));
    108     } catch (Throwable t) {
    109       System.out.println("Exception: " + t.getClass().toString());
    110     }
    111 
    112     try {
    113       // Array creation that cannot be turned into fill-array-data because an exception would
    114       // cause the initialization sequence to be interrupted.
    115       int[] ints = new int[5];
    116       ints[0] = 0;
    117       ints[1] = 1;
    118       ints[2] = 2;
    119       ints[3] = 3;
    120       int i = 7 / divisor;
    121       ints[4] = 4;
    122       System.out.println("i = " + i);
    123       System.out.println("ints = " + Arrays.toString(ints));
    124     } catch (Throwable t) {
    125       System.out.println("Exception: " + t.getClass().toString());
    126     }
    127   }
    128 
    129   public static void main(String[] args) {
    130     filledArrays();
    131     filledArraysExceptions(1);
    132     filledArraysExceptions(0);
    133   }
    134 }
    135