Example usage for org.objectweb.asm MethodVisitor visitLabel

List of usage examples for org.objectweb.asm MethodVisitor visitLabel

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitLabel.

Prototype

public void visitLabel(final Label label) 

Source Link

Document

Visits a label.

Usage

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.CollectionSizeExpression.java

@Override
public void generate(CodeEmitter code) {
    Label done = new Label();
    Label isNull = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    code.exec(target);/*from  w ww  . ja  v a 2  s. c om*/
    boolean nullable = code.nullTest(target.getType(), isNull);
    code.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Collection.class),
            "size", Type.getMethodDescriptor(Type.INT_TYPE), true);
    if (nullable) {
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(isNull);
        mv.visitInsn(Opcodes.ICONST_0);
        mv.visitLabel(done);
    }
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IntegerSwitchSequence.java

@Override
public void generate(CodeEmitter code) {
    Map<Integer, Label> labelMap = Maps.newHashMapWithExpectedSize(sequenceMap.size());
    for (Integer key : sequenceMap.keySet()) {
        labelMap.put(key, new Label());
    }//from  w  ww  .  j a  v a 2s.  c o  m
    Label done = new Label();
    Label defaultCase = defaultSequence == BytecodeSequence.NOOP ? done : new Label();
    code.emitIntegerSwitch(labelMap, defaultCase);
    MethodVisitor mv = code.getMethodVisitor();
    for (Map.Entry<Integer, BytecodeSequence> e : sequenceMap.entrySet()) {
        mv.visitLabel(labelMap.get(e.getKey()));
        code.exec(e.getValue());
        mv.visitJumpInsn(Opcodes.GOTO, done);
    }
    if (defaultCase != done) {
        mv.visitLabel(defaultCase);
        code.exec(defaultSequence);
    }
    mv.visitLabel(done);

}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IterateFirstSequence.java

@Override
public void generate(CodeEmitter start) {
    CodeEmitter code = start.createScope();
    Label done = new Label();
    Label isNull = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    BytecodeExpression tgt = code.evaluateOnce(target);
    tgt.generate(code);//from   w  ww  .  ja v a  2  s. c  o m
    code.emitInstanceCheck(tgt.getType(), Iterable.class, isNull);
    AssignableValue iterator = code.allocate(Iterator.class);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterable.class), "iterator",
            Type.getMethodDescriptor(Type.getType(Iterator.class)), true);
    code.exec(iterator.write(code.adapt(Iterator.class)));
    code.exec(iterator.read());
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "hasNext",
            Type.getMethodDescriptor(Type.BOOLEAN_TYPE), true);
    mv.visitJumpInsn(Opcodes.IFEQ, isNull);
    code.exec(iterator.read());
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "next",
            Type.getMethodDescriptor(Type.getType(Object.class)), true);
    code.cast(valueType, AnyTypeWidget.getInstance(), isNull);
    mv.visitJumpInsn(Opcodes.GOTO, done);
    mv.visitLabel(isNull);
    mv.visitInsn(Opcodes.ACONST_NULL);
    mv.visitLabel(done);
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IterateSequence.java

@Override
public void generate(CodeEmitter code) {
    Label done = new Label();
    Label next = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    BytecodeExpression tgt = code.evaluateOnce(target);
    code.exec(tgt);/* www.j  a  v  a2 s. c o  m*/
    code.emitInstanceCheck(tgt.getType(), Iterable.class, done);
    AssignableValue item = this.item == null ? code.allocate(valueType) : this.item;
    AssignableValue iterator = code.allocate(Iterator.class);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterable.class), "iterator",
            Type.getMethodDescriptor(Type.getType(Iterator.class)), true);
    code.exec(iterator.write(code.adapt(Iterator.class)));
    mv.visitLabel(next);
    code.exec(iterator.read());
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "hasNext",
            Type.getMethodDescriptor(Type.BOOLEAN_TYPE), true);
    mv.visitJumpInsn(Opcodes.IFEQ, done);
    code.exec(iterator.read());
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "next",
            Type.getMethodDescriptor(Type.getType(Object.class)), true);
    code.cast(valueType, AnyTypeWidget.getInstance()); // , next);   // don't skip nulls
    code.exec(item.write(item.getType()));
    loop.item(code, item.read(), done, next);
    mv.visitJumpInsn(Opcodes.GOTO, next);
    mv.visitLabel(done);
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.NullTestingSerializationAdapter.java

