Example usage for org.objectweb.asm Opcodes ALOAD

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

Introduction

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

Prototype

int ALOAD

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

Click Source Link

Usage

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

License:Apache License

private ClassData generateSimpleClass(Context context, UserOperator operator, ClassDescription target) {
    TypeDescription dataType = operator.getInput(Fold.ID_INPUT).getDataType();

    ClassWriter writer = newWriter(target, SimpleCombineResult.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    FieldRef acc = defineField(writer, target, "acc", typeOf(dataType)); //$NON-NLS-1$
    Map<OperatorProperty, FieldRef> map = defineConstructor(context, operator, target, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL,
                AsmUtil.typeOf(SimpleCombineResult.class).getInternalName(), CONSTRUCTOR_NAME,
                Type.getMethodDescriptor(Type.VOID_TYPE), false);

        setOperatorField(method, operator, impl);

        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, dataType);/*w  w w  . ja  v a2s  .  c  om*/
        putField(method, acc);
    }, method -> Lang.pass());
    defineSimpleStart(operator, writer, acc);
    defineSimpleCombine(context, operator, writer, impl, acc, map);
    defineSimpleFinish(writer, acc, map.get(operator.getOutput(Fold.ID_OUTPUT)));
    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

private void defineSimpleStart(UserOperator operator, ClassWriter writer, FieldRef acc) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "start",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), null, null);

    TypeDescription dataType = operator.getInput(Fold.ID_INPUT).getDataType();

    acc.load(method);//from w  w w .j  av  a 2s.  co m
    method.visitVarInsn(Opcodes.ALOAD, 1);
    method.visitTypeInsn(Opcodes.CHECKCAST, typeOf(dataType).getInternalName());
    copyDataModel(method, dataType);

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

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

License:Apache License

private ClassData generateClass(Context context, UserOperator operator, ClassDescription target) {
    String report = getReportName(context, operator);

    OperatorInput input = operator.getInput(Logging.ID_INPUT);
    OperatorOutput output = operator.getOutput(Logging.ID_OUTPUT);

    ClassWriter writer = newWriter(target, Object.class, Result.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    Map<OperatorProperty, FieldRef> map = defineConstructor(context, operator, target, writer, method -> {
        setOperatorField(method, operator, impl);
    });/*from   w w  w. jav  a2  s . c  om*/
    defineResultAdd(writer, method -> {
        cast(method, 1, input.getDataType());

        List<ValueRef> arguments = new ArrayList<>();
        arguments.add(impl);
        arguments.add(new LocalVarRef(Opcodes.ALOAD, 1));
        appendSecondaryInputs(arguments::add, operator, map::get);
        appendArguments(arguments::add, operator, map::get);
        invoke(method, context, operator, arguments);

        method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(Report.class).getInternalName(), report,
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(String.class)), false);

        method.visitVarInsn(Opcodes.ALOAD, 0);
        getField(method, map.get(output));
        method.visitVarInsn(Opcodes.ALOAD, 1);
        invokeResultAdd(method);
    });
    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

private ClassData genTableClass(Context context, UserOperator operator, ClassDescription target) {
    OperatorInput master = MasterJoinOperatorUtil.getMasterInput(operator);
    List<OperatorProperty> externals = getExternalProperties(operator);
    int masterIndex = externals.indexOf(master);
    Invariants.require(masterIndex >= 0);

    ClassWriter writer = newWriter(target, TableJoinResult.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    Consumer<MethodVisitor> initializer = defineExtraFields(writer, context, operator, target);
    Map<OperatorProperty, FieldRef> dependencies = defineConstructor(context, externals, target, writer,
            method -> {/*w w w  .j a  va  2s. c  om*/
                method.visitVarInsn(Opcodes.ALOAD, 0);
                method.visitVarInsn(Opcodes.ALOAD, masterIndex + 1);
                method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(TableJoinResult.class).getInternalName(),
                        CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(DataTable.class)),
                        false);
            }, method -> {
                setOperatorField(method, operator, impl);
                initializer.accept(method);
            });
    OperatorInput transaction = MasterJoinOperatorUtil.getTransactionInput(operator);
    defineBuildKey(context, writer, transaction.getDataType(), transaction.getGroup());
    defineSelection(context, writer, operator, impl, dependencies);
    defineProcess(context, writer, operator, impl, dependencies, target);
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

