/** * 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; }
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 jitLeftIsNull(Label nullLabel) { Label notNullLabel = new Label(); mv.visitJumpInsn(GOTO, notNullLabel); mv.visitLabel(nullLabel); return notNullLabel; }
l0 = new Label(); mv.visitLabel( l0 ); mv.visitInsn(Opcodes.RETURN); Label l1 = null; if ( this.debug ) { l1 = new Label(); mv.visitLabel( l1 ); mv.visitLocalVariable( "this", BuildUtils.getTypeDescriptor( classDef.getClassName() ),
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); }
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 ( this.debug ) { l0 = new Label(); mv.visitLabel( l0 ); mv.visitInsn( Opcodes.RETURN ); Label l1 = null; if ( this.debug ) { l1 = new Label(); mv.visitLabel( l1 ); mv.visitLocalVariable( "this", BuildUtils.getTypeDescriptor( classDef.getClassName() ), 0 ); for ( FieldDefinition field : classDef.getFieldsDefinitions() ) { Label l11 = new Label(); mv.visitLabel( l11 ); mv.visitLocalVariable( field.getName(), BuildUtils.getTypeDescriptor( field.getTypeName() ),
@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); }
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); }
mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitCode(); visitConstantClass(returnType); mv.visitInsn(ARETURN); mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(buildLog.toString() + "\n\n## { " + new String(expr) + " }"); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitMaxs(1, 1); mv.visitEnd();
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 ); }
mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitCode(); visitConstantClass(returnType); mv.visitInsn(ARETURN); mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(buildLog.toString() + "\n\n## { " + new String(expr) + " }"); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitMaxs(1, 1); mv.visitEnd();
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 ); }
mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitCode(); mv.visitLdcInsn(org.mvel2.asm.Type.getType(returnType != null ? returnType : Object.class)); mv.visitInsn(ARETURN); mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(buildLog.toString() + "\n\n## { " + new String(expr) + " }"); mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitMaxs(1, 1); mv.visitEnd();
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); }
Label shortcutEvaluation = new Label(); BooleanOperator operation = singleCondition.getOperation(); prepareLeftOperand(operation, type, leftType, rightType, shortcutEvaluation); invokeVirtual(type, "compareTo", int.class, findComparingClass(type)); mv.visitInsn(ICONST_0); jitPrimitiveOperation(operation == BooleanOperator.NE ? BooleanOperator.EQ : operation, int.class); mv.visitLabel(shortcutEvaluation);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethods", "()[Ljava/lang/reflect/Method;"); mv.visitVarInsn(ASTORE, 7); 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.visitInsn(AALOAD); mv.visitVarInsn(ASTORE, 4); Label l3 = new Label(); mv.visitLabel(l3); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "getName", "()Ljava/lang/String;"); 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.visitLabel(l4); mv.visitIincInsn(5, 1); mv.visitLabel(l1); mv.visitJumpInsn(IF_ICMPLT, l2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethods", "()[Ljava/lang/reflect/Method;"); mv.visitVarInsn(ASTORE, 7); 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.visitInsn(AALOAD); mv.visitVarInsn(ASTORE, 4); Label l3 = new Label(); mv.visitLabel(l3); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "getName", "()Ljava/lang/String;"); 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.visitLabel(l4); mv.visitIincInsn(5, 1); mv.visitLabel(l1); mv.visitJumpInsn(IF_ICMPLT, l2);
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getMethods", "()[Ljava/lang/reflect/Method;"); mv.visitVarInsn(ASTORE, 7); 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.visitInsn(AALOAD); mv.visitVarInsn(ASTORE, 4); Label l3 = new Label(); mv.visitLabel(l3); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/Method", "getName", "()Ljava/lang/String;"); 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.visitLabel(l4); mv.visitIincInsn(5, 1); mv.visitLabel(l1); mv.visitJumpInsn(IF_ICMPLT, l2);
protected void traverseTuplesUntilDeclarationWithOr(int declarIndex, int declarReg, int tupleReg, int declarOffsetReg) { mv.visitVarInsn(ALOAD, declarReg); push(declarIndex); mv.visitInsn(AALOAD); // declarations[i] invokeVirtual(Declaration.class, "getPattern", Pattern.class); invokeVirtual(Pattern.class, "getOffset", Integer.TYPE); // declarations[i].getPattern().getOffset() mv.visitVarInsn(ISTORE, declarOffsetReg); // declarations[i].getPattern().getOffset() // while (tuple.getIndex() > declaration[i].getPattern().getOffset()) tuple = tuple.getParent() Label whileStart = new Label(); Label whileExit = new Label(); mv.visitLabel(whileStart); mv.visitVarInsn(ALOAD, tupleReg); invokeInterface(LeftTuple.class, "getIndex", Integer.TYPE); // tuple.getIndex() mv.visitVarInsn(ILOAD, declarOffsetReg); // declarations[i].getPattern().getOffset() mv.visitJumpInsn(IF_ICMPLE, whileExit); // if tuple.getIndex() <= declarations[i].getPattern().getOffset() jump to whileExit mv.visitVarInsn(ALOAD, tupleReg); invokeInterface(LeftTuple.class, "getParent", LeftTuple.class); mv.visitVarInsn(ASTORE, tupleReg); // tuple = tuple.getParent() mv.visitJumpInsn(GOTO, whileStart); mv.visitLabel(whileExit); } }