Example usage for org.objectweb.asm Opcodes DRETURN

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

Introduction

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

Prototype

int DRETURN

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

Click Source Link

Usage

From source file:lombok.patcher.MethodLogistics.java

License:Open Source License

private static int returnOpcodeFor(String returnSpec) {
    switch (returnSpec.charAt(0)) {
    case 'D':
        return Opcodes.DRETURN;
    case 'J':
        return Opcodes.LRETURN;
    case 'F':
        return Opcodes.FRETURN;
    case 'I':
    case 'S':
    case 'B':
    case 'Z':
        return Opcodes.IRETURN;
    case 'V':
        return Opcodes.RETURN;
    case 'L':
    case '[':
        return Opcodes.ARETURN;
    }/*from   ww  w.  j a  v a2  s .  c o m*/

    throw new IllegalStateException("Uhoh - bug - unrecognized JVM type: " + returnSpec);
}

From source file:lucee.transformer.bytecode.util.JavaProxyFactory.java

License:Open Source License

private static void _createMethod(ClassWriter cw, Map<String, Class> mDone, Method src, String className)
        throws IOException {
    Class<?>[] classArgs = src.getParameterTypes();
    Class<?> classRtn = src.getReturnType();

    String str = src.getName() + "(" + Reflector.getDspMethods(classArgs) + ")";
    Class rtnClass = mDone.get(str);
    if (rtnClass != null) {
        if (rtnClass != classRtn)
            throw new IOException("there is a conflict with method [" + str
                    + "], this method is declared more than once with different return types.");
        return;/*from w  w  w  .java 2 s .  c om*/
    }
    mDone.put(str, classRtn);

    Type[] typeArgs = ASMUtil.toTypes(classArgs);
    Type typeRtn = Type.getType(classRtn);

    org.objectweb.asm.commons.Method method = new org.objectweb.asm.commons.Method(src.getName(), typeRtn,
            typeArgs);
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, method, null, null,
            cw);
    //BytecodeContext bc = new BytecodeContext(statConstr,constr,null,null,keys,cw,className,adapter,method,writeLog);
    Label start = adapter.newLabel();
    adapter.visitLabel(start);

    //JavaProxy.call(cfc,"add",new Object[]{arg0})
    // config
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitFieldInsn(Opcodes.GETFIELD, className, "config", CONFIG_WEB_NAME);

    // cfc
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitFieldInsn(Opcodes.GETFIELD, className, "cfc", COMPONENT_NAME);

    // name
    adapter.push(src.getName());

    // arguments
    ArrayVisitor av = new ArrayVisitor();
    av.visitBegin(adapter, Types.OBJECT, typeArgs.length);
    for (int y = 0; y < typeArgs.length; y++) {
        av.visitBeginItem(adapter, y);
        adapter.loadArg(y);
        if (classArgs[y] == boolean.class)
            adapter.invokeStatic(JAVA_PROXY, _BOOLEAN);
        else if (classArgs[y] == byte.class)
            adapter.invokeStatic(JAVA_PROXY, _BYTE);
        else if (classArgs[y] == char.class)
            adapter.invokeStatic(JAVA_PROXY, _CHAR);
        else if (classArgs[y] == double.class)
            adapter.invokeStatic(JAVA_PROXY, _DOUBLE);
        else if (classArgs[y] == float.class)
            adapter.invokeStatic(JAVA_PROXY, _FLOAT);
        else if (classArgs[y] == int.class)
            adapter.invokeStatic(JAVA_PROXY, _INT);
        else if (classArgs[y] == long.class)
            adapter.invokeStatic(JAVA_PROXY, _LONG);
        else if (classArgs[y] == short.class)
            adapter.invokeStatic(JAVA_PROXY, _SHORT);
        else {
            adapter.invokeStatic(JAVA_PROXY, _OBJECT);
        }

        av.visitEndItem(adapter);
    }
    av.visitEnd();
    adapter.invokeStatic(JAVA_PROXY, CALL);

    //JavaProxy.to...(...);
    int rtn = Opcodes.IRETURN;
    if (classRtn == boolean.class)
        adapter.invokeStatic(JAVA_PROXY, TO_BOOLEAN);
    else if (classRtn == byte.class)
        adapter.invokeStatic(JAVA_PROXY, TO_BYTE);
    else if (classRtn == char.class)
        adapter.invokeStatic(JAVA_PROXY, TO_CHAR);
    else if (classRtn == double.class) {
        rtn = Opcodes.DRETURN;
        adapter.invokeStatic(JAVA_PROXY, TO_DOUBLE);
    } else if (classRtn == float.class) {
        rtn = Opcodes.FRETURN;
        adapter.invokeStatic(JAVA_PROXY, TO_FLOAT);
    } else if (classRtn == int.class)
        adapter.invokeStatic(JAVA_PROXY, TO_INT);
    else if (classRtn == long.class) {
        rtn = Opcodes.LRETURN;
        adapter.invokeStatic(JAVA_PROXY, TO_LONG);
    } else if (classRtn == short.class)
        adapter.invokeStatic(JAVA_PROXY, TO_SHORT);
    else if (classRtn == void.class) {
        rtn = Opcodes.RETURN;
        adapter.pop();
    } else {
        rtn = Opcodes.ARETURN;
        adapter.checkCast(typeRtn);
    }

    /*mv = cw.visitMethod(ACC_PUBLIC, "add", "(Ljava/lang/Object;)Z", null, null);
    mv.visitCode();
    Label l0 = new Label();
    mv.visitLabel(l0);
    mv.visitLineNumber(20, l0);
    mv.visitVarInsn(ALOAD, 0);
    mv.visitFieldInsn(GETFIELD, "Test", "cfc", "Ljava/lang/Object;");
    mv.visitLdcInsn("add");
    mv.visitInsn(ICONST_1);
    mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    mv.visitInsn(DUP);
    mv.visitInsn(ICONST_0);
    mv.visitVarInsn(ALOAD, 1);
    mv.visitInsn(AASTORE);
    mv.visitMethodInsn(INVOKESTATIC, "JavaProxy", "call", "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;");
    mv.visitMethodInsn(INVOKESTATIC, "JavaProxy", "toBoolean", "(Ljava/lang/Object;)Z");
    mv.visitInsn(IRETURN);
    Label l1 = new Label();
    mv.visitLabel(l1);
    mv.visitLocalVariable("this", "LTest;", null, l0, l1, 0);
    mv.visitLocalVariable("arg0", "Ljava/lang/Object;", null, l0, l1, 1);
    mv.visitMaxs(6, 2);
    mv.visitEnd();*/

    adapter.visitInsn(rtn);
    adapter.endMethod();

}

