/** * Visits a jump instruction. A jump instruction is an instruction that may jump to another * instruction. * * @param opcode the opcode of the type instruction to be visited. This opcode is either IFEQ, * IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, * IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL. * @param label the operand of the instruction to be visited. This operand is a label that * designates the instruction to which the jump instruction may jump. */ public void visitJumpInsn(final int opcode, final Label label) { if (mv != null) { mv.visitJumpInsn(opcode, label); } }
/** * Visits a jump instruction. A jump instruction is an instruction that may jump to another * instruction. * * @param opcode the opcode of the type instruction to be visited. This opcode is either IFEQ, * IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, * IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL. * @param label the operand of the instruction to be visited. This operand is a label that * designates the instruction to which the jump instruction may jump. */ public void visitJumpInsn(final int opcode, final Label label) { if (mv != null) { mv.visitJumpInsn(opcode, label); } }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { this.children[0].generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitJumpInsn(IFNE,elseTarget); mv.visitInsn(ICONST_1); // TRUE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); // FALSE mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
skipIfNull = new Label(); Label continueLabel = new Label(); mv.visitJumpInsn(IFNONNULL, continueLabel); CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor); mv.visitJumpInsn(GOTO, skipIfNull); mv.visitLabel(continueLabel);
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { PropertyAccessor accessorToUse = this.cachedReadAccessor; if (!(accessorToUse instanceof CompilablePropertyAccessor)) { throw new IllegalStateException("Property accessor is not compilable: " + accessorToUse); } Label skipIfNull = null; if (this.nullSafe) { mv.visitInsn(DUP); skipIfNull = new Label(); Label continueLabel = new Label(); mv.visitJumpInsn(IFNONNULL, continueLabel); CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor); mv.visitJumpInsn(GOTO, skipIfNull); mv.visitLabel(continueLabel); } ((CompilablePropertyAccessor) accessorToUse).generateCode(this.name, mv, cf); cf.pushDescriptor(this.exitTypeDescriptor); if (this.originalPrimitiveExitTypeDescriptor != null) { // The output of the accessor is a primitive but from the block above it might be null, // so to have a common stack element type at skipIfNull target it is necessary // to box the primitive CodeFlow.insertBoxIfNecessary(mv, this.originalPrimitiveExitTypeDescriptor); } if (skipIfNull != null) { mv.visitLabel(skipIfNull); } }
if (targetType == 'D') { mv.visitInsn(DCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); mv.visitJumpInsn(compInstruction1, elseTarget); mv.visitJumpInsn(compInstruction1, elseTarget); mv.visitJumpInsn(compInstruction2, elseTarget); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0);
mv.visitJumpInsn(IFNE, notZero); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, end); mv.visitLabel(notZero); mv.visitInsn(ICONST_0);
Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitJumpInsn(IFEQ, elseTarget); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope();
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { this.children[0].generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitJumpInsn(IFNE,elseTarget); mv.visitInsn(ICONST_1); // TRUE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0); // FALSE mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
Label endOfIf = new Label(); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, elseTarget); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false); mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget mv.visitLabel(elseTarget); mv.visitInsn(POP);
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; } Label elseTarget = new Label(); Label endOfIf = new Label(); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitJumpInsn(IFNE, elseTarget); mv.visitLdcInsn(0); // FALSE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
skipIfNull = new Label(); Label continueLabel = new Label(); mv.visitJumpInsn(IFNONNULL, continueLabel); CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor); mv.visitJumpInsn(GOTO, skipIfNull); mv.visitLabel(continueLabel);
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; } Label elseTarget = new Label(); Label endOfIf = new Label(); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitJumpInsn(IFEQ, elseTarget); mv.visitLdcInsn(1); // TRUE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { PropertyAccessor accessorToUse = this.cachedReadAccessor; if (!(accessorToUse instanceof CompilablePropertyAccessor)) { throw new IllegalStateException("Property accessor is not compilable: " + accessorToUse); } Label skipIfNull = null; if (this.nullSafe) { mv.visitInsn(DUP); skipIfNull = new Label(); Label continueLabel = new Label(); mv.visitJumpInsn(IFNONNULL, continueLabel); CodeFlow.insertCheckCast(mv, this.exitTypeDescriptor); mv.visitJumpInsn(GOTO, skipIfNull); mv.visitLabel(continueLabel); } ((CompilablePropertyAccessor) accessorToUse).generateCode(this.name, mv, cf); cf.pushDescriptor(this.exitTypeDescriptor); if (this.originalPrimitiveExitTypeDescriptor != null) { // The output of the accessor is a primitive but from the block above it might be null, // so to have a common stack element type at skipIfNull target it is necessary // to box the primitive CodeFlow.insertBoxIfNecessary(mv, this.originalPrimitiveExitTypeDescriptor); } if (skipIfNull != null) { mv.visitLabel(skipIfNull); } }
mv.visitJumpInsn(IFNE, notZero); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, end); mv.visitLabel(notZero); mv.visitInsn(ICONST_0);
if (targetType == 'D') { mv.visitInsn(DCMPG); mv.visitJumpInsn(compInstruction1, elseTarget); mv.visitJumpInsn(compInstruction1, elseTarget); mv.visitJumpInsn(compInstruction1, elseTarget); mv.visitJumpInsn(compInstruction2, elseTarget); mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); mv.visitInsn(ICONST_0);
Label elseTarget = new Label(); Label endOfIf = new Label(); mv.visitJumpInsn(IFEQ, elseTarget); cf.enterCompilationScope(); this.children[1].generateCode(mv, cf); mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope();
Label endOfIf = new Label(); mv.visitInsn(DUP); mv.visitJumpInsn(IFNULL, elseTarget); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false); mv.visitJumpInsn(IFEQ, endOfIf); // if not empty, drop through to elseTarget mv.visitLabel(elseTarget); mv.visitInsn(POP);
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; } Label elseTarget = new Label(); Label endOfIf = new Label(); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitJumpInsn(IFEQ, elseTarget); mv.visitLdcInsn(1); // TRUE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
@Override public void generateCode(MethodVisitor mv, CodeFlow cf) { // Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; } Label elseTarget = new Label(); Label endOfIf = new Label(); cf.enterCompilationScope(); getLeftOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitJumpInsn(IFNE, elseTarget); mv.visitLdcInsn(0); // FALSE mv.visitJumpInsn(GOTO,endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); getRightOperand().generateCode(mv, cf); cf.unboxBooleanIfNecessary(mv); cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }