List of usage examples for org.objectweb.asm Opcodes CASTORE
int CASTORE
To view the source code for org.objectweb.asm Opcodes CASTORE.
Click Source Link
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitInsn(final int opcode) { T t = null;/*from w w w . j av a2 s.c o 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.evosuite.instrumentation.error.ArrayInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Check array accesses if (opcode == Opcodes.IALOAD || opcode == Opcodes.BALOAD || opcode == Opcodes.CALOAD || opcode == Opcodes.SALOAD || opcode == Opcodes.LALOAD || opcode == Opcodes.FALOAD || opcode == Opcodes.DALOAD || opcode == Opcodes.AALOAD) { mv.visitInsn(Opcodes.DUP);// w w w.j a v a 2 s.c om insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); //mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.ARRAYLENGTH); insertBranch(Opcodes.IF_ICMPLT, "java/lang/ArrayIndexOutOfBoundsException"); } else if (opcode == Opcodes.IASTORE || opcode == Opcodes.BASTORE || opcode == Opcodes.CASTORE || opcode == Opcodes.SASTORE || opcode == Opcodes.AASTORE || opcode == Opcodes.LASTORE || opcode == Opcodes.FASTORE || opcode == Opcodes.DASTORE) { int loc = 0; if (opcode == Opcodes.IASTORE) loc = mv.newLocal(Type.INT_TYPE); else if (opcode == Opcodes.BASTORE) loc = mv.newLocal(Type.BYTE_TYPE); else if (opcode == Opcodes.CASTORE) loc = mv.newLocal(Type.CHAR_TYPE); else if (opcode == Opcodes.SASTORE) loc = mv.newLocal(Type.SHORT_TYPE); else if (opcode == Opcodes.AASTORE) loc = mv.newLocal(Type.getType(Object.class)); else if (opcode == Opcodes.LASTORE) loc = mv.newLocal(Type.LONG_TYPE); else if (opcode == Opcodes.FASTORE) loc = mv.newLocal(Type.FLOAT_TYPE); else if (opcode == Opcodes.DASTORE) loc = mv.newLocal(Type.DOUBLE_TYPE); else throw new RuntimeException("Unknown type"); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP); insertBranch(Opcodes.IFGE, "java/lang/ArrayIndexOutOfBoundsException"); mv.visitInsn(Opcodes.DUP2); mv.visitInsn(Opcodes.SWAP); //mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.ARRAYLENGTH); insertBranch(Opcodes.IF_ICMPLT, "java/lang/ArrayIndexOutOfBoundsException"); mv.loadLocal(loc); } }
From source file:org.evosuite.instrumentation.error.NullPointerExceptionInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { switch (opcode) { case Opcodes.ARRAYLENGTH: // TODO//w ww . ja v a2s.c om break; case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: // TODO break; case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: // TODO break; default: // Ignore everything else } super.visitInsn(opcode); }
From source file:org.evosuite.instrumentation.mutation.ReplaceArithmeticOperator.java
License:Open Source License
@SuppressWarnings("rawtypes") private static int getNextIndexFromLoad(MethodNode mn) { Iterator it = mn.instructions.iterator(); int index = 0; while (it.hasNext()) { AbstractInsnNode node = (AbstractInsnNode) it.next(); if (node instanceof VarInsnNode) { VarInsnNode varNode = (VarInsnNode) node; int varIndex = varNode.var; switch (varNode.getOpcode()) { case Opcodes.ALOAD: case Opcodes.ILOAD: case Opcodes.FLOAD: case Opcodes.IALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.AALOAD: case Opcodes.ASTORE: case Opcodes.ISTORE: case Opcodes.FSTORE: case Opcodes.IASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.AASTORE: index = Math.max(index, varIndex + 1); break; case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: case Opcodes.DALOAD: case Opcodes.DASTORE: case Opcodes.LALOAD: case Opcodes.LASTORE: index = Math.max(index, varIndex + 2); break; }//w ww . j a va2 s . co m } } return index; }
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 ww w . j a va 2 s . co m 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.rule.expression.ArrayExpression.java
License:Open Source License
@Override public void compileAssign(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); Type valueType = arrayRef.getType().getBaseType(); int currentStack = compileContext.getStackCount(); boolean isTwoWords = (valueType.getNBytes() > 4); int toPop = 0; int size = (isTwoWords ? 2 : 1); // value to be assigned is TOS and will already be coerced to the correct value type // copy it so we can install the copy and leave the original as a a return value on the stack if (isTwoWords) { // [... val1 val2 ==> ... val1 val2 val1 val2] mv.visitInsn(Opcodes.DUP2);//from w ww. j a v a2s . c o m } else { // [... val ==> ... val val] mv.visitInsn(Opcodes.DUP); } compileContext.addStackCount(size); // compile load of array reference -- adds 1 to stack height arrayRef.compile(mv, compileContext); // for each index expression compile the expression and the do an array load Iterator<Expression> iterator = idxList.iterator(); while (iterator.hasNext()) { Expression idxExpr = iterator.next(); if (iterator.hasNext()) { // dereference the array to get an embedded array // compile expression index -- adds 1 to height idxExpr.compile(mv, compileContext); // make sure the index is an integer compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext); // fetch embedded array pop 2 and add 1 mv.visitInsn(Opcodes.AALOAD); compileContext.addStackCount(-1); valueType = valueType.getBaseType(); } else { if (isTwoWords) { // stack is [..., val1, val2, val1, val2, aref ] and we want [..., val1, val2, aref, val1, val2 ] mv.visitInsn(Opcodes.DUP_X2); // ==> [..., val1, val2, aref. val1, val2, aref ] compileContext.addStackCount(1); mv.visitInsn(Opcodes.POP); // ==> [..., val1, val2, aref. val1, val2 ] compileContext.addStackCount(-1); } else { // stack is [..., val, val, aref ] and we want [..., val, aref, val ] mv.visitInsn(Opcodes.SWAP); } // compile expression index -- adds 1 to height idxExpr.compile(mv, compileContext); // make sure the index is an integer compileTypeConversion(idxExpr.getType(), Type.I, mv, compileContext); if (isTwoWords) { // stack is [..., val1, val2, aref, val1, val2, idx] and we want [..., val1, val2, aref, idx, val1, val2 ] mv.visitInsn(Opcodes.DUP_X2); // ==> [..., val1, val2, aref, idx, val1, val2, idx] compileContext.addStackCount(1); mv.visitInsn(Opcodes.POP); // ==> [..., val1, val2, aref, idx, val1, val2 ] compileContext.addStackCount(-1); } else { // stack is [..., val, aref, val, idx] and we want [..., val, aref, idx, val ] mv.visitInsn(Opcodes.SWAP); } // now we can do the array store if (valueType.isObject() || valueType.isArray()) { // compile load object - pops 3 mv.visitInsn(Opcodes.AASTORE); toPop = -3; } else if (valueType == Type.Z || valueType == Type.B) { // compile load byte - pops 3 mv.visitInsn(Opcodes.BASTORE); toPop = -3; } else if (valueType == Type.S) { // compile load short - pops 3 mv.visitInsn(Opcodes.SASTORE); toPop = -3; } else if (valueType == Type.C) { // compile load char - pops 3 mv.visitInsn(Opcodes.CASTORE); toPop = -3; } else if (valueType == Type.I) { // compile load int - pops 3 mv.visitInsn(Opcodes.IASTORE); toPop = -3; } else if (valueType == Type.J) { // compile load long - pops 4 mv.visitInsn(Opcodes.LASTORE); toPop = -4; } else if (valueType == Type.F) { // compile load float - pops 3 mv.visitInsn(Opcodes.FASTORE); toPop = -3; } else if (valueType == Type.D) { // compile load double - pops 4 mv.visitInsn(Opcodes.DASTORE); toPop = -4; } compileContext.addStackCount(toPop); if (iterator.hasNext()) { assert valueType.isArray(); valueType = valueType.getBaseType(); } } } // check stack height if (compileContext.getStackCount() != currentStack) { throw new CompileException("ArrayExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack); } // we needed room for an aray and an index or for a one or two word result // but the recursive evaluations will have made sure the max stack is big enough // so there is no need to update the maximum stack height }
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);/* ww w .j ava 2 s.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.openquark.cal.internal.javamodel.AsmJavaBytecodeGenerator.java
License:Open Source License
/** * @param elemType element type of the array. * @return java op-code to use for storing into arrays with elements of the specified type. *//* w w w. ja v a2 s .co m*/ private static int getArrayStoreOpCode(JavaTypeName elemType) { switch (elemType.getTag()) { case JavaTypeName.VOID_TAG: throw new IllegalArgumentException(); case JavaTypeName.BOOLEAN_TAG: case JavaTypeName.BYTE_TAG: return Opcodes.BASTORE; case JavaTypeName.SHORT_TAG: return Opcodes.SASTORE; case JavaTypeName.CHAR_TAG: return Opcodes.CASTORE; case JavaTypeName.INT_TAG: return Opcodes.IASTORE; case JavaTypeName.LONG_TAG: return Opcodes.LASTORE; case JavaTypeName.DOUBLE_TAG: return Opcodes.DASTORE; case JavaTypeName.FLOAT_TAG: return Opcodes.FASTORE; case JavaTypeName.ARRAY_TAG: case JavaTypeName.OBJECT_TAG: return Opcodes.AASTORE; default: { throw new IllegalArgumentException(); } } }
From source file:org.sonar.java.bytecode.se.BytecodeEGWalkerExecuteTest.java
License:Open Source License
@Test public void test_array_store() throws Exception { int[] storeArrayOpcodes = new int[] { Opcodes.IASTORE, Opcodes.LASTORE, Opcodes.FASTORE, Opcodes.DASTORE, Opcodes.AASTORE, Opcodes.BASTORE, Opcodes.CASTORE, Opcodes.SASTORE }; SymbolicValue array = new SymbolicValue(); SymbolicValue index = new SymbolicValue(); SymbolicValue value = new SymbolicValue(); ProgramState initState = ProgramState.EMPTY_STATE.stackValue(array).stackValue(index).stackValue(value); for (int opcode : storeArrayOpcodes) { ProgramState ps = execute(new Instruction(opcode), initState); assertEmptyStack(ps);// ww w . j ava 2s. c o m } }
From source file:serianalyzer.JVMImpl.java
License:Open Source License
/** * @param opcode/*from w w w.j av a2 s .c o m*/ * @param s */ static void handleJVMInsn(int opcode, JVMStackState s) { BaseType o1; BaseType o2; BaseType o3; List<BaseType> l1; List<BaseType> l2; switch (opcode) { case Opcodes.NOP: break; case Opcodes.ARRAYLENGTH: o1 = s.pop(); s.push(new BasicConstant(Type.INT_TYPE, 0, !(o1 != null && !o1.isTainted()))); break; case Opcodes.ACONST_NULL: s.push(new BasicConstant(Type.VOID_TYPE, "<null>")); //$NON-NLS-1$ 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: s.push(new BasicConstant(Type.INT_TYPE, opcode - 3)); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: s.push(new BasicConstant(Type.LONG_TYPE, opcode - 9L)); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: s.push(new BasicConstant(Type.FLOAT_TYPE, opcode - 11f)); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: s.push(new BasicConstant(Type.DOUBLE_TYPE, opcode - 14d)); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: o1 = s.pop(); o2 = s.pop(); s.push(new BasicVariable(toType(opcode), "primitive array elem", //$NON-NLS-1$ (o1 == null || o1.isTainted()) | (o2 == null || o2.isTainted()))); break; case Opcodes.AALOAD: o1 = s.pop(); o2 = s.pop(); if (o1 != null && o2 instanceof SimpleType && ((SimpleType) o2).getType().toString().startsWith("[")) { //$NON-NLS-1$ Type atype = Type.getType(((SimpleType) o2).getType().toString().substring(1)); if (o2.getAlternativeTypes() != null && !o2.getAlternativeTypes().isEmpty()) { s.clear(); break; } s.push(new BasicVariable(atype, "array elem " + atype, o1.isTainted() | o2.isTainted())); //$NON-NLS-1$ } else { s.clear(); } break; case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: s.pop(3); break; case Opcodes.POP2: s.pop(); case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: case Opcodes.POP: s.pop(); break; case Opcodes.DUP: if (!s.isEmpty()) { o1 = s.pop(); s.push(o1); s.push(o1); } break; case Opcodes.DUP_X1: o1 = s.pop(); o2 = s.pop(); s.push(o1); s.push(o2); s.push(o1); break; case Opcodes.DUP_X2: o1 = s.pop(); o2 = s.pop(); o3 = s.pop(); s.push(o1); s.push(o3); s.push(o2); s.push(o1); break; case Opcodes.DUP2: l1 = s.popWord(); if (l1.isEmpty()) { log.trace("DUP2 with unknown operand"); //$NON-NLS-1$ s.clear(); } else { s.pushWord(l1); s.pushWord(l1); } break; case Opcodes.DUP2_X1: l1 = s.popWord(); o1 = s.pop(); if (l1.isEmpty()) { log.trace("DUP2 with unknown operand"); //$NON-NLS-1$ s.clear(); } else { s.pushWord(l1); s.push(o1); s.pushWord(l1); } break; case Opcodes.DUP2_X2: l1 = s.popWord(); l2 = s.popWord(); if (l1.isEmpty() || l2.isEmpty()) { log.trace("DUP2 with unknown operand"); //$NON-NLS-1$ s.clear(); } else { s.pushWord(l1); s.pushWord(l2); s.pushWord(l1); } break; case Opcodes.SWAP: o1 = s.pop(); o2 = s.pop(); s.push(o1); s.push(o2); break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: case Opcodes.IAND: case Opcodes.LAND: case Opcodes.IOR: case Opcodes.LOR: case Opcodes.IXOR: case Opcodes.LXOR: case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.FCMPG: case Opcodes.DCMPL: case Opcodes.DCMPG: s.merge(2); break; case Opcodes.ISHL: case Opcodes.LSHL: case Opcodes.ISHR: case Opcodes.LSHR: case Opcodes.IUSHR: case Opcodes.LUSHR: s.pop(); // amount // ignore value break; case Opcodes.INEG: case Opcodes.F2I: case Opcodes.D2I: case Opcodes.L2I: s.push(cast(s.pop(), Type.INT_TYPE)); break; case Opcodes.LNEG: case Opcodes.I2L: case Opcodes.F2L: case Opcodes.D2L: s.push(cast(s.pop(), Type.LONG_TYPE)); break; case Opcodes.FNEG: case Opcodes.I2F: case Opcodes.L2F: case Opcodes.D2F: s.push(cast(s.pop(), Type.FLOAT_TYPE)); case Opcodes.DNEG: case Opcodes.I2D: case Opcodes.L2D: case Opcodes.F2D: s.push(cast(s.pop(), Type.DOUBLE_TYPE)); case Opcodes.I2B: s.push(cast(s.pop(), Type.BYTE_TYPE)); break; case Opcodes.I2C: s.push(cast(s.pop(), Type.CHAR_TYPE)); break; case Opcodes.I2S: s.push(cast(s.pop(), Type.SHORT_TYPE)); break; case Opcodes.ARETURN: s.clear(); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.RETURN: if (log.isTraceEnabled()) { log.trace("Found return " + s.pop()); //$NON-NLS-1$ } s.clear(); break; case Opcodes.ATHROW: Object thrw = s.pop(); log.trace("Found throw " + thrw); //$NON-NLS-1$ s.clear(); break; default: log.warn("Unsupported instruction code " + opcode); //$NON-NLS-1$ } }