Example usage for org.objectweb.asm Opcodes INVOKESTATIC

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

Introduction

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

Prototype

int INVOKESTATIC

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

Click Source Link

Usage

From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java

License:Apache License

private static void defineCheckNull(ClassWriter writer, UserOperator operator, DataModelReference inputType) {

    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, METHOD_CHECK_NON_NULL,
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ValueOption.class), typeOf(Object.class),
                    typeOf(String.class)),
            null, null);/*  ww  w  .j  a  va2s  .  c  o m*/

    LocalVarRef optionVar = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef objectVar = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef nameVar = new LocalVarRef(Opcodes.ALOAD, 2);

    // if (option.isNull()) {
    Label ifEnd = new Label();
    optionVar.load(method);
    getNullity(method, VALUE_DESC);
    method.visitJumpInsn(Opcodes.IFEQ, ifEnd);

    // new NullPointerException ...
    method.visitTypeInsn(Opcodes.NEW, typeOf(NullPointerException.class).getInternalName());
    method.visitInsn(Opcodes.DUP);

    // str = String.format("<type>.%s must not be null (in <operator>): %s", name, object)
    getConst(method,
            String.format("%s.%%s must not be null (in %s.%s): %%s", inputType.getDeclaration().getSimpleName(),
                    operator.getMethod().getDeclaringClass().getSimpleName(), operator.getMethod().getName()));

    getArray(method, typeOf(Object.class), new LocalVarRef[] { nameVar, objectVar });
    method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(String.class).getInternalName(), "format",
            Type.getMethodDescriptor(typeOf(String.class), typeOf(String.class), typeOf(Object[].class)),
            false);

    // throw new NullPointerException(str)
    method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(NullPointerException.class).getInternalName(),
            CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(String.class)), false);

    method.visitInsn(Opcodes.ATHROW);

    method.visitLabel(ifEnd);
    // }
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

From source file:com.asakusafw.dag.compiler.builtin.Util.java

License:Apache License

static void getGroupList(MethodVisitor method, Context context, OperatorInput input) {
    method.visitVarInsn(Opcodes.ALOAD, 1);
    getInt(method, context.getGroupIndex(input));
    method.visitMethodInsn(Opcodes.INVOKESTATIC, AsmUtil.typeOf(CoGroupOperationUtil.class).getInternalName(),
            "getList", Type.getMethodDescriptor(AsmUtil.typeOf(List.class),
                    AsmUtil.typeOf(CoGroupOperation.Input.class), Type.INT_TYPE),
            false);/* ww  w.  j  a  v a  2  s.c o m*/
}

From source file:com.asakusafw.dag.compiler.builtin.Util.java

License:Apache License

static void getGroupIterable(MethodVisitor method, Context context, OperatorInput input) {
    method.visitVarInsn(Opcodes.ALOAD, 1);
    getInt(method, context.getGroupIndex(input));
    method.visitMethodInsn(Opcodes.INVOKESTATIC, AsmUtil.typeOf(CoGroupOperationUtil.class).getInternalName(),
            "getIterable", Type.getMethodDescriptor(AsmUtil.typeOf(Iterable.class),
                    AsmUtil.typeOf(CoGroupOperation.Input.class), Type.INT_TYPE),
            false);//from w w w .j  a  v a2 s  . c o m
}

From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java

License:Apache License

/**
 * Adds a value list on to the top of the stack.
 * @param method the current method visitor
 * @param values the array elements/*from w  w  w. j  a  v  a  2 s  . co  m*/
 */
public static void getList(MethodVisitor method, Collection<?> values) {
    getInt(method, values.size());
    method.visitTypeInsn(Opcodes.ANEWARRAY, typeOf(Object.class).getInternalName());
    int index = 0;
    for (Object value : values) {
        method.visitInsn(Opcodes.DUP);
        getInt(method, index++);
        getConst(method, value);
        method.visitInsn(Opcodes.AASTORE);
    }
    method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(Arrays.class).getInternalName(), "asList",
            Type.getMethodDescriptor(typeOf(List.class), typeOf(Object[].class)), false);
}

From source file:com.asakusafw.dag.compiler.codegen.DataComparatorGenerator.java

License:Apache License

