Example usage for org.objectweb.asm Opcodes IF_ICMPGT

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

Introduction

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

Prototype

int IF_ICMPGT

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

Click Source Link

Usage

From source file:dyco4j.instrumentation.internals.InitTracingMethodVisitor.java

License:BSD License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    mv.visitJumpInsn(opcode, label);/*  www.  ja v a  2s . c  o  m*/
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        this.stackFrame.pop();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        this.stackFrame.pop();
        this.stackFrame.pop();
        break;
    case Opcodes.JSR:
        this.stackFrame.push(OTHER);
        break;
    }
    addBranch(label);
}

From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java

License:Open Source License

private void interpret(JumpInsnNode insn, FrameState frame, BBInfo block) {
    //All JumpInsnNodes have a target.  Find it.
    BBInfo target = blockByInsn(insn.label);
    assert target != null;

    if (insn.getOpcode() == Opcodes.GOTO) {
        block.block.instructions().add(new JumpInst(target.block));
        return;/*w  w  w  .j  a v a  2  s .c  o m*/
    } else if (insn.getOpcode() == Opcodes.JSR)
        throw new UnsupportedOperationException("jsr not supported; upgrade to Java 6-era class files");

    //Remaining opcodes are branches.
    BBInfo fallthrough = blocks.get(blocks.indexOf(block) + 1);
    BranchInst.Sense sense = OPCODE_TO_SENSE.get(insn.getOpcode());
    //The second operand may come from the stack or may be a constant 0 or null.
    Value right;
    switch (insn.getOpcode()) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        right = module.constants().getConstant(0);
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        right = module.constants().getNullConstant();
        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        right = frame.stack.pop();
        break;
    default:
        throw new AssertionError("Can't happen! Branch opcode missing? " + insn.getOpcode());
    }
    //First operand always comes from the stack.
    Value left = frame.stack.pop();
    block.block.instructions().add(new BranchInst(left, sense, right, target.block, fallthrough.block));
}

From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java

License:Open Source License

private void emit(BranchInst i, InsnList insns) {
    //TODO: accessor methods on BranchInst
    Value left = i.getOperand(0), right = i.getOperand(1);
    BasicBlock target = (BasicBlock) i.getOperand(2), fallthrough = (BasicBlock) i.getOperand(3);
    if (!method.basicBlocks().contains(target))
        throw new IllegalArgumentException("Branch targets block not in method: " + i);
    if (!method.basicBlocks().contains(fallthrough))
        throw new IllegalArgumentException("Branch falls through to block not in method: " + i);
    load(i.getOperand(0), insns);//from   w  w  w.ja  va 2 s.c  o m
    load(i.getOperand(1), insns);
    //TODO: long, float, doubles need to go through CMP inst first
    int opcode;
    if (left.getType() instanceof ReferenceType || left.getType() instanceof VoidType) {
        switch (i.getSense()) {
        case EQ:
            opcode = Opcodes.IF_ACMPEQ;
            break;
        case NE:
            opcode = Opcodes.IF_ACMPNE;
            break;
        default:
            throw new AssertionError(i);
        }
    } else if (left.getType().isSubtypeOf(intType)) {
        switch (i.getSense()) {
        case EQ:
            opcode = Opcodes.IF_ICMPEQ;
            break;
        case NE:
            opcode = Opcodes.IF_ICMPNE;
            break;
        case LT:
            opcode = Opcodes.IF_ICMPLT;
            break;
        case GT:
            opcode = Opcodes.IF_ICMPGT;
            break;
        case LE:
            opcode = Opcodes.IF_ICMPLE;
            break;
        case GE:
            opcode = Opcodes.IF_ICMPGE;
            break;
        default:
            throw new AssertionError(i);
        }
    } else
        throw new AssertionError(i);
    insns.add(new JumpInsnNode(opcode, labels.get(target)));
    insns.add(new JumpInsnNode(Opcodes.GOTO, labels.get(fallthrough)));
}

From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDBVisitor.java

License:Open Source License

