Example usage for org.objectweb.asm Opcodes INVOKESPECIAL

List of usage examples for org.objectweb.asm Opcodes INVOKESPECIAL

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes INVOKESPECIAL.

Prototype

int INVOKESPECIAL

To view the source code for org.objectweb.asm Opcodes INVOKESPECIAL.

Click Source Link

Usage

From source file:com.android.tools.klint.client.api.LintDriver.java

License:Apache License

@Nullable
private static MethodInsnNode findConstructorInvocation(@NonNull MethodNode method, @NonNull String className) {
    InsnList nodes = method.instructions;
    for (int i = 0, n = nodes.size(); i < n; i++) {
        AbstractInsnNode instruction = nodes.get(i);
        if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
            MethodInsnNode call = (MethodInsnNode) instruction;
            if (className.equals(call.owner)) {
                return call;
            }// w  w w.  j av a 2s .  c o  m
        }
    }

    return null;
}

From source file:com.android.tools.lint.checks.WrongCallDetector.java

License:Apache License

@Override
public void checkCall(@NonNull ClassContext context, @NonNull ClassNode classNode, @NonNull MethodNode method,
        @NonNull MethodInsnNode call) {/*from www .  j a va  2s.  c  o  m*/
    String name = call.name;
    // Call is only allowed if it is both only called on the super class (invoke special)
    // as well as within the same overriding method (e.g. you can't call super.onLayout
    // from the onMeasure method)
    if (call.getOpcode() != Opcodes.INVOKESPECIAL || !name.equals(method.name)) {
        String suggestion = Character.toLowerCase(name.charAt(2)) + name.substring(3);
        String message = String.format(
                "Suspicious method call; should probably call \"%1$s\" rather than \"%2$s\"", suggestion, name);
        context.report(ISSUE, method, call, context.getLocation(call), message, null);
    }
}

From source file:com.android.tools.lint.client.api.LintDriver.java

License:Apache License

@Nullable
private static MethodInsnNode findConstructorInvocation(@NonNull MethodNode method, @NonNull String className) {
    InsnList nodes = ((MethodNode) method).instructions;
    for (int i = 0, n = nodes.size(); i < n; i++) {
        AbstractInsnNode instruction = nodes.get(i);
        if (instruction.getOpcode() == Opcodes.INVOKESPECIAL) {
            MethodInsnNode call = (MethodInsnNode) instruction;
            if (className.equals(call.owner)) {
                return call;
            }//from ww  w  .j  a va  2 s.  c  o  m
        }
    }

    return null;
}

From source file:com.asakusafw.dag.compiler.builtin.FoldOperatorGenerator.java

License:Apache License

private ClassData generateClass(Context context, UserOperator operator, ClassDescription target) {
    ClassDescription combinerClass = generateCombinerClass(context, operator, target);
    ClassWriter writer = newWriter(target, CombineResult.class);
    writer.visitInnerClass(combinerClass.getInternalName(), target.getInternalName(),
            combinerClass.getSimpleName(), Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);

    OperatorInput input = operator.getInput(Fold.ID_INPUT);
    defineDependenciesConstructor(context, operator.getOutputs(), target, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, combinerClass);// w  w  w .  ja va2  s .c  o  m
        getNew(method, input.getDataType());
        method.visitVarInsn(Opcodes.ALOAD, 1);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(CombineResult.class).getInternalName(), "<init>",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ObjectCombiner.class), typeOf(DataModel.class),
                        typeOf(Result.class)),
                false);
    }, Lang.discard());
    writer.visitEnd();

    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.builtin.FoldOperatorGenerator.java

License:Apache License

private ClassData generateSimpleClass(Context context, UserOperator operator, ClassDescription target) {
    TypeDescription dataType = operator.getInput(Fold.ID_INPUT).getDataType();

    ClassWriter writer = newWriter(target, SimpleCombineResult.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    FieldRef acc = defineField(writer, target, "acc", typeOf(dataType)); //$NON-NLS-1$
    Map<OperatorProperty, FieldRef> map = defineConstructor(context, operator, target, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL,
                AsmUtil.typeOf(SimpleCombineResult.class).getInternalName(), CONSTRUCTOR_NAME,
                Type.getMethodDescriptor(Type.VOID_TYPE), false);

        setOperatorField(method, operator, impl);

        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, dataType);/*  w  w w  . j  av a  2  s .  c om*/
        putField(method, acc);
    }, method -> Lang.pass());
    defineSimpleStart(operator, writer, acc);
    defineSimpleCombine(context, operator, writer, impl, acc, map);
    defineSimpleFinish(writer, acc, map.get(operator.getOutput(Fold.ID_OUTPUT)));
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.builtin.MasterJoinLikeOperatorGenerator.java

License:Apache License

private ClassData genTableClass(Context context, UserOperator operator, ClassDescription target) {
    OperatorInput master = MasterJoinOperatorUtil.getMasterInput(operator);
    List<OperatorProperty> externals = getExternalProperties(operator);
    int masterIndex = externals.indexOf(master);
    Invariants.require(masterIndex >= 0);

    ClassWriter writer = newWriter(target, TableJoinResult.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    Consumer<MethodVisitor> initializer = defineExtraFields(writer, context, operator, target);
    Map<OperatorProperty, FieldRef> dependencies = defineConstructor(context, externals, target, writer,
            method -> {//from w ww  . ja  v a  2s  .  co  m
                method.visitVarInsn(Opcodes.ALOAD, 0);
                method.visitVarInsn(Opcodes.ALOAD, masterIndex + 1);
                method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(TableJoinResult.class).getInternalName(),
                        CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(DataTable.class)),
                        false);
            }, method -> {
                setOperatorField(method, operator, impl);
                initializer.accept(method);
            });
    OperatorInput transaction = MasterJoinOperatorUtil.getTransactionInput(operator);
    defineBuildKey(context, writer, transaction.getDataType(), transaction.getGroup());
    defineSelection(context, writer, operator, impl, dependencies);
    defineProcess(context, writer, operator, impl, dependencies, target);
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.builtin.MasterJoinLikeOperatorGenerator.java

