• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2016, 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 arrayaccess;
5 
6 public class ArrayAccess {
7 
loadStoreBoolean(int i, boolean b)8   public static int loadStoreBoolean(int i, boolean b) {
9     boolean[] array = new boolean[i + 2];
10     array[i] = b;
11     array[i + 1] = !array[i];
12     return (array[i] ? 1 : 0) + (array[i + 1] ? 1 : 0);
13   }
14 
loadStoreByte(int i)15   public static int loadStoreByte(int i) {
16     byte[] array = new byte[i + 2];
17     array[i] = 1;
18     array[i + 1] = (byte) (array[i] + (byte) 1);
19     return array[i] + array[i + 1];
20   }
21 
loadStoreChar(int i)22   public static int loadStoreChar(int i) {
23     char[] array = new char[i + 2];
24     array[i] = 1;
25     array[i + 1] = (char) (array[i] + (char) 1);
26     return array[i] + array[i + 1];
27   }
28 
loadStoreShort(int i)29   public static int loadStoreShort(int i) {
30     short[] array = new short[i + 2];
31     array[i] = 1;
32     array[i + 1] = (short) (array[i] + (short) 1);
33     return array[i] + array[i + 1];
34   }
35 
loadStoreFloat(int i)36   public static float loadStoreFloat(int i) {
37     float[] array = new float[i + 2];
38     array[i] = 1.0f;
39     array[i + 1] = array[i] + 1.0f;
40     return array[i] + array[i + 1];
41   }
42 
loadStoreDouble(int i)43   public static double loadStoreDouble(int i) {
44     double[] array = new double[i + 2];
45     array[i] = 1.0;
46     array[i + 1] = array[i] + 1.0;
47     return array[i] + array[i + 1];
48   }
49 
loadStoreObject(int i, Object o)50   public static int loadStoreObject(int i, Object o) {
51     Object[] array = new Object[i + 2];
52     array[i] = o;
53     array[i + 1] = o;
54     return 1 + (array[i].hashCode() - array[i + 1].hashCode());
55   }
56 
loadStoreArray(int i, Object[] os)57   public static int loadStoreArray(int i, Object[] os) {
58     Object[][] array = new Object[i + 2][];
59     array[i] = os;
60     array[i + 1] = os;
61     return array[i].length + array[i + 1].length;
62   }
63 
main(String[] args)64   public static void main(String[] args) {
65     int i = 0;
66     i += loadStoreBoolean(1, true);
67     i += loadStoreByte(0);
68     i += loadStoreChar(1);
69     i += loadStoreShort(2);
70     i += loadStoreFloat(3);
71     i += loadStoreDouble(4);
72     i += loadStoreObject(1, "foo");
73     i += loadStoreArray(1, new Object[10]);
74     System.out.println("37=" + i);
75   }
76 }