List of usage examples for org.objectweb.asm MethodVisitor visitInsn
public void visitInsn(final int opcode)
From source file:com.asakusafw.dag.compiler.codegen.ObjectCopierGenerator.java
License:Apache License
private static void generateBody(MethodVisitor v, TypeDescription type, LocalVarRef target, LocalVarRef source) {//from ww w . ja va 2s.c o m target.load(v); source.load(v); copyDataModel(v, type); target.load(v); v.visitInsn(Opcodes.ARETURN); v.visitMaxs(0, 0); v.visitEnd(); }
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 .co m 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);/*from w w w.jav a 2 s .c o m*/ 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 addElementMethods(ClassWriter writer, ClassDescription target, List<VertexElement> elements, Function<VertexElement, String> ids) { for (VertexElement element : elements) { String id = ids.apply(element); MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE, id, Type.getMethodDescriptor(Type.VOID_TYPE), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); switch (element.getElementKind()) { case VALUE: getValue(method, target, (ValueElement) element, ids); break; case OPERATOR: case AGGREGATE: getClass(method, target, (ClassNode) element, ids); break; case OUTPUT: getOutput(method, target, (OutputNode) element, ids); break; case DATA_TABLE: getDataTable(method, target, (DataTableNode) element, ids); break; case CONTEXT: getContext(method, target, ids); break; case EMPTY_DATA_TABLE: getEmptyDataTable(method, target, ids); break; default://from ww w. j a v a2 s . c om throw new AssertionError(element.getElementKind()); } method.visitFieldInsn(Opcodes.PUTFIELD, target.getInternalName(), id, typeOf(element.getRuntimeType()).getDescriptor()); 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 getClass(MethodVisitor method, ClassDescription target, ClassNode element, Function<VertexElement, String> ids) { method.visitTypeInsn(Opcodes.NEW, element.getImplementationType().getInternalName()); method.visitInsn(Opcodes.DUP); List<Type> parameterTypes = new ArrayList<>(); for (VertexElement dep : element.getDependencies()) { parameterTypes.add(typeOf(dep.getRuntimeType())); get(method, target, dep, ids);// w ww. jav a2s. c o m } method.visitMethodInsn(Opcodes.INVOKESPECIAL, element.getImplementationType().getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, parameterTypes.stream().toArray(Type[]::new)), 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 ww w.j ava2 s . c om 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 ww w .ja v a2 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.codegen.VertexAdapterGenerator.java
License:Apache License
private static void putConf(MethodVisitor method, ClassDescription target, LocalVarRef self, ClassDescription value, String name) { self.load(method);/*from w ww . jav a 2 s .co m*/ getConst(method, value); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), name, Type.getMethodDescriptor(typeOf(VertexAdapter.class), typeOf(Class.class)), false); method.visitInsn(Opcodes.POP); }
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;/*w w w.ja v a 2s. c om*/ } 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 www .ja 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(); }