License:Apache License

private ClassData genMergeClass(Context context, UserOperator operator, ClassDescription target) {
    OperatorInput master = MasterJoinOperatorUtil.getMasterInput(operator);
    OperatorInput transaction = MasterJoinOperatorUtil.getTransactionInput(operator);
    ClassWriter writer = newWriter(target, MergeJoinResult.class);
    FieldRef impl = defineOperatorField(writer, operator, target);
    Consumer<MethodVisitor> initializer = defineExtraFields(writer, context, operator, target);
    Map<OperatorProperty, FieldRef> dependencies = defineConstructor(context, operator, target, writer,
            method -> {/* ww w .  j  av  a 2s.c  o m*/
                method.visitVarInsn(Opcodes.ALOAD, 0);
                getInt(method, context.getGroupIndex(master));
                getInt(method, context.getGroupIndex(transaction));
                method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(MergeJoinResult.class).getInternalName(),
                        CONSTRUCTOR_NAME,
                        Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE, Type.INT_TYPE), false);
            }, method -> {
                setOperatorField(method, operator, impl);
                initializer.accept(method);
            });
    defineSelection(context, writer, operator, impl, dependencies);
    defineProcess(context, writer, operator, impl, dependencies, target);
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java

License:Apache License

private static ClassData generateClass(Context context, UserOperator operator, ClassDescription target) {
    ClassDescription mapperClass = generateMapperClass(context, operator, target);
    ClassDescription combinerClass = generateCombinerClass(context, operator, target);

    ClassWriter writer = newWriter(target, CombineResult.class);
    writer.visitInnerClass(mapperClass.getInternalName(), target.getInternalName(), mapperClass.getSimpleName(),
            Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
    writer.visitInnerClass(combinerClass.getInternalName(), target.getInternalName(),
            combinerClass.getSimpleName(), Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);

    OperatorOutput output = operator.getOutput(Summarize.ID_OUTPUT);
    defineDependenciesConstructor(context, operator.getOutputs(), target, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        getNew(method, combinerClass);/*from   www  .java  2s  . c o  m*/
        getNew(method, output.getDataType());
        method.visitVarInsn(Opcodes.ALOAD, 1);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(CombineResult.class).getInternalName(),
                CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ObjectCombiner.class),
                        typeOf(DataModel.class), typeOf(Result.class)),
                false);
    }, Lang.discard());

    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.builtin.SummarizeOperatorGenerator.java

License:Apache License

private static void defineCheckNull(ClassWriter writer, UserOperator operator, DataModelReference inputType) {

    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, METHOD_CHECK_NON_NULL,
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(ValueOption.class), typeOf(Object.class),
                    typeOf(String.class)),
            null, null);/*from   w  ww  .ja  v  a 2 s.c  o  m*/

    LocalVarRef optionVar = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef objectVar = new LocalVarRef(Opcodes.ALOAD, 1);
    LocalVarRef nameVar = new LocalVarRef(Opcodes.ALOAD, 2);

    // if (option.isNull()) {
    Label ifEnd = new Label();
    optionVar.load(method);
    getNullity(method, VALUE_DESC);
    method.visitJumpInsn(Opcodes.IFEQ, ifEnd);

    // new NullPointerException ...
    method.visitTypeInsn(Opcodes.NEW, typeOf(NullPointerException.class).getInternalName());
    method.visitInsn(Opcodes.DUP);

    // str = String.format("<type>.%s must not be null (in <operator>): %s", name, object)
    getConst(method,
            String.format("%s.%%s must not be null (in %s.%s): %%s", inputType.getDeclaration().getSimpleName(),
                    operator.getMethod().getDeclaringClass().getSimpleName(), operator.getMethod().getName()));

    getArray(method, typeOf(Object.class), new LocalVarRef[] { nameVar, objectVar });
    method.visitMethodInsn(Opcodes.INVOKESTATIC, typeOf(String.class).getInternalName(), "format",
            Type.getMethodDescriptor(typeOf(String.class), typeOf(String.class), typeOf(Object[].class)),
            false);

    // throw new NullPointerException(str)
    method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(NullPointerException.class).getInternalName(),
            CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(String.class)), false);

    method.visitInsn(Opcodes.ATHROW);

    method.visitLabel(ifEnd);
    // }
    method.visitInsn(Opcodes.RETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
}

From source file:com.asakusafw.dag.compiler.builtin.Util.java

License:Apache License

static Map<OperatorProperty, FieldRef> defineConstructor(Context context, Operator operator,
        ClassDescription aClass, ClassVisitor writer, Consumer<MethodVisitor> body) {
    return defineConstructor(context, operator, aClass, writer, method -> {
        method.visitVarInsn(Opcodes.ALOAD, 0);
        method.visitMethodInsn(Opcodes.INVOKESPECIAL, AsmUtil.typeOf(Object.class).getInternalName(),
                CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false);
    }, body);/*  w  w w. ja v a  2s.  c  o  m*/
}