Example usage for org.objectweb.asm Opcodes DUP2_X1

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

Introduction

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

Prototype

int DUP2_X1

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

Click Source Link

Usage

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

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    T t = null;/*w w w. j  a  v  a2  s.co m*/
    int iValue = Integer.MIN_VALUE;
    Object oValue = null;

    switch (opcode) {
    case Opcodes.NOP:
        // nothing to do, ignore
        break;
    /*******
     * ADD *
     *******/
    case Opcodes.DADD:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FADD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IADD:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LADD:
        if (t == null) {
            t = T.LONG;
        }
        add(new ADD(this.ops.size(), opcode, this.line, t));
        break;
    /*********
     * ALOAD *
     *********/
    case Opcodes.AALOAD:
        t = T.REF;
        // fall through
    case Opcodes.BALOAD:
        if (t == null) {
            t = T.SMALL;
        }
        // fall through
    case Opcodes.CALOAD:
        if (t == null) {
            t = T.CHAR;
        }
        // fall through
    case Opcodes.DALOAD:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FALOAD:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IALOAD:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LALOAD:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.SALOAD:
        if (t == null) {
            t = T.SHORT;
        }
        add(new ALOAD(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * AND *
     *******/
    case Opcodes.IAND:
        t = T.AINT;
        // fall through
    case Opcodes.LAND:
        if (t == null) {
            t = T.LONG;
        }
        add(new AND(this.ops.size(), opcode, this.line, t));
        break;
    /***************
     * ARRAYLENGTH *
     ***************/
    case Opcodes.ARRAYLENGTH:
        add(new ARRAYLENGTH(this.ops.size(), opcode, this.line));
        break;
    /**********
     * ASTORE *
     **********/
    case Opcodes.AASTORE:
        t = T.REF;
        // fall through
    case Opcodes.BASTORE:
        if (t == null) {
            t = T.SMALL;
        }
        // fall through
    case Opcodes.CASTORE:
        if (t == null) {
            t = T.CHAR;
        }
        // fall through
    case Opcodes.DASTORE:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FASTORE:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IASTORE:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LASTORE:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.SASTORE:
        if (t == null) {
            t = T.SHORT;
        }
        add(new ASTORE(this.ops.size(), opcode, this.line, t));
        break;
    /********
     * CAST *
     ********/
    case Opcodes.D2F:
        t = T.DOUBLE;
        oValue = T.FLOAT;
        // fall through
    case Opcodes.D2I:
        if (t == null) {
            t = T.DOUBLE;
            oValue = T.INT;
        }
        // fall through
    case Opcodes.D2L:
        if (t == null) {
            t = T.DOUBLE;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.F2D:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.F2I:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.INT;
        }
        // fall through
    case Opcodes.F2L:
        if (t == null) {
            t = T.FLOAT;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.I2B:
        if (t == null) {
            t = T.INT;
            oValue = T.BYTE;
        }
        // fall through
    case Opcodes.I2C:
        if (t == null) {
            t = T.INT;
            oValue = T.CHAR;
        }
        // fall through
    case Opcodes.I2D:
        if (t == null) {
            t = T.INT;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.I2F:
        if (t == null) {
            t = T.INT;
            oValue = T.FLOAT;
        }
        // fall through
    case Opcodes.I2L:
        if (t == null) {
            t = T.INT;
            oValue = T.LONG;
        }
        // fall through
    case Opcodes.I2S:
        if (t == null) {
            t = T.INT;
            oValue = T.SHORT;
        }
        // fall through
    case Opcodes.L2D:
        if (t == null) {
            t = T.LONG;
            oValue = T.DOUBLE;
        }
        // fall through
    case Opcodes.L2F:
        if (t == null) {
            t = T.LONG;
            oValue = T.FLOAT;
        }
        // fall through
    case Opcodes.L2I:
        if (t == null) {
            t = T.LONG;
            oValue = T.INT;
        }
        assert oValue instanceof T;
        add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue));
        break;
    /*******
     * CMP *
     *******/
    case Opcodes.DCMPG:
        t = T.DOUBLE;
        iValue = CMP.T_G;
        // fall through
    case Opcodes.DCMPL:
        if (t == null) {
            t = T.DOUBLE;
            iValue = CMP.T_L;
        }
        // fall through
    case Opcodes.FCMPG:
        if (t == null) {
            t = T.FLOAT;
            iValue = CMP.T_G;
        }
        // fall through
    case Opcodes.FCMPL:
        if (t == null) {
            t = T.FLOAT;
            iValue = CMP.T_L;
        }
        // fall through
    case Opcodes.LCMP:
        if (t == null) {
            t = T.LONG;
            iValue = CMP.T_0;
        }
        add(new CMP(this.ops.size(), opcode, this.line, t, iValue));
        break;
    /*******
     * DIV *
     *******/
    case Opcodes.DDIV:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FDIV:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IDIV:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LDIV:
        if (t == null) {
            t = T.LONG;
        }
        add(new DIV(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * DUP *
     *******/
    case Opcodes.DUP:
        oValue = DUP.Kind.DUP;
        // fall through
    case Opcodes.DUP_X1:
        if (oValue == null) {
            oValue = DUP.Kind.DUP_X1;
        }
        // fall through
    case Opcodes.DUP_X2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP_X2;
        }
        // fall through
    case Opcodes.DUP2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2;
        }
        // fall through
    case Opcodes.DUP2_X1:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2_X1;
        }
        // fall through
    case Opcodes.DUP2_X2:
        if (oValue == null) {
            oValue = DUP.Kind.DUP2_X2;
        }
        add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue));
        break;
    /***********
     * MONITOR *
     ***********/
    case Opcodes.MONITORENTER:
        oValue = MONITOR.Kind.ENTER;
        // fall through
    case Opcodes.MONITOREXIT:
        if (oValue == null) {
            oValue = MONITOR.Kind.EXIT;
        }
        add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue));
        break;
    /*******
     * MUL *
     *******/
    case Opcodes.DMUL:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FMUL:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IMUL:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LMUL:
        if (t == null) {
            t = T.LONG;
        }
        add(new MUL(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * NEG *
     *******/
    case Opcodes.DNEG:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FNEG:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.INEG:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LNEG:
        if (t == null) {
            t = T.LONG;
        }
        add(new NEG(this.ops.size(), opcode, this.line, t));
        break;
    /******
     * OR *
     ******/
    case Opcodes.IOR:
        t = T.AINT;
        // fall through
    case Opcodes.LOR:
        if (t == null) {
            t = T.LONG;
        }
        add(new OR(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * POP *
     *******/
    case Opcodes.POP:
        oValue = POP.Kind.POP;
        // fall through
    case Opcodes.POP2:
        if (oValue == null) {
            oValue = POP.Kind.POP2;
        }
        add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue));
        break;
    /********
     * PUSH *
     ********/
    case Opcodes.ACONST_NULL:
        t = T.REF;
        // fall through
    case Opcodes.DCONST_0:
        if (t == null) {
            oValue = 0D;
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FCONST_0:
        if (t == null) {
            oValue = 0F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_0:
        if (t == null) {
            oValue = 0;
            t = T.getJvmIntT(0);
        }
        // fall through
    case Opcodes.LCONST_0:
        if (t == null) {
            oValue = 0L;
            t = T.LONG;
        }
        // fall through
    case Opcodes.DCONST_1:
        if (t == null) {
            oValue = 1D;
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FCONST_1:
        if (t == null) {
            oValue = 1F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_1:
        if (t == null) {
            oValue = 1;
            t = T.getJvmIntT(1);
        }
        // fall through
    case Opcodes.LCONST_1:
        if (t == null) {
            oValue = 1L;
            t = T.LONG;
        }
        // fall through
    case Opcodes.FCONST_2:
        if (t == null) {
            oValue = 2F;
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ICONST_2:
        if (t == null) {
            oValue = 2;
            t = T.getJvmIntT(2);
        }
        // fall through
    case Opcodes.ICONST_3:
        if (t == null) {
            oValue = 3;
            t = T.getJvmIntT(3);
        }
        // fall through
    case Opcodes.ICONST_4:
        if (t == null) {
            oValue = 4;
            t = T.getJvmIntT(4);
        }
        // fall through
    case Opcodes.ICONST_5:
        if (t == null) {
            oValue = 5;
            t = T.getJvmIntT(5);
        }
        // fall through
    case Opcodes.ICONST_M1:
        if (t == null) {
            oValue = -1;
            t = T.getJvmIntT(-1);
        }
        add(new PUSH(this.ops.size(), opcode, this.line, t, oValue));
        break;
    /*******
     * REM *
     *******/
    case Opcodes.DREM:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FREM:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IREM:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LREM:
        if (t == null) {
            t = T.LONG;
        }
        add(new REM(this.ops.size(), opcode, this.line, t));
        break;
    /**********
     * RETURN *
     **********/
    case Opcodes.ARETURN:
        t = T.REF;
        // fall through
    case Opcodes.DRETURN:
        if (t == null) {
            t = T.DOUBLE;
        }
        // fall through
    case Opcodes.FRETURN:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.IRETURN:
        if (t == null) {
            t = T.AINT;
        }
        // fall through
    case Opcodes.LRETURN:
        if (t == null) {
            t = T.LONG;
        }
        // fall through
    case Opcodes.RETURN:
        if (t == null) {
            t = T.VOID;
        }
        add(new RETURN(this.ops.size(), opcode, this.line, t));
        break;
    /*******
     * SHL *
     *******/
    case Opcodes.ISHL:
        t = T.INT;
        // fall through
    case Opcodes.LSHL:
        if (t == null) {
            t = T.LONG;
        }
        add(new SHL(this.ops.size(), opcode, this.line, t, T.INT));
        break;
    /*******
     * SHR *
     *******/
    case Opcodes.ISHR:
    case Opcodes.IUSHR:
        t = T.INT;
        // fall through
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        if (t == null) {
            t = T.LONG;
        }
        add(new SHR(this.ops.size(), opcode, this.line, t, T.INT,
                opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR));
        break;
    /*******
     * SUB *
     *******/
    case Opcodes.DSUB:
        t = T.DOUBLE;
        // fall through
    case Opcodes.FSUB:
        if (t == null) {
            t = T.FLOAT;
        }
        // fall through
    case Opcodes.ISUB:
        if (t == null) {
            t = T.INT;
        }
        // fall through
    case Opcodes.LSUB:
        if (t == null) {
            t = T.LONG;
        }
        add(new SUB(this.ops.size(), opcode, this.line, t));
        break;
    /********
     * SWAP *
     ********/
    case Opcodes.SWAP:
        add(new SWAP(this.ops.size(), opcode, this.line));
        break;
    /*********
     * THROW *
     *********/
    case Opcodes.ATHROW:
        add(new THROW(this.ops.size(), opcode, this.line));
        break;
    /*******
     * XOR *
     *******/
    case Opcodes.IXOR:
        t = T.AINT;
        // fall through
    case Opcodes.LXOR: {
        if (t == null) {
            t = T.LONG;
        }
        add(new XOR(this.ops.size(), opcode, this.line, t));
        break;
    }
    default:
        log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!");
    }
}

From source file:org.elasticsearch.plan.a.External.java

License:Apache License

private void field(final ParserRuleContext source, final String name, final boolean last) {
    if (current.metadata == TypeMetadata.ARRAY) {
        if ("length".equals(name)) {
            if (!read || last && write != null) {
                throw new IllegalArgumentException(error(source) + "Cannot write to read-only field [length].");
            }/*from  w w  w .j av a 2  s  .  com*/

            segments.add(new LengthSegment(source));
            current = standard.intType;
        } else {
            throw new IllegalArgumentException(error(source) + "Unexpected array field [" + name + "].");
        }
    } else {
        final Struct struct = current.struct;
        final Field field = statik ? struct.statics.get(name) : struct.members.get(name);

        if (field == null) {
            throw new IllegalArgumentException(
                    error(source) + "Unknown field [" + name + "] for type [" + struct.name + "].");
        }

        if (last && write != null) {
            if (java.lang.reflect.Modifier.isFinal(field.field.getModifiers())) {
                throw new IllegalArgumentException(error(source) + "Cannot write to read-only" + " field ["
                        + name + "] for type [" + struct.name + "].");
            }

            final ExpressionMetadata writeemd = adapter.createExpressionMetadata(write);
            final Type type = field.type;

            if (token == CAT) {
                writeemd.promotion = caster.concat;
                analyzer.visit(write);
                writeemd.to = writeemd.from;
                caster.markCast(writeemd);

                final Cast cast = caster.getLegalCast(source, standard.stringType, type, false);

                segments.add(new InstructionSegment(source, Opcodes.DUP_X1));
                segments.add(new FieldSegment(source, field, false));
                segments.add(new AppendStringsSegment(source, type, true));
                segments.add(new NodeSegment(write));
                segments.add(new AppendStringsSegment(write, writeemd.to, false));
                segments.add(new ToStringsSegment(source));
                segments.add(new CastSegment(source, cast));

                if (read) {
                    if (type.metadata.size == 1) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP_X1));
                    } else if (type.metadata.size == 2) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP2_X1));
                    } else {
                        throw new IllegalStateException(error(source) + "Unexpected type size.");
                    }
                }

                segments.add(new FieldSegment(source, field, true));
            } else if (token > 0) {
                current = type;
                final Cast[] casts = toNumericCasts(source);
                writeemd.to = current;
                analyzer.visit(write);

                segments.add(new InstructionSegment(source, Opcodes.DUP));
                segments.add(new FieldSegment(source, field, false));

                if (read && post) {
                    if (type.metadata.size == 1) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP_X1));
                    } else if (type.metadata.size == 2) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP2_X1));
                    } else {
                        throw new IllegalStateException(error(source) + "Unexpected type size.");
                    }
                }

                segments.add(new CastSegment(source, casts[0]));
                segments.add(new NodeSegment(write));
                segments.add(new TokenSegment(source, current, token));
                segments.add(new CastSegment(source, casts[1]));

                if (read && !post) {
                    if (type.metadata.size == 1) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP_X1));
                    } else if (type.metadata.size == 2) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP2_X1));
                    } else {
                        throw new IllegalStateException(error(source) + "Unexpected type size.");
                    }
                }

                segments.add(new FieldSegment(source, field, true));
            } else {
                writeemd.to = type;
                analyzer.visit(write);

                segments.add(new NodeSegment(write));

                if (read && !post) {
                    if (type.metadata.size == 1) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP_X1));
                    } else if (type.metadata.size == 2) {
                        segments.add(new InstructionSegment(source, Opcodes.DUP2_X1));
                    } else {
                        throw new IllegalStateException(error(source) + "Unexpected type size.");
                    }
                }

                segments.add(new FieldSegment(source, field, true));
            }

            current = read ? type : standard.voidType;
        } else {
            segments.add(new FieldSegment(source, field, false));
            current = field.type;
        }
    }
}

From source file:org.elasticsearch.plan.a.External.java

License:Apache License

private void array(final ParserRuleContext source, final ExpressionContext exprctx, final boolean last) {
    if (current.dimensions == 0) {
        throw new IllegalArgumentException(
                error(source) + "Attempting to address a non-array type [" + current.name + "] as an array.");
    }/*w  w w . j a  va2 s  . c o  m*/

    final ExpressionMetadata expremd = adapter.createExpressionMetadata(exprctx);
    expremd.to = standard.intType;
    analyzer.visit(exprctx);
    segments.add(new NodeSegment(exprctx));

    final Type type = getTypeWithArrayDimensions(current.struct, current.dimensions - 1);

    if (last && write != null) {
        final ExpressionMetadata writeemd = adapter.createExpressionMetadata(write);

        if (token == CAT) {
            writeemd.promotion = caster.concat;
            analyzer.visit(write);
            writeemd.to = writeemd.from;
            caster.markCast(writeemd);

            final Cast cast = caster.getLegalCast(source, standard.stringType, type, false);

            segments.add(new InstructionSegment(source, Opcodes.DUP2_X1));
            segments.add(new ArraySegment(source, type, false));
            segments.add(new AppendStringsSegment(source, type, true));
            segments.add(new NodeSegment(write));
            segments.add(new AppendStringsSegment(write, writeemd.to, false));
            segments.add(new ToStringsSegment(source));
            segments.add(new CastSegment(source, cast));

            if (read) {
                if (type.metadata.size == 1) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP_X2));
                } else if (type.metadata.size == 2) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP2_X2));
                } else {
                    throw new IllegalStateException(error(source) + "Unexpected type size.");
                }
            }

            segments.add(new ArraySegment(source, type, true));
        } else if (token > 0) {
            current = type;
            final Cast[] casts = toNumericCasts(source);
            writeemd.to = current;
            analyzer.visit(write);

            segments.add(new InstructionSegment(source, Opcodes.DUP2));
            segments.add(new ArraySegment(source, type, false));

            if (read && post) {
                if (type.metadata.size == 1) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP_X2));
                } else if (type.metadata.size == 2) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP2_X2));
                } else {
                    throw new IllegalStateException(error(source) + "Unexpected type size.");
                }
            }

            segments.add(new CastSegment(source, casts[0]));
            segments.add(new NodeSegment(write));
            segments.add(new TokenSegment(source, current, token));
            segments.add(new CastSegment(source, casts[1]));

            if (read && !post) {
                if (type.metadata.size == 1) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP_X2));
                } else if (type.metadata.size == 2) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP2_X2));
                } else {
                    throw new IllegalStateException(error(source) + "Unexpected type size.");
                }
            }

            segments.add(new ArraySegment(source, type, true));
        } else {
            writeemd.to = type;
            analyzer.visit(write);

            segments.add(new NodeSegment(write));

            if (read && !post) {
                if (type.metadata.size == 1) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP_X2));
                } else if (type.metadata.size == 2) {
                    segments.add(new InstructionSegment(source, Opcodes.DUP2_X2));
                } else {
                    throw new IllegalStateException(error(source) + "Unexpected type size.");
                }
            }

            segments.add(new ArraySegment(source, type, true));
        }

        current = read ? type : standard.voidType;
    } else {
        segments.add(new ArraySegment(source, type, false));
        current = type;
    }
}

