List of usage examples for org.objectweb.asm Opcodes BASTORE
int BASTORE
To view the source code for org.objectweb.asm Opcodes BASTORE.
Click Source Link
From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java
License:Open Source License
@Test public void testVariableStatic() { ProbeInserter pi = new ProbeInserter(Opcodes.ACC_STATIC, "()V", actualVisitor, arrayStrategy); pi.insertProbe(0);//from w w w . j a v a 2 s .c o m expectedVisitor.visitVarInsn(Opcodes.ALOAD, 0); expectedVisitor.visitInsn(Opcodes.ICONST_0); expectedVisitor.visitInsn(Opcodes.ICONST_1); expectedVisitor.visitInsn(Opcodes.BASTORE); }
From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java
License:Open Source License
@Test public void testVariableNonStatic() { ProbeInserter pi = new ProbeInserter(0, "()V", actualVisitor, arrayStrategy); pi.insertProbe(0);/*ww w. ja v a 2 s .c o m*/ expectedVisitor.visitVarInsn(Opcodes.ALOAD, 1); expectedVisitor.visitInsn(Opcodes.ICONST_0); expectedVisitor.visitInsn(Opcodes.ICONST_1); expectedVisitor.visitInsn(Opcodes.BASTORE); }
From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java
License:Open Source License
@Test public void testVariableNonStatic_IZObject() { ProbeInserter pi = new ProbeInserter(0, "(IZLjava/lang/Object;)V", actualVisitor, arrayStrategy); pi.insertProbe(0);//from w ww . j a va 2 s . co m expectedVisitor.visitVarInsn(Opcodes.ALOAD, 4); expectedVisitor.visitInsn(Opcodes.ICONST_0); expectedVisitor.visitInsn(Opcodes.ICONST_1); expectedVisitor.visitInsn(Opcodes.BASTORE); }
From source file:org.jacoco.core.internal.instr.ProbeInserterTest.java
License:Open Source License
@Test public void testVariableNonStatic_JD() { ProbeInserter pi = new ProbeInserter(0, "(JD)V", actualVisitor, arrayStrategy); pi.insertProbe(0);/*from www . j ava2 s . c o m*/ expectedVisitor.visitVarInsn(Opcodes.ALOAD, 5); expectedVisitor.visitInsn(Opcodes.ICONST_0); expectedVisitor.visitInsn(Opcodes.ICONST_1); expectedVisitor.visitInsn(Opcodes.BASTORE); }
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 ww w . j ava 2s . co 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);/*w w w.jav a 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 ww .j a va 2 s .c o 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.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator1.java
License:Apache License
@Override public void visitInsn(final int opcode) { // I F L D + BS switch (opcode) { case Opcodes.IALOAD: if (this.shouldMutate("Incremented (a++) integer array field")) { mv.visitInsn(Opcodes.DUP2); // Array and its index on stack, times two mv.visitInsn(opcode); // IALOAD mv.visitInsn(Opcodes.DUP_X2); // put the result of array[index] under [array ref] [index] [array[index]] mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD);// w w w. ja va 2s . c o m mv.visitInsn(Opcodes.IASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.FALOAD: if (this.shouldMutate("Incremented (a++) float array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FADD); mv.visitInsn(Opcodes.FASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.LALOAD: if (this.shouldMutate("Incremented (a++) long array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LADD); mv.visitInsn(Opcodes.LASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.DALOAD: if (this.shouldMutate("Incremented (a++) double array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DADD); mv.visitInsn(Opcodes.DASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.BALOAD: if (this.shouldMutate("Incremented (a++) byte array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.I2B); mv.visitInsn(Opcodes.BASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.SALOAD: if (this.shouldMutate("Incremented (a++) short array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.I2S); mv.visitInsn(Opcodes.SASTORE); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator2.java
License:Apache License
@Override public void visitInsn(final int opcode) { // I F L D + BS switch (opcode) { case Opcodes.IALOAD: if (this.shouldMutate("Decremented (a--) integer array field")) { // stack = [array] [index] , wanted to perform an IALOAD mv.visitInsn(Opcodes.DUP2); // stack = [array] [index] [array] [index] mv.visitInsn(opcode); // stack = [array] [index] [array(index)] mv.visitInsn(Opcodes.DUP_X2); // stack = [array(index)] [array] [index] [array(index)] mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); // stack = [array(index)] [array] [index] [array(index)-1] mv.visitInsn(Opcodes.IASTORE); } else {//from w w w .j av a 2s .c om mv.visitInsn(opcode); } break; case Opcodes.FALOAD: if (this.shouldMutate("Decremented (a--) float array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FSUB); mv.visitInsn(Opcodes.FASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.LALOAD: if (this.shouldMutate("Decremented (a--) long array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LSUB); mv.visitInsn(Opcodes.LASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.DALOAD: if (this.shouldMutate("Decremented (a--) double array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DSUB); mv.visitInsn(Opcodes.DASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.BALOAD: if (this.shouldMutate("Decremented (a--) byte array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2B); mv.visitInsn(Opcodes.BASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.SALOAD: if (this.shouldMutate("Decremented (a--) short array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.I2S); mv.visitInsn(Opcodes.SASTORE); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }
From source file:org.pitest.mutationtest.engine.gregor.mutators.experimental.extended.UOIMutator3.java
License:Apache License
@Override public void visitInsn(final int opcode) { // I F L D + BS switch (opcode) { case Opcodes.IALOAD: if (this.shouldMutate("Incremented (++a) integer array field")) { // stack = [array] [index] mv.visitInsn(Opcodes.DUP2);/* ww w . j ava 2 s . c o m*/ // stack = [array] [index] [array] [index] mv.visitInsn(opcode); // stack = [array] [index] [array(index)] mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); // stack = [array] [index] [array(index)+1] mv.visitInsn(Opcodes.DUP_X2); // stack = [array(index)+1] [array] [index] [array(index)+1] mv.visitInsn(Opcodes.IASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.FALOAD: if (this.shouldMutate("Incremented (++a) float array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.FCONST_1); mv.visitInsn(Opcodes.FADD); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.FASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.LALOAD: if (this.shouldMutate("Incremented (++a) long array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.LCONST_1); mv.visitInsn(Opcodes.LADD); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.LASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.DALOAD: if (this.shouldMutate("Incremented (++a) double array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.DCONST_1); mv.visitInsn(Opcodes.DADD); mv.visitInsn(Opcodes.DUP2_X2); mv.visitInsn(Opcodes.DASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.BALOAD: if (this.shouldMutate("Incremented (++a) byte array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.I2B); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.BASTORE); } else { mv.visitInsn(opcode); } break; case Opcodes.SALOAD: if (this.shouldMutate("Incremented (++a) short array field")) { mv.visitInsn(Opcodes.DUP2); mv.visitInsn(opcode); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.I2S); mv.visitInsn(Opcodes.DUP_X2); mv.visitInsn(Opcodes.SASTORE); } else { mv.visitInsn(opcode); } break; default: mv.visitInsn(opcode); break; } }