@Override
public void visitJumpInsn(int opcode, Label label) {
    currentMethod.setEmpty(false);// ww  w  . ja va2 s.c o  m
    currentMethod.setEmpty(false);
    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        //      case Opcodes.GOTO:
        //      case Opcodes.JSR:
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        // add all label reads/writes as condition reads/writes
        currentMethod.getConditionReads().addAll(labelReads);
        currentMethod.getConditionWrites().addAll(labelWrites);
        break;
    }
}

From source file:jpcsp.Allegrex.compiler.CompilerContext.java

License:Open Source License

/**
 * Generate the required Java code to call a syscall function.
 * The code generated must match the Java behavior implemented in
 * jpcsp.HLE.modules.HLEModuleFunctionReflection
 *
 * The following code is generated:/*from   w  w w  .j a  v  a2  s  .co m*/
 *     if (func.getFirmwareVersion() <= RuntimeContext.firmwareVersion) {
 *         if (!fastSyscall) {
 *             RuntimeContext.preSyscall();
 *         }
 *         if (func.checkInsideInterrupt()) {
 *             if (IntrManager.getInstance.isInsideInterrupt()) {
 *                 cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT;
 *                 goto afterSyscall;
 *             }
 *         }
 *         if (func.checkDispatchThreadEnabled()) {
 *             if (!Modules.ThreadManForUserModule.isDispatchThreadEnabled()) {
 *                 cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT;
 *                 goto afterSyscall;
 *             }
 *         }
 *         if (func.isUnimplemented()) {
 *             Modules.getLogger(func.getModuleName()).warn("Unimplemented <function name> parameterName1=parameterValue1, parameterName2=parameterValue2, ...");
 *         }
 *         foreach parameter {
 *             loadParameter(parameter);
 *         }
 *         try {
 *             returnValue = <module name>.<function name>(...parameters...);
 *             storeReturnValue();
 *             if (parameterReader.hasErrorPointer()) {
 *                 errorPointer.setValue(0);
 *             }
 *         } catch (SceKernelErrorException e) {
 *             errorCode = e.errorCode;
 *             if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) {
 *                 Modules.getLogger(func.getModuleName()).debug(String.format("<function name> return errorCode 0x%08X", errorCode));
 *             }
 *             if (parameterReader.hasErrorPointer()) {
 *                 errorPointer.setValue(errorCode);
 *                 cpu.gpr[_v0] = 0;
 *             } else {
 *                 cpu.gpr[_v0] = errorCode;
 *             }
 *             reload cpu.gpr[_ra]; // an exception is always clearing the whole stack
 *         }
 *         afterSyscall:
 *         if (fastSyscall) {
 *             RuntimeContext.postSyscallFast();
 *         } else {
 *             RuntimeContext.postSyscall();
 *         }
 *     } else {
 *         Modules.getLogger(func.getModuleName()).warn("<function name> is not supported in firmware version <firmwareVersion>, it requires at least firmware version <function firmwareVersion>");
 *         cpu.gpr[_v0] = -1;
 *     }
 *
 * @param func         the syscall function
 * @param fastSyscall  true if this is a fast syscall (i.e. without context switching)
 *                     false if not (i.e. a syscall where context switching could happen)
 */
