List of usage examples for org.objectweb.asm Opcodes PUTSTATIC
int PUTSTATIC
To view the source code for org.objectweb.asm Opcodes PUTSTATIC.
Click Source Link
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { if (owner == null || name == null || desc == null) { log.warn(getM() + ": Cannot read get operation with field '" + owner + "." + name + "' and descriptor '" + desc + "'!"); return;/*from w w w. java 2s .c o m*/ } switch (opcode) { /******* * GET * *******/ case Opcodes.GETFIELD: case Opcodes.GETSTATIC: { final T ownerT = getDu().getT(owner); final F f = ownerT.getF(name, desc); f.setStatic(opcode == Opcodes.GETSTATIC); add(new GET(this.ops.size(), opcode, this.line, f)); return; } /******* * PUT * *******/ case Opcodes.PUTFIELD: case Opcodes.PUTSTATIC: { final T ownerT = getDu().getT(owner); final F f = ownerT.getF(name, desc); f.setStatic(opcode == Opcodes.PUTSTATIC); add(new PUT(this.ops.size(), opcode, this.line, f)); return; } default: log.warn(getM() + ": Unknown field insn opcode '" + opcode + "'!"); } }
From source file:org.eclipse.objectteams.otredyn.bytecode.asm.CreateFieldAccessAdapter.java
License:Open Source License
@Override public boolean transform() { InsnList instructions = new InsnList(); // put accessId on the stack instructions.add(new IntInsnNode(Opcodes.ILOAD, firstArgIndex + 1)); // read or write access LabelNode writeAccess = new LabelNode(); instructions.add(new JumpInsnNode(Opcodes.IFNE, writeAccess)); // read access if (field.isStatic()) { // get value of field instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, name, field.getName(), field.getSignature())); } else {/*from w w w . j a v a 2 s .co m*/ // put "this" on the stack instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); // get value of field instructions.add(new FieldInsnNode(Opcodes.GETFIELD, name, field.getName(), field.getSignature())); } //box value as "Object" Type type = Type.getType(field.getSignature()); instructions.add(AsmTypeHelper.getBoxingInstructionForType(type)); instructions.add(new InsnNode(Opcodes.ARETURN)); //write access instructions.add(writeAccess); //put "args" on the stack instructions.add(new IntInsnNode(Opcodes.ALOAD, firstArgIndex + 2)); //get the first element of "args" instructions.add(new InsnNode(Opcodes.ICONST_0)); instructions.add(new InsnNode(Opcodes.AALOAD)); //unbox it if (type.getSort() != Type.ARRAY && type.getSort() != Type.OBJECT) { String objectType = AsmTypeHelper.getObjectType(type); instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, objectType)); instructions.add(AsmTypeHelper.getUnboxingInstructionForType(type, objectType)); } else { instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, type.getInternalName())); } if (field.isStatic()) { //save value in field instructions.add(new FieldInsnNode(Opcodes.PUTSTATIC, name, field.getName(), field.getSignature())); } else { //put "this" on the stack instructions.add(new IntInsnNode(Opcodes.ALOAD, 0)); instructions.add(new InsnNode(Opcodes.SWAP)); //save value in field instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, name, field.getName(), field.getSignature())); } //dummy return instructions.add(new InsnNode(Opcodes.ACONST_NULL)); instructions.add(new InsnNode(Opcodes.ARETURN)); //add the instructions to a new label in the existing switch MethodNode method = getMethod(access); addNewLabelToSwitch(method.instructions, instructions, accessId); return true; }
From source file:org.evosuite.graphs.cfg.ASMWrapper.java
License:Open Source License
/** * <p>//www . j av a 2 s. co m * isFieldDefinition * </p> * * @return a boolean. */ public boolean isFieldDefinition() { return asmNode.getOpcode() == Opcodes.PUTFIELD || asmNode.getOpcode() == Opcodes.PUTSTATIC || isFieldArrayDefinition() || isFieldMethodCallDefinition(); }
From source file:org.evosuite.graphs.cfg.ASMWrapper.java
License:Open Source License
/** * <p>//ww w . j av a 2s . c o m * isFieldDefinition * </p> * * @return a boolean. */ public boolean isFieldNodeDefinition() { return asmNode.getOpcode() == Opcodes.PUTFIELD || asmNode.getOpcode() == Opcodes.PUTSTATIC || isFieldArrayDefinition(); }
From source file:org.evosuite.graphs.cfg.ASMWrapper.java
License:Open Source License
/** * <p>/*from ww w. j ava 2 s .c o m*/ * isStaticDefUse * </p> * * @return a boolean. */ public boolean isStaticDefUse() { return asmNode.getOpcode() == Opcodes.PUTSTATIC || asmNode.getOpcode() == Opcodes.GETSTATIC || isStaticArrayUsage(); }
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/*from ww w . j av a 2 s. com*/ * * @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 ww w .ja va 2 s . 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; }
From source file:org.evosuite.instrumentation.CreateClassResetClassAdapter.java
License:Open Source License
private void createEmptyStaticReset() { logger.info("Creating brand-new static initializer in class {}", className); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, ClassResetter.STATIC_RESET, "()V", null, null); mv.visitCode();/*from w w w. j av a 2 s .c o m*/ for (StaticField staticField : static_fields) { if (!finalFields.contains(staticField.name)) { logger.info("Adding bytecode for initializing field {}", staticField.name); if (staticField.value != null) { mv.visitLdcInsn(staticField.value); } else { Type type = Type.getType(staticField.desc); switch (type.getSort()) { case Type.BOOLEAN: case Type.BYTE: case Type.CHAR: case Type.SHORT: case Type.INT: mv.visitInsn(Opcodes.ICONST_0); break; case Type.FLOAT: mv.visitInsn(Opcodes.FCONST_0); break; case Type.LONG: mv.visitInsn(Opcodes.LCONST_0); break; case Type.DOUBLE: mv.visitInsn(Opcodes.DCONST_0); break; case Type.ARRAY: case Type.OBJECT: mv.visitInsn(Opcodes.ACONST_NULL); break; } } mv.visitFieldInsn(Opcodes.PUTSTATIC, className, staticField.name, staticField.desc); } } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.evosuite.instrumentation.PurityAnalysisMethodVisitor.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w ww .j a va2s .co m*/ public void visitFieldInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.PUTSTATIC || opcode == Opcodes.PUTFIELD) { updatesField = true; } super.visitFieldInsn(opcode, owner, name, desc); }
From source file:org.evosuite.instrumentation.PutStaticMethodAdapter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www . ja va 2s. com public void visitFieldInsn(int opcode, String owner, String name, String desc) { if (opcode == Opcodes.PUTSTATIC && !(className.equals(owner) && methodName.equals("<clinit>")) && !(className.equals(owner) && methodName.equals(ClassResetter.STATIC_RESET))) { String executionTracerClassName = ExecutionTracer.class.getName().replace(".", "/"); String executionTracerDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class), Type.getType(String.class)); String classNameWithDots = owner.replace("/", "."); super.visitLdcInsn(classNameWithDots); super.visitLdcInsn(name); super.visitMethodInsn(INVOKESTATIC, executionTracerClassName, PASSED_PUT_STATIC, executionTracerDescriptor); } super.visitFieldInsn(opcode, owner, name, desc); }