private ClassData genMergeClass(Context context, UserOperator operator, ClassDescription target) {
    OperatorInput master = MasterJoinOperatorUtil.getMasterInput(operator);
    OperatorInput transaction = MasterJoinOperatorUtil.getTransactionInput(operator);
    ClassWriter writer = newWriter(target, MergeJoinResult.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    Consumer<MethodVisitor> initializer = defineExtraFields(writer, context, operator, target);
    Map<OperatorProperty, FieldRef> dependencies = defineConstructor(context, operator, target, writer,
            method -> {/*w  w  w.  j  ava 2s .  c o m*/
                method.visitVarInsn(Opcodes.ALOAD, 0);
                getInt(method, context.getGroupIndex(master));
                getInt(method, context.getGroupIndex(transaction));
                method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(MergeJoinResult.class).getInternalName(),
                        CONSTRUCTOR_NAME,
                        Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE, Type.INT_TYPE), false);
            }, method -> {
                setOperatorField(method, operator, impl);
                initializer.accept(method);
            });
    defineSelection(context, writer, operator, impl, dependencies);
    defineProcess(context, writer, operator, impl, dependencies, target);
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

private static void defineSelection(Context context, ClassWriter writer, UserOperator operator, FieldRef impl,
        Map<OperatorProperty, FieldRef> dependencies) {
    Method selector = Invariants.safe(() -> {
        return MasterJoinOperatorUtil.getSelection(context.getClassLoader(), operator);
    });/* w ww .java 2 s .c o m*/
    if (selector == null) {
        return;
    }
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PROTECTED | Opcodes.ACC_FINAL, "selectMaster",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(List.class), typeOf(Object.class)), null,
            null);
    cast(method, 2, MasterJoinOperatorUtil.getTransactionInput(operator).getDataType());

    List<ValueRef> arguments = new ArrayList<>();
    impl.load(method);
    arguments.add(new LocalVarRef(Opcodes.ALOAD, 1));
    arguments.add(new LocalVarRef(Opcodes.ALOAD, 2));
    arguments
            .addAll(Lang.project(getExtraViews(operator), v -> Invariants.requireNonNull(dependencies.get(v))));
    arguments
            .addAll(Lang.project(operator.getArguments(), v -> Invariants.requireNonNull(dependencies.get(v))));
    for (int i = 0, n = selector.getParameterCount(); i < n; i++) {
        arguments.get(i).load(method);
    }
    method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(selector.getDeclaringClass()).getInternalName(),
            selector.getName(), Type.getMethodDescriptor(selector), false);
    method.visitInsn(Opcodes.ARETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

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

License:Apache License

private void defineProcess(Context context, ClassWriter writer, UserOperator operator, FieldRef impl,
        Map<OperatorProperty, FieldRef> dependencies, ClassDescription target) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PROTECTED | Opcodes.ACC_FINAL, "process",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(Object.class)), null, null);
    cast(method, 1, MasterJoinOperatorUtil.getMasterInput(operator).getDataType());
    cast(method, 2, MasterJoinOperatorUtil.getTransactionInput(operator).getDataType());
    defineProcess(method, context, operator, new LocalVarRef(Opcodes.ALOAD, 1),
            new LocalVarRef(Opcodes.ALOAD, 2), impl, dependencies, target);
    method.visitInsn(Opcodes.RETURN);//from  www  .j  a va 2 s .co  m
    method.visitMaxs(0, 0);
    method.visitEnd();
}

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

License:Apache License