private void visitSyscall(HLEModuleFunction func, boolean fastSyscall) {
    // The compilation of a syscall requires more stack size than usual
    maxStackSize = SYSCALL_MAX_STACK_SIZE;

    boolean needFirmwareVersionCheck = true;
    if (func.getFirmwareVersion() >= 999) {
        // Dummy version number meaning valid for all versions
        needFirmwareVersionCheck = false;
    } else if (isCodeInstructionInKernelMemory()) {
        // When compiling code in the kernel memory space, do not perform any version check.
        // This is used by overwritten HLE functions.
        needFirmwareVersionCheck = false;
    } else {
        // When compiling code loaded from flash0, do not perform any version check.
        // This is used by overwritten HLE functions.
        SceModule module = Managers.modules.getModuleByAddress(codeInstruction.getAddress());
        if (module != null && module.pspfilename != null && module.pspfilename.startsWith("flash0:")) {
            if (log.isDebugEnabled()) {
                log.debug(String.format("syscall from a flash0 module(%s, '%s'), no firmware version check",
                        module, module.pspfilename));
            }
            needFirmwareVersionCheck = false;
        }
    }

    Label unsupportedVersionLabel = null;
    if (needFirmwareVersionCheck) {
        unsupportedVersionLabel = new Label();
        loadImm(func.getFirmwareVersion());
        mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "firmwareVersion", "I");
        mv.visitJumpInsn(Opcodes.IF_ICMPGT, unsupportedVersionLabel);
    }

    // Save the syscall parameter to locals for debugging
    if (!fastSyscall) {
        saveParametersToLocals();
    }

    if (!fastSyscall) {
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "preSyscall", "()V");
    }

    Label afterSyscallLabel = new Label();

    if (func.checkInsideInterrupt()) {
        // if (IntrManager.getInstance().isInsideInterrupt()) {
        //     if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) {
        //         Modules.getLogger(func.getModuleName()).debug("<function name> return errorCode 0x80020064 (ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)");
        //     }
        //     cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT;
        //     goto afterSyscall
        // }
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(IntrManager.class), "getInstance",
                "()" + Type.getDescriptor(IntrManager.class));
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(IntrManager.class), "isInsideInterrupt",
                "()Z");
        Label notInsideInterrupt = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, notInsideInterrupt);

        loadModuleLoggger(func);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "isDebugEnabled", "()Z");
        Label notDebug = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, notDebug);
        loadModuleLoggger(func);
        mv.visitLdcInsn(
                String.format("%s returning errorCode 0x%08X (ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)",
                        func.getFunctionName(), SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT));
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "debug",
                "(" + Type.getDescriptor(Object.class) + ")V");
        mv.visitLabel(notDebug);

        storeRegister(_v0, SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT);
        mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel);
        mv.visitLabel(notInsideInterrupt);
    }

    if (func.checkDispatchThreadEnabled()) {
        // if (!Modules.ThreadManForUserModule.isDispatchThreadEnabled() || !Interrupts.isInterruptsEnabled()) {
        //     if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) {
        //         Modules.getLogger(func.getModuleName()).debug("<function name> return errorCode 0x800201A7 (ERROR_KERNEL_WAIT_CAN_NOT_WAIT)");
        //     }
        //     cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT;
        //     goto afterSyscall
        // }
        loadModule("ThreadManForUser");
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ThreadManForUser.class),
                "isDispatchThreadEnabled", "()Z");
        Label returnError = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, returnError);
        loadProcessor();
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Processor.class), "isInterruptsEnabled",
                "()Z");
        Label noError = new Label();
        mv.visitJumpInsn(Opcodes.IFNE, noError);

        mv.visitLabel(returnError);
        loadModuleLoggger(func);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "isDebugEnabled", "()Z");
        Label notDebug = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, notDebug);
        loadModuleLoggger(func);
        mv.visitLdcInsn(String.format("%s returning errorCode 0x%08X (ERROR_KERNEL_WAIT_CAN_NOT_WAIT)",
                func.getFunctionName(), SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT));
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "debug",
                "(" + Type.getDescriptor(Object.class) + ")V");
        mv.visitLabel(notDebug);

        storeRegister(_v0, SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT);
        mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel);
        mv.visitLabel(noError);
    }

    logSyscallStart(func);

    if (func.hasStackUsage()) {
        loadMemory();
        loadRegister(_sp);
        loadImm(func.getStackUsage());
        mv.visitInsn(Opcodes.ISUB);
        loadImm(0);
        loadImm(func.getStackUsage());
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "memset", "(IBI)V");
    }

    // Collecting the parameters and calling the module function...
    CompilerParameterReader parameterReader = new CompilerParameterReader(this);

    loadModule(func.getModuleName());
    parameterReader.incrementCurrentStackSize();

    Label tryStart = new Label();
    Label tryEnd = new Label();
    Label catchSceKernelErrorException = new Label();
    mv.visitTryCatchBlock(tryStart, tryEnd, catchSceKernelErrorException,
            Type.getInternalName(SceKernelErrorException.class));

    Class<?>[] parameterTypes = func.getHLEModuleMethod().getParameterTypes();
    Class<?> returnType = func.getHLEModuleMethod().getReturnType();
    StringBuilder methodDescriptor = new StringBuilder();
    methodDescriptor.append("(");

    Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations();
    int paramIndex = 0;
    for (Class<?> parameterType : parameterTypes) {
        methodDescriptor.append(Type.getDescriptor(parameterType));
        loadParameter(parameterReader, func, parameterType, paramsAnotations[paramIndex], afterSyscallLabel,
                catchSceKernelErrorException);
        paramIndex++;
    }
    methodDescriptor.append(")");
    methodDescriptor.append(Type.getDescriptor(returnType));

    mv.visitLabel(tryStart);

    mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
            Type.getInternalName(func.getHLEModuleMethod().getDeclaringClass()), func.getFunctionName(),
            methodDescriptor.toString());

    storeReturnValue(func, returnType);

    if (parameterReader.hasErrorPointer()) {
        // errorPointer.setValue(0);
        mv.visitVarInsn(Opcodes.ALOAD, LOCAL_ERROR_POINTER);
        loadImm(0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TErrorPointer32.class), "setValue",
                "(I)V");
    }

    loadRegister(_v0);
    logSyscallEnd(func, false);
    mv.visitInsn(Opcodes.POP);

    mv.visitLabel(tryEnd);
    mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel);

    // catch (SceKernelErrorException e) {
    //     errorCode = e.errorCode;
    //     if (Modules.log.isDebugEnabled()) {
    //         Modules.log.debug(String.format("<function name> return errorCode 0x%08X", errorCode));
    //     }
    //     if (hasErrorPointer()) {
    //         errorPointer.setValue(errorCode);
    //         cpu.gpr[_v0] = 0;
    //     } else {
    //         cpu.gpr[_v0] = errorCode;
    //     }
    // }
    mv.visitLabel(catchSceKernelErrorException);
    mv.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(SceKernelErrorException.class), "errorCode", "I");
    logSyscallEnd(func, true);
    if (parameterReader.hasErrorPointer()) {
        // errorPointer.setValue(errorCode);
        // cpu.gpr[_v0] = 0;
        mv.visitVarInsn(Opcodes.ALOAD, LOCAL_ERROR_POINTER);
        mv.visitInsn(Opcodes.SWAP);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TErrorPointer32.class), "setValue",
                "(I)V");
        storeRegister(_v0, 0);
    } else {
        // cpu.gpr[_v0] = errorCode;
        storeRegister(_v0);
    }

    // Reload the $ra register, the stack is lost after an exception
    CodeInstruction previousInstruction = codeBlock.getCodeInstruction(codeInstruction.getAddress() - 4);
    if (previousInstruction != null && previousInstruction.getInsn() == Instructions.JR) {
        int jumpRegister = (previousInstruction.getOpcode() >> 21) & 0x1F;
        loadRegister(jumpRegister);
    }

    mv.visitLabel(afterSyscallLabel);

    if (fastSyscall) {
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "postSyscallFast", "()V");
    } else {
        mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "postSyscall", "()V");
    }

    if (needFirmwareVersionCheck) {
        Label afterVersionCheckLabel = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, afterVersionCheckLabel);

        mv.visitLabel(unsupportedVersionLabel);
        loadModuleLoggger(func);
        mv.visitLdcInsn(String.format(
                "%s is not supported in firmware version %d, it requires at least firmware version %d",
                func.getFunctionName(), RuntimeContext.firmwareVersion, func.getFirmwareVersion()));
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "warn",
                "(" + Type.getDescriptor(Object.class) + ")V");
        storeRegister(_v0, -1);

        mv.visitLabel(afterVersionCheckLabel);
    }
}

From source file:name.martingeisse.minimal.compiler.Compiler.java

License:Open Source License

/**
 * Compiles a {@link MethodNode} to MCode.
 * // w w  w .  j  av a2s .  co  m
 * @param methodNode the method node to compile
 * @return the compiled code
 */
public ImmutableList<MCodeEntry> compile(final MethodNode methodNode) {
    for (int i = 0; i < methodNode.instructions.size(); i++) {
        final AbstractInsnNode instruction = methodNode.instructions.get(i);
        if (instruction instanceof LineNumberNode) {
            // ignored
        } else if (instruction instanceof FrameNode) {
            // this could be useful in the future
        } else if (instruction instanceof LabelNode) {
            label(((LabelNode) instruction).getLabel());
        } else if (instruction instanceof InsnNode) {
            switch (instruction.getOpcode()) {

            case Opcodes.ICONST_M1:
                iconst(-1);
                break;

            case Opcodes.ICONST_0:
                iconst(0);
                break;

            case Opcodes.ICONST_1:
                iconst(1);
                break;

            case Opcodes.ICONST_2:
                iconst(2);
                break;

            case Opcodes.ICONST_3:
                iconst(3);
                break;

            case Opcodes.ICONST_4:
                iconst(4);
                break;

            case Opcodes.ICONST_5:
                iconst(5);
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof VarInsnNode) {
            final VarInsnNode varInsnNode = (VarInsnNode) instruction;
            switch (varInsnNode.getOpcode()) {

            case Opcodes.ILOAD:
                iload(varInsnNode.var);
                break;

            case Opcodes.ISTORE:
                istore(varInsnNode.var);
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof IincInsnNode) {
            final IincInsnNode iincInsnNode = (IincInsnNode) instruction;
            iinc(iincInsnNode.var, iincInsnNode.incr);
        } else if (instruction instanceof JumpInsnNode) {
            final JumpInsnNode jumpInsnNode = (JumpInsnNode) instruction;
            switch (jumpInsnNode.getOpcode()) {

            case Opcodes.IFEQ:
            case Opcodes.IFNE:
            case Opcodes.IFLT:
            case Opcodes.IFGE:
            case Opcodes.IFGT:
            case Opcodes.IFLE:
                branch1(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode());
                break;

            case Opcodes.IF_ICMPEQ:
            case Opcodes.IF_ICMPNE:
            case Opcodes.IF_ICMPLT:
            case Opcodes.IF_ICMPGE:
            case Opcodes.IF_ICMPGT:
            case Opcodes.IF_ICMPLE:
                branch2(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode());
                break;

            case Opcodes.IFNULL:
            case Opcodes.IFNONNULL:
                // unsupported: one-argument reference comparison operator
                unsupported(instruction);
                break;

            case Opcodes.IF_ACMPEQ:
            case Opcodes.IF_ACMPNE:
                // unsupported: two-argument reference comparison operator
                unsupported(instruction);
                break;

            case Opcodes.GOTO:
                jump(jumpInsnNode.label.getLabel());
                break;

            case Opcodes.JSR:
                jsr(jumpInsnNode.label.getLabel());
                break;

            default:
                unsupported(instruction);
                break;

            }
        } else if (instruction instanceof IntInsnNode) {
            final IntInsnNode intInsnNode = (IntInsnNode) instruction;
            if (instruction.getOpcode() == Opcodes.BIPUSH || instruction.getOpcode() == Opcodes.SIPUSH) {
                iconst(intInsnNode.operand);
            } else {
                // NEWARRAY
                unsupported(instruction);
            }
        } else if (instruction instanceof MethodInsnNode) {
            final MethodInsnNode methodInsnNode = (MethodInsnNode) instruction;
            if (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC) {
                if (methodInsnNode.owner.replace('/', '.').equals(Native.class.getName())) {
                    nativeCall(methodInsnNode.name, methodInsnNode.desc);
                } else {
                    unsupported(instruction);
                }
            } else {
                unsupported(instruction);
            }
        } else {
            unsupported(instruction);
        }
    }
    return builder.build();
}

From source file:name.martingeisse.minimal.compiler.Compiler.java

License:Open Source License

private MBinaryIntegerOperator mapOperator(final int jvmOpcode) {
    switch (jvmOpcode) {

    case Opcodes.IFEQ:
    case Opcodes.IF_ICMPEQ:
        return MBinaryIntegerOperator.EQUAL;

    case Opcodes.IFNE:
    case Opcodes.IF_ICMPNE:
        return MBinaryIntegerOperator.NOT_EQUAL;

    case Opcodes.IFLT:
    case Opcodes.IF_ICMPLT:
        return MBinaryIntegerOperator.LESS_THAN;

    case Opcodes.IFLE:
    case Opcodes.IF_ICMPLE:
        return MBinaryIntegerOperator.LESS_THAN_OR_EQUAL;

    case Opcodes.IFGT:
    case Opcodes.IF_ICMPGT:
        return MBinaryIntegerOperator.GREATER_THAN;

    case Opcodes.IFGE:
    case Opcodes.IF_ICMPGE:
        return MBinaryIntegerOperator.GREATER_THAN_OR_EQUAL;

    default://from  w  ww  . j  a va  2  s.  c  om
        throw new IllegalArgumentException("cannot map comparison operator for JVM opcode: " + jvmOpcode);

    }
}

From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java

License:Open Source License

@Override
public void visitJumpInsn(final int opcode, final Label label) {
    T t = null;/*from  w w w  .ja v a  2s. c  om*/
    Object oValue = null;

    final int targetPc = getPc(label);

    switch (opcode) {
    /********
     * GOTO *
     ********/
    case Opcodes.GOTO: {
        final GOTO op = new GOTO(this.ops.size(), opcode, this.line);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
        break;
    }
    /********
     * JCMP *
     ********/
    case Opcodes.IF_ACMPEQ:
        t = T.REF;
        oValue = CmpType.T_EQ;
        // fall through
    case Opcodes.IF_ACMPNE:
        if (t == null) {
            t = T.REF;
            oValue = CmpType.T_NE;
        }
        // fall through
    case Opcodes.IF_ICMPEQ:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_EQ;
        }
        // fall through
    case Opcodes.IF_ICMPGE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GE;
        }
        // fall through
    case Opcodes.IF_ICMPGT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GT;
        }
        // fall through
    case Opcodes.IF_ICMPLE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LE;
        }
        // fall through
    case Opcodes.IF_ICMPLT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LT;
        }
        // fall through
    case Opcodes.IF_ICMPNE:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_NE;
        } {
        assert oValue instanceof CmpType;
        final JCMP op = new JCMP(this.ops.size(), opcode, this.line, t, (CmpType) oValue);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
    }
        break;
    /********
     * JCND *
     ********/
    case Opcodes.IFNULL:
        t = T.REF;
        oValue = CmpType.T_EQ;
        // fall through
    case Opcodes.IFNONNULL:
        if (t == null) {
            t = T.REF;
            oValue = CmpType.T_NE;
        }
        // fall through
    case Opcodes.IFEQ:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_EQ;
        }
        // fall through
    case Opcodes.IFGE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GE;
        }
        // fall through
    case Opcodes.IFGT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_GT;
        }
        // fall through
    case Opcodes.IFLE:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LE;
        }
        // fall through
    case Opcodes.IFLT:
        if (t == null) {
            t = T.INT;
            oValue = CmpType.T_LT;
        }
        // fall through
    case Opcodes.IFNE:
        if (t == null) {
            t = T.AINT; // boolean too
            oValue = CmpType.T_NE;
        } {
        assert oValue instanceof CmpType;
        final JCND op = new JCND(this.ops.size(), opcode, this.line, t, (CmpType) oValue);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
    }
        break;
    /*******
     * JSR *
     *******/
    case Opcodes.JSR: {
        final JSR op = new JSR(this.ops.size(), opcode, this.line);
        add(op);
        op.setTargetPc(targetPc);
        if (targetPc < 0) {
            getUnresolved(label).add(op);
        }
        break;
    }
    default:
        log.warn(getM() + ": Unknown jump insn opcode '" + opcode + "'!");
    }
}

