Example usage for org.objectweb.asm Opcodes T_INT

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

Introduction

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

Prototype

int T_INT

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

Click Source Link

Usage

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

License:Apache License

public static int getTypeCode(Class<?> type) {
    if (type == Character.TYPE) {
        return Opcodes.T_CHAR;
    }// ww w  .  ja v a2  s .c  o m
    if (type == Byte.TYPE) {
        return Opcodes.T_BYTE;
    }
    if (type == Integer.TYPE) {
        return Opcodes.T_INT;
    }
    if (type == Boolean.TYPE) {
        return Opcodes.T_BOOLEAN;
    }
    if (type == Short.TYPE) {
        return Opcodes.T_SHORT;
    }
    if (type == Long.TYPE) {
        return Opcodes.T_LONG;
    }
    if (type == Float.TYPE) {
        return Opcodes.T_FLOAT;
    }
    if (type == Double.TYPE) {
        return Opcodes.T_DOUBLE;
    }
    throw new IllegalArgumentException("Not a primitive " + type);
}

From source file:org.evosuite.instrumentation.testability.transformer.BooleanArrayTransformer.java

License:Open Source License

@Override
protected AbstractInsnNode transformIntInsnNode(MethodNode mn, IntInsnNode intInsnNode) {
    if (intInsnNode.operand == Opcodes.T_BOOLEAN) {
        intInsnNode.operand = Opcodes.T_INT;
    }//from  ww  w  .j  ava 2s  .  c om
    return intInsnNode;
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitIntInsn(final int opcode, final int operand) {
    switch (opcode) {
    case Opcodes.BIPUSH:
    case Opcodes.SIPUSH:
        push(Opcodes.INTEGER);/*from  w ww. j a v  a  2 s .  com*/
        break;
    case Opcodes.NEWARRAY:
        pop(1);
        switch (operand) {
        case Opcodes.T_BOOLEAN:
            push("[Z");
            break;
        case Opcodes.T_CHAR:
            push("[C");
            break;
        case Opcodes.T_FLOAT:
            push("[F");
            break;
        case Opcodes.T_DOUBLE:
            push("[D");
            break;
        case Opcodes.T_BYTE:
            push("[B");
            break;
        case Opcodes.T_SHORT:
            push("[S");
            break;
        case Opcodes.T_INT:
            push("[I");
            break;
        case Opcodes.T_LONG:
            push("[J");
            break;
        default:
            throw new IllegalArgumentException();
        }
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitIntInsn(opcode, operand);
}

From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

/**
 * Generates the instruction to create a new array.
 *
 * @param type the type of the array elements.
 *///from   w  w w.  j av  a  2  s . c o  m
public void newArray(final Type type) {
    int typ;
    switch (type.getSort()) {
    case Type.BOOLEAN:
        typ = Opcodes.T_BOOLEAN;
        break;
    case Type.CHAR:
        typ = Opcodes.T_CHAR;
        break;
    case Type.BYTE:
        typ = Opcodes.T_BYTE;
        break;
    case Type.SHORT:
        typ = Opcodes.T_SHORT;
        break;
    case Type.INT:
        typ = Opcodes.T_INT;
        break;
    case Type.FLOAT:
        typ = Opcodes.T_FLOAT;
        break;
    case Type.LONG:
        typ = Opcodes.T_LONG;
        break;
    case Type.DOUBLE:
        typ = Opcodes.T_DOUBLE;
        break;
    default:
        typeInsn(Opcodes.ANEWARRAY, type);
        return;
    }
    visitIntInsn(Opcodes.NEWARRAY, typ);
}

From source file:org.jboss.byteman.rule.expression.ArrayInitExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    Type baseType = getType().getBaseType();
    int currentStack = compileContext.getStackCount();
    int expected = 1;
    int length = elements.size();

    // stack array size and then create the array
    mv.visitLdcInsn(length);//from   w  w  w.  j a v a  2s  . c  o  m
    compileContext.addStackCount(1);
    // new array pops count and pushes array so no change to stack size
    if (baseType.isArray()) {
        mv.visitMultiANewArrayInsn(getType().getInternalName(), 1);
    } else if (baseType.isObject()) {
        mv.visitTypeInsn(Opcodes.ANEWARRAY, baseType.getInternalName());
    } else {
        int operand = 0;
        if (baseType.equals(Type.Z)) {
            operand = Opcodes.T_BOOLEAN;
        } else if (baseType.equals(Type.B)) {
            operand = Opcodes.T_BYTE;
        } else if (baseType.equals(Type.S)) {
            operand = Opcodes.T_SHORT;
        } else if (baseType.equals(Type.C)) {
            operand = Opcodes.T_CHAR;
        } else if (baseType.equals(Type.I)) {
            operand = Opcodes.T_INT;
        } else if (baseType.equals(Type.J)) {
            operand = Opcodes.T_LONG;
        } else if (baseType.equals(Type.F)) {
            operand = Opcodes.T_FLOAT;
        } else if (baseType.equals(Type.D)) {
            operand = Opcodes.T_DOUBLE;
        }
        mv.visitIntInsn(Opcodes.NEWARRAY, operand);
    }

    int idx = 0;
    boolean isTwoWords = (baseType.getNBytes() > 4);

    for (Expression element : elements) {
        int toPop = 0;
        // copy array so we can assign it -- adds one to height
        mv.visitInsn(Opcodes.DUP);
        // compile expression index -- adds 1 to height
        mv.visitLdcInsn(idx++);
        compileContext.addStackCount(2);
        // compile value -- adds one or two words to height
        element.compile(mv, compileContext);
        // ensure we have the correct value type
        compileContext.compileTypeConversion(element.type, baseType);
        // now we can do the array store
        if (baseType.isObject() || baseType.isArray()) {
            // compile load object - pops 3
            mv.visitInsn(Opcodes.AASTORE);
            toPop = -3;
        } else if (baseType == Type.Z || baseType == Type.B) {
            // compile load byte - pops 3
            mv.visitInsn(Opcodes.BASTORE);
            toPop = -3;
        } else if (baseType == Type.S) {
            // compile load short - pops 3
            mv.visitInsn(Opcodes.SASTORE);
            toPop = -3;
        } else if (baseType == Type.C) {
            // compile load char - pops 3
            mv.visitInsn(Opcodes.CASTORE);
            toPop = -3;
        } else if (baseType == Type.I) {
            // compile load int - pops 3
            mv.visitInsn(Opcodes.IASTORE);
            toPop = -3;
        } else if (baseType == Type.J) {
            // compile load long - pops 4
            mv.visitInsn(Opcodes.LASTORE);
            toPop = -4;
        } else if (baseType == Type.F) {
            // compile load float - pops 3
            mv.visitInsn(Opcodes.FASTORE);
            toPop = -3;
        } else if (baseType == Type.D) {
            // compile load double - pops 4
            mv.visitInsn(Opcodes.DASTORE);
            toPop = -4;
        }
        // pop the appropriate number of elements off the stack
        compileContext.addStackCount(toPop);
    }

    // check stack height
    if (compileContext.getStackCount() != currentStack + expected) {
        throw new CompileException("ArrayInitExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + (currentStack + expected));
    }

    // no need to update stack max
}

From source file:org.jboss.byteman.rule.expression.NewExpression.java

License:Open Source License

public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException {
    // make sure we are at the right source line
    compileContext.notifySourceLine(line);

    int currentStack = compileContext.getStackCount();
    int expected = 1;
    int extraParams = 0;

    if (arrayDimCount == 0) {
        // ok, we need to create the new instance and then initialise it.

        // create the new instance -- adds 1 to stack
        String instantiatedClassName = type.getInternalName();
        mv.visitTypeInsn(Opcodes.NEW, instantiatedClassName);
        compileContext.addStackCount(1);
        // copy the exception so we can init it
        mv.visitInsn(Opcodes.DUP);/*  w ww  .j a v  a 2  s  .c o m*/
        compileContext.addStackCount(1);

        int argCount = arguments.size();

        // stack each of the arguments to the constructor
        for (int i = 0; i < argCount; i++) {
            Type argType = argumentTypes.get(i);
            Type paramType = paramTypes.get(i);
            int paramCount = (paramType.getNBytes() > 4 ? 2 : 1);

            // track extra storage used after type conversion
            extraParams += (paramCount);
            arguments.get(i).compile(mv, compileContext);
            compileTypeConversion(argType, paramType, mv, compileContext);
        }

        // construct the exception
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, instantiatedClassName, "<init>", getDescriptor());

        // modify the stack height to account for the removed exception and params
        compileContext.addStackCount(-(extraParams + 1));
    } else {
        // TODO !!! implement compilation for array types !!!
        if (arrayDimCount == 1) {
            // we can use a NEWARRAY or ANEWARRAY
            Type baseType = type.getBaseType();
            // compile first array dimension adds 1 to stack
            arrayDims.get(0).compile(mv, compileContext);
            // compile new array op -- pops 1 and adds 1 to stack
            if (baseType.isObject()) {
                mv.visitTypeInsn(Opcodes.ANEWARRAY, baseType.getInternalName());
                // } else if (baseType.isArray()) {  // cannot happen!!!
            } else {
                int operand = 0;
                if (baseType.equals(Type.Z)) {
                    operand = Opcodes.T_BOOLEAN;
                } else if (baseType.equals(Type.B)) {
                    operand = Opcodes.T_BYTE;
                } else if (baseType.equals(Type.S)) {
                    operand = Opcodes.T_SHORT;
                } else if (baseType.equals(Type.C)) {
                    operand = Opcodes.T_CHAR;
                } else if (baseType.equals(Type.I)) {
                    operand = Opcodes.T_INT;
                } else if (baseType.equals(Type.J)) {
                    operand = Opcodes.T_LONG;
                } else if (baseType.equals(Type.F)) {
                    operand = Opcodes.T_FLOAT;
                } else if (baseType.equals(Type.D)) {
                    operand = Opcodes.T_DOUBLE;
                }
                mv.visitIntInsn(Opcodes.NEWARRAY, operand);
            }
        } else {
            // we need to use MULTIANEWARRAY

            for (int i = 0; i < arrayDimDefinedCount; i++) {
                // compile next array dimension adds 1 to stack
                arrayDims.get(i).compile(mv, compileContext);
            }
            // execute the MULTIANEWARRAY operation -- pops arrayDims operands and pushes 1
            mv.visitMultiANewArrayInsn(type.getInternalName(), arrayDimDefinedCount);
            compileContext.addStackCount(1 - arrayDimDefinedCount);
        }
    }

    if (compileContext.getStackCount() != currentStack + expected) {
        throw new CompileException("NewExpression.compile : invalid stack height "
                + compileContext.getStackCount() + " expecting " + (currentStack + expected));
    }
}

From source file:org.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java

License:Open Source License

/**
 * @param elemType element type of the array. Must be a primitive type.
 * @return java op-code to use as the argument for the NEWARRAY op.
 *//*ww  w . ja  v a2 s .  c om*/
private static int getNewArrayArgCode(JavaTypeName elemType) {

    switch (elemType.getTag()) {

    case JavaTypeName.VOID_TAG:
        throw new IllegalArgumentException();

    case JavaTypeName.BOOLEAN_TAG:
        return Opcodes.T_BOOLEAN;

    case JavaTypeName.BYTE_TAG:
        return Opcodes.T_BYTE;

    case JavaTypeName.SHORT_TAG:
        return Opcodes.T_SHORT;

    case JavaTypeName.CHAR_TAG:
        return Opcodes.T_CHAR;

    case JavaTypeName.INT_TAG:
        return Opcodes.T_INT;

    case JavaTypeName.LONG_TAG:
        return Opcodes.T_LONG;

    case JavaTypeName.DOUBLE_TAG:
        return Opcodes.T_DOUBLE;

    case JavaTypeName.FLOAT_TAG:
        return Opcodes.T_FLOAT;

    case JavaTypeName.ARRAY_TAG:
    case JavaTypeName.OBJECT_TAG:
    default: {
        throw new IllegalArgumentException();
    }
    }
}

From source file:pku.sei.checkedcoverage.tracer.instrumentation.TracingMethodInstrumenter.java

License:Creative Commons License

private void transformMultiANewArrayInsn(final MultiANewArrayInsnNode insn) {
    // create a new int array to hold the dimensions and fill the dimensions in there.
    // then push the dimensions back onto the stack, call the MULTIANEWARRAY instruction
    // and afterward, call a method that gets the dimensions array and the newly
    // created array and traces the object ids.
    this.instructionIterator.previous();
    this.instructionIterator.add(getIntConstInsn(insn.dims));
    this.instructionIterator.add(new IntInsnNode(NEWARRAY, Opcodes.T_INT));
    // now fill in the dimensions
    for (int dim = insn.dims - 1; dim >= 0; --dim) {
        this.instructionIterator.add(new InsnNode(DUP_X1));
        this.instructionIterator.add(new InsnNode(SWAP));
        this.instructionIterator.add(getIntConstInsn(dim));
        this.instructionIterator.add(new InsnNode(SWAP));
        this.instructionIterator.add(new InsnNode(IASTORE));
    }//from   w  w w.j  a  v a2  s .  co m
    // duplicate the array reference
    this.instructionIterator.add(new InsnNode(DUP));
    // push the dimensions back onto the stack
    for (int dim = 0; dim < insn.dims; ++dim) {
        // don't duplicate if this is the last entry
        if (dim != insn.dims - 1)
            this.instructionIterator.add(new InsnNode(DUP));
        this.instructionIterator.add(getIntConstInsn(dim));
        this.instructionIterator.add(new InsnNode(IALOAD));
        // swap with the reference below us
        if (dim != insn.dims - 1)
            this.instructionIterator.add(new InsnNode(SWAP));
    }
    this.instructionIterator.next();
    final int newObjCountSeqIndex = this.tracer.newIntegerTraceSequence();
    final int newObjIdSeqIndex = this.tracer.newLongTraceSequence();
    // now call the original MULTIANEWARRAY instruction
    registerInstruction(new MultiANewArrayInstruction(this.readMethod, this.currentLine, insn.desc, insn.dims,
            newObjCountSeqIndex, newObjIdSeqIndex), InstructionType.UNSAFE);
    // and now call a tracing method that gets the dimensions array, the newly
    // created multi-dimensional array, and the sequence ids
    this.instructionIterator.add(new InsnNode(DUP_X1));
    this.instructionIterator.add(new VarInsnNode(ALOAD, this.tracerLocalVarIndex));
    this.instructionIterator.add(getIntConstInsn(newObjCountSeqIndex));
    this.instructionIterator.add(getIntConstInsn(newObjIdSeqIndex));
    this.instructionIterator.add(new MethodInsnNode(INVOKESTATIC,
            Type.getInternalName(TracingMethodInstrumenter.class), "traceMultiANewArray",
            "([I[Ljava/lang/Object;" + Type.getDescriptor(ThreadTracer.class) + "II)V"));
}

From source file:pxb.android.dex2jar.asm.PDescMethodVisitor.java

License:Apache License

public void visitIntInsn(int opcode, int operand) {
    super.visitIntInsn(opcode, operand);
    switch (opcode) {
    case BIPUSH://  w w  w  . ja va2 s . c om
        stack.push(Type.BYTE_TYPE);
        break;
    case SIPUSH:
        stack.push(Type.SHORT_TYPE);
        break;
    case NEWARRAY:
        stack.pop();
        switch (operand) {
        case Opcodes.T_BOOLEAN:
            stack.push(Type.getType("[Z"));
            break;
        case Opcodes.T_BYTE:
            stack.push(Type.getType("[B"));
            break;
        case Opcodes.T_CHAR:
            stack.push(Type.getType("[C"));
            break;
        case Opcodes.T_DOUBLE:
            stack.push(Type.getType("[D"));
            break;
        case Opcodes.T_FLOAT:
            stack.push(Type.getType("[F"));
            break;
        case Opcodes.T_INT:
            stack.push(Type.getType("[I"));
            break;
        case Opcodes.T_LONG:
            stack.push(Type.getType("[J"));
            break;
        case Opcodes.T_SHORT:
            stack.push(Type.getType("[Z"));
            break;
        }
        break;
    }
}

From source file:serianalyzer.JVMImpl.java

License:Open Source License

/**
 * @param operand//from  w  w  w.  j av  a2 s  .c o m
 * @return
 */
private static Type makeBasicArrayType(int operand) {

    switch (operand) {
    case Opcodes.T_BOOLEAN:
        return Type.getType("[Z"); //$NON-NLS-1$
    case Opcodes.T_BYTE:
        return Type.getType("[B"); //$NON-NLS-1$
    case Opcodes.T_CHAR:
        return Type.getType("[C"); //$NON-NLS-1$
    case Opcodes.T_DOUBLE:
        return Type.getType("[D"); //$NON-NLS-1$
    case Opcodes.T_FLOAT:
        return Type.getType("[F"); //$NON-NLS-1$
    case Opcodes.T_INT:
        return Type.getType("[I"); //$NON-NLS-1$
    case Opcodes.T_LONG:
        return Type.getType("[J"); //$NON-NLS-1$
    case Opcodes.T_SHORT:
        return Type.getType("[S"); //$NON-NLS-1$

    default:
        log.error("Unknown array type " + operand); //$NON-NLS-1$
    }
    return null;
}