|
|
Since the opcode for set/get value to/from a boolean array is the same as it is for the byte array
(BASTORE/BALOAD), and since the boolean array is saved as a java.lang.Object slot, and since
there is no real way to tell which array it is from the Opcode.
So the origin code of:
// method vars:
boolean[] arr = ...;
int idx = ...;
// code:
stack <- arr[idx];
Results in code that does essentially this:
// vars are promoted to member slots:
Object arr = this.slot$1;
int idx = this.slot$2;
boolean c;
// need to know the type of array:
if (arr.getClass().getComponentType().equals(Byte.TYPE)) {
stack <- java.lang.reflect.Array.getByte(arr, idx);
else {
stack <- java.lang.reflect.Array.getBoolean(arr, idx);
}
This could be improved by looking-ahead and checking is the type of the assigned variable, and
then create the correct CHECKCAST bytecode (to [Z or [B), or by keeping metadata on the slots so
that we could tell what was their original type, even after merger with other types, to better
deduce bytecode creation.
|