From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    // If non-static, add a null check

    if (opcode == Opcodes.GETFIELD) {
        mv.visitInsn(Opcodes.DUP);/*from w  w  w  .ja v  a2s  .  com*/
        insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException");

    } else if (opcode == Opcodes.PUTFIELD && !methodName.equals("<init>")) {
        if (Type.getType(desc).getSize() == 2) {
            // 2 words
            // v1 v2 v3
            mv.visitInsn(Opcodes.DUP2_X1);
            // v2 v3 v1 v2 v3

            mv.visitInsn(Opcodes.POP2);
            // v2 v3 v1

            mv.visitInsn(Opcodes.DUP_X2);
            // v1 v2 v3 v1

        } else {
            // 1 word
            mv.visitInsn(Opcodes.DUP2);
            //mv.visitInsn(Opcodes.SWAP);
            mv.visitInsn(Opcodes.POP);
        }
        insertBranch(Opcodes.IFNONNULL, "java/lang/NullPointerException");
    }
}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

private void instrumentGETXXXFieldAccesses(final ClassNode cn, final String internalClassName,
        final MethodNode methodNode) {
    final InsnList instructions = methodNode.instructions;

    AbstractInsnNode ins = null;//from   w w w. jav a 2 s  .com
    FieldInsnNode fieldIns = null;

    for (int i = 0; i < instructions.size(); i++) {
        ins = instructions.get(i);
        if (ins instanceof FieldInsnNode) {
            fieldIns = (FieldInsnNode) ins;

            /*
             * Is field referencing outermost instance? if yes, ignore it
             * http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
             */
            if (fieldIns.name.endsWith("$0")) {
                continue;
            }

            final int opcode = ins.getOpcode();
            if (opcode == Opcodes.GETFIELD || opcode == Opcodes.GETSTATIC) {
                final InsnList il = new InsnList();

                if (opcode == Opcodes.GETFIELD) {
                    Type fieldType = Type.getType(fieldIns.desc);
                    if (fieldType.getSize() == 1) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
                        il.add(new InsnNode(Opcodes.SWAP));
                    } else if (fieldType.getSize() == 2) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP));
                        // v
                        // GETFIELD
                        // v, w
                        il.add(new InsnNode(Opcodes.DUP2_X1));
                        // w, v, w
                        il.add(new InsnNode(Opcodes.POP2));
                        // w, v
                        // -> Call
                        // w
                    }
                } else
                    il.add(new InsnNode(Opcodes.ACONST_NULL));

                il.add(new LdcInsnNode(this.captureId));
                il.add(new LdcInsnNode(fieldIns.owner));
                il.add(new LdcInsnNode(fieldIns.name));
                il.add(new LdcInsnNode(fieldIns.desc));

                il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                        PackageInfo.getNameWithSlash(org.evosuite.testcarver.capture.FieldRegistry.class),
                        "notifyReadAccess",
                        "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));

                i += il.size();

                instructions.insert(fieldIns, il);
                this.captureId++;
            }
        }
    }
}

