List of usage examples for org.objectweb.asm MethodVisitor visitVarInsn
public void visitVarInsn(final int opcode, final int var)
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 a v a2s.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.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);/*from w ww . ja v a2 s .co m*/ }); 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.Util.java
License:Apache License
static void setOperatorField(MethodVisitor method, UserOperator operator, FieldRef field) { method.visitVarInsn(Opcodes.ALOAD, 0); AsmUtil.getNew(method, operator.getImplementationClass()); AsmUtil.putField(method, field);/*from w w w. j av a 2s .c o m*/ }
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);// w w w. ja v a 2s. c om }
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);/* ww w. ja v a 2 s .c om*/ }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an empty constructor.// w ww. j av a2 s. c o m * @param writer the target class * @param superClass the super class * @param body the constructor body */ public static void defineEmptyConstructor(ClassWriter writer, Class<?> superClass, Consumer<MethodVisitor> body) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(superClass).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false); body.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an adapter constructor./* w w w . ja v a 2 s .c o m*/ * @param writer the target class * @param superClass the super class * @param body the constructor body */ public static void defineAdapterConstructor(ClassWriter writer, Class<?> superClass, Consumer<MethodVisitor> body) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(VertexProcessorContext.class)), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(superClass).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(VertexProcessorContext.class)), false); body.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Performs {@code T_STORE} instruction. * @param method the target method//from w ww .j a v a 2 s .c o m * @param sort the target type sort * @param index the target local variable index * @return the target local variable ref */ public static LocalVarRef putLocalVar(MethodVisitor method, int sort, int index) { int load; int store; switch (sort) { case Type.BOOLEAN: case Type.BYTE: case Type.SHORT: case Type.CHAR: case Type.INT: load = Opcodes.ILOAD; store = Opcodes.ISTORE; break; case Type.LONG: load = Opcodes.LLOAD; store = Opcodes.LSTORE; break; case Type.FLOAT: load = Opcodes.FLOAD; store = Opcodes.FSTORE; break; case Type.DOUBLE: load = Opcodes.DLOAD; store = Opcodes.DSTORE; break; case Type.ARRAY: case Type.OBJECT: load = Opcodes.ALOAD; store = Opcodes.ASTORE; break; default: throw new AssertionError(sort); } method.visitVarInsn(store, index); return new LocalVarRef(load, index); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Cast the local variable.//from w ww.j a v a 2 s. com * @param method the writer * @param index the variable index * @param type the target type * @return the target variable */ public static LocalVarRef cast(MethodVisitor method, int index, TypeDescription type) { method.visitVarInsn(Opcodes.ALOAD, index); method.visitTypeInsn(Opcodes.CHECKCAST, AsmUtil.typeOf(type).getInternalName()); return putLocalVar(method, Type.OBJECT, index); }
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); }//from w w w .j ava 2 s .c o m method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }