Example usage for org.objectweb.asm Opcodes LDC

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

Introduction

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

Prototype

int LDC

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

Click Source Link

Usage

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

License:Open Source License

private void interpret(LdcInsnNode insn, FrameState frame, BBInfo block) {
    assert insn.getOpcode() == Opcodes.LDC;
    ConstantFactory cf = module.constants();
    Object c = insn.cst;//  w  w w  . ja  v a2s.  co  m
    if (c instanceof Integer)
        frame.stack.push(cf.getSmallestIntConstant((Integer) c));
    else if (c instanceof Long)
        frame.stack.push(cf.getConstant((Long) c));
    else if (c instanceof Float)
        frame.stack.push(cf.getConstant((Float) c));
    else if (c instanceof Double)
        frame.stack.push(cf.getConstant((Double) c));
    else if (c instanceof String)
        frame.stack.push(cf.getConstant((String) c));
    else if (c instanceof org.objectweb.asm.Type) {
        org.objectweb.asm.Type t = (org.objectweb.asm.Type) c;
        Constant<Class<?>> d = cf.getConstant(getKlassByInternalName(t.getInternalName()).getBackingClass());
        frame.stack.push(d);
    } else
        throw new AssertionError(c);
}

From source file:ivorius.ivtoolkit.asm.IvNodeMatcherLDC.java

License:Apache License

@Override
public boolean matchNode(AbstractInsnNode node) {
    if (node.getOpcode() != Opcodes.LDC) {
        return false;
    }//w ww  . j  a va  2  s .  com

    LdcInsnNode ldcInsnNode = (LdcInsnNode) node;

    if (cst != null && !cst.equals(ldcInsnNode.cst)) {
        return false;
    }

    return true;
}

From source file:org.adjective.stout.instruction.LoadConstantInstruction.java

License:Apache License

public LoadConstantInstruction(Object value) {
    super(Opcodes.LDC);
    _value = value;
}

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

License:Apache License

public void visitLdcInsn(Object cst) {
    Type type;//ww w.  ja  v  a2s .co  m
    if (cst instanceof String) {
        type = Type.getType(String.class);
    } else if (cst instanceof Long) {
        type = Type.LONG_TYPE;
    } else {
        error("Unknown LDC type " + cst.getClass());
        type = Type.INT_TYPE;
    }
    push(cst.toString(), type);
    print(Opcodes.LDC, cst.toString());
}

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

License:Open Source License

@Override
public void visitLdcInsn(final Object cst) {
    T t = null;/*w  w  w.j av a 2  s  . c o m*/
    Object oValue = null;

    /********
     * PUSH *
     ********/
    if (cst instanceof Type) {
        oValue = getDu().getDescT(((Type) cst).getDescriptor());
        t = getDu().getT(Class.class);
    } else {
        oValue = cst;
        if (cst instanceof Double) {
            t = T.DOUBLE;
        } else if (cst instanceof Float) {
            t = T.FLOAT;
        } else if (cst instanceof Integer) {
            t = T.getJvmIntT((Integer) oValue);
        } else if (cst instanceof Long) {
            t = T.LONG;
        } else if (cst instanceof String) {
            t = getDu().getT(String.class);
        } else {
            log.warn(getM() + ": Unknown ldc insn cst '" + cst + "'!");
            t = T.ANY;
        }
    }
    add(new PUSH(this.ops.size(), Opcodes.LDC, this.line, t, oValue));
}

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

License:Open Source License

/**
 * <p>
 * isLoadConstant
 * </p>
 * 
 * @return a boolean.
 */
public boolean isLoadConstant() {
    return asmNode.getOpcode() == Opcodes.LDC;
}

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

License:Open Source License

/**
 * <p>/*from w  w w. ja  va 2  s  .  c  o m*/
 * isConstant
 * </p>
 * 
 * @return a boolean.
 */
