InstructionList newList = new InstructionList();
InstructionFactory factory = new InstructionFactory();
for(int i = 0; i < advice.size(); i++) {
Instruction ins = advice.get(i);
newList.add(ins);
switch(ins.getOpcode()) {
// -- ALOAD family --------------------------------------
case Opcodes.ALOAD_0:
newList.replace(i, factory.aload(maxLocalsInOtherList));
break;
case Opcodes.ALOAD_1:
newList.replace(i, factory.aload(maxLocalsInOtherList + 1));
break;
case Opcodes.ALOAD_2:
newList.replace(i, factory.aload(maxLocalsInOtherList + 2));
break;
case Opcodes.ALOAD_3:
newList.replace(i, factory.aload(maxLocalsInOtherList + 3));
break;
case Opcodes.ALOAD:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
case Opcodes.ASTORE_0:
newList.replace(i, factory.astore(maxLocalsInOtherList));
break;
case Opcodes.ASTORE_1:
newList.replace(i, factory.astore(maxLocalsInOtherList + 1));
break;
case Opcodes.ASTORE_2:
newList.replace(i, factory.astore(maxLocalsInOtherList + 2));
break;
case Opcodes.ASTORE_3:
newList.replace(i, factory.astore(maxLocalsInOtherList + 3));
break;
case Opcodes.ASTORE:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
// -- ILOAD family --------------------------------------
case Opcodes.ILOAD_0:
newList.replace(i, factory.iload(maxLocalsInOtherList));
break;
case Opcodes.ILOAD_1:
newList.replace(i, factory.iload(maxLocalsInOtherList + 1));
break;
case Opcodes.ILOAD_2:
newList.replace(i, factory.iload(maxLocalsInOtherList + 2));
break;
case Opcodes.ILOAD_3:
newList.replace(i, factory.iload(maxLocalsInOtherList + 3));
break;
case Opcodes.ILOAD:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
case Opcodes.ISTORE_0:
newList.replace(i, factory.istore(maxLocalsInOtherList));
break;
case Opcodes.ISTORE_1:
newList.replace(i, factory.istore(maxLocalsInOtherList + 1));
break;
case Opcodes.ISTORE_2:
newList.replace(i, factory.istore(maxLocalsInOtherList + 2));
break;
case Opcodes.ISTORE_3:
newList.replace(i, factory.istore(maxLocalsInOtherList + 3));
break;
case Opcodes.ISTORE:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
// -- DLOAD family --------------------------------------
case Opcodes.DLOAD_0:
newList.replace(i, factory.dload(maxLocalsInOtherList));
break;
case Opcodes.DLOAD_1:
newList.replace(i, factory.dload(maxLocalsInOtherList + 1));
break;
case Opcodes.DLOAD_2:
newList.replace(i, factory.dload(maxLocalsInOtherList + 2));
break;
case Opcodes.DLOAD_3:
newList.replace(i, factory.dload(maxLocalsInOtherList + 3));
break;
case Opcodes.DLOAD:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
case Opcodes.DSTORE_0:
newList.replace(i, factory.dstore(maxLocalsInOtherList));
break;
case Opcodes.DSTORE_1:
newList.replace(i, factory.dstore(maxLocalsInOtherList + 1));
break;
case Opcodes.DSTORE_2:
newList.replace(i, factory.dstore(maxLocalsInOtherList + 2));
break;
case Opcodes.DSTORE_3:
newList.replace(i, factory.dstore(maxLocalsInOtherList + 3));
break;
case Opcodes.DSTORE:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
// -- LLOAD family --------------------------------------
case Opcodes.LLOAD_0:
newList.replace(i, factory.lload(maxLocalsInOtherList));
break;
case Opcodes.LLOAD_1:
newList.replace(i, factory.lload(maxLocalsInOtherList + 1));
break;
case Opcodes.LLOAD_2:
newList.replace(i, factory.lload(maxLocalsInOtherList + 2));
break;
case Opcodes.LLOAD_3:
newList.replace(i, factory.lload(maxLocalsInOtherList + 3));
break;
case Opcodes.LLOAD:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
case Opcodes.LSTORE_0:
newList.replace(i, factory.lstore(maxLocalsInOtherList));
break;
case Opcodes.LSTORE_1:
newList.replace(i, factory.lstore(maxLocalsInOtherList + 1));
break;
case Opcodes.LSTORE_2:
newList.replace(i, factory.lstore(maxLocalsInOtherList + 2));
break;
case Opcodes.LSTORE_3:
newList.replace(i, factory.lstore(maxLocalsInOtherList + 3));
break;
case Opcodes.LSTORE:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
// -- FLOAD family --------------------------------------
case Opcodes.FLOAD_0:
newList.replace(i, factory.fload(maxLocalsInOtherList));
break;
case Opcodes.FLOAD_1:
newList.replace(i, factory.fload(maxLocalsInOtherList + 1));
break;
case Opcodes.FLOAD_2:
newList.replace(i, factory.fload(maxLocalsInOtherList + 2));
break;
case Opcodes.FLOAD_3:
newList.replace(i, factory.fload(maxLocalsInOtherList + 3));
break;
case Opcodes.FLOAD:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
case Opcodes.FSTORE_0:
newList.replace(i, factory.fstore(maxLocalsInOtherList));
break;
case Opcodes.FSTORE_1:
newList.replace(i, factory.fstore(maxLocalsInOtherList + 1));
break;
case Opcodes.FSTORE_2:
newList.replace(i, factory.fstore(maxLocalsInOtherList + 2));
break;
case Opcodes.FSTORE_3:
newList.replace(i, factory.fstore(maxLocalsInOtherList + 3));
break;
case Opcodes.FSTORE:
// Handle this differently. This
// form of handling does not break exception table
// So, we minimize damage by handling this differently
ins.getBytes()[1] += (byte)maxLocalsInOtherList;
break;
}
}