@Override
public BytecodeSequence serializeTo(final BytecodeExpression input, final BytecodeExpression generator) {
    return new BytecodeSequence() {
        @Override//from  w  ww.j a  v a 2  s.  c  o m
        public void generate(CodeEmitter code) {
            Label isNull = new Label();
            Label done = new Label();
            BytecodeExpression source = code.evaluateOnce(input);
            code.gotoIfNull(source, isNull);
            MethodVisitor mv = code.getMethodVisitor();
            code.exec(targetAdapter.serializeTo(source, generator));
            mv.visitJumpInsn(Opcodes.GOTO, done);
            mv.visitLabel(isNull);
            switch (encoding) {
            case TBIN:
                code.exec(generator);
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TBinEncoder.class), "writeNull",
                        Type.getMethodDescriptor(Type.VOID_TYPE), false);
                break;
            case JSON:
                code.exec(generator);
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class),
                        "writeNull", Type.getMethodDescriptor(Type.VOID_TYPE), false);
                break;
            default:
                throw new UnsupportedOperationException("unknown NativeEncoding: " + encoding);
            }
            mv.visitLabel(done);
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.StringSwitchSequence.java

@Override
public void generate(CodeEmitter code) {
    Map<String, Label> labelMap = Maps.newHashMapWithExpectedSize(sequenceMap.size());
    for (String key : sequenceMap.keySet()) {
        labelMap.put(key, new Label());
    }//from   ww w  .ja  v a 2  s .c  o m
    Label done = new Label();
    Label defaultCase = defaultSequence == BytecodeSequence.NOOP ? done : new Label();
    code.exec(input);
    code.emitInstanceCheck(input.getType(), String.class, defaultCase);
    code.emitStringSwitch(labelMap, defaultCase, caseInsensitive);
    MethodVisitor mv = code.getMethodVisitor();
    for (Map.Entry<String, BytecodeSequence> e : sequenceMap.entrySet()) {
        mv.visitLabel(labelMap.get(e.getKey()));
        code.exec(e.getValue());
        mv.visitJumpInsn(Opcodes.GOTO, done);
    }
    if (defaultCase != done) {
        mv.visitLabel(defaultCase);
        code.exec(defaultSequence);
    }
    mv.visitLabel(done);

}

From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java

License:Open Source License

protected void generatePropertyMethod(PropertyInfo property) {
    MethodVisitor mv = cv.visitMethod(property.writeAccessLevel + ACC_FINAL, property.propertyMethodName,
            "()" + property.propertyInterfaceSignature,
            property.propertyInterfaceSignatureGeneric != null
                    ? "()" + property.propertyInterfaceSignatureGeneric
                    : null,//from   w  w  w .ja va 2  s  . c  o m
            null);
    {
        AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";",
                true);
        av0.visit("writeable", Boolean.TRUE);
        av0.visit("name", property.propertyName);
        av0.visit("dataSignature", property.dataSignature);
        av0.visit("dataSignatureGeneric",
                property.dataSignatureGeneric != null ? property.dataSignatureGeneric : "");
        av0.visit("humanReadableName",
                property.humanReadablePropertyName != null ? property.humanReadablePropertyName : "");
        av0.visitEnd();
    }
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, property.propertyDataType);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(property.propertyName);
    mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>",
            "(Ljava/lang/Object;Ljava/lang/String;)V");
    mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitLabel(l1);
    mv.visitFrame(F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitTypeInsn(CHECKCAST, property.propertyInterfaceType);
    mv.visitInsn(ARETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0);
    mv.visitMaxs(5, 1);
    mv.visitEnd();
}

From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java

License:Open Source License

