List of usage examples for org.objectweb.asm MethodVisitor visitMaxs
public void visitMaxs(final int maxStack, final int maxLocals)
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds constant {@code toString()} method. * @param writer the current writer/* w ww.j ava2 s . c om*/ * @param value the constant value */ public static void defineToString(ClassVisitor writer, String value) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, "toString", Type.getMethodDescriptor(typeOf(String.class)), null, null); getConst(method, value); method.visitInsn(Opcodes.ARETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
private static List<Tuple<VertexElement, FieldRef>> defineDependenciesConstructor0(ClassDescription aClass, ClassVisitor writer, Iterable<? extends VertexElement> dependencies, Consumer<MethodVisitor> superConstructor, Consumer<MethodVisitor> callback) { List<Tuple<VertexElement, FieldRef>> results = new ArrayList<>(); int index = 0; int varIndex = 1; List<Type> parameterTypes = new ArrayList<>(); List<Consumer<MethodVisitor>> ctor = new ArrayList<>(); for (VertexElement element : dependencies) { int current = index++; int currentVar = varIndex; String name = getDependencyId(current); Type type = typeOf(element.getRuntimeType()); parameterTypes.add(type);/*from w ww . ja v a 2 s. com*/ FieldRef ref = defineField(writer, aClass, name, type); ctor.add(v -> { v.visitVarInsn(Opcodes.ALOAD, 0); v.visitVarInsn(loadOpcodeOf(element.getRuntimeType()), currentVar); putField(v, ref); }); varIndex += categoryOf(element.getRuntimeType()); results.add(new Tuple<>(element, ref)); } MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, parameterTypes.stream().toArray(Type[]::new)), null, null); superConstructor.accept(method); ctor.forEach(c -> c.accept(method)); callback.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); return results; }
From source file:com.asakusafw.dag.compiler.codegen.CleanupStageClientGenerator.java
License:Apache License
private static void defineString(ClassWriter writer, String name, String value) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PROTECTED, name, Type.getMethodDescriptor(typeOf(String.class)), null, new String[0]); getConst(method, value);/*from w ww .ja v a 2 s . c o m*/ method.visitInsn(Opcodes.ARETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.DataComparatorGenerator.java
License:Apache License
private static void defineCompare(ClassWriter writer, DataModelReference reference, List<Group.Ordering> orderings) { MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "compare", DESC_COMPARE, null, new String[] { typeOf(IOException.class).getInternalName(), }); LocalVarRef a = new LocalVarRef(Opcodes.ALOAD, 1); LocalVarRef b = new LocalVarRef(Opcodes.ALOAD, 2); for (Group.Ordering ordering : orderings) { PropertyReference property = Invariants .requireNonNull(reference.findProperty(ordering.getPropertyName())); // int diff = ValueOptionSerDe.compareT({a, b}, {b, a}); switch (ordering.getDirection()) { case ASCENDANT: a.load(v);// ww w. j a va 2 s .c o m b.load(v); break; case DESCENDANT: b.load(v); a.load(v); break; default: throw new AssertionError(ordering); } v.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(ValueOptionSerDe.class).getInternalName(), Invariants.requireNonNull(METHOD_NAMES.get(property.getType())), DESC_COMPARE, false); 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.EdgeDataTableAdapterGenerator.java
License:Apache License
private static void defineBuildKey(ClassGeneratorContext context, ClassWriter writer, TypeDescription dataType, Group group) {/*from w ww . ja va2 s. co m*/ 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.KeyValueSerDeGenerator.java
License:Apache License
private static void putSerialize(String methodName, DataModelReference reference, List<PropertyReference> properties, ClassWriter writer) { MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, methodName, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null, new String[] { typeOf(IOException.class).getInternalName(), typeOf(InterruptedException.class).getInternalName(), }); if (properties.isEmpty()) { LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2); output.load(v);/*from w w w .j a v a2s. com*/ getConst(v, 0); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataOutput.class).getInternalName(), "writeByte", Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), true); } else { 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(); }
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);/*from www . j a va 2 s. com*/ 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 w w . j av 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 generateBody(MethodVisitor v, TypeDescription type, LocalVarRef target, LocalVarRef source) {//from w ww . j ava 2 s. com 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); }/*from w w w . ja v a 2s . c o m*/ method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }