List of usage examples for org.objectweb.asm Opcodes INVOKEVIRTUAL
int INVOKEVIRTUAL
To view the source code for org.objectweb.asm Opcodes INVOKEVIRTUAL.
Click Source Link
From source file:com.asakusafw.dag.compiler.builtin.MasterJoinLikeOperatorGenerator.java
License:Apache License
private static void defineSelection(Context context, ClassWriter writer, UserOperator operator, FieldRef impl, Map<OperatorProperty, FieldRef> dependencies) { Method selector = Invariants.safe(() -> { return MasterJoinOperatorUtil.getSelection(context.getClassLoader(), operator); });/*from w w w . j a va 2 s . c o m*/ if (selector == null) { return; } MethodVisitor method = writer.visitMethod(Opcodes.ACC_PROTECTED | Opcodes.ACC_FINAL, "selectMaster", Type.getMethodDescriptor(typeOf(Object.class), typeOf(List.class), typeOf(Object.class)), null, null); cast(method, 2, MasterJoinOperatorUtil.getTransactionInput(operator).getDataType()); List<ValueRef> arguments = new ArrayList<>(); impl.load(method); arguments.add(new LocalVarRef(Opcodes.ALOAD, 1)); arguments.add(new LocalVarRef(Opcodes.ALOAD, 2)); arguments .addAll(Lang.project(getExtraViews(operator), v -> Invariants.requireNonNull(dependencies.get(v)))); arguments .addAll(Lang.project(operator.getArguments(), v -> Invariants.requireNonNull(dependencies.get(v)))); for (int i = 0, n = selector.getParameterCount(); i < n; i++) { arguments.get(i).load(method); } method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(selector.getDeclaringClass()).getInternalName(), selector.getName(), Type.getMethodDescriptor(selector), false); method.visitInsn(Opcodes.ARETURN); method.visitMaxs(0, 0); method.visitEnd(); }
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 a 2s.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
private static void countMapper(MethodVisitor method, PropertyReference src, PropertyReference dst, LocalVarRef srcVar, LocalVarRef dstVar) { Invariants.require(dst.getType().equals(LONG_DESC)); dstVar.load(method);//from ww w . j a v a2 s .c o m getOption(method, dst); getConst(method, 1L); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(LONG_DESC).getInternalName(), "modify", Type.getMethodDescriptor(typeOf(LONG_DESC), Type.LONG_TYPE), false); }
From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java
License:Apache License
private static void sumMapper(MethodVisitor method, ClassDescription target, PropertyReference src, PropertyReference dst, LocalVarRef srcVar, LocalVarRef dstVar, Set<PropertyReference> nullChecked) { dstVar.load(method);/*from w w w . j av a2s . c o m*/ getOption(method, dst); srcVar.load(method); getOption(method, src); checkNull(method, target, src, srcVar, nullChecked); TypeDescription srcOptionType = src.getType(); Type srcEntityType = Invariants.requireNonNull(ENTITY_TYPE_MAP.get(srcOptionType)); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(srcOptionType).getInternalName(), "get", Type.getMethodDescriptor(srcEntityType), false); if (srcOptionType.equals(BYTE_DESC) || srcOptionType.equals(SHORT_DESC) || srcOptionType.equals(INT_DESC)) { method.visitInsn(Opcodes.I2L); } else if (srcOptionType.equals(FLOAT_DESC)) { method.visitInsn(Opcodes.F2D); } TypeDescription dstOptionType = dst.getType(); Type dstEntityType = Invariants.requireNonNull(ENTITY_TYPE_MAP.get(dstOptionType)); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dstOptionType).getInternalName(), "modify", Type.getMethodDescriptor(typeOf(dstOptionType), dstEntityType), false); }
From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java
License:Apache License
private static void combine(MethodVisitor method, String targetName, PropertyReference prop, LocalVarRef leftVar, LocalVarRef rightVar, boolean parent) { leftVar.load(method);/* w ww . ja v a 2 s . c o m*/ getOption(method, prop); rightVar.load(method); getOption(method, prop); Type declaring = typeOf(parent ? VALUE_DESC : prop.getType()); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, declaring.getInternalName(), targetName, Type.getMethodDescriptor(Type.VOID_TYPE, declaring), false); }
From source file:com.asakusafw.dag.compiler.builtin.Util.java
License:Apache License
static void invoke(MethodVisitor method, Context context, UserOperator operator, List<ValueRef> arguments) { for (ValueRef var : arguments) { var.load(method); }// www. j a v a 2s. c o m Method ref = Invariants.safe(() -> operator.getMethod().resolve(context.getClassLoader())); Invariants.require(Modifier.isStatic(ref.getModifiers()) == false); Invariants.require(ref.getDeclaringClass().isInterface() == false); Invariants.require(arguments.size() == ref.getParameterCount() + 1); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, AsmUtil.typeOf(ref.getDeclaringClass()).getInternalName(), ref.getName(), Type.getMethodDescriptor(ref), false); }
From source file:com.asakusafw.dag.compiler.builtin.Util.java
License:Apache License
static void mapping(MethodVisitor method, DataModelLoader loader, List<PropertyMapping> mappings, Map<OperatorInput, ValueRef> inputRefs, Map<OperatorOutput, ValueRef> outputRefs) { Map<OperatorInput, DataModelReference> inputTypes = inputRefs.keySet().stream().collect( Collectors.toMap(Function.identity(), p -> Invariants.safe(() -> loader.load(p.getDataType())))); Map<OperatorOutput, DataModelReference> outputTypes = outputRefs.keySet().stream().collect( Collectors.toMap(Function.identity(), p -> Invariants.safe(() -> loader.load(p.getDataType())))); Map<OperatorOutput, Map<PropertyName, PropertyReference>> open = new HashMap<>(); outputTypes.forEach((p, m) -> open.put(p, m.getProperties().stream() .collect(Collectors.toMap(PropertyReference::getName, Function.identity())))); for (PropertyMapping mapping : mappings) { ValueRef srcRef = Invariants.requireNonNull(inputRefs.get(mapping.getSourcePort())); PropertyReference srcProp = Invariants.requireNonNull( inputTypes.get(mapping.getSourcePort()).findProperty(mapping.getSourceProperty())); ValueRef dstRef = Invariants.requireNonNull(outputRefs.get(mapping.getDestinationPort())); PropertyReference dstProp = Invariants.requireNonNull( outputTypes.get(mapping.getDestinationPort()).findProperty(mapping.getDestinationProperty())); Invariants.require(srcProp.getType().equals(dstProp.getType())); open.get(mapping.getDestinationPort()).remove(mapping.getDestinationProperty()); dstRef.load(method);/* ww w. j a va2s .c o m*/ AsmUtil.getOption(method, dstProp); srcRef.load(method); AsmUtil.getOption(method, srcProp); AsmUtil.copyOption(method, srcProp.getType()); } open.forEach((p, map) -> { ValueRef ref = outputRefs.get(p); // always non null? if (ref != null) { map.forEach((name, prop) -> { ref.load(method); AsmUtil.getOption(method, prop); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(ValueOption.class).getInternalName(), "setNull", Type.getMethodDescriptor(typeOf(ValueOption.class)), false); }); } }); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds a {@code get*Option()} method invocation. * @param method the target method/*from w ww. j av a 2 s. com*/ * @param property the target property */ public static void getOption(MethodVisitor method, PropertyReference property) { MethodDescription decl = property.getDeclaration(); assert decl.getParameterTypes().isEmpty(); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, decl.getDeclaringClass().getInternalName(), decl.getName(), Type.getMethodDescriptor(typeOf(property.getType())), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Invokes {@code ValueOption#isNull()}. * @param method the target method/* w w w.j a v a 2 s.co m*/ * @param dataType the data type */ public static void getNullity(MethodVisitor method, TypeDescription dataType) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "isNull", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Invokes {@code ValueOption#copyFrom(ValueOption)}. * @param method the target method//w ww . j av a 2s . c o m * @param dataType the data type */ public static void copyOption(MethodVisitor method, TypeDescription dataType) { method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "copyFrom", Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(dataType)), false); }