protected void generateReadOnlyPropertyMethod(PropertyInfo property) {
    MethodVisitor mv = cv.visitMethod(property.readAccessLevel + ACC_FINAL, property.readOnlyPropertyMethodName,
            "()" + property.readOnlyPropertyInterfaceSignature,
            property.readOnlyPropertyInterfaceSignatureGeneric != null
                    ? "()" + property.readOnlyPropertyInterfaceSignatureGeneric
                    : null,/*from   w  ww.  jav  a 2s  . c  om*/
            null);
    {
        AnnotationVisitor av0 = mv.visitAnnotation("L" + Property.class.getName().replace('.', '/') + ";",
                true);
        av0.visit("writeable", Boolean.FALSE);
        av0.visit("name", property.propertyName);
        av0.visit("dataSignature", property.dataSignature);
        av0.visit("dataSignatureGeneric",
                property.dataSignatureGeneric != null ? property.dataSignatureGeneric : "");
        av0.visit("humanReadableName",
                property.humanReadablePropertyName != null ? property.humanReadablePropertyName : "");
        av0.visitEnd();
    }
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    Label l1 = new Label();
    mv.visitJumpInsn(IFNONNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitTypeInsn(NEW, property.propertyDataType);
    mv.visitInsn(DUP);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitLdcInsn(property.propertyName);
    mv.visitMethodInsn(INVOKESPECIAL, property.propertyDataType, "<init>",
            "(Ljava/lang/Object;Ljava/lang/String;)V");
    mv.visitFieldInsn(PUTFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitLabel(l1);
    mv.visitFrame(F_SAME, 0, null, 0, null);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, className, property.propertyFieldName, property.propertyDataSignature);
    mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyDataType, "getReadOnlyProperty",
            "()" + property.readOnlyPropertyInterfaceSignature);
    mv.visitTypeInsn(CHECKCAST, property.readOnlyPropertyInterfaceType);
    mv.visitInsn(ARETURN);
    Label l3 = new Label();
    mv.visitLabel(l3);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0);
    mv.visitMaxs(5, 1);
    mv.visitEnd();
}

From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java

License:Open Source License

protected void generateInternalGetterMethod(PropertyInfo property) {
    MethodVisitor mv = cv.visitMethod(ACC_PRIVATE + ACC_FINAL, property.internalGetterMethodName,
            "()" + property.dataSignature,
            property.dataSignatureGeneric != null ? "()" + property.dataSignatureGeneric : null, null);
    mv.visitCode();/*from   w  w w  .jav a  2 s .  c  o m*/
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, className, property.propertyMethodName,
            "()" + property.propertyInterfaceSignature);
    mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyInterfaceType, "getValue", "()Ljava/lang/Object;");
    mv.visitTypeInsn(CHECKCAST, property.dataType);
    mv.visitInsn(ARETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l1, 0);
    mv.visitMaxs(1, 1);
    mv.visitEnd();
}

From source file:de.chimos.property.compiler.passtwo.javafx.PassTwoJFXClassVisitor.java

License:Open Source License

protected void generateInternalSetterMethod(PropertyInfo property) {
    MethodVisitor mv = cv.visitMethod(ACC_PRIVATE + ACC_FINAL, property.internalSetterMethodName,
            "(" + property.dataSignature + ")V",
            property.dataSignatureGeneric != null ? "(" + property.dataSignatureGeneric + ")V" : null, null);
    mv.visitCode();/*from w  ww .j  av a 2s.  c o m*/
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitMethodInsn(INVOKEVIRTUAL, className, property.propertyMethodName,
            "()" + property.propertyInterfaceSignature);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitMethodInsn(INVOKEVIRTUAL, property.propertyInterfaceType, "setValue", "(Ljava/lang/Object;)V");
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitInsn(RETURN);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLocalVariable("this", "L" + className + ";", null, l0, l2, 0);
    mv.visitLocalVariable("value", property.dataSignature, null, l0, l2, 1);
    mv.visitMaxs(2, 2);
    mv.visitEnd();
}