From source file:org.evosuite.testcarver.instrument.Instrumenter.java

License:Open Source License

private void instrumentPUTXXXFieldAccesses(final ClassNode cn, final String internalClassName,
        final MethodNode methodNode) {
    final InsnList instructions = methodNode.instructions;

    AbstractInsnNode ins = null;/*from w  ww.  ja  v  a  2s  . co  m*/
    FieldInsnNode fieldIns = null;

    // needed get right receiver var in case of PUTFIELD

    for (int i = 0; i < instructions.size(); i++) {
        ins = instructions.get(i);
        if (ins instanceof FieldInsnNode) {
            fieldIns = (FieldInsnNode) ins;

            /*
             * Is field referencing outermost instance? if yes, ignore it
             * http://tns-www.lcs.mit.edu/manuals/java-1.1.1/guide/innerclasses/spec/innerclasses.doc10.html
             */
            if (fieldIns.name.endsWith("$0")) {
                continue;
            }

            final int opcode = ins.getOpcode();
            if (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC) {
                // construction of  
                //   Capturer.capture(final Object receiver, final String methodName, final Object[] methodParams)
                // call
                final InsnList il = new InsnList();

                if (opcode == Opcodes.PUTFIELD) {
                    Type fieldType = Type.getType(fieldIns.desc);
                    if (fieldType.getSize() == 1) {
                        instructions.insertBefore(fieldIns, new InsnNode(Opcodes.DUP2));
                        il.add(new InsnNode(Opcodes.POP));
                    } else if (fieldType.getSize() == 2) {
                        InsnList uglyList = new InsnList();
                        // v, w
                        uglyList.add(new InsnNode(Opcodes.DUP2_X1));
                        // w, v, w
                        uglyList.add(new InsnNode(Opcodes.POP2));
                        // w, v
                        uglyList.add(new InsnNode(Opcodes.DUP));
                        // w, v, v
                        uglyList.add(new InsnNode(Opcodes.DUP2_X2));
                        // v, v, w, v, v
                        uglyList.add(new InsnNode(Opcodes.POP2));
                        // v, v, w
                        instructions.insertBefore(fieldIns, uglyList);
                        // PUTFIELD
                        // v
                    }
                } else
                    il.add(new InsnNode(Opcodes.ACONST_NULL));

                il.add(new LdcInsnNode(this.captureId));
                il.add(new LdcInsnNode(fieldIns.owner));
                il.add(new LdcInsnNode(fieldIns.name));
                il.add(new LdcInsnNode(fieldIns.desc));

                il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
                        PackageInfo.getNameWithSlash(FieldRegistry.class), "notifyModification",
                        "(Ljava/lang/Object;ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"));

                // PUTFIELDRegistry.notifyModification also adds corresponding GETFIELD capture instructions
                this.captureId++;
                i += il.size();

                instructions.insert(fieldIns, il);
                this.captureId++;
            }
        }
    }
}

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

License:Open Source License

@Override
public void visitInsn(final int opcode) {
    final Object t1, t2, t3, t4;
    switch (opcode) {
    case Opcodes.NOP:
    case Opcodes.RETURN:
        break;/*from  w ww  .j  a va  2s . com*/
    case Opcodes.ARETURN:
    case Opcodes.ATHROW:
    case Opcodes.FRETURN:
    case Opcodes.IRETURN:
    case Opcodes.MONITORENTER:
    case Opcodes.MONITOREXIT:
    case Opcodes.POP:
        pop(1);
        break;
    case Opcodes.DRETURN:
    case Opcodes.LRETURN:
    case Opcodes.POP2:
        pop(2);
        break;
    case Opcodes.AASTORE:
    case Opcodes.BASTORE:
    case Opcodes.CASTORE:
    case Opcodes.FASTORE:
    case Opcodes.IASTORE:
    case Opcodes.SASTORE:
        pop(3);
        break;
    case Opcodes.LASTORE:
    case Opcodes.DASTORE:
        pop(4);
        break;
    case Opcodes.ICONST_M1:
    case Opcodes.ICONST_0:
    case Opcodes.ICONST_1:
    case Opcodes.ICONST_2:
    case Opcodes.ICONST_3:
    case Opcodes.ICONST_4:
    case Opcodes.ICONST_5:
        push(Opcodes.INTEGER);
        break;
    case Opcodes.ARRAYLENGTH:
    case Opcodes.F2I:
    case Opcodes.I2B:
    case Opcodes.I2C:
    case Opcodes.I2S:
    case Opcodes.INEG:
        pop(1);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.BALOAD:
    case Opcodes.CALOAD:
    case Opcodes.D2I:
    case Opcodes.FCMPG:
    case Opcodes.FCMPL:
    case Opcodes.IADD:
    case Opcodes.IALOAD:
    case Opcodes.IAND:
    case Opcodes.IDIV:
    case Opcodes.IMUL:
    case Opcodes.IOR:
    case Opcodes.IREM:
    case Opcodes.ISHL:
    case Opcodes.ISHR:
    case Opcodes.ISUB:
    case Opcodes.IUSHR:
    case Opcodes.IXOR:
    case Opcodes.L2I:
    case Opcodes.SALOAD:
        pop(2);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.DCMPG:
    case Opcodes.DCMPL:
    case Opcodes.LCMP:
        pop(4);
        push(Opcodes.INTEGER);
        break;
    case Opcodes.FCONST_0:
    case Opcodes.FCONST_1:
    case Opcodes.FCONST_2:
        push(Opcodes.FLOAT);
        break;
    case Opcodes.FNEG:
    case Opcodes.I2F:
        pop(1);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.D2F:
    case Opcodes.FADD:
    case Opcodes.FALOAD:
    case Opcodes.FDIV:
    case Opcodes.FMUL:
    case Opcodes.FREM:
    case Opcodes.FSUB:
    case Opcodes.L2F:
        pop(2);
        push(Opcodes.FLOAT);
        break;
    case Opcodes.LCONST_0:
    case Opcodes.LCONST_1:
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2L:
    case Opcodes.I2L:
        pop(1);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.D2L:
    case Opcodes.LALOAD:
    case Opcodes.LNEG:
        pop(2);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LSHL:
    case Opcodes.LSHR:
    case Opcodes.LUSHR:
        pop(3);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.LADD:
    case Opcodes.LAND:
    case Opcodes.LDIV:
    case Opcodes.LMUL:
    case Opcodes.LOR:
    case Opcodes.LREM:
    case Opcodes.LSUB:
    case Opcodes.LXOR:
        pop(4);
        push(Opcodes.LONG);
        push(Opcodes.TOP);
        break;
    case Opcodes.DCONST_0:
    case Opcodes.DCONST_1:
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.F2D:
    case Opcodes.I2D:
        pop(1);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DALOAD:
    case Opcodes.DNEG:
    case Opcodes.L2D:
        pop(2);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.DADD:
    case Opcodes.DDIV:
    case Opcodes.DMUL:
    case Opcodes.DREM:
    case Opcodes.DSUB:
        pop(4);
        push(Opcodes.DOUBLE);
        push(Opcodes.TOP);
        break;
    case Opcodes.ACONST_NULL:
        push(Opcodes.NULL);
        break;
    case Opcodes.AALOAD:
        pop(1);
        t1 = pop();
        push(Type.getType(((String) t1).substring(1)));
        break;
    case Opcodes.DUP:
        t1 = pop();
        push(t1);
        push(t1);
        break;
    case Opcodes.DUP_X1:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2:
        t1 = pop();
        t2 = pop();
        push(t2);
        push(t1);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X1:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        push(t2);
        push(t1);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.DUP2_X2:
        t1 = pop();
        t2 = pop();
        t3 = pop();
        t4 = pop();
        push(t2);
        push(t1);
        push(t4);
        push(t3);
        push(t2);
        push(t1);
        break;
    case Opcodes.SWAP:
        t1 = pop();
        t2 = pop();
        push(t1);
        push(t2);
        break;
    default:
        throw new IllegalArgumentException();
    }
    mv.visitInsn(opcode);
}

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