From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java

License:Open Source License

/**
 * Determine how many bytes the current instruction occupies together with
 * its operands// ww w.java2s. co m
 * 
 * @return
 */
private int getBytecodeIncrement(AbstractInsnNode instructionNode) {
    int opcode = instructionNode.getOpcode();
    switch (opcode) {
    case Opcodes.ALOAD: // index
    case Opcodes.ASTORE: // index
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
        VarInsnNode varNode = (VarInsnNode) instructionNode;
        if (varNode.var > 3)
            return 1;
        else
            return 0;
    case Opcodes.BIPUSH: // byte
    case Opcodes.NEWARRAY:
    case Opcodes.RET:
        return 1;
    case Opcodes.LDC:
        LdcInsnNode ldcNode = (LdcInsnNode) instructionNode;
        if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long)
            return 2; // LDC2_W
        else
            return 1;
    case 19: //LDC_W
    case 20: //LDC2_W
        return 2;
    case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2
    case Opcodes.CHECKCAST: // indexbyte1, indexbyte2
    case Opcodes.GETFIELD:
    case Opcodes.GETSTATIC:
    case Opcodes.GOTO:
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IFLE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFNE:
    case Opcodes.IFEQ:
    case Opcodes.IFNONNULL:
    case Opcodes.IFNULL:
    case Opcodes.IINC:
    case Opcodes.INSTANCEOF:
    case Opcodes.INVOKESPECIAL:
    case Opcodes.INVOKESTATIC:
    case Opcodes.INVOKEVIRTUAL:
    case Opcodes.JSR:
    case Opcodes.NEW:
    case Opcodes.PUTFIELD:
    case Opcodes.PUTSTATIC:
    case Opcodes.SIPUSH:
        // case Opcodes.LDC_W
        // case Opcodes.LDC2_W

        return 2;
    case Opcodes.MULTIANEWARRAY:
        return 3;
    case Opcodes.INVOKEDYNAMIC:
    case Opcodes.INVOKEINTERFACE:
        return 4;

    case Opcodes.LOOKUPSWITCH:
    case Opcodes.TABLESWITCH:
        // TODO: Could be more
        return 4;
    // case Opcodes.GOTO_W 
    // case Opcodes.JSR_W
    }
    return 0;
}

