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.codegen.KeyValueSerDeGenerator.java

License:Apache License

private static void putDeserialize(DataModelReference reference, List<PropertyReference> keys,
        List<PropertyReference> values, FieldRef buffer, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserializePair",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(DataInput.class), typeOf(DataInput.class)),
            null, new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef keyInput = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef valueInput = new LocalVarRef(Opcodes.ALOAD, 2);
    self.load(v);/*w w  w.j a  v a 2  s  .  c  o  m*/
    getField(v, buffer);
    LocalVarRef object = putLocalVar(v, Type.OBJECT, 3);
    putDeserializeBody(v, keys, keyInput, object);
    putDeserializeBody(v, values, valueInput, object);
    object.load(v);
    v.visitInsn(Opcodes.ARETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

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

License:Apache License

private static void defineCompare(ClassWriter writer, DataModelReference reference,
        List<Group.Ordering> orderings) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "compare",
            Type.getMethodDescriptor(typeOf(int.class), typeOf(Object.class), typeOf(Object.class)), null,
            null);/*from  w  ww  .jav a 2 s  .  c  o m*/
    LocalVarRef a = cast(v, 1, reference.getDeclaration());
    LocalVarRef b = cast(v, 2, reference.getDeclaration());
    for (Group.Ordering ordering : orderings) {
        LocalVarRef left;
        LocalVarRef right;
        switch (ordering.getDirection()) {
        case ASCENDANT:
            left = a;
            right = b;
            break;
        case DESCENDANT:
            left = b;
            right = a;
            break;
        default:
            throw new AssertionError(ordering);
        }

        // int diff = left.getXOption().compareTo(right.getXOption());
        PropertyReference property = Invariants
                .requireNonNull(reference.findProperty(ordering.getPropertyName()));
        left.load(v);
        getOption(v, property);
        right.load(v);
        getOption(v, property);
        v.visitMethodInsn(Opcodes.INVOKEINTERFACE, TYPE_COMPARABLE.getInternalName(), "compareTo",
                Type.getMethodDescriptor(typeOf(int.class), typeOf(Object.class)), true);
        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.ObjectCopierGenerator.java

License:Apache License

private static void defineNew(ClassWriter writer, TypeDescription source) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "newCopy",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(Object.class)), null, null);
    LocalVarRef input = cast(v, 1, source);
    getNew(v, source);/*from w  w w  .  j a  v a2  s .c  o  m*/
    LocalVarRef target = putLocalVar(v, Type.OBJECT, 2);
    generateBody(v, source, target, input);
}

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

License:Apache License

private static void defineNewWithBuffer(ClassWriter writer, TypeDescription source) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "newCopy",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(Object.class), typeOf(Object.class)), null,
            null);/*from w  ww  . j  a  v a  2s  .c o  m*/
    LocalVarRef input = cast(v, 1, source);
    LocalVarRef target = cast(v, 2, source);
    generateBody(v, source, target, input);
}

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

License:Apache License

private static void addConstructor(ClassWriter writer, ClassDescription target, List<VertexElement> elements,
        Function<VertexElement, String> ids) {
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(OperationAdapter.Context.class)), null, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(Object.class).getInternalName(), "<init>",
            Type.getMethodDescriptor(Type.VOID_TYPE), false);

    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitVarInsn(Opcodes.ALOAD, 1);
    method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), FIELD_CONTEXT,
            typeOf(OperationAdapter.Context.class).getDescriptor());

    for (VertexElement element : elements) {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, target.getInternalName(), ids.apply(element),
                Type.getMethodDescriptor(Type.VOID_TYPE), false);
    }//w w w . j  a  va2s  .  c om
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

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

License:Apache License

private static void addProcessMethod(ClassWriter writer, ClassDescription target, OperationSpec graph) {
    VertexElement consumer = graph.getInput().getConsumer();
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "process",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class)), null, null);
    method.visitVarInsn(Opcodes.ALOAD, 0);
    method.visitFieldInsn(Opcodes.GETFIELD, target.getInternalName(), graph.getId(consumer),
            typeOf(consumer.getRuntimeType()).getDescriptor());
    method.visitVarInsn(Opcodes.ALOAD, 1);
    invokeResultAdd(method);//ww  w .j av a2 s .co  m
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

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 va2s .  c o 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);//w  w  w . j ava 2 s.  com
    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();
}

From source file:com.asakusafw.dag.compiler.directio.OutputPatternSerDeGenerator.java

License:Apache License

private static void putGetProperty(ClassWriter writer, DataModelReference reference, OutputPattern pattern) {
    List<PropertyReference> properties = pattern.getResourcePattern().stream()
            .filter(s -> s.getKind() == OutputPattern.SourceKind.PROPERTY).map(CompiledSegment::getTarget)
            .collect(Collectors.toList());
    if (properties.isEmpty()) {
        return;//from w  w  w .j a va2s.co  m
    }
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "getProperty",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(Object.class), typeOf(int.class)), null,
            null);
    LocalVarRef object = cast(v, 1, reference.getDeclaration());
    LocalVarRef index = new LocalVarRef(Opcodes.ILOAD, 2);
    Label[] caseLabels = properties.stream().map(o -> new Label()).toArray(Label[]::new);
    Label defaultLabel = new Label();

    index.load(v);
    v.visitTableSwitchInsn(0, caseLabels.length - 1, defaultLabel, caseLabels);

    for (int i = 0, n = properties.size(); i < n; i++) {
        v.visitLabel(caseLabels[i]);
        PropertyReference property = properties.get(i);
        object.load(v);
        getOption(v, property);
        v.visitInsn(Opcodes.ARETURN);
    }
    v.visitLabel(defaultLabel);
    getNew(v, Descriptions.typeOf(AssertionError.class));
    v.visitInsn(Opcodes.ATHROW);

    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.directio.OutputPatternSerDeGenerator.java

License:Apache License

private static void putSerialize(DataModelReference reference, List<PropertyReference> properties,
        ClassWriter writer) {//from  ww w .  j a v a 2  s. c o m
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "serializeValue",
            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 : 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();
}