public int length(int offset) { int newOffset = offset; for (int index = 0; index < instructions.length; index++) { newOffset += instructions[index].length(newOffset); } return newOffset - offset; }
public int length(int offset) { int newOffset = offset; for (int index = 0; index < instructions.length; index++) { newOffset += instructions[index].length(newOffset); } return newOffset - offset; }
public int length(int offset) { int newOffset = offset; for (int index = 0; index < instructions.length; index++) { newOffset += instructions[index].length(newOffset); } return newOffset - offset; }
public int length(int offset) { int newOffset = offset; for (int index = 0; index < instructions.length; index++) { newOffset += instructions[index].length(newOffset); } return newOffset - offset; }
public void write(byte[] code, int offset) { for (int index = 0; index < instructions.length; index++) { Instruction instruction = instructions[index]; instruction.write(code, offset); offset += instruction.length(offset); } }
public void write(byte[] code, int offset) { for (int index = 0; index < instructions.length; index++) { Instruction instruction = instructions[index]; instruction.write(code, offset); offset += instruction.length(offset); } }
public void write(byte[] code, int offset) { for (int index = 0; index < instructions.length; index++) { Instruction instruction = instructions[index]; instruction.write(code, offset); offset += instruction.length(offset); } }
public void write(byte[] code, int offset) { for (int index = 0; index < instructions.length; index++) { Instruction instruction = instructions[index]; instruction.write(code, offset); offset += instruction.length(offset); } }
public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, InstructionVisitor instructionVisitor) { if (instructionVisitor != CodeAttributeEditor.this) { throw new UnsupportedOperationException("Unexpected visitor ["+instructionVisitor+"]"); } for (int index = 0; index < instructions.length; index++) { Instruction instruction = instructions[index]; instruction.accept(clazz, method, codeAttribute, offset, CodeAttributeEditor.this); offset += instruction.length(offset); } }
/** * Applies the given instruction visitor to all instructions in the * specified range of offsets. */ public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor) { int offset = startOffset; while (offset < endOffset) { // Note that the instruction is only volatile. Instruction instruction = InstructionFactory.create(code, offset); int instructionLength = instruction.length(offset); instruction.accept(clazz, method, this, offset, instructionVisitor); offset += instructionLength; } }
/** * Applies the given instruction visitor to all instructions in the * specified range of offsets. */ public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor) { int offset = startOffset; while (offset < endOffset) { // Note that the instruction is only volatile. Instruction instruction = InstructionFactory.create(code, offset); int instructionLength = instruction.length(offset); instruction.accept(clazz, method, this, offset, instructionVisitor); offset += instructionLength; } }
/** * Applies the given instruction visitor to all instructions in the * specified range of offsets. */ public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor) { int offset = startOffset; while (offset < endOffset) { // Note that the instruction is only volatile. Instruction instruction = InstructionFactory.create(code, offset); int instructionLength = instruction.length(offset); instruction.accept(clazz, method, this, offset, instructionVisitor); offset += instructionLength; } }
/** * Applies the given instruction visitor to all instructions in the * specified range of offsets. */ public void instructionsAccept(Clazz clazz, Method method, int startOffset, int endOffset, InstructionVisitor instructionVisitor) { int offset = startOffset; while (offset < endOffset) { // Note that the instruction is only volatile. Instruction instruction = InstructionFactory.create(code, offset); int instructionLength = instruction.length(offset); instruction.accept(clazz, method, this, offset, instructionVisitor); offset += instructionLength; } }
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { boolean delegateVisit = false; // Directly iterate of all instructions and exit early if // we encounter a "NEWARRAY" instruction. for (int offset = 0; offset < codeAttribute.u4codeLength;) { Instruction instruction = InstructionFactory.create(codeAttribute.code, offset); if (instruction.opcode == InstructionConstants.OP_NEWARRAY) { delegateVisit = true; break; } offset += instruction.length(offset); } if (delegateVisit) { acceptedVisitor.visitCodeAttribute(clazz, method, codeAttribute); } } }
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { boolean delegateVisit = false; // Directly iterate of all instructions and exit early if // we encounter a "NEWARRAY" instruction. for (int offset = 0; offset < codeAttribute.u4codeLength;) { Instruction instruction = InstructionFactory.create(codeAttribute.code, offset); if (instruction.opcode == InstructionConstants.OP_NEWARRAY) { delegateVisit = true; break; } offset += instruction.length(offset); } if (delegateVisit) { acceptedVisitor.visitCodeAttribute(clazz, method, codeAttribute); } } }
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { boolean delegateVisit = false; // Directly iterate of all instructions and exit early if // we encounter a "NEWARRAY" instruction. for (int offset = 0; offset < codeAttribute.u4codeLength;) { Instruction instruction = InstructionFactory.create(codeAttribute.code, offset); if (instruction.opcode == InstructionConstants.OP_NEWARRAY) { delegateVisit = true; break; } offset += instruction.length(offset); } if (delegateVisit) { acceptedVisitor.visitCodeAttribute(clazz, method, codeAttribute); } } }
/** * Returns whether the specified block of code may throw exceptions. */ private boolean mayThrowExceptions(Clazz clazz, Method method, CodeAttribute codeAttribute, int startOffset, int endOffset) { byte[] code = codeAttribute.code; // Go over all instructions. int offset = startOffset; while (offset < endOffset) { // Get the current instruction. Instruction instruction = InstructionFactory.create(code, offset); // Check if it may be throwing exceptions. if (instruction.mayThrowExceptions()) { return true; } // Go to the next instruction. offset += instruction.length(offset); } return false; }
/** * Returns whether the specified block of code may throw exceptions. */ private boolean mayThrowExceptions(Clazz clazz, Method method, CodeAttribute codeAttribute, int startOffset, int endOffset) { byte[] code = codeAttribute.code; // Go over all instructions. int offset = startOffset; while (offset < endOffset) { // Get the current instruction. Instruction instruction = InstructionFactory.create(code, offset); // Check if it may be throwing exceptions. if (instruction.mayThrowExceptions()) { return true; } // Go to the next instruction. offset += instruction.length(offset); } return false; }
/** * Returns whether the specified block of code may throw exceptions. */ private boolean mayThrowExceptions(Clazz clazz, Method method, CodeAttribute codeAttribute, int startOffset, int endOffset) { byte[] code = codeAttribute.code; // Go over all instructions. int offset = startOffset; while (offset < endOffset) { // Get the current instruction. Instruction instruction = InstructionFactory.create(code, offset); // Check if it may be throwing exceptions. if (instruction.mayThrowExceptions()) { return true; } // Go to the next instruction. offset += instruction.length(offset); } return false; }
/** * Fills out the instruction offset map for the given code block. * @param oldCode the instructions to be moved. * @param oldLength the code length. * @return the new code length. */ private int mapInstructions(byte[] oldCode, int oldLength) { // Start mapping instructions at the beginning. newOffset = 0; lengthIncreased = false; int oldOffset = 0; do { // Get the next instruction. Instruction instruction = InstructionFactory.create(oldCode, oldOffset); // Compute the mapping of the instruction. mapInstruction(oldOffset, instruction); oldOffset += instruction.length(oldOffset); if (newOffset > oldOffset) { lengthIncreased = true; } } while (oldOffset < oldLength); // Also add an entry for the first offset after the code. newInstructionOffsets[oldOffset] = newOffset; return newOffset; }