From source file:org.evosuite.instrumentation.coverage.BranchInstrumentation.java

License:Open Source License

/**
 * <p>// w  w  w  .j a v a2 s . c om
 * getInstrumentation
 * </p>
 *
 * @param instruction
 *            a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object.
 * @return a {@link org.objectweb.asm.tree.InsnList} object.
 */
protected InsnList getInstrumentation(BytecodeInstruction instruction) {
    if (instruction == null)
        throw new IllegalArgumentException("null given");
    if (!instruction.isActualBranch())
        throw new IllegalArgumentException("branch instruction expected");
    if (!BranchPool.getInstance(classLoader).isKnownAsNormalBranchInstruction(instruction))
        throw new IllegalArgumentException(
                "expect given instruction to be known by the BranchPool as a normal branch instruction");

    int opcode = instruction.getASMNode().getOpcode();
    int instructionId = instruction.getInstructionId();
    int branchId = BranchPool.getInstance(classLoader).getActualBranchIdForNormalBranchInstruction(instruction);
    if (branchId < 0)
        throw new IllegalStateException("expect BranchPool to know branchId for all branch instructions");

    InsnList instrumentation = new InsnList();

    switch (opcode) {
    case Opcodes.IFEQ:
    case Opcodes.IFNE:
    case Opcodes.IFLT:
    case Opcodes.IFGE:
    case Opcodes.IFGT:
    case Opcodes.IFLE:
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIII)V", false));
        logger.debug("Adding passedBranch val=?, opcode=" + opcode + ", branch=" + branchId + ", bytecode_id="
                + instructionId);

        break;
    case Opcodes.IF_ICMPEQ:
    case Opcodes.IF_ICMPNE:
    case Opcodes.IF_ICMPLT:
    case Opcodes.IF_ICMPGE:
    case Opcodes.IF_ICMPGT:
    case Opcodes.IF_ICMPLE:
        instrumentation.add(new InsnNode(Opcodes.DUP2));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(
                new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch", "(IIIII)V", false));
        break;
    case Opcodes.IF_ACMPEQ:
    case Opcodes.IF_ACMPNE:
        instrumentation.add(new InsnNode(Opcodes.DUP2));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch",
                "(Ljava/lang/Object;Ljava/lang/Object;III)V", false));
        break;
    case Opcodes.IFNULL:
    case Opcodes.IFNONNULL:
        instrumentation.add(new InsnNode(Opcodes.DUP));
        instrumentation.add(new LdcInsnNode(opcode));
        // instrumentation.add(new LdcInsnNode(id));
        instrumentation.add(new LdcInsnNode(branchId));
        instrumentation.add(new LdcInsnNode(instructionId));
        instrumentation.add(new MethodInsnNode(Opcodes.INVOKESTATIC, EXECUTION_TRACER, "passedBranch",
                "(Ljava/lang/Object;III)V", false));
        break;
    }
    return instrumentation;
}