/** * Remembers to replace the instruction at the given offset by the given * instruction. */ private void replaceInstruction(int instructionOffset, Instruction instruction) { ensureCodeAttributeEditor(); // Replace the instruction. codeAttributeEditor.replaceInstruction(instructionOffset, instruction); }
/** * Starts a new code definition. */ public void reset() { maximumCodeLength = 0; codeLength = 0; exceptionTableLength = 0; lineNumberTableLength = 0; level = -1; // Make sure the instruction writer has at least the same buffer size // as the local arrays. instructionWriter.reset(code.length); }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Write out the instruction. instructionWriter.visitConstantInstruction(clazz, method, codeAttribute, newOffset, constantInstruction); newOffset += constantInstruction.length(newOffset); }
(1+2) + (1+4)); insertBeforeInstruction(offset, complementaryConditionalBranch); (1+2) + (1+4)); insertBeforeInstruction(offset, complementaryConditionalBranch); replaceInstruction(offset, replacementInstruction);
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction) { try { // Try to write out the instruction. variableInstruction.write(codeAttribute, offset); } catch (IllegalArgumentException exception) { // Create a new variable instruction that will fit. Instruction replacementInstruction = new VariableInstruction(variableInstruction.opcode, variableInstruction.variableIndex, variableInstruction.constant); replaceInstruction(offset, replacementInstruction); if (DEBUG) { System.out.println(" "+variableInstruction.toString(offset)+" will be widened to "+replacementInstruction.toString()); } // Write out a dummy variable instruction for now. variableInstruction.variableIndex = 0; variableInstruction.constant = 0; variableInstruction.write(codeAttribute, offset); } }
instructionWriter.visitCodeAttribute(clazz, method, codeAttribute);
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction) { // Write out the instruction. instructionWriter.visitSimpleInstruction(clazz, method, codeAttribute, newOffset, simpleInstruction); newOffset += simpleInstruction.length(newOffset); }
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction) { // Update the branch offset, relative to the precise new offset. branchInstruction.branchOffset = newBranchOffset(offset, branchInstruction.branchOffset, newOffset); // Write out the instruction. instructionWriter.visitBranchInstruction(clazz, method, codeAttribute, newOffset, branchInstruction); newOffset += branchInstruction.length(newOffset); }
public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) { // Adjust the default jump offset. lookUpSwitchInstruction.defaultOffset = remapBranchOffset(offset, lookUpSwitchInstruction.defaultOffset); // Adjust the jump offsets. remapJumpOffsets(offset, lookUpSwitchInstruction.jumpOffsets); // Write out the instruction. instructionWriter.visitLookUpSwitchInstruction(clazz, method, codeAttribute, newOffset, lookUpSwitchInstruction); newOffset += lookUpSwitchInstruction.length(newOffset); }
public void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction) { // Adjust the default jump offset. tableSwitchInstruction.defaultOffset = remapBranchOffset(offset, tableSwitchInstruction.defaultOffset); // Adjust the jump offsets. remapJumpOffsets(offset, tableSwitchInstruction.jumpOffsets); // Write out the instruction. instructionWriter.visitTableSwitchInstruction(clazz, method, codeAttribute, newOffset, tableSwitchInstruction); newOffset += tableSwitchInstruction.length(newOffset); }
(1+2) + (1+4)); insertBeforeInstruction(offset, complementaryConditionalBranch); (1+2) + (1+4)); insertBeforeInstruction(offset, complementaryConditionalBranch); 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); if (DEBUG) { System.out.println(" "+constantInstruction.toString(offset)+" will be widened to "+replacementInstruction.toString()); } replaceInstruction(offset, replacementInstruction); // Write out a dummy constant instruction for now. constantInstruction.constantIndex = 0; constantInstruction.constant = 0; constantInstruction.write(codeAttribute, offset); } }
instructionWriter.visitCodeAttribute(clazz, method, codeAttribute);
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction) { // Write out the instruction. instructionWriter.visitSimpleInstruction(clazz, method, codeAttribute, newOffset, simpleInstruction); newOffset += simpleInstruction.length(newOffset); }
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction) { // Adjust the branch offset. branchInstruction.branchOffset = remapBranchOffset(offset, branchInstruction.branchOffset); // Write out the instruction. instructionWriter.visitBranchInstruction(clazz, method, codeAttribute, newOffset, branchInstruction); newOffset += branchInstruction.length(newOffset); }
public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction) { // Update the default jump offset, relative to the precise new offset. lookUpSwitchInstruction.defaultOffset = newBranchOffset(offset, lookUpSwitchInstruction.defaultOffset, newOffset); // Update the jump offsets, relative to the precise new offset. newJumpOffsets(offset, lookUpSwitchInstruction.jumpOffsets, newOffset); // Write out the instruction. instructionWriter.visitLookUpSwitchInstruction(clazz, method, codeAttribute, newOffset, lookUpSwitchInstruction); newOffset += lookUpSwitchInstruction.length(newOffset); }
public void visitTableSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, TableSwitchInstruction tableSwitchInstruction) { // Update the default jump offset, relative to the precise new offset. tableSwitchInstruction.defaultOffset = newBranchOffset(offset, tableSwitchInstruction.defaultOffset, newOffset); // Update the jump offsets, relative to the precise new offset. newJumpOffsets(offset, tableSwitchInstruction.jumpOffsets, newOffset); // Write out the instruction. instructionWriter.visitTableSwitchInstruction(clazz, method, codeAttribute, newOffset, tableSwitchInstruction); newOffset += tableSwitchInstruction.length(newOffset); }
(1+2) + (1+4)); insertBeforeInstruction(offset, complementaryConditionalBranch); (1+2) + (1+4)); insertBeforeInstruction(offset, complementaryConditionalBranch); replaceInstruction(offset, replacementInstruction);
/** * Remembers to replace the instruction at the given offset by the given * instruction. */ private void replaceInstruction(int instructionOffset, Instruction instruction) { ensureCodeAttributeEditor(); // Replace the instruction. codeAttributeEditor.replaceInstruction(instructionOffset, instruction); }
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); if (DEBUG) { System.out.println(" "+constantInstruction.toString(offset)+" will be widened to "+replacementInstruction.toString()); } replaceInstruction(offset, replacementInstruction); // Write out a dummy constant instruction for now. constantInstruction.constantIndex = 0; constantInstruction.constant = 0; constantInstruction.write(codeAttribute, offset); } }