private static void defineCompare(ClassWriter writer, DataModelReference reference,
        List<Group.Ordering> orderings) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "compare", DESC_COMPARE, null,
            new String[] { typeOf(IOException.class).getInternalName(), });
    LocalVarRef a = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef b = new LocalVarRef(Opcodes.ALOAD, 2);
    for (Group.Ordering ordering : orderings) {
        PropertyReference property = Invariants
                .requireNonNull(reference.findProperty(ordering.getPropertyName()));

        // int diff = ValueOptionSerDe.compareT({a, b}, {b, a});
        switch (ordering.getDirection()) {
        case ASCENDANT:
            a.load(v);/*w  w w.  j a  va2s. c  o m*/
            b.load(v);
            break;
        case DESCENDANT:
            b.load(v);
            a.load(v);
            break;
        default:
            throw new AssertionError(ordering);
        }
        v.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(ValueOptionSerDe.class).getInternalName(),
                Invariants.requireNonNull(METHOD_NAMES.get(property.getType())), DESC_COMPARE, false);
        LocalVarRef cmp = putLocalVar(v, Type.INT, 3);
        Label eq = new Label();

        // if (diff != 0) {
        cmp.load(v);
        v.visitJumpInsn(Opcodes.IFEQ, eq);

        // return diff;
        cmp.load(v);
        v.visitInsn(Opcodes.IRETURN);

        // } @ eq
        v.visitLabel(eq);
    }
    getConst(v, 0);
    v.visitInsn(Opcodes.IRETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java

License:Apache License

private static void putSerialize(String methodName, DataModelReference reference,
        List<PropertyReference> properties, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, methodName,
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null,
            new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    if (properties.isEmpty()) {
        LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2);
        output.load(v);//w  ww.j av  a  2s  . com
        getConst(v, 0);
        v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataOutput.class).getInternalName(), "writeByte",
                Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), true);
    } else {
        LocalVarRef object = cast(v, 1, reference.getDeclaration());
        LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2);
        for (PropertyReference property : properties) {
            object.load(v);
            getOption(v, property);
            output.load(v);
            v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "serialize", Type
                    .getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataOutput.class)),
                    false);
        }
    }
    v.visitInsn(Opcodes.RETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java

License:Apache License

private static void putDeserializeBody(MethodVisitor v, List<PropertyReference> props, LocalVarRef input,
        LocalVarRef object) {/*from www.j  av  a2s .  co  m*/
    if (props.isEmpty()) {
        input.load(v);
        v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataInput.class).getInternalName(), "readByte",
                Type.getMethodDescriptor(Type.BYTE_TYPE), true);
        v.visitInsn(Opcodes.POP);
    } else {
        for (PropertyReference property : props) {
            object.load(v);
            getOption(v, property);
            input.load(v);
            v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "deserialize", Type
                    .getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataInput.class)),
                    false);
        }
    }
}

From source file:com.asakusafw.dag.compiler.codegen.OperationGenerator.java

License:Apache License

private static void getEmptyDataTable(MethodVisitor method, ClassDescription target,
        Function<VertexElement, String> ids) {
    method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(BasicDataTable.class).getInternalName(), "empty", //$NON-NLS-1$
            Type.getMethodDescriptor(typeOf(DataTable.class)), false);
}

From source file:com.asakusafw.dag.compiler.codegen.ValueSerDeGenerator.java

License:Apache License

private static void putSerialize(DataModelReference reference, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "serialize",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null,
            new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef object = cast(v, 1, reference.getDeclaration());
    LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2);
    for (PropertyReference property : reference.getProperties()) {
        object.load(v);//from  w  w w . j a  v a 2s .co m
        getOption(v, property);
        output.load(v);
        v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "serialize",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataOutput.class)),
                false);
    }
    v.visitInsn(Opcodes.RETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.codegen.ValueSerDeGenerator.java

License:Apache License

private static void putDeserialize(DataModelReference reference, FieldRef buffer, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserialize",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(DataInput.class)), null,
            new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef input = new LocalVarRef(Opcodes.ALOAD, 1);

    self.load(v);/*from w w  w .j a  v  a 2s  .  c  o  m*/
    getField(v, buffer);
    LocalVarRef object = putLocalVar(v, Type.OBJECT, 2);
    for (PropertyReference property : reference.getProperties()) {
        object.load(v);
        getOption(v, property);
        input.load(v);
        v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "deserialize",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataInput.class)),
                false);
    }
    object.load(v);
    v.visitInsn(Opcodes.ARETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}