List of usage examples for org.objectweb.asm Opcodes ISTORE
int ISTORE
To view the source code for org.objectweb.asm Opcodes ISTORE.
Click Source Link
From source file:org.elasticsearch.plan.a.Writer.java
License:Apache License
private void writeExecute() { final int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC; execute = new GeneratorAdapter(access, EXECUTE, SIGNATURE, null, writer); final Label fals = new Label(); final Label end = new Label(); execute.visitVarInsn(Opcodes.ALOAD, metadata.inputValueSlot); execute.push("#score"); execute.invokeInterface(MAP_TYPE, MAP_GET); execute.dup();//from w ww . j a va2s .c o m execute.ifNull(fals); execute.checkCast(SCORE_ACCESSOR_TYPE); execute.invokeVirtual(SCORE_ACCESSOR_TYPE, SCORE_ACCESSOR_FLOAT); execute.goTo(end); execute.mark(fals); execute.pop(); execute.push(0F); execute.mark(end); execute.visitVarInsn(Opcodes.FSTORE, metadata.scoreValueSlot); execute.push(settings.getMaxLoopCounter()); execute.visitVarInsn(Opcodes.ISTORE, metadata.loopCounterSlot); visit(root); execute.endMethod(); }
From source file:org.elasticsearch.plan.a.Writer.java
License:Apache License
@Override public Void visitDeclvar(final DeclvarContext ctx) { final ExpressionMetadata declvaremd = metadata.getExpressionMetadata(ctx); final org.objectweb.asm.Type type = declvaremd.to.type; final Sort sort = declvaremd.to.sort; final int slot = (int) declvaremd.postConst; final ExpressionContext exprctx = ctx.expression(); final boolean initialize = exprctx == null; if (!initialize) { visit(exprctx);//from www . j av a 2 s.c o m } switch (sort) { case VOID: throw new IllegalStateException(error(ctx) + "Unexpected writer state."); case BOOL: case BYTE: case SHORT: case CHAR: case INT: if (initialize) execute.push(0); break; case LONG: if (initialize) execute.push(0L); break; case FLOAT: if (initialize) execute.push(0.0F); break; case DOUBLE: if (initialize) execute.push(0.0); break; default: if (initialize) execute.visitInsn(Opcodes.ACONST_NULL); } execute.visitVarInsn(type.getOpcode(Opcodes.ISTORE), slot); return null; }
From source file:org.elasticsearch.plan.a.Writer.java
License:Apache License
private void writeLoadStoreVariable(final ParserRuleContext source, final boolean store, final Type type, final int slot) { if (type.sort == Sort.VOID) { throw new IllegalStateException(error(source) + "Cannot load/store void type."); }//from w ww . j a v a 2 s . c om if (store) { execute.visitVarInsn(type.type.getOpcode(Opcodes.ISTORE), slot); } else { execute.visitVarInsn(type.type.getOpcode(Opcodes.ILOAD), slot); } }
From source file:org.evosuite.graphs.cfg.ASMWrapper.java
License:Open Source License
/** * <p>//w w w .ja v a 2s. co m * isLocalVarDefinition * </p> * * @return a boolean. */ public boolean isLocalVariableDefinition() { return asmNode.getOpcode() == Opcodes.ISTORE || asmNode.getOpcode() == Opcodes.LSTORE || asmNode.getOpcode() == Opcodes.FSTORE || asmNode.getOpcode() == Opcodes.DSTORE || asmNode.getOpcode() == Opcodes.ASTORE || asmNode.getOpcode() == Opcodes.IINC || isLocalArrayDefinition(); }
From source file:org.evosuite.graphs.cfg.BytecodeInstructionPool.java
License:Open Source License
/** * Determine how many bytes the current instruction occupies together with * its operands//w ww .ja v a 2s . c om * * @return */ private int getBytecodeIncrement(AbstractInsnNode instructionNode) { int opcode = instructionNode.getOpcode(); switch (opcode) { case Opcodes.ALOAD: // index case Opcodes.ASTORE: // index case Opcodes.DLOAD: case Opcodes.DSTORE: case Opcodes.FLOAD: case Opcodes.FSTORE: case Opcodes.ILOAD: case Opcodes.ISTORE: case Opcodes.LLOAD: case Opcodes.LSTORE: VarInsnNode varNode = (VarInsnNode) instructionNode; if (varNode.var > 3) return 1; else return 0; case Opcodes.BIPUSH: // byte case Opcodes.NEWARRAY: case Opcodes.RET: return 1; case Opcodes.LDC: LdcInsnNode ldcNode = (LdcInsnNode) instructionNode; if (ldcNode.cst instanceof Double || ldcNode.cst instanceof Long) return 2; // LDC2_W else return 1; case 19: //LDC_W case 20: //LDC2_W return 2; case Opcodes.ANEWARRAY: // indexbyte1, indexbyte2 case Opcodes.CHECKCAST: // indexbyte1, indexbyte2 case Opcodes.GETFIELD: case Opcodes.GETSTATIC: case Opcodes.GOTO: case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: case Opcodes.IF_ICMPLT: case Opcodes.IFLE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFNE: case Opcodes.IFEQ: case Opcodes.IFNONNULL: case Opcodes.IFNULL: case Opcodes.IINC: case Opcodes.INSTANCEOF: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: case Opcodes.JSR: case Opcodes.NEW: case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: case Opcodes.SIPUSH: // case Opcodes.LDC_W // case Opcodes.LDC2_W return 2; case Opcodes.MULTIANEWARRAY: return 3; case Opcodes.INVOKEDYNAMIC: case Opcodes.INVOKEINTERFACE: return 4; case Opcodes.LOOKUPSWITCH: case Opcodes.TABLESWITCH: // TODO: Could be more return 4; // case Opcodes.GOTO_W // case Opcodes.JSR_W } return 0; }
From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java
License:Open Source License
/** * This helper function determines whether the boolean on the stack at the * current position will be stored in a Boolean variable * /*from w ww . java2 s .c om*/ * @param position * @param mn * @return */ public boolean isBooleanAssignment(AbstractInsnNode position, MethodNode mn) { AbstractInsnNode node = position.getNext(); logger.info("Checking for ISTORE after boolean"); boolean done = false; while (!done) { if (node.getOpcode() == Opcodes.PUTFIELD || node.getOpcode() == Opcodes.PUTSTATIC) { // TODO: Check whether field is static logger.info("Checking field assignment"); FieldInsnNode fn = (FieldInsnNode) node; if (Type.getType(DescriptorMapping.getInstance().getFieldDesc(fn.owner, fn.name, fn.desc)) == Type.BOOLEAN_TYPE) { return true; } else { return false; } } else if (node.getOpcode() == Opcodes.ISTORE) { logger.info("Found ISTORE after boolean"); VarInsnNode vn = (VarInsnNode) node; // TODO: Check whether variable at this position is a boolean if (isBooleanVariable(vn.var, mn)) { logger.info("Assigning boolean to variable "); return true; } else { logger.info("Variable is not a bool"); return false; } } else if (node.getOpcode() == Opcodes.IRETURN) { logger.info("Checking return value of method {}.{}", cn.name, mn.name); if (DescriptorMapping.getInstance().isTransformedOrBooleanMethod(cn.name, mn.name, mn.desc)) { logger.info("Method returns a bool"); return true; } else { logger.info("Method does not return a bool"); return false; } } else if (node.getOpcode() == Opcodes.BASTORE) { // We remove all bytes, so BASTORE is only used for booleans AbstractInsnNode start = position.getNext(); boolean reassignment = false; while (start != node) { if (node instanceof InsnNode) { reassignment = true; } start = start.getNext(); } logger.info("Possible assignment to array?"); if (reassignment) return false; else return true; } else if (node instanceof MethodInsnNode) { // if it is a boolean parameter of a converted method, then it needs to be converted // Problem: How do we know which parameter it represents? MethodInsnNode methodNode = (MethodInsnNode) node; String desc = DescriptorMapping.getInstance().getMethodDesc(methodNode.owner, methodNode.name, methodNode.desc); Type[] types = Type.getArgumentTypes(desc); if (types.length > 0 && types[types.length - 1] == Type.BOOLEAN_TYPE) { return true; } else { return false; } } else if (node.getOpcode() == Opcodes.GOTO || node.getOpcode() == Opcodes.ICONST_0 || node.getOpcode() == Opcodes.ICONST_1 || node.getOpcode() == -1) { logger.info("Continuing search"); // continue search } else if (!(node instanceof LineNumberNode || node instanceof FrameNode)) { logger.info("Search ended with opcode {}", node.getOpcode()); return false; } if (node != mn.instructions.getLast()) node = node.getNext(); else done = true; } return false; }
From source file:org.evosuite.instrumentation.coverage.DefUseInstrumentation.java
License:Open Source License
private InsnList getMethodInstrumentation(BytecodeInstruction call, boolean staticContext, InsnList instrumentation, MethodNode mn) { String descriptor = call.getMethodCallDescriptor(); Type[] args = Type.getArgumentTypes(descriptor); int loc = getNextLocalNum(mn); Map<Integer, Integer> to = new HashMap<Integer, Integer>(); for (int i = args.length - 1; i >= 0; i--) { Type type = args[i];/*from w w w .j ava 2 s .com*/ instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ISTORE), loc)); to.put(i, loc); loc++; } // instrumentation.add(new InsnNode(Opcodes.DUP));//callee addObjectInstrumentation(call, instrumentation, mn); addCallingObjectInstrumentation(staticContext, instrumentation); // field method calls get special treatment: // during instrumentation it is not clear whether a field method // call constitutes a definition or a use. So the instrumentation // will call a special function of the ExecutionTracer which will // redirect the call to either passedUse() or passedDefinition() // using the information available during runtime (the CCFGs) instrumentation.add(new LdcInsnNode(DefUsePool.getDefUseCounter())); instrumentation .add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ExecutionTracer.class), "passedFieldMethodCall", "(Ljava/lang/Object;Ljava/lang/Object;I)V")); for (int i = 0; i < args.length; i++) { Type type = args[i]; instrumentation.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), to.get(i))); } return instrumentation; }
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; }//from w w w.j ava2s . c om } } return index; }
From source file:org.evosuite.instrumentation.mutation.ReplaceBitwiseOperator.java
License:Open Source License
/** * <p>getInfectionDistance</p> * * @param opcodeOrig a int./* ww w . j a va 2 s. c o m*/ * @param opcodeNew a int. * @return a {@link org.objectweb.asm.tree.InsnList} object. */ public InsnList getInfectionDistance(int opcodeOrig, int opcodeNew) { InsnList distance = new InsnList(); if (opcodesInt.contains(opcodeOrig)) { distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceInt", "(IIII)D", false)); } else if (opcodesIntShift.contains(opcodeOrig)) { distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceInt", "(IIII)D", false)); } else if (opcodesLong.contains(opcodeOrig)) { distance.add(new VarInsnNode(Opcodes.LSTORE, numVariable)); distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new VarInsnNode(Opcodes.LLOAD, numVariable)); distance.add(new InsnNode(Opcodes.DUP2_X2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceLong", "(JJII)D", false)); numVariable += 2; } else if (opcodesLongShift.contains(opcodeOrig)) { distance.add(new VarInsnNode(Opcodes.ISTORE, numVariable)); distance.add(new InsnNode(Opcodes.DUP2)); distance.add(new VarInsnNode(Opcodes.ILOAD, numVariable)); distance.add(new InsnNode(Opcodes.DUP_X2)); distance.add(new LdcInsnNode(opcodeOrig)); distance.add(new LdcInsnNode(opcodeNew)); distance.add(new MethodInsnNode(Opcodes.INVOKESTATIC, PackageInfo.getNameWithSlash(ReplaceBitwiseOperator.class), "getInfectionDistanceLong", "(JIII)D", false)); numVariable += 1; } return distance; }
From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java
License:Open Source License
/** * This helper function determines whether the boolean on the stack at the * current position will be stored in a Boolean variable * /*from www . j a v a 2s .c o m*/ * @param position * @param mn * @return */ public boolean isBooleanAssignment(AbstractInsnNode position, MethodNode mn) { AbstractInsnNode node = position.getNext(); logger.info("Checking for ISTORE after boolean"); boolean done = false; while (!done) { if (node.getOpcode() == Opcodes.PUTFIELD || node.getOpcode() == Opcodes.PUTSTATIC) { // TODO: Check whether field is static logger.info("Checking field assignment"); FieldInsnNode fn = (FieldInsnNode) node; if (Type.getType(DescriptorMapping.getInstance().getFieldDesc(fn.owner, fn.name, fn.desc)) == Type.BOOLEAN_TYPE) { return true; } else { return false; } } else if (node.getOpcode() == Opcodes.ISTORE) { logger.info("Found ISTORE after boolean"); VarInsnNode vn = (VarInsnNode) node; // TODO: Check whether variable at this position is a boolean if (isBooleanVariable(vn.var, mn)) { logger.info("Assigning boolean to variable "); return true; } else { logger.info("Variable is not a bool"); return false; } } else if (node.getOpcode() == Opcodes.IRETURN) { logger.info("Checking return value of method " + cn.name + "." + mn.name); if (DescriptorMapping.getInstance().isTransformedOrBooleanMethod(cn.name, mn.name, mn.desc)) { logger.info("Method returns a bool"); return true; } else { logger.info("Method does not return a bool"); return false; } } else if (node.getOpcode() == Opcodes.BASTORE) { // We remove all bytes, so BASTORE is only used for booleans AbstractInsnNode start = position.getNext(); boolean reassignment = false; while (start != node) { if (node instanceof InsnNode) { reassignment = true; } start = start.getNext(); } logger.info("Possible assignment to array?"); if (reassignment) return false; else return true; } else if (node instanceof MethodInsnNode) { // if it is a boolean parameter of a converted method, then it needs to be converted // Problem: How do we know which parameter it represents? MethodInsnNode methodNode = (MethodInsnNode) node; String desc = DescriptorMapping.getInstance().getMethodDesc(methodNode.owner, methodNode.name, methodNode.desc); Type[] types = Type.getArgumentTypes(desc); if (types.length > 0 && types[types.length - 1] == Type.BOOLEAN_TYPE) { return true; } else { return false; } } else if (node.getOpcode() == Opcodes.GOTO || node.getOpcode() == Opcodes.ICONST_0 || node.getOpcode() == Opcodes.ICONST_1 || node.getOpcode() == -1) { logger.info("Continuing search"); // continue search } else if (!(node instanceof LineNumberNode || node instanceof FrameNode)) { logger.info("Search ended with opcode " + node.getOpcode()); return false; } if (node != mn.instructions.getLast()) node = node.getNext(); else done = true; } return false; }