From source file:net.cazzar.corelib.asm.MethodTransformer.java

License:Open Source License

private boolean isReturn(AbstractInsnNode node) {
    switch (node.getOpcode()) {
    case Opcodes.RET:
    case Opcodes.RETURN:
    case Opcodes.ARETURN:
    case Opcodes.DRETURN:
    case Opcodes.FRETURN:
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
        return true;

    default:/*from   w w  w .  j  a  v  a2  s  .c  o  m*/
        return false;
    }
}

From source file:org.apache.sling.metrics.impl.ReturnAdapter.java

License:Apache License

@Override
protected void onMethodExit(int opcode) {
    switch (opcode) {
    case Opcodes.IRETURN:
    case Opcodes.LRETURN:
    case Opcodes.FRETURN:
    case Opcodes.DRETURN:
    case Opcodes.ARETURN:

        try {/*w  w  w  . j a va2 s. co  m*/
            addReturnMetric(opcode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    super.onMethodExit(opcode);
}

From source file:org.apache.sling.metrics.impl.ReturnAdapter.java

License:Apache License

public void addReturnMetric(int opcode) {
    // make a copt of the top of the stack so the return value can ba passed
    // to the resource
    // Class.record(returnValue, timerName);
    if (Opcodes.DRETURN == opcode || Opcodes.LRETURN == opcode) {
        mv.visitInsn(Opcodes.DUP2);//from  ww  w  . jav a2  s  . c  o m
    } else {
        mv.visitInsn(Opcodes.DUP);
    }
    if (helperClassName != null) {
        mv.visitLdcInsn(timerName);
        mv.visitLdcInsn(helperClassName);
        if (mark) {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, MARK_CAPTURE_USING_HELPER,
                    RETURN_METHOD_CAPTURE_DESC, false);
        } else {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, COUNT_CAPTURE_USING_HELPER,
                    RETURN_METHOD_CAPTURE_DESC, false);
        }
    } else if (keyMethodName != null) {
        mv.visitLdcInsn(timerName);
        mv.visitLdcInsn(keyMethodName);
        if (mark) {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, MARK_CAPTURE,
                    RETURN_METHOD_CAPTURE_DESC, false);
        } else {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, COUNT_CAPTURE,
                    RETURN_METHOD_CAPTURE_DESC, false);
        }
    } else {
        mv.visitLdcInsn(timerName);
        if (mark) {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, MARK_CAPTURE, RETURN_CAPTURE_DESC,
                    false);
        } else {
            mv.visitMethodInsn(Opcodes.INVOKESTATIC, RETURN_CAPTURE_CL, COUNT_CAPTURE, RETURN_CAPTURE_DESC,
                    false);
        }
    }
}

