private void convertFieldInsn(FieldInsnNode insn) { int op = insn.getOpcode(); if (op == GETSTATIC || op == GETFIELD) { convertGetFieldInsn(insn); } else { convertPutFieldInsn(insn); } }
if (finsn.getOpcode() == GETSTATIC) { java.lang.reflect.Type possibleEnum = loadType(loader, finsn.owner); if (MoreTypes.getRawType(possibleEnum).isEnum()) {
private void convertPutFieldInsn(FieldInsnNode insn) { boolean instance = insn.getOpcode() == PUTFIELD; StackFrame frame = getFrame(insn); Operand[] out = frame.out();
private static InsnList generateAddressInstructions(final FieldInsnNode fieldInsn) { if ( !"J".equals(fieldInsn.desc) ) throw new IllegalStateException(); if ( fieldInsn.getOpcode() == GETFIELD ) // do not change a thing return null; if ( fieldInsn.getOpcode() == PUTFIELD ) throwAccessErrorOnReadOnlyField(fieldInsn.owner, fieldInsn.name); throw new InternalError(); }
private boolean methodMutatesField(List<MethodNode> methods, FieldNode field, ClassNode fieldOwner) { for(MethodNode methodNode : methods) { Iterator<AbstractInsnNode> instructionIterator = methodNode.instructions.iterator(); while (instructionIterator.hasNext()) { AbstractInsnNode abstractInsNode = instructionIterator.next(); if(abstractInsNode.getType() != AbstractInsnNode.FIELD_INSN) { continue; } FieldInsnNode fieldInsnNode = (FieldInsnNode) abstractInsNode; if(fieldInsnNode.getOpcode() != Opcodes.PUTFIELD) { continue; } if(fieldInsnNode.name.equals(field.name) && fieldInsnNode.owner.equals(fieldOwner.name)) { return true; } } } return false; }
private static InsnList generateSIZEOFInstructions(final FieldInsnNode fieldInsn, final MappedSubtypeInfo mappedSubtype) { if ( !"I".equals(fieldInsn.desc) ) throw new InternalError(); final InsnList list = new InsnList(); if ( fieldInsn.getOpcode() == GETSTATIC ) { list.add(getIntNode(mappedSubtype.sizeof)); return list; } if ( fieldInsn.getOpcode() == PUTSTATIC ) throwAccessErrorOnReadOnlyField(fieldInsn.owner, fieldInsn.name); throw new InternalError(); }
@Override protected AbstractInsnNode transformFieldInsnNode(MethodNode mn, FieldInsnNode fieldNode) { // This handles the else branch for field assignments if (DescriptorMapping.getInstance().isTransformedOrBooleanField(this.booleanTestabilityTransformation.className, fieldNode.name, fieldNode.desc)) { if (fieldNode.getNext() instanceof FieldInsnNode) { FieldInsnNode other = (FieldInsnNode) fieldNode.getNext(); if (fieldNode.owner.equals(other.owner) && fieldNode.name.equals(other.name) && fieldNode.desc.equals(other.desc)) { if (fieldNode.getOpcode() == Opcodes.GETFIELD && other.getOpcode() == Opcodes.PUTFIELD) { this.booleanTestabilityTransformation.insertGetBefore(other, mn.instructions); } else if (fieldNode.getOpcode() == Opcodes.GETSTATIC && other.getOpcode() == Opcodes.PUTSTATIC) { this.booleanTestabilityTransformation.insertGetBefore(other, mn.instructions); } } } } return fieldNode; }
/** * <p> * getInfectionDistance * </p> * * @param original * a {@link org.objectweb.asm.tree.FieldInsnNode} object. * @param mutant * a {@link org.objectweb.asm.tree.InsnList} object. * @return a {@link org.objectweb.asm.tree.InsnList} object. */ public InsnList getInfectionDistance(FieldInsnNode original, InsnList mutant) { InsnList distance = new InsnList(); if (original.getOpcode() == Opcodes.GETFIELD) distance.add(new InsnNode(Opcodes.DUP)); //make sure to re-load this for GETFIELD distance.add(new FieldInsnNode(original.getOpcode(), original.owner, original.name, original.desc)); Type type = Type.getType(original.desc); if (type.getDescriptor().startsWith("L") || type.getDescriptor().startsWith("[")) { ReplaceVariable.addReferenceDistanceCheck(distance, type, mutant); } else { ReplaceVariable.addPrimitiveDistanceCheck(distance, type, mutant); } return distance; }
private static InsnList generateSetViewInstructions(final FieldInsnNode fieldInsn) { if ( fieldInsn.getOpcode() == GETFIELD ) throwAccessErrorOnReadOnlyField(fieldInsn.owner, fieldInsn.name); if ( fieldInsn.getOpcode() != PUTFIELD ) throw new InternalError(); final InsnList list = new InsnList(); // stack: index, this if ( MAPPED_SET2_JVM.equals(fieldInsn.owner) ) list.add(new MethodInsnNode(INVOKESTATIC, MAPPED_HELPER_JVM, "put_views", "(L" + MAPPED_SET2_JVM + ";I)V")); else if ( MAPPED_SET3_JVM.equals(fieldInsn.owner) ) list.add(new MethodInsnNode(INVOKESTATIC, MAPPED_HELPER_JVM, "put_views", "(L" + MAPPED_SET3_JVM + ";I)V")); else if ( MAPPED_SET4_JVM.equals(fieldInsn.owner) ) list.add(new MethodInsnNode(INVOKESTATIC, MAPPED_HELPER_JVM, "put_views", "(L" + MAPPED_SET4_JVM + ";I)V")); else throw new InternalError(); // stack: - return list; }
if (insn instanceof FieldInsnNode) { FieldInsnNode fieldInsn = (FieldInsnNode) insn; if (fieldInsn.getOpcode() != Opcodes.PUTSTATIC) { continue;
private void checkInstructionInternal(ClassContext context, ClassNode classNode, AbstractInsnNode instruction) { FieldInsnNode node = (FieldInsnNode) instruction; if (node.getOpcode() == Opcodes.PUTSTATIC && node.owner.equals(FQN_CORDOVA_DEVICE) && node.name.equals(FIELD_NAME_CORDOVA_VERSION)) { AbstractInsnNode prevInstruction = LintUtils.getPrevInstruction(node); if (prevInstruction == null || prevInstruction.getOpcode() != Opcodes.LDC) { return; } LdcInsnNode ldcInsnNode = (LdcInsnNode) prevInstruction; if (ldcInsnNode.cst instanceof String) { mCordovaVersion = createVersion((String) ldcInsnNode.cst); if (mCordovaVersion != null) { validateCordovaVersion(context, mCordovaVersion, context.getLocation(classNode)); } } } }
/** * Descend into a static field read * */ private static void handleFieldInsnNode(GetStaticGraph staticUsageTree, ClassNode cn, MethodNode mn, FieldInsnNode insn, int depth) { // Skip field instructions that are not reads to static fields if (insn.getOpcode() != Opcodes.GETSTATIC) { return; } // Only collect relations for instrumentable classes String calleeClassName = insn.owner.replaceAll("/", "."); if (BytecodeInstrumentation.checkIfCanInstrument(calleeClassName)) { logger.debug("Handling field read: " + insn.name); if (!staticUsageTree.hasStaticFieldRead(cn.name, mn.name + mn.desc, insn.owner, insn.name)) { handleClassInitializer(staticUsageTree, cn, mn, insn.owner, depth); // Add static read from mn to insn to static usage graph staticUsageTree.addStaticFieldRead(cn.name, mn.name + mn.desc, insn.owner, insn.name); handle(staticUsageTree, insn.owner, insn.name + insn.desc, depth); } } }
/** {@inheritDoc} */ @Override public List<Mutation> apply(MethodNode mn, String className, String methodName, BytecodeInstruction instruction, Frame frame) { List<Mutation> mutations = new LinkedList<Mutation>(); FieldInsnNode node = (FieldInsnNode) instruction.getASMNode(); Type fieldType = Type.getType(node.desc); // insert mutation into bytecode with conditional InsnList mutation = new InsnList(); logger.debug("Mutation deletefield for statement " + node.name + node.desc); if (node.getOpcode() == Opcodes.GETFIELD) { logger.debug("Deleting source of type " + node.owner); mutation.add(new InsnNode(Opcodes.POP)); } mutation.add(getDefault(fieldType)); // insert mutation into pool Mutation mutationObject = MutationPool.addMutation(className, methodName, NAME + " " + node.name + node.desc, instruction, mutation, getInfectionDistance(node, mutation)); mutations.add(mutationObject); return mutations; }
distance.add(new FieldInsnNode(node.getOpcode(), node.owner, node.name, node.desc)); if (type.getDescriptor().startsWith("L")
private static InsnList generateFieldInstructions(final FieldInsnNode fieldInsn, final FieldInfo field) { final InsnList list = new InsnList(); if ( fieldInsn.getOpcode() == PUTFIELD ) { // stack: value, ref list.add(getIntNode((int)field.offset)); // stack: fieldOffset, value, ref list.add(new MethodInsnNode(INVOKESTATIC, MAPPED_HELPER_JVM, field.getAccessType() + "put", "(L" + MAPPED_OBJECT_JVM + ";" + fieldInsn.desc + "I)V")); // stack - return list; } if ( fieldInsn.getOpcode() == GETFIELD ) { // stack: ref list.add(getIntNode((int)field.offset)); // stack: fieldOffset, ref list.add(new MethodInsnNode(INVOKESTATIC, MAPPED_HELPER_JVM, field.getAccessType() + "get", "(L" + MAPPED_OBJECT_JVM + ";I)" + fieldInsn.desc)); // stack: - return list; } throw new InternalError(); }
private static InsnList generateByteBufferInstructions(final FieldInsnNode fieldInsn, final MappedSubtypeInfo mappedSubtype, final long fieldOffset) { if ( fieldInsn.getOpcode() == PUTFIELD ) throwAccessErrorOnReadOnlyField(fieldInsn.owner, fieldInsn.name); if ( fieldInsn.getOpcode() == GETFIELD ) { final InsnList list = new InsnList(); // stack: ref list.add(new FieldInsnNode(GETFIELD, mappedSubtype.className, "viewAddress", "J")); // stack: long list.add(new LdcInsnNode(fieldOffset)); // stack: long, long list.add(new InsnNode(LADD)); // stack: long list.add(new LdcInsnNode(mappedSubtype.fields.get(fieldInsn.name).length)); // stack: long, long list.add(new InsnNode(L2I)); // stack: int, long list.add(new MethodInsnNode(INVOKESTATIC, MAPPED_HELPER_JVM, "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";")); // stack: buffer return list; } throw new InternalError(); }
} else if (node instanceof FieldInsnNode) { FieldInsnNode fn = (FieldInsnNode) node; copy.add(new FieldInsnNode(fn.getOpcode(), fn.owner, fn.name, fn.desc)); } else if (node instanceof InsnNode) { if (node.getOpcode() != Opcodes.POP)