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:org.adjective.stout.operation.ConstructorExpression.java

License:Apache License

public void getInstructions(ExecutionStack stack, InstructionCollector collector) {
    addInstruction(collector, new TypeInstruction(Opcodes.NEW, _constructor.getType().getInternalName()));
    addInstruction(collector, new GenericInstruction(Opcodes.DUP));
    for (Expression expression : _expressions) {
        expression.getInstructions(stack, collector);
    }/*w  ww  .  j a  v a 2 s.co m*/
    String descriptor = MethodInstruction.getMethodDescriptor(Void.TYPE, _constructor.getParameterTypes());
    addInstruction(collector, new MethodInstruction(Opcodes.INVOKESPECIAL,
            _constructor.getType().getInternalName(), "<init>", descriptor));
}

From source file:org.adjective.stout.operation.InvokeSuperConstructorStatement.java

License:Apache License

public void getInstructions(ExecutionStack stack, InstructionCollector collector) {
    addInstruction(collector, new VarInstruction(Opcodes.ALOAD, 0));
    for (int i = 0; i < _arguments.length; i++) {
        Expression expr = _arguments[i];
        UnresolvedType expressionType = expr.getExpressionType(stack);
        UnresolvedType parameterType = _method.getParameterTypes()[i];
        if (!expressionType.canAssignTo(parameterType)) {
            throw new OperationException("Cannot assign expression " + expr + " (" + expressionType
                    + ") to parameter " + i + "(" + parameterType + ") of " + _method);
        }/*from   ww  w  . j a va2s. c o m*/
        expr.getInstructions(stack, collector);
    }
    String superName = stack.currentClass().getSuperClass().getInternalName();
    new MethodInstruction(Opcodes.INVOKESPECIAL, superName, _method).getInstructions(stack, collector);
}

From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java

License:Apache License

public void visitMethodInsn(int opcode, String owner, String name, String desc) {

    Type[] argumentTypes = Type.getArgumentTypes(desc);
    Type returnType = Type.getReturnType(desc);

    StringBuilder args = new StringBuilder();

    for (int i = argumentTypes.length; i > 0; i--) {
        args.insert(0, pop(argumentTypes[i - 1]).description + ",");
    }/*from   w ww .jav a 2s. co m*/
    switch (opcode) {
    case Opcodes.INVOKESTATIC:
        break;
    case Opcodes.INVOKEINTERFACE:
    case Opcodes.INVOKEVIRTUAL:
    case Opcodes.INVOKESPECIAL:
        pop(Type.getObjectType(owner));
        break;
    default:
        throw new IllegalArgumentException("Unsupported opcode " + OPCODES[opcode]);
    }

    String description = simpleName(owner) + "." + name + "(" + args + ")";
    if (!returnType.equals(Type.VOID_TYPE)) {
        push(description, returnType);
    }
    print(opcode, description + " {" + desc + "}");
}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherEvaluatorCreationVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (!name.equals(METHOD_NAME)) {
        return null;
    }//from   w  w w . j  a v a  2  s .  c  om
    return new MethodVisitor(Opcodes.ASM5, null) {

        @Override
        public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
            if (opcode != Opcodes.INVOKESPECIAL) {
                return;
            }
            if (owner.startsWith(ownerPrefix)) {
                createdEvaluatorClassNames.add(owner);
            }
        }
    };

}

From source file:org.apache.asterix.runtime.evaluators.staticcodegen.GatherEvaluatorFactoryCreationVisitor.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if (!name.equals(METHOD_NAME)) {
        return null;
    }//  w w w  .j a  v a2s .c o  m
    return new MethodVisitor(Opcodes.ASM5, null) {

        @Override
        public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
            if (opcode != Opcodes.INVOKESPECIAL) {
                return;
            }
            if (owner.startsWith(ownerPrefix)) {
                createdEvaluatorFactoryClassNames.add(owner);
            }
        }
    };
}

From source file:org.apache.commons.javaflow.bytecode.transformation.asm.ContinuationMethodAnalyzer.java

License:Apache License

boolean needsFrameGuard(int opcode, String owner, String name, String desc) {
    /* TODO: need to customize a way enchancer skips classes/methods
    if (owner.startsWith("java/")) {//ww w .  ja v a2s  .  com
        System.out.println("SKIP:: " + owner + "." + name + desc);
        return false;
    }
    */

    if (opcode == Opcodes.INVOKEINTERFACE || (opcode == Opcodes.INVOKESPECIAL && !"<init>".equals(name))
            || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEVIRTUAL) {
        return true;
    }
    return false;
}