From source file:org.apache.tuscany.sca.interfacedef.java.jaxrs.CodeGenerationHelper.java

License:Apache License

public static int getReturnOPCode(String signature) {
    if ("Z".equals(signature) || "B".equals(signature) || "C".equals(signature) || "S".equals(signature)
            || "I".equals(signature)) {
        return Opcodes.IRETURN;
    }//from  w w w. j  av a 2  s  .  co m

    if ("J".equals(signature)) {
        return Opcodes.LRETURN;
    }

    if ("F".equals(signature)) {
        return Opcodes.FRETURN;
    }

    if ("D".equals(signature)) {
        return Opcodes.DRETURN;
    }
    if ("V".equals(signature)) {
        return Opcodes.RETURN;
    }

    return Opcodes.ARETURN;

}

From source file:org.batoo.jpa.core.impl.instance.Enhancer.java

License:Open Source License

private static int getReturnType(Class<?> paramClass) {
    if (!paramClass.isPrimitive() || paramClass.isArray()) {
        return Opcodes.ARETURN;
    }/*from   w  ww. j  a v  a 2 s .  com*/

    if (Long.TYPE == paramClass) {
        return Opcodes.LRETURN;
    }

    if (Float.TYPE == paramClass) {
        return Opcodes.FRETURN;
    }

    if (Double.TYPE == paramClass) {
        return Opcodes.DRETURN;
    }

    return Opcodes.IRETURN;
}

From source file:org.brutusin.instrumentation.Instrumentator.java

License:Apache License

private void addTraceReturn() {

    InsnList il = this.mn.instructions;

    Iterator<AbstractInsnNode> it = il.iterator();
    while (it.hasNext()) {
        AbstractInsnNode abstractInsnNode = it.next();

        switch (abstractInsnNode.getOpcode()) {
        case Opcodes.RETURN:
            il.insertBefore(abstractInsnNode, getVoidReturnTraceInstructions());
            break;
        case Opcodes.IRETURN:
        case Opcodes.LRETURN:
        case Opcodes.FRETURN:
        case Opcodes.ARETURN:
        case Opcodes.DRETURN:
            il.insertBefore(abstractInsnNode, getReturnTraceInstructions());
        }/*from  w  w  w  .  j  a  va 2s  . c  o  m*/
    }
}

From source file:org.cacheonix.impl.transformer.ByteInstructionTest.java

License:LGPL

/**
 * Test method for {@link ByteInstruction#getReturnCode(String desc)} .
 *///from  w  w w.  j a  va 2  s  .  c  om
public void testGetReturnCode() {

    String desc = "(IF)V";
    int ret = ByteInstruction.getReturnCode(desc);
    assertEquals(ret, Opcodes.RETURN);

    desc = "(IF)I";
    ret = ByteInstruction.getReturnCode(desc);
    assertEquals(ret, Opcodes.IRETURN);

    desc = "(IF)D";
    ret = ByteInstruction.getReturnCode(desc);
    assertEquals(ret, Opcodes.DRETURN);

    desc = "(IF)Ljava/lang/Object;";
    ret = ByteInstruction.getReturnCode(desc);
    assertEquals(ret, Opcodes.ARETURN);

}

From source file:org.coldswap.util.MethodUtil.java

License:Open Source License

public static int getRetOpcodeToReplace(Type retType) {
    String retDesc = retType.getDescriptor();
    int opcode = Opcodes.IRETURN;
    if ("Z".equals(retDesc)) {
        opcode = Opcodes.IRETURN;/*from   w  w  w .j  a v  a 2  s .  c  om*/
    } else if ("B".equals(retDesc)) {
        opcode = Opcodes.IRETURN;
    } else if ("C".equals(retDesc)) {
        opcode = Opcodes.IRETURN;
    } else if ("S".equals(retDesc)) {
        opcode = Opcodes.IRETURN;
    } else if ("I".equals(retDesc)) {
        opcode = Opcodes.IRETURN;
    } else if ("J".equals(retDesc)) {
        opcode = Opcodes.LRETURN;
    } else if ("F".equals(retDesc)) {
        opcode = Opcodes.FRETURN;
    } else if ("D".equals(retDesc)) {
        opcode = Opcodes.DRETURN;
    }
    return opcode;
}