@Override
protected Consumer<MethodVisitor> defineExtraFields(ClassVisitor writer, Context context, UserOperator operator,
        ClassDescription target) {//  w  w  w  .ja va  2 s. c o m
    OperatorOutput joined = operator.getOutput(MasterJoin.ID_OUTPUT_JOINED);
    FieldRef field = defineField(writer, target, FIELD_BUFFER, typeOf(joined.getDataType()));
    return method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, joined.getDataType());
        putField(method, field);
    };
}

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

License:Apache License

private static void performJoin(MethodVisitor method, Context context, UserOperator operator,
        LocalVarRef masterRef, LocalVarRef txRef, FieldRef impl, Map<OperatorProperty, FieldRef> dependencies,
        ClassDescription target) {//from  w  w w .j  av  a 2 s  . c  o m
    OperatorInput master = operator.getInput(MasterJoin.ID_INPUT_MASTER);
    OperatorInput tx = operator.getInput(MasterJoin.ID_INPUT_TRANSACTION);
    OperatorOutput joined = operator.getOutput(MasterJoin.ID_OUTPUT_JOINED);

    method.visitVarInsn(Opcodes.ALOAD, 0);
    getField(method, target, FIELD_BUFFER, typeOf(joined.getDataType()));
    LocalVarRef bufferVar = putLocalVar(method, Type.OBJECT, 3);

    bufferVar.load(method);
    method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(joined.getDataType()).getInternalName(), "reset",
            Type.getMethodDescriptor(Type.VOID_TYPE), false);

    List<PropertyMapping> mappings = Invariants
            .safe(() -> JoinedModelUtil.getPropertyMappings(context.getClassLoader(), operator));
    Map<OperatorInput, ValueRef> inputs = new HashMap<>();
    Map<OperatorOutput, ValueRef> outputs = new HashMap<>();
    inputs.put(master, masterRef);
    inputs.put(tx, txRef);
    outputs.put(joined, bufferVar);
    mapping(method, context.getDataModelLoader(), mappings, inputs, outputs);
    bufferVar.load(method);
}

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

License:Apache License

private static ClassData genClass(Context context, CoreOperator operator, ClassDescription target) {
    DataModelLoader loader = context.getDataModelLoader();
    DataModelReference inputType = loader.load(operator.getInput(Project.ID_INPUT).getDataType());
    DataModelReference outputType = loader.load(operator.getOutput(Project.ID_OUTPUT).getDataType());
    List<PropertyMapping> mappings = ProjectionOperatorUtil.getPropertyMappings(loader, operator);

    ClassWriter writer = newWriter(target, Object.class, Result.class);
    FieldRef bufferField = defineField(writer, target, "buffer", typeOf(outputType));

    Map<OperatorProperty, FieldRef> deps = defineDependenciesConstructor(context, operator.getOutputs(), target,
            writer, method -> {/*from   w ww  .j  a v  a 2 s .  co m*/
                method.visitVarInsn(Opcodes.ALOAD, 0);
                getNew(method, outputType.getDeclaration());
                putField(method, bufferField);
            });
    defineResultAdd(writer, method -> {
        cast(method, 1, inputType.getDeclaration());

        method.visitVarInsn(Opcodes.ALOAD, 0);
        getField(method, bufferField);
        method.visitVarInsn(Opcodes.ASTORE, 2);

        Map<OperatorInput, ValueRef> inputs = new HashMap<>();
        Map<OperatorOutput, ValueRef> outputs = new HashMap<>();
        inputs.put(operator.getInput(Project.ID_INPUT), new LocalVarRef(Opcodes.ALOAD, 1));
        outputs.put(operator.getOutput(Project.ID_OUTPUT), new LocalVarRef(Opcodes.ALOAD, 2));
        mapping(method, loader, mappings, inputs, outputs);

        method.visitVarInsn(Opcodes.ALOAD, 0);
        getField(method, deps.get(operator.getOutput(Project.ID_OUTPUT)));
        method.visitVarInsn(Opcodes.ALOAD, 2);
        invokeResultAdd(method);
    });
    return new ClassData(target, writer::toByteArray);
}