License:Open Source License

/**
 * Generates a DUP2_X1 instruction.
 */
public void dup2X1() {
    visitInsn(Opcodes.DUP2_X1);
}

From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java

License:Apache License

/**
 * box the primitive value on the stack/*  w  w  w . j  a v  a2s  .  c  o m*/
 *
 * @param type
 * @param mv
 */
public void quickBoxIfNecessary(ClassNode type, MethodVisitor mv) {
    String descr = getTypeDescription(type);
    if (type == boolean_TYPE) {
        boxBoolean(mv);
    } else if (isPrimitiveType(type) && type != VOID_TYPE) {
        ClassNode wrapper = TypeUtil.wrapSafely(type);
        String internName = getClassInternalName(wrapper);
        mv.visitTypeInsn(Opcodes.NEW, internName);
        mv.visitInsn(Opcodes.DUP);
        if (type == double_TYPE || type == long_TYPE) {
            mv.visitInsn(Opcodes.DUP2_X2);
            mv.visitInsn(Opcodes.POP2);
        } else {
            mv.visitInsn(Opcodes.DUP2_X1);
            mv.visitInsn(Opcodes.POP2);
        }
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, internName, "<init>", "(" + descr + ")V");
    }
}

From source file:org.mbte.groovypp.compiler.bytecode.BytecodeExpr.java

License:Apache License

public void swapWithObject(ClassNode type, MethodVisitor mv) {
    if (type == long_TYPE || type == double_TYPE) {
        mv.visitInsn(Opcodes.DUP2_X1);
        mv.visitInsn(Opcodes.POP2);/* w  w  w .  j  av a2s  .c  o m*/
    } else {
        mv.visitInsn(Opcodes.SWAP);
    }
}