List of usage examples for org.objectweb.asm Opcodes ALOAD
int ALOAD
To view the source code for org.objectweb.asm Opcodes ALOAD.
Click Source Link
From source file:com.asakusafw.dag.compiler.codegen.CoGroupInputAdapterGenerator.java
License:Apache License
/** * Generates {@link ExtractInputAdapter} class. * @param context the current context/* w w w .java2 s . c o m*/ * @param inputs the target output ports * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, List<Spec> inputs, ClassDescription target) { ClassWriter writer = AsmUtil.newWriter(target, CoGroupInputAdapter.class); defineAdapterConstructor(writer, CoGroupInputAdapter.class, v -> { for (Spec spec : inputs) { ClassDescription supplier = SupplierGenerator.get(context, spec.dataType); v.visitVarInsn(Opcodes.ALOAD, 0); getConst(v, spec.id); getConst(v, typeOf(supplier)); getEnumConstant(v, spec.bufferType); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$ Type.getMethodDescriptor(typeOf(CoGroupInputAdapter.class), typeOf(String.class), typeOf(Class.class), typeOf(CoGroupInputAdapter.BufferType.class)), false); v.visitInsn(Opcodes.POP); } }); return new ClassData(target, writer::toByteArray); }
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);//from w w w . j a v a 2 s. co 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
/** * Generates {@link EdgeDataTableAdapter} class. * @param context the current context//from w ww. j av a 2 s . co m * @param specs the target output ports * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) { ClassWriter writer = AsmUtil.newWriter(target, EdgeDataTableAdapter.class); defineAdapterConstructor(writer, EdgeDataTableAdapter.class, v -> { LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0); int index = 0; for (Spec spec : specs) { ClassDescription keyBuilder; if (spec.group.getGrouping().isEmpty()) { keyBuilder = null; } else { keyBuilder = generateKeyBuilder(context, spec, qualify(target, "k", index)); } ClassDescription copier = ObjectCopierGenerator.get(context, spec.dataType); ClassDescription comparator = toComparatorClass(context, spec); TypeDescription[] keyElementTypes = toKeyElementTypes(context, spec); self.load(v); getConst(v, spec.tableId); getConst(v, spec.inputId); getConst(v, keyBuilder); getConst(v, copier); getConst(v, comparator); getArray(v, typeOf(Class.class), keyElementTypes); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", Type.getMethodDescriptor(typeOf(EdgeDataTableAdapter.class), typeOf(String.class), typeOf(String.class), typeOf(Class.class), typeOf(Class.class), typeOf(Class.class), typeOf(Class[].class)), false); v.visitInsn(Opcodes.POP); index++; } }); return new ClassData(target, writer::toByteArray); }
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 ww w . ja v a 2 s . c o 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.EdgeOutputAdapterGenerator.java
License:Apache License
/** * Generates {@link EdgeOutputAdapter} class. * @param context the current context/*from w w w .ja va 2s.c o m*/ * @param specs the target output ports * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) { ClassWriter writer = AsmUtil.newWriter(target, EdgeOutputAdapter.class); defineAdapterConstructor(writer, EdgeOutputAdapter.class, v -> { for (Spec spec : specs) { v.visitVarInsn(Opcodes.ALOAD, 0); getConst(v, spec.id); getConst(v, spec.mapper); getConst(v, spec.copier); getConst(v, spec.combiner); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", Type.getMethodDescriptor(typeOf(EdgeOutputAdapter.class), typeOf(String.class), typeOf(Class.class), typeOf(Class.class), typeOf(Class.class)), false); v.visitInsn(Opcodes.POP); } }); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.ExtractAdapterGenerator.java
License:Apache License
/** * Generates the class./* ww w . jav a 2 s . co m*/ * @param successor the successor * @param target the target class * @return the generated class */ public ClassData generate(VertexElement successor, ClassDescription target) { Arguments.require(successor.getRuntimeType().equals(RESULT_TYPE)); ClassWriter writer = newWriter(target, Object.class, Result.class); List<Tuple<VertexElement, FieldRef>> pairs = defineDependenciesConstructor(target, writer, Arrays.asList(successor), Lang.discard()); Invariants.require(pairs.size() == 1); defineResultAdd(writer, method -> { pairs.get(0).right().load(method); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitTypeInsn(Opcodes.CHECKCAST, typeOf(ExtractOperation.Input.class).getInternalName()); method.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(ExtractOperation.Input.class).getInternalName(), "getObject", Type.getMethodDescriptor(typeOf(Object.class)), true); invokeResultAdd(method); }); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.ExtractInputAdapterGenerator.java
License:Apache License
/** * Generates {@link ExtractInputAdapter} class. * @param context the current context/*from w w w. j a v a 2 s . com*/ * @param input the target input spec * @param target the target class * @return the generated class data */ public ClassData generate(ClassGeneratorContext context, Spec input, ClassDescription target) { ClassWriter writer = newWriter(target, ExtractInputAdapter.class); defineAdapterConstructor(writer, ExtractInputAdapter.class, v -> { v.visitVarInsn(Opcodes.ALOAD, 0); getConst(v, input.id); v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$ Type.getMethodDescriptor(typeOf(ExtractInputAdapter.class), typeOf(String.class)), false); v.visitInsn(Opcodes.POP); }); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java
License:Apache License
private static ClassData generate0(DataModelReference reference, Group grouping, ClassDescription target) { List<PropertyReference> keys = Lang.project(grouping.getGrouping(), n -> Invariants.requireNonNull(reference.findProperty(n))); List<PropertyReference> values = collectValues(reference, grouping); ClassWriter writer = newWriter(target, Object.class, KeyValueSerDe.class); FieldRef buffer = defineField(writer, target, "buffer", typeOf(reference)); defineEmptyConstructor(writer, Object.class, v -> { v.visitVarInsn(Opcodes.ALOAD, 0); getNew(v, reference.getDeclaration()); putField(v, buffer);//from w w w . j ava 2 s . com }); putSerialize("serializeKey", reference, keys, writer); putSerialize("serializeValue", reference, values, writer); putDeserialize(reference, keys, values, buffer, writer); return new ClassData(target, writer::toByteArray); }
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 ww .java2 s . 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);// ww w.j a v a2 s . co 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(); }