From source file:org.apache.commons.javaflow.providers.asm3.ContinuableMethodNode.java

License:Apache License

boolean needsFrameGuard(int opcode, String owner, String name, String desc) {
    if (owner.startsWith("java/") || owner.startsWith("javax/")) {
        //System.out.println("SKIP:: " + owner + "." + name + desc);
        return false;
    }//w w w . j  ava  2s. c o m

    // Always create save-point before Continuation methods (like suspend)
    if (CONTINUATION_CLASS_INTERNAL_NAME.equals(owner)) {
        return CONTINUATION_CLASS_CONTINUABLE_METHODS.contains(name);
    }

    // No need to create save-point before constructors -- it's forbidden to suspend in constructors anyway
    if (opcode == Opcodes.INVOKESPECIAL && "<init>".equals(name)) {
        return false;
    }

    if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC
            || opcode == Opcodes.INVOKEVIRTUAL) {
        final ContinuableClassInfo classInfo;
        try {
            classInfo = cciResolver.resolve(owner);
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
        return null != classInfo && classInfo.isContinuableMethod(opcode, name, desc, desc);
    }
    return false;
}

From source file:org.apache.commons.javaflow.providers.asm4.ContinuableMethodNode.java

License:Apache License

boolean needsFrameGuard(int opcode, String owner, String name, String desc) {
    if (owner.startsWith("java/") || owner.startsWith("javax/")) {
        //System.out.println("SKIP:: " + owner + "." + name + desc);
        return false;
    }/*from  w  w  w.j a va  2 s  .  c o  m*/

    // Always create save-point before Continuation methods (like suspend)
    if (CONTINUATION_CLASS_INTERNAL_NAME.equals(owner)) {
        return CONTINUATION_CLASS_CONTINUABLE_METHODS.contains(name);
    }

    // No need to create save-point before constructors -- it's forbidden to suspend in constructors anyway
    if (opcode == Opcodes.INVOKESPECIAL && "<init>".equals(name)) {
        return false;
    }

    if (opcode == Opcodes.INVOKEDYNAMIC) {
        // TODO verify CallSite to be continuable?
        return true;
    }

    if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC
            || opcode == Opcodes.INVOKEVIRTUAL) {
        final ContinuableClassInfo classInfo;
        try {
            classInfo = cciResolver.resolve(owner);
        } catch (final IOException ex) {
            throw new RuntimeException(ex);
        }
        return null != classInfo && classInfo.isContinuableMethod(opcode, name, desc, desc);
    }
    return false;
}

From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java

License:Apache License

private static void addReadOverride(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "read_value",
            "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V", null, null);
    mv.visitCode();/*from  w ww.j  a  v  a  2s.  com*/
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(54, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(55, l2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_read",
            "(Lorg/omg/CORBA/portable/InputStream;)V");
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l3);
    mv.visitLabel(l1);
    mv.visitLineNumber(57, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 2);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "read_value",
            "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V");
    mv.visitLabel(l3);
    mv.visitLineNumber(59, l3);
    mv.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0);
    mv.visitLocalVariable("is", "Lorg/omg/CORBA/portable/InputStream;", null, l0, l4, 1);
    mv.visitLocalVariable("t", "Lorg/omg/CORBA/TypeCode;", null, l0, l4, 2);
    mv.visitMaxs(3, 3);
    mv.visitEnd();
}

From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java

License:Apache License

private static void addWriteOverride(ClassWriter cw) {
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "write_value",
            "(Lorg/omg/CORBA/portable/OutputStream;)V", null, null);
    mv.visitCode();//from w  w  w .jav  a2  s  .  co m
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(61, l0);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IFNULL, l1);
    Label l2 = new Label();
    mv.visitLabel(l2);
    mv.visitLineNumber(62, l2);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj",
            "Lorg/omg/CORBA/portable/Streamable;");
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_write",
            "(Lorg/omg/CORBA/portable/OutputStream;)V");
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.GOTO, l3);
    mv.visitLabel(l1);
    mv.visitLineNumber(64, l1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "write_value",
            "(Lorg/omg/CORBA/portable/OutputStream;)V");
    mv.visitLabel(l3);
    mv.visitLineNumber(66, l3);
    mv.visitInsn(Opcodes.RETURN);
    Label l4 = new Label();
    mv.visitLabel(l4);
    mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0);
    mv.visitLocalVariable("os", "Lorg/omg/CORBA/portable/OutputStream;", null, l0, l4, 1);
    mv.visitMaxs(2, 2);
    mv.visitEnd();

}