@Override public final MethodVisitor visitMethod( final int access, final String name, final String descriptor, final String signature, final String[] exceptions) { MethodWriter methodWriter = new MethodWriter(symbolTable, access, name, descriptor, signature, exceptions, compute); if (firstMethod == null) { firstMethod = methodWriter; } else { lastMethod.mv = methodWriter; } return lastMethod = methodWriter; }
addSuccessorToCurrentBasicBlock(Edge.JUMP, label); if (baseOpcode != Opcodes.GOTO) { addSuccessorToCurrentBasicBlock(relativeStackSize + 1, label); addSuccessorToCurrentBasicBlock(relativeStackSize, label); nextBasicBlock.flags |= Label.FLAG_JUMP_TARGET; visitLabel(nextBasicBlock); endCurrentBasicBlockWithNoSuccessor();
@Override public void visitTableSwitchInsn( final int min, final int max, final Label dflt, final Label... labels) { lastBytecodeOffset = code.length; // Add the instruction to the bytecode of the method. code.putByte(Opcodes.TABLESWITCH).putByteArray(null, 0, (4 - code.length % 4) % 4); dflt.put(code, lastBytecodeOffset, true); code.putInt(min).putInt(max); for (Label label : labels) { label.put(code, lastBytecodeOffset, true); } // If needed, update the maximum stack size and number of locals, and stack map frames. visitSwitchInsn(dflt, labels); }
@Override public void visitMaxs(final int maxStack, final int maxLocals) { if (compute == COMPUTE_ALL_FRAMES) { computeAllFrames(); } else if (compute == COMPUTE_MAX_STACK_AND_LOCAL) { computeMaxStackAndLocal(); } else if (compute == COMPUTE_MAX_STACK_AND_LOCAL_FROM_FRAMES) { this.maxStack = maxRelativeStackSize; } else { this.maxStack = maxStack; this.maxLocals = maxLocals; } }
private void visitSwitchInsn(final Label dflt, final Label[] labels) { if (currentBasicBlock != null) { if (compute == COMPUTE_ALL_FRAMES) { currentBasicBlock.frame.execute(Opcodes.LOOKUPSWITCH, 0, null, null); // Add all the labels as successors of the current basic block. addSuccessorToCurrentBasicBlock(Edge.JUMP, dflt); dflt.getCanonicalInstance().flags |= Label.FLAG_JUMP_TARGET; for (Label label : labels) { addSuccessorToCurrentBasicBlock(Edge.JUMP, label); label.getCanonicalInstance().flags |= Label.FLAG_JUMP_TARGET; } } else if (compute == COMPUTE_MAX_STACK_AND_LOCAL) { // No need to update maxRelativeStackSize (the stack size delta is always negative). --relativeStackSize; // Add all the labels as successors of the current basic block. addSuccessorToCurrentBasicBlock(relativeStackSize, dflt); for (Label label : labels) { addSuccessorToCurrentBasicBlock(relativeStackSize, label); } } // End the current basic block. endCurrentBasicBlockWithNoSuccessor(); } }
endCurrentBasicBlockWithNoSuccessor(); } else { // xLOAD or xSTORE int size = relativeStackSize + STACK_SIZE_DELTA[opcode]; visitLabel(new Label());
while (methodWriter != null) { ++methodsCount; size += methodWriter.computeMethodInfoSize(); methodWriter = (MethodWriter) methodWriter.mv; methodWriter = firstMethod; while (methodWriter != null) { hasFrames |= methodWriter.hasFrames(); hasAsmInstructions |= methodWriter.hasAsmInstructions(); methodWriter.putMethodInfo(result); methodWriter = (MethodWriter) methodWriter.mv;
visitLabel(firstBasicBlock);
addSuccessor(Edge.NORMAL, label); if (opcode != Opcodes.GOTO) { addSuccessor(stackSize + 1, label); addSuccessor(stackSize, label); visitLabel(nextInsn); noSuccessor();
noSuccessor(); } else { // xLOAD or xSTORE int size = stackSize + Frame.SIZE[opcode]; visitLabel(new Label());
/** * Returns the prototypes of the attributes used by this class, its fields and its methods. * * @return the prototypes of the attributes used by this class, its fields and its methods. */ private Attribute[] getAttributePrototypes() { Attribute.Set attributePrototypes = new Attribute.Set(); attributePrototypes.addAttributes(firstAttribute); FieldWriter fieldWriter = firstField; while (fieldWriter != null) { fieldWriter.collectAttributePrototypes(attributePrototypes); fieldWriter = (FieldWriter) fieldWriter.fv; } MethodWriter methodWriter = firstMethod; while (methodWriter != null) { methodWriter.collectAttributePrototypes(attributePrototypes); methodWriter = (MethodWriter) methodWriter.mv; } return attributePrototypes.toArray(); }
@Override public void visitInsn(final int opcode) { lastBytecodeOffset = code.length; // Add the instruction to the bytecode of the method. code.putByte(opcode); // If needed, update the maximum stack size and number of locals, and stack map frames. if (currentBasicBlock != null) { if (compute == COMPUTE_ALL_FRAMES || compute == COMPUTE_INSERTED_FRAMES) { currentBasicBlock.frame.execute(opcode, 0, null, null); } else { int size = relativeStackSize + STACK_SIZE_DELTA[opcode]; if (size > maxRelativeStackSize) { maxRelativeStackSize = size; } relativeStackSize = size; } if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN) || opcode == Opcodes.ATHROW) { endCurrentBasicBlockWithNoSuccessor(); } } }
addSuccessorToCurrentBasicBlock(Edge.JUMP, label); addSuccessorToCurrentBasicBlock(relativeStackSize, label);
if (methodWriter.canCopyMethodAttributes( this, methodInfoOffset,
while (methodWriter != null) { ++methodsCount; size += methodWriter.computeMethodInfoSize(); methodWriter = (MethodWriter) methodWriter.mv; methodWriter = firstMethod; while (methodWriter != null) { hasFrames |= methodWriter.hasFrames(); hasAsmInstructions |= methodWriter.hasAsmInstructions(); methodWriter.putMethodInfo(result); methodWriter = (MethodWriter) methodWriter.mv;
endCurrentBasicBlockWithNoSuccessor(); } else { // xLOAD or xSTORE int size = relativeStackSize + STACK_SIZE_DELTA[opcode]; visitLabel(new Label());
addSuccessor(Edge.NORMAL, label); if (opcode != Opcodes.GOTO) { addSuccessor(stackSize + 1, label); addSuccessor(stackSize, label); visitLabel(nextInsn); noSuccessor();
noSuccessor(); } else { // xLOAD or xSTORE int size = stackSize + Frame.SIZE[opcode]; visitLabel(new Label());
@Override public void visitMaxs(final int maxStack, final int maxLocals) { if (compute == COMPUTE_ALL_FRAMES) { computeAllFrames(); } else if (compute == COMPUTE_MAX_STACK_AND_LOCAL) { computeMaxStackAndLocal(); } else if (compute == COMPUTE_MAX_STACK_AND_LOCAL_FROM_FRAMES) { this.maxStack = maxRelativeStackSize; } else { this.maxStack = maxStack; this.maxLocals = maxLocals; } }