use of org.objectweb.asm.tree.FieldInsnNode in project bytecode-viewer by Konloch.
the class BasicVerifier method binaryOperation.
@Override
public BasicValue binaryOperation(final AbstractInsnNode insn, final BasicValue value1, final BasicValue value2) throws AnalyzerException {
BasicValue expected1;
BasicValue expected2;
switch(insn.opcode()) {
case IALOAD:
expected1 = newValue(Type.getType("[I"));
expected2 = BasicValue.INT_VALUE;
break;
case BALOAD:
if (isSubTypeOf(value1, newValue(Type.getType("[Z")))) {
expected1 = newValue(Type.getType("[Z"));
} else {
expected1 = newValue(Type.getType("[B"));
}
expected2 = BasicValue.INT_VALUE;
break;
case CALOAD:
expected1 = newValue(Type.getType("[C"));
expected2 = BasicValue.INT_VALUE;
break;
case SALOAD:
expected1 = newValue(Type.getType("[S"));
expected2 = BasicValue.INT_VALUE;
break;
case LALOAD:
expected1 = newValue(Type.getType("[J"));
expected2 = BasicValue.INT_VALUE;
break;
case FALOAD:
expected1 = newValue(Type.getType("[F"));
expected2 = BasicValue.INT_VALUE;
break;
case DALOAD:
expected1 = newValue(Type.getType("[D"));
expected2 = BasicValue.INT_VALUE;
break;
case AALOAD:
expected1 = newValue(Type.getType("[Ljava/lang/Object;"));
expected2 = BasicValue.INT_VALUE;
break;
case IADD:
case ISUB:
case IMUL:
case IDIV:
case IREM:
case ISHL:
case ISHR:
case IUSHR:
case IAND:
case IOR:
case IXOR:
case IF_ICMPEQ:
case IF_ICMPNE:
case IF_ICMPLT:
case IF_ICMPGE:
case IF_ICMPGT:
case IF_ICMPLE:
expected1 = BasicValue.INT_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case FADD:
case FSUB:
case FMUL:
case FDIV:
case FREM:
case FCMPL:
case FCMPG:
expected1 = BasicValue.FLOAT_VALUE;
expected2 = BasicValue.FLOAT_VALUE;
break;
case LADD:
case LSUB:
case LMUL:
case LDIV:
case LREM:
case LAND:
case LOR:
case LXOR:
case LCMP:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.LONG_VALUE;
break;
case LSHL:
case LSHR:
case LUSHR:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case DADD:
case DSUB:
case DMUL:
case DDIV:
case DREM:
case DCMPL:
case DCMPG:
expected1 = BasicValue.DOUBLE_VALUE;
expected2 = BasicValue.DOUBLE_VALUE;
break;
case IF_ACMPEQ:
case IF_ACMPNE:
expected1 = BasicValue.REFERENCE_VALUE;
expected2 = BasicValue.REFERENCE_VALUE;
break;
case PUTFIELD:
FieldInsnNode fin = (FieldInsnNode) insn;
expected1 = newValue(Type.getObjectType(fin.owner));
expected2 = newValue(Type.getType(fin.desc));
break;
default:
throw new Error("Internal error.");
}
if (!isSubTypeOf(value1, expected1)) {
throw new AnalyzerException(insn, "First argument", expected1, value1);
} else if (!isSubTypeOf(value2, expected2)) {
throw new AnalyzerException(insn, "Second argument", expected2, value2);
}
if (insn.opcode() == AALOAD) {
return getElementValue(value1);
} else {
return super.binaryOperation(insn, value1, value2);
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class BooleanTestabilityTransformation method isBooleanAssignment.
/**
* This helper function determines whether the boolean on the stack at the
* current position will be stored in a Boolean variable
*
* @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;
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class DeleteField method apply.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.mutation.MutationOperator#apply(org.objectweb.asm.tree.MethodNode, java.lang.String, java.lang.String, org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@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;
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class InsertUnaryOperator method isApplicable.
/* (non-Javadoc)
* @see org.evosuite.cfg.instrumentation.mutation.MutationOperator#isApplicable(org.evosuite.cfg.BytecodeInstruction)
*/
/**
* {@inheritDoc}
*/
@Override
public boolean isApplicable(BytecodeInstruction instruction) {
AbstractInsnNode node = instruction.getASMNode();
switch(node.getOpcode()) {
case Opcodes.ILOAD:
case Opcodes.LLOAD:
case Opcodes.FLOAD:
case Opcodes.DLOAD:
return true;
case Opcodes.GETFIELD:
case Opcodes.GETSTATIC:
FieldInsnNode fieldNode = (FieldInsnNode) instruction.getASMNode();
Type type = Type.getType(fieldNode.desc);
if (type == Type.BYTE_TYPE || type == Type.SHORT_TYPE || type == Type.LONG_TYPE || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE || type == Type.BOOLEAN_TYPE || type == Type.INT_TYPE) {
return true;
}
default:
return false;
}
}
use of org.objectweb.asm.tree.FieldInsnNode in project evosuite by EvoSuite.
the class PutStaticMethodCollector method collectMethods.
@SuppressWarnings("unchecked")
public Set<MethodIdentifier> collectMethods() {
Set<MethodIdentifier> methods = new LinkedHashSet<MethodIdentifier>();
for (String calledClassName : getStaticFields.keySet()) {
ClassNode classNode = DependencyAnalysis.getClassNode(calledClassName);
List<MethodNode> classMethods = classNode.methods;
for (MethodNode mn : classMethods) {
if (mn.name.equals(CLINIT))
continue;
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> it = instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode insn = it.next();
if (insn instanceof FieldInsnNode) {
FieldInsnNode fieldInsn = (FieldInsnNode) insn;
if (fieldInsn.getOpcode() != Opcodes.PUTSTATIC) {
continue;
}
String calleeClassName = fieldInsn.owner.replaceAll("/", ".");
String calleeFieldName = fieldInsn.name;
if (contains(getStaticFields, calleeClassName, calleeFieldName)) {
MethodIdentifier methodIdentifier = new MethodIdentifier(calledClassName, mn.name, mn.desc);
methods.add(methodIdentifier);
}
}
}
}
}
return methods;
}
Aggregations