4.1. JAVA
The value to be written is set at offset 12.
iastoreat 13 writes the array’s element.
How it is an element accessed?
public static int get12 (int[][] in)
{
return in[1][2];
}
public static int get12(int[][]);
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=1, args_size=1
0: aload_0
1: iconst_1
2: aaload
3: iconst_2
4: iaload
5: ireturn
AReferenceto the array’s row is loaded at offset 2, the column is set at offset 3, thenialoadloads the
array’s element.
Three-dimensional arrays
Three-dimensional arrays are just one-dimensional arrays ofreferencesto one-dimensional arrays ofref-
erences.
public static void main(String[] args)
{
int[][][] a = new int[5][10][15];
a[1][2][3]=4;
get_elem(a);
}
public static void main(java.lang.String[]);
flags: ACC_PUBLIC, ACC_STATIC
Code:
stack=3, locals=2, args_size=1
0: iconst_5
1: bipush 10
3: bipush 15
5: multianewarray #2, 3 // class "[[[I"
9: astore_1
10: aload_1
11: iconst_1
12: aaload
13: iconst_2
14: aaload
15: iconst_3
16: iconst_4
17: iastore
18: aload_1
19: invokestatic #3 // Method get_elem:([[[I)I
22: pop
23: return
Now it takes twoaaloadinstructions to find rightreference:
public static int get_elem (int[][][] a)
{
return a[1][2][3];
}