/** * Replaces the instruction at a given offset by a static invocation. */ private void replaceByStaticInvocation(Clazz clazz, int offset, ConstantInstruction constantInstruction) { // Remember the replacement instruction. Instruction replacementInstruction = new ConstantInstruction(InstructionConstants.OP_INVOKESTATIC, constantInstruction.constantIndex).shrink(); if (DEBUG) System.out.println(" Replacing by static invocation "+constantInstruction.toString(offset)+" -> "+replacementInstruction.toString()); codeAttributeEditor.replaceInstruction(offset, replacementInstruction); }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Create a copy of the instruction. Instruction newConstantInstruction = new ConstantInstruction(constantInstruction.opcode, constantAdder.addConstant(clazz, constantInstruction.constantIndex), constantInstruction.constant).shrink(); // Add the instruction. codeAttributeComposer.appendInstruction(offset, newConstantInstruction); } }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Is the new constant pool index different from the original one? int newConstantIndex = remapConstantIndex(constantInstruction.constantIndex); if (newConstantIndex != constantInstruction.constantIndex) { // Replace the instruction. Instruction replacementInstruction = new ConstantInstruction(constantInstruction.opcode, newConstantIndex, constantInstruction.constant).shrink(); codeAttributeEditor.replaceInstruction(offset, replacementInstruction); } }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { try { // Try to write out the instruction. constantInstruction.write(codeAttribute, offset); } catch (IllegalArgumentException exception) { // Create a new constant instruction that will fit. Instruction replacementInstruction = new ConstantInstruction(constantInstruction.opcode, constantInstruction.constantIndex, constantInstruction.constant).shrink(); replaceInstruction(offset, replacementInstruction); // Write out a dummy constant instruction for now. constantInstruction.constantIndex = 0; constantInstruction.constant = 0; constantInstruction.write(codeAttribute, offset); } }
codeAttributeComposer.appendInstruction(offset, constantInstruction.shrink());
constantPoolEditor.addFloatConstant(value)).shrink();
constantPoolEditor.addIntegerConstant(value)).shrink();
constantPoolEditor.addLongConstant(value)).shrink();
constantPoolEditor.addDoubleConstant(value)).shrink();
codeAttributeComposer.appendInstruction(offset, constantInstruction.shrink());