/** * Creates a new {@link Label}. * * @return a new {@link Label}. */ public Label newLabel() { return new Label(); }
public Label getLabel() { if (label == null) { label = new Label(); } return label; }
/** * Returns the label corresponding to the given offset. The default * implementation of this method creates a label for the given offset if it * has not been already created. * * @param offset * a bytecode offset in a method. * @param labels * the already created labels, indexed by their offset. If a * label already exists for offset this method must not create a * new one. Otherwise it must store the new label in this array. * @return a non null Label, which must be equal to labels[offset]. */ protected Label readLabel(int offset, Label[] labels) { if (labels[offset] == null) { labels[offset] = new Label(); } return labels[offset]; }
/** * Marks the current code position with a new label. * * @return the label that was created to mark the current code position. */ public Label mark() { Label label = new Label(); mv.visitLabel(label); return label; }
@Override public void visitTypeInsn(final int opcode, final String type) { if (opcode == Opcodes.NEW) { if (labels == null) { Label l = new Label(); labels = new ArrayList<Label>(3); labels.add(l); if (mv != null) { mv.visitLabel(l); } } for (int i = 0; i < labels.size(); ++i) { uninitializedTypes.put(labels.get(i), type); } } if (mv != null) { mv.visitTypeInsn(opcode, type); } execute(opcode, 0, type); }
/** * Ends the current basic block. This method must be used in the case where * the current basic block does not have any successor. */ private void noSuccessor() { if (compute == FRAMES) { Label l = new Label(); l.frame = new Frame(); l.frame.owner = l; l.resolve(this, code.length, code.data); previousBlock.successor = l; previousBlock = l; } else { currentBlock.outputStackMax = maxStackSize; } currentBlock = null; }
private static void defineNewArray(Class<?> clazz, String classNameInternal,ClassWriter cw){ MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newArray", "(I)Ljava/lang/Object;", null, null); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ILOAD, 1); if(clazz.isPrimitive()){ mv.visitIntInsn(Opcodes.NEWARRAY,getPrimitiveTypeCode(clazz)); }else{ mv.visitTypeInsn(ANEWARRAY, classNameInternal); } mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0); mv.visitLocalVariable("length", "I", null, l0, l1, 1); mv.visitMaxs(1, 2); mv.visitEnd(); }
currentLocals = size; labels = new Label(); labels.status |= Label.PUSHED; visitLabel(labels);
Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0); }else{ mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0);
Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKEVIRTUAL, wraperTypeInternalName, unboxMethodName, "()" + primitiveInternalName); mv.visitInsn(opcode); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l2, 0); }else{ mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitVarInsn(ALOAD, 3); mv.visitInsn(Opcodes.AASTORE); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l2, 0);
Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, wraperTypeInternalName, "valueOf", "(" + primitiveInternalName + ")L" + wraperTypeInternalName + ";"); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0); }else{ mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(AALOAD); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0);
visitLabel(new Label());