private Label jitLeftIsNull(Label nullLabel) { Label notNullLabel = new Label(); mv.visitJumpInsn(GOTO, notNullLabel); mv.visitLabel(nullLabel); return notNullLabel; }
private void jitNegation() { Label trueBranch = new Label(); Label falseBranch = new Label(); mv.visitJumpInsn(IFNE, trueBranch); mv.visitInsn(ICONST_1); mv.visitJumpInsn(GOTO, falseBranch); mv.visitLabel(trueBranch); mv.visitInsn(ICONST_0); mv.visitLabel(falseBranch); }
private Label jitNullSafeOperationStart() { Label nullLabel = new Label(); load(LEFT_OPERAND); mv.visitJumpInsn(IFNULL, nullLabel); return nullLabel; }
private void prepareLeftOperand(BooleanOperator operation, Class<?> type, Class<?> leftType, Class<?> rightType, Label shortcutEvaluation) { if (leftType.isPrimitive()) { if (type != null) { castOrCoercePrimitive(LEFT_OPERAND, leftType, type); } return; } Label notNullLabel = jitLeftIsNull(type == null || leftType == type ? jitNullSafeOperationStart() : jitNullSafeCoercion(leftType, type)); if (operation.isEquality() && !rightType.isPrimitive()) { // if (left == null) return right == null checkNullEquality(); } else { // if (left == null) return false mv.visitInsn(ICONST_0); } mv.visitJumpInsn(GOTO, shortcutEvaluation); mv.visitLabel(notNullLabel); }
switch (type.getSort()) { case Type.LONG: mv.visitInsn(Opcodes.LCMP); break; case Type.DOUBLE: mv.visitInsn(mode == GE || mode == GT ? Opcodes.DCMPL : Opcodes.DCMPG); break; case Type.FLOAT: mv.visitInsn(mode == GE || mode == GT ? Opcodes.FCMPL : Opcodes.FCMPG); break; switch (mode) { case EQ: mv.visitJumpInsn(Opcodes.IF_ACMPEQ, label); return; case NE: mv.visitJumpInsn(Opcodes.IF_ACMPNE, label); return; break; mv.visitJumpInsn(intOp, label); return; mv.visitJumpInsn(mode, label);
private void checkNullEquality() { Label rightNullLabel = new Label(); Label rightNotNullLabel = new Label(); load(RIGHT_OPERAND); mv.visitJumpInsn(IFNULL, rightNullLabel); mv.visitInsn(ICONST_0); mv.visitJumpInsn(GOTO, rightNotNullLabel); mv.visitLabel(rightNullLabel); mv.visitInsn(ICONST_1); mv.visitLabel(rightNotNullLabel); }
Label l0 = null; if ( ! BuildUtils.isPrimitive( fld.getTypeName() ) ) { l0 = new Label(); mv.visitJumpInsn( IFNONNULL, l0 ); "(" + BuildUtils.getTypeDescriptor( fld.getTypeName() ) + ")" + Type.getDescriptor( void.class ) ); if ( ! BuildUtils.isPrimitive( fld.getTypeName() ) ) { mv.visitLabel( l0 );
getCodeVisitor().visitInsn(o.opcode); break; getCodeVisitor().visitJumpInsn(o.opcode, getLabel(attrs.getValue("label"))); break;
private Label jitNullSafeCoercion(Class<?> fromType, Class<?> toType) { Label nullLabel = new Label(); load(LEFT_OPERAND); mv.visitJumpInsn(IFNULL, nullLabel); castOrCoerceTo(LEFT_OPERAND, fromType, toType, nullLabel); return nullLabel; }
private void jitPrimitiveOperation(BooleanOperator op, Class<?> type) { int opCode = toOpCode(op, type); Label trueBranchLabel = new Label(); Label returnLabel = new Label(); if (type == double.class) { mv.visitInsn(DCMPL); } else if (type == long.class) { mv.visitInsn(LCMP); } else if (type == float.class) { mv.visitInsn(FCMPL); } mv.visitJumpInsn(opCode, trueBranchLabel); mv.visitInsn(ICONST_0); mv.visitJumpInsn(GOTO, returnLabel); mv.visitLabel(trueBranchLabel); mv.visitInsn(ICONST_1); mv.visitLabel(returnLabel); }
l0 = new Label(); mv.visitJumpInsn( IFNONNULL, l0 ); "(" + BuildUtils.getTypeDescriptor( fld.getTypeName() ) + ")" + Type.getDescriptor( void.class ) ); if ( ! BuildUtils.isPrimitive( fld.getTypeName() ) ) { mv.visitLabel( l0 );
private void jitCombinedCondition(CombinedCondition combinedCondition) { boolean isAnd = combinedCondition.isAnd(); Label shortcut = new Label(); Label noShortcut = new Label(); for (Condition condition : combinedCondition.getConditions()) { jitCondition(condition); mv.visitJumpInsn(isAnd ? IFEQ : IFNE, shortcut); } mv.visitInsn(isAnd ? ICONST_1 : ICONST_0); mv.visitJumpInsn(GOTO, noShortcut); mv.visitLabel(shortcut); mv.visitInsn(isAnd ? ICONST_0 : ICONST_1); mv.visitLabel(noShortcut); }
private void prepareRightOperand(Expression right, Class<?> type, Class<?> rightType, Label shortcutEvaluation) { if (rightType.isPrimitive()) { if (type != null) { castOrCoercePrimitive(RIGHT_OPERAND, rightType, type); } return; } Label nullLabel = new Label(); Label notNullLabel = new Label(); load(RIGHT_OPERAND); mv.visitJumpInsn(IFNULL, nullLabel); if (type != null && !isFixed(right) && rightType != type) { castOrCoerceTo(RIGHT_OPERAND, rightType, type, nullLabel); } mv.visitJumpInsn(GOTO, notNullLabel); mv.visitLabel(nullLabel); mv.visitInsn(ICONST_0); mv.visitJumpInsn(GOTO, shortcutEvaluation); mv.visitLabel(notNullLabel); }
protected void invokeContainsKey( MethodVisitor mv, String fieldName ) { mv.visitLdcInsn( fieldName ); mv.visitVarInsn( ALOAD, 1 ); mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( String.class ), "equals", "(" + Type.getDescriptor( Object.class ) + ")Z" ); Label l0 = new Label(); mv.visitJumpInsn( IFEQ, l0 ); mv.visitInsn( ICONST_1 ); mv.visitInsn( IRETURN ); mv.visitLabel( l0 ); }
protected void invokeContainsKey( MethodVisitor mv, String fieldName ) { mv.visitLdcInsn( fieldName ); mv.visitVarInsn( ALOAD, 1 ); mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( String.class ), "equals", "(" + Type.getDescriptor( Object.class ) + ")Z" ); Label l0 = new Label(); mv.visitJumpInsn( IFEQ, l0 ); mv.visitInsn( ICONST_1 ); mv.visitInsn( IRETURN ); mv.visitLabel( l0 ); }
private void castOrCoerceTo(int regNr, Class<?> fromType, Class<?> toType, Label nullLabel) { Label nonInstanceOfLabel = new Label(); Label endOfCoercionLabel = new Label(); load(regNr); instanceOf(toType); mv.visitJumpInsn(IFEQ, nonInstanceOfLabel); load(regNr); cast(toType); store(regNr, toType); mv.visitJumpInsn(GOTO, endOfCoercionLabel); mv.visitLabel(nonInstanceOfLabel); mv.visitInsn(DUP); load(regNr); coerceByConstructor(fromType, toType); Label afterCatch = new Label(); mv.visitLabel(tryOk); mv.visitJumpInsn(GOTO, afterCatch); mv.visitLabel(inCatch); mv.visitInsn(POP); mv.visitInsn(ACONST_NULL); mv.visitVarInsn(ASTORE, regNr); mv.visitJumpInsn(GOTO, nullLabel); mv.visitLabel(afterCatch);
@Override public void body(MethodVisitor mv) { Label l1 = new Label(); Label l2 = new Label(); mv.visitVarInsn(ALOAD, 1); // if (object == null) mv.visitJumpInsn(IFNULL, l1); mv.visitVarInsn(ALOAD, 1); instanceOf(CompiledInvoker.class); mv.visitJumpInsn(IFNE, l2); // if (!(object instanceof org.drools.spi.CompiledInvoker)) mv.visitLabel(l1); mv.visitInsn(ICONST_0); // return false mv.visitInsn(IRETURN); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 0); invokeThis("getMethodBytecode", List.class); mv.visitVarInsn(ALOAD, 1); cast(CompiledInvoker.class); invokeInterface(CompiledInvoker.class, "getMethodBytecode", List.class); invokeStatic(MethodComparator.class, "compareBytecode", Boolean.TYPE, List.class, List.class); // return MethodComparator.compareBytecode(getMethodBytecode(), ((CompiledInvoker)object).getMethodBytecode()); mv.visitInsn(IRETURN); } }
private void ldcClassConstant(Class cls) { if (OPCODES_VERSION == Opcodes.V1_4) { assert debug("LDC \"" + cls.getName() + "\""); mv.visitLdcInsn(cls.getName()); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); Label l4 = new Label(); mv.visitJumpInsn(GOTO, l4); mv.visitTypeInsn(NEW, "java/lang/NoClassDefFoundError"); mv.visitInsn(DUP_X1); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NoClassDefFoundError", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l4); } else { assert debug("LDC " + getType(cls)); mv.visitLdcInsn(getType(cls)); } }
mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, 5); mv.visitVarInsn(ALOAD, 7); mv.visitInsn(ARRAYLENGTH); mv.visitVarInsn(ISTORE, 6); Label l1 = new Label(); mv.visitJumpInsn(GOTO, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitVarInsn(ALOAD, 7); mv.visitVarInsn(ILOAD, 5); mv.visitInsn(AALOAD); mv.visitVarInsn(ASTORE, 4); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLdcInsn(m.getName()); mv.visitVarInsn(ALOAD, 4); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z"); Label l4 = new Label(); mv.visitJumpInsn(IFEQ, l4); Label l5 = new Label(); mv.visitLabel(l5); mv.visitVarInsn(ALOAD, 4); mv.visitInsn(ARETURN); mv.visitVarInsn(ILOAD, 5); mv.visitVarInsn(ILOAD, 6); mv.visitJumpInsn(IF_ICMPLT, l2);
private void ldcClassConstant(Class cls) { if (OPCODES_VERSION == Opcodes.V1_4) { assert debug("LDC \"" + cls.getName() + "\""); mv.visitLdcInsn(cls.getName()); mv.visitMethodInsn(INVOKESTATIC, "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;"); Label l4 = new Label(); mv.visitJumpInsn(GOTO, l4); mv.visitTypeInsn(NEW, "java/lang/NoClassDefFoundError"); mv.visitInsn(DUP_X1); mv.visitInsn(SWAP); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Throwable", "getMessage", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NoClassDefFoundError", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l4); } else { assert debug("LDC " + getType(cls)); mv.visitLdcInsn(getType(cls)); } }