Example usage for org.objectweb.asm Opcodes INVOKEINTERFACE

List of usage examples for org.objectweb.asm Opcodes INVOKEINTERFACE

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes INVOKEINTERFACE.

Prototype

int INVOKEINTERFACE

To view the source code for org.objectweb.asm Opcodes INVOKEINTERFACE.

Click Source Link

Usage

From source file:com.yahoo.yqlplus.engine.internal.compiler.CompareExpression.java

@Override
public void generate(CodeEmitter code) {
    // a bit of a hack; should not need to go to dynamic invocation for this unless one arg is ANY
    Label done = new Label();
    MethodVisitor mv = code.getMethodVisitor();
    Label leftNull = new Label();
    Label rightNull = new Label();
    Label bothNull = new Label();
    CodeEmitter.Unification unified = code.unifiedEmit(leftExpr, rightExpr, leftNull, rightNull, bothNull);
    if (unified.type.isPrimitive()) {
        emitPrimitiveCompare(code, unified.type);
    } else {/*from  w  w w.j  a  v a 2  s  .  c  o m*/
        // TODO: statically determine if the unified type is Comparable -- for now treat them all like "any"
        CodeEmitter scope = code.createScope();
        MethodVisitor mv2 = scope.getMethodVisitor();
        AssignableValue right = scope.allocate(unified.type);
        AssignableValue left = scope.allocate(unified.type);
        scope.exec(right.write(unified.type));
        scope.exec(left.write(unified.type));
        scope.exec(left.read());
        Label leftIsNotComparable = new Label();
        scope.emitInstanceCheck(unified.type, Comparable.class, leftIsNotComparable);
        scope.exec(right.read());
        mv2.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Comparable.class), "compareTo",
                Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(Object.class)), true);
        scope.gotoExitScope();
        mv2.visitLabel(leftIsNotComparable);
        scope.exec(scope.getLocal("$program").read());
        scope.exec(left.read());
        scope.emitIntConstant((loc != null) ? loc.getLineNumber() : -1);
        scope.emitIntConstant((loc != null) ? loc.getCharacterOffset() : 0);
        mv2.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ProgramInvocation.class),
                "notComparable", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class),
                        Type.INT_TYPE, Type.INT_TYPE),
                false);
        // this bit is not reachable, notComparable throws
        mv2.visitInsn(Opcodes.ICONST_0);
        mv2.visitJumpInsn(Opcodes.GOTO, done);
        scope.endScope();
    }
    if (unified.nullPossible) {
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(leftNull);
        mv.visitInsn(Opcodes.ICONST_M1);
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(rightNull);
        mv.visitInsn(Opcodes.ICONST_1);
        mv.visitJumpInsn(Opcodes.GOTO, done);
        mv.visitLabel(bothNull);
        mv.visitInsn(Opcodes.ICONST_0);
    }
    mv.visitLabel(done);
}

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

@Override
public final BytecodeSequence mergeIntoFieldWriter(BytecodeExpression target,
        final BytecodeExpression fieldWriter) {
    return visitProperties(target, new PropertyVisit() {
        @Override/*from  w  w  w  .j  a  va 2  s.  c  o  m*/
        public void item(CodeEmitter code, BytecodeExpression propertyName, BytecodeExpression propertyValue,
                Label abortLoop, Label nextItem) {
            code.exec(fieldWriter);
            code.exec(propertyName);
            code.exec(propertyValue);
            code.box(propertyValue.getType());
            code.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEINTERFACE,
                    Type.getInternalName(FieldWriter.class), "put", Type.getMethodDescriptor(Type.VOID_TYPE,
                            Type.getType(String.class), Type.getType(Object.class)),
                    true);
        }
    });
}

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

@Override
public BytecodeExpression getPropertyNameIterable(final BytecodeExpression target) {
    return new BaseTypeExpression(new IterableTypeWidget(BaseTypeAdapter.STRING)) {
        @Override//ww  w  . java2s.c om
        public void generate(CodeEmitter code) {
            ListTypeWidget listOfString = new ListTypeWidget(BaseTypeAdapter.STRING);
            final BytecodeExpression list = code.evaluateOnce(listOfString.construct());
            code.exec(visitProperties(target, new PropertyVisit() {
                @Override
                public void item(CodeEmitter code, BytecodeExpression propertyName,
                        BytecodeExpression propertyValue, Label abortLoop, Label nextItem) {
                    code.exec(list);
                    code.exec(propertyName);
                    code.box(propertyName.getType());
                    code.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEINTERFACE,
                            Type.getInternalName(List.class), "add",
                            Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), true);
                    code.pop(BaseTypeAdapter.BOOLEAN);
                }
            }));
            code.exec(list);
        }
    };
}

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);//  ww  w .j  a v  a 2 s  .com
    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.InvokeExpression.java

public InvokeExpression(Class<?> owner, String methodName, TypeWidget returnType, BytecodeExpression target,
        List<BytecodeExpression> arguments) {
    this.owner = Type.getType(owner);
    if (owner.isInterface()) {
        this.op = Opcodes.INVOKEINTERFACE;
    } else {//w  w  w  .java  2  s. c om
        this.op = Opcodes.INVOKEVIRTUAL;
    }
    this.methodName = methodName;
    this.target = target;
    this.returnType = returnType;
    this.arguments = arguments;
    this.descriptor = getDescriptor(returnType, arguments);
}

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

@Override
public void generate(CodeEmitter code) {
    if (op != Opcodes.INVOKESTATIC) {
        target.generate(code);//ww w .j a  v a  2 s . c  om
    }
    for (BytecodeExpression arg : arguments) {
        arg.generate(code);
    }
    MethodVisitor mv = code.getMethodVisitor();
    mv.visitMethodInsn(op, owner.getInternalName(), methodName, descriptor, op == Opcodes.INVOKEINTERFACE);
}

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 va  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);/*from  w  w w.j a v  a 2  s.  c om*/
    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.ListAssignableValue.java

@Override
public BytecodeExpression read() {
    return new BaseTypeExpression(valueType) {
        @Override/*w w w  .j  av  a  2  s.c o  m*/
        public void generate(CodeEmitter code) {
            target.generate(code);
            indexExpression.generate(code);
            code.cast(BaseTypeAdapter.INT32, indexExpression.getType());
            code.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(List.class),
                    "get", Type.getMethodDescriptor(Type.getType(Object.class), Type.INT_TYPE), true);
            code.cast(valueType, BaseTypeAdapter.ANY);
        }
    };
}

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

@Override
public BytecodeSequence write(final BytecodeExpression value) {
    return new BytecodeSequence() {
        @Override/*from  w w  w . j  a  v a 2  s  .c  o m*/
        public void generate(CodeEmitter code) {
            target.generate(code);
            indexExpression.generate(code);
            code.cast(BaseTypeAdapter.INT32, indexExpression.getType());
            value.generate(code);
            code.box(value.getType());
            code.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(List.class),
                    "set", Type.getMethodDescriptor(Type.getType(Object.class), Type.INT_TYPE,
                            Type.getType(Object.class)),
                    true);
            code.pop(BaseTypeAdapter.ANY);
        }
    };
}