Example usage for org.objectweb.asm Opcodes ACC_PUBLIC

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

Introduction

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

Prototype

int ACC_PUBLIC

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

Click Source Link

Usage

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

License:Apache License

private ClassData generateClass(Context context, UserOperator operator, ClassDescription target) {
    ClassDescription combinerClass = generateCombinerClass(context, operator, target);
    ClassWriter writer = newWriter(target, CombineResult.class);
    writer.visitInnerClass(combinerClass.getInternalName(), target.getInternalName(),
            combinerClass.getSimpleName(), Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);

    OperatorInput input = operator.getInput(Fold.ID_INPUT);
    defineDependenciesConstructor(context, operator.getOutputs(), target, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, combinerClass);//from   w w w . j a va  2s .  co m
        getNew(method, input.getDataType());
        method.visitVarInsn(Opcodes.ALOAD, 1);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(CombineResult.class).getInternalName(), "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ObjectCombiner.class), typeOf(DataModel.class),
                        typeOf(Result.class)),
                false);
    }, Lang.discard());
    writer.visitEnd();

    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

private ClassDescription generateCombinerClass(Context context, UserOperator operator, ClassDescription outer) {
    ClassDescription target = getCombinerName(outer);
    OperatorInput input = operator.getInput(0);

    ClassWriter writer = newWriter(target, Object.class, ObjectCombiner.class);
    writer.visitOuterClass(outer.getInternalName(), target.getInternalName(), null);

    FieldRef impl = defineOperatorField(writer, operator, target);
    defineEmptyConstructor(writer, Object.class, method -> {
        setOperatorField(method, operator, impl);
    });//from   ww w  .j a  v  a 2s  . co m
    defineBuildKey(context, writer, input.getDataType(), input.getGroup());

    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "combine",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(Object.class)), null, null);

    List<ValueRef> arguments = new ArrayList<>();
    arguments.add(impl);
    arguments.add(m -> {
        m.visitVarInsn(Opcodes.ALOAD, 1);
        m.visitTypeInsn(Opcodes.CHECKCAST, typeOf(input.getDataType()).getInternalName());
    });
    arguments.add(m -> {
        m.visitVarInsn(Opcodes.ALOAD, 2);
        m.visitTypeInsn(Opcodes.CHECKCAST, typeOf(input.getDataType()).getInternalName());
    });
    for (VertexElement dep : context.getDependencies(operator.getArguments())) {
        Invariants.require(dep.getElementKind() == ElementKind.VALUE);
        ValueDescription value = ((ValueElement) dep).getValue();
        arguments.add(m -> {
            getConst(method, Invariants.safe(() -> value.resolve(context.getClassLoader())));
        });
    }
    invoke(method, context, operator, arguments);
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
    return context.addClassFile(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  ww . j  a va2  s . c o  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.FoldOperatorGenerator.java

License:Apache License

private void defineSimpleCombine(Context context, UserOperator operator, ClassWriter writer, FieldRef impl,
        FieldRef acc, Map<OperatorProperty, FieldRef> map) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "combine",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), null, null);

    TypeDescription dataType = operator.getInput(Fold.ID_INPUT).getDataType();
    LocalVarRef object = cast(method, 1, dataType);

    List<ValueRef> arguments = new ArrayList<>();
    arguments.add(impl);// w  w  w  .java 2  s.  co  m
    arguments.add(acc);
    arguments.add(object);
    appendSecondaryInputs(arguments::add, operator, map::get);
    appendArguments(arguments::add, operator, map::get);
    invoke(method, context, operator, arguments);

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

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

License:Apache License

private void defineSimpleFinish(ClassWriter writer, FieldRef acc, ValueRef result) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "finish",
            Type.getMethodDescriptor(typeOf(void.class)), null, null);

    result.load(method);//from   w  ww .j  av a2  s. com
    acc.load(method);
    invokeResultAdd(method);

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

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

License:Apache License

private static ClassData generateClass(Context context, UserOperator operator, ClassDescription target) {
    ClassDescription mapperClass = generateMapperClass(context, operator, target);
    ClassDescription combinerClass = generateCombinerClass(context, operator, target);

    ClassWriter writer = newWriter(target, CombineResult.class);
    writer.visitInnerClass(mapperClass.getInternalName(), target.getInternalName(), mapperClass.getSimpleName(),
            Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
    writer.visitInnerClass(combinerClass.getInternalName(), target.getInternalName(),
            combinerClass.getSimpleName(), Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);

    OperatorOutput output = operator.getOutput(Summarize.ID_OUTPUT);
    defineDependenciesConstructor(context, operator.getOutputs(), target, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, combinerClass);//from   w w w.ja v a  2  s.com
        getNew(method, output.getDataType());
        method.visitVarInsn(Opcodes.ALOAD, 1);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(CombineResult.class).getInternalName(),
                CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ObjectCombiner.class),
                        typeOf(DataModel.class), typeOf(Result.class)),
                false);
    }, Lang.discard());

    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