public boolean isConstant() {
    switch (asmNode.getOpcode()) {
    case Opcodes.LDC:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
    case Opcodes.ICONST_M1:
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
    case Opcodes.BIPUSH:
    case Opcodes.SIPUSH:
        return true;
    default:
        return false;
    }
}

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/*from w ww .  jav a 2 s.  com*/
 * 
 * @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.mutation.ReplaceConstant.java

License:Open Source License

private Object getValue(AbstractInsnNode constant) {
    switch (constant.getOpcode()) {
    case Opcodes.LDC:
        return ((LdcInsnNode) constant).cst;
    case Opcodes.ICONST_0:
        return 0;
    case Opcodes.ICONST_1:
        return 1;
    case Opcodes.ICONST_2:
        return 2;
    case Opcodes.ICONST_3:
        return 3;
    case Opcodes.ICONST_4:
        return 4;
    case Opcodes.ICONST_5:
        return 5;
    case Opcodes.ICONST_M1:
        return -1;
    case Opcodes.LCONST_0:
        return 0L;
    case Opcodes.LCONST_1:
        return 1L;
    case Opcodes.DCONST_0:
        return 0.0;
    case Opcodes.DCONST_1:
        return 1.0;
    case Opcodes.FCONST_0:
        return 0.0F;
    case Opcodes.FCONST_1:
        return 1.0F;
    case Opcodes.FCONST_2:
        return 2.0F;
    case Opcodes.SIPUSH:
        return ((IntInsnNode) constant).operand;
    case Opcodes.BIPUSH:
        return ((IntInsnNode) constant).operand;
    default://from  w  w w.  j  a v  a  2  s. com
        throw new RuntimeException("Unknown constant: " + constant.getOpcode());
    }
}

From source file:org.evosuite.seeding.CastClassAnalyzer.java

License:Open Source License

/**
 * Add all possible calls for a given method
 * //w  w  w.  j a v a2s .  c om
 * @param callGraph
 * @param mn
 */
@SuppressWarnings("unchecked")
public void handleMethodNode(ClassNode cn, MethodNode mn, int depth) {

    if (mn.signature != null) {
        logger.debug("Visiting signature: " + mn.signature);
        CollectParameterTypesVisitor visitor = new CollectParameterTypesVisitor(cn.name);
        new SignatureReader(mn.signature).accept(visitor);
        for (Type castType : visitor.getClasses()) {
            if (!castClassMap.containsKey(castType)) {
                logger.debug("Adding new cast class from signature visitor: " + castType);
                castClassMap.put(castType, depth + 1);
            }
        }
    }

    InsnList instructions = mn.instructions;
    Iterator<AbstractInsnNode> iterator = instructions.iterator();

    // TODO: This really shouldn't be here but in its own class
    while (iterator.hasNext()) {
        AbstractInsnNode insn = iterator.next();
        if (insn.getOpcode() == Opcodes.CHECKCAST) {
            TypeInsnNode typeNode = (TypeInsnNode) insn;
            Type castType = Type.getObjectType(typeNode.desc);
            while (castType.getSort() == Type.ARRAY) {
                castType = castType.getElementType();
            }
            logger.debug("Adding new cast class from cast: " + castType);
            if (!castClassMap.containsKey(castType))
                castClassMap.put(castType, depth + 1);
        } else if (insn.getOpcode() == Opcodes.INSTANCEOF) {
            TypeInsnNode typeNode = (TypeInsnNode) insn;
            Type castType = Type.getObjectType(typeNode.desc);
            while (castType.getSort() == Type.ARRAY) {
                castType = castType.getElementType();
            }
            logger.debug("Adding new cast class from instanceof: " + castType);
            if (!castClassMap.containsKey(castType))
                castClassMap.put(castType, depth + 1);
        } else if (insn.getOpcode() == Opcodes.LDC) {
            LdcInsnNode ldcNode = (LdcInsnNode) insn;
            if (ldcNode.cst instanceof Type) {
                Type type = (Type) ldcNode.cst;
                while (type.getSort() == Type.ARRAY) {
                    type = type.getElementType();
                }
                if (!castClassMap.containsKey(type))
                    castClassMap.put(type, depth + 1);
            }

        }
    }
}