static ClassDescription generateMapperClass(Context context, UserOperator operator, ClassDescription outer) {
    ClassDescription target = getMapperName(outer);

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

    ClassWriter writer = newWriter(target, Object.class, Function.class);
    writer.visitOuterClass(outer.getInternalName(), target.getSimpleName(), null);

    FieldRef buffer = defineField(writer, target, "buffer", typeOf(output.getDataType()));
    defineEmptyConstructor(writer, Object.class, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, output.getDataType());
        putField(method, buffer);/* w w w  .  j a v a  2s.com*/
    });

    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "apply",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(Object.class)), null, null);

    LocalVarRef inputVar = cast(method, 1, input.getDataType());
    buffer.load(method);
    LocalVarRef outputVar = putLocalVar(method, Type.OBJECT, 2);

    outputVar.load(method);
    resetDataModel(method, output.getDataType());

    List<PropertyFolding> foldings = Invariants
            .safe(() -> SummarizedModelUtil.getPropertyFoldings(context.getClassLoader(), operator));
    DataModelReference inputModel = context.getDataModelLoader().load(input.getDataType());
    DataModelReference outputModel = context.getDataModelLoader().load(output.getDataType());
    Set<PropertyReference> nullChecked = new HashSet<>();
    for (PropertyFolding folding : foldings) {
        PropertyMapping mapping = folding.getMapping();
        Aggregation aggregation = folding.getAggregation();
        PropertyReference src = Invariants.requireNonNull(inputModel.findProperty(mapping.getSourceProperty()));
        PropertyReference dst = Invariants
                .requireNonNull(outputModel.findProperty(mapping.getDestinationProperty()));
        mapping(method, target, aggregation, src, dst, inputVar, outputVar, nullChecked);
    }

    outputVar.load(method);
    method.visitInsn(Opcodes.ARETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();

    if (nullChecked.isEmpty() == false) {
        defineCheckNull(writer, operator, inputModel);
    }

    return context.addClassFile(new ClassData(target, writer::toByteArray));
}

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

License:Apache License

static ClassDescription generateCombinerClass(Context context, UserOperator operator, ClassDescription outer) {
    ClassDescription target = getCombinerName(outer);
    OperatorInput input = operator.getInput(Summarize.ID_INPUT);
    OperatorOutput output = operator.getOutput(Summarize.ID_OUTPUT);

    ClassWriter writer = newWriter(target, Object.class, ObjectCombiner.class);
    writer.visitOuterClass(outer.getInternalName(), target.getSimpleName(), null);
    defineEmptyConstructor(writer, Object.class);
    defineBuildKey(context, writer, output.getDataType(), input.getGroup());

    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "combine",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(Object.class)), null, null);

    LocalVarRef leftVar = cast(method, 1, output.getDataType());
    LocalVarRef rightVar = cast(method, 2, output.getDataType());

    List<PropertyFolding> foldings = Invariants
            .safe(() -> SummarizedModelUtil.getPropertyFoldings(context.getClassLoader(), operator));
    DataModelReference outputModel = context.getDataModelLoader().load(output.getDataType());
    for (PropertyFolding folding : foldings) {
        PropertyMapping mapping = folding.getMapping();
        Aggregation aggregation = folding.getAggregation();
        PropertyReference property = Invariants
                .requireNonNull(outputModel.findProperty(mapping.getDestinationProperty()));
        combine(method, aggregation, property, leftVar, rightVar);
    }/*from   w  w  w .  j  a  v  a  2 s  . co  m*/

    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
    return context.addClassFile(new ClassData(target, writer::toByteArray));
}

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

License:Apache License

static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType,
        Group group) {//from w w  w  .  j  a  v a2  s  . c om
    DataModelReference type = context.getDataModelLoader().load(dataType);
    List<PropertyReference> props = group.getGrouping().stream()
            .map(p -> Invariants.requireNonNull(type.findProperty(p))).collect(Collectors.toList());

    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "buildKey",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(KeyBuffer.class), typeOf(Object.class)), null,
            null);

    LocalVarRef key = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef object = cast(v, 2, dataType);
    for (PropertyReference p : props) {
        key.load(v);
        object.load(v);
        getOption(v, p);
        v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(KeyBuffer.class).getInternalName(), "append",
                Type.getMethodDescriptor(typeOf(KeyBuffer.class), typeOf(Object.class)), true);
        v.visitInsn(Opcodes.POP);
    }

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

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

License:Apache License

/**
 * Creates a new {@link ClassWriter}.//  ww w  . j av  a  2s. c  om
 * @param aClass the target class
 * @param superClass the super class
 * @param interfaces the interface types
 * @return the created class writer
 */
public static ClassWriter newWriter(ClassDescription aClass, Class<?> superClass, Class<?>... interfaces) {
    Arguments.require(superClass.isInterface() == false);
    Lang.forEach(interfaces, c -> Arguments.require(c.isInterface()));
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    writer.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, aClass.getInternalName(), null,
            typeOf(superClass).getInternalName(),
            Stream.of(interfaces).map(c -> typeOf(c).getInternalName()).toArray(String[]::new));
    return writer;
}