Program: 186867
Project: 186867
Buggy source:
public ContextMap<CallString,Map<Location,ValueMapping>> transfer(InstructionHandle stmt,FlowEdge edge,ContextMap<CallString,Map<Location,ValueMapping>> input,Interpreter<CallString,Map<Location,ValueMapping>> interpreter,Map<InstructionHandle,ContextMap<CallString,Map<Location,ValueMapping>>> state){
  Context context=new Context(input.getContext());
  Map<Location,ValueMapping> in=(Map<Location,ValueMapping>)input.get(context.callString);
  ContextMap<CallString,Map<Location,ValueMapping>> retval=new ContextMap<CallString,Map<Location,ValueMapping>>(context,new HashMap<CallString,Map<Location,ValueMapping>>());
  Instruction instruction=stmt.getInstruction();
  if (in == null) {
    context.stackPtr+=instruction.produceStack(context.constPool) - instruction.consumeStack(context.constPool);
    return retval;
  }
  Map<Location,ValueMapping> result=new HashMap<Location,ValueMapping>();
  retval.put(context.callString,result);
switch (instruction.getOpcode()) {
case Constants.ICONST_M1:
case Constants.ICONST_0:
case Constants.ICONST_1:
case Constants.ICONST_2:
case Constants.ICONST_3:
case Constants.ICONST_4:
case Constants.ICONST_5:
case Constants.BIPUSH:
case Constants.SIPUSH:
{
      ConstantPushInstruction instr=(ConstantPushInstruction)instruction;
      result=new HashMap<Location,ValueMapping>(in);
      retval.put(context.callString,result);
      int value=instr.getValue().intValue();
      result.put(new Location(context.stackPtr),new ValueMapping(value));
    }
  break;
case Constants.ACONST_NULL:
result=in;
retval.put(context.callString,result);
break;
case Constants.LDC:
case Constants.LDC_W:
{
LDC instr=(LDC)instruction;
result=new HashMap<Location,ValueMapping>(in);
retval.put(context.callString,result);
Type type=instr.getType(context.constPool);
if (type.equals(Type.INT)) {
Integer value=(Integer)instr.getValue(context.constPool);
result.put(new Location(context.stackPtr),new ValueMapping(value));
}
 else if (type.equals(Type.STRING)) {
String value=(String)instr.getValue(context.constPool);
String name="String_Node_Str";
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
result.put(new Location(name + "String_Node_Str"),new ValueMapping(value.length()));
}
}
break;
case Constants.LDC2_W:
result=in;
retval.put(context.callString,result);
break;
case Constants.ISTORE_0:
case Constants.ISTORE_1:
case Constants.ISTORE_2:
case Constants.ISTORE_3:
case Constants.ISTORE:
{
StoreInstruction instr=(StoreInstruction)instruction;
int index=instr.getIndex();
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1 && l.stackLoc != index) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
ValueMapping v=new ValueMapping(in.get(l),true);
if (in.get(l).source == null || in.get(l).source.stackLoc != index) {
v.defscope=ValueMapping.scope;
}
result.put(new Location(index),v);
}
}
}
break;
case Constants.ASTORE_0:
case Constants.ASTORE_1:
case Constants.ASTORE_2:
case Constants.ASTORE_3:
case Constants.ASTORE:
result=in;
retval.put(context.callString,result);
break;
case Constants.LSTORE_0:
case Constants.LSTORE_1:
case Constants.LSTORE_2:
case Constants.LSTORE_3:
case Constants.LSTORE:
filterSet(in,result,context.stackPtr - 2);
break;
case Constants.ILOAD_0:
case Constants.ILOAD_1:
case Constants.ILOAD_2:
case Constants.ILOAD_3:
case Constants.ILOAD:
{
LoadInstruction instr=(LoadInstruction)instruction;
filterSet(in,result,context.stackPtr);
int index=instr.getIndex();
for (Location l : in.keySet()) {
if (l.stackLoc == index) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.source=l;
result.put(new Location(context.stackPtr),m);
}
}
}
break;
case Constants.ALOAD_0:
case Constants.ALOAD_1:
case Constants.ALOAD_2:
case Constants.ALOAD_3:
case Constants.ALOAD:
result=in;
retval.put(context.callString,result);
break;
case Constants.ARRAYLENGTH:
{
filterSet(in,result,context.stackPtr - 1);
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
Location location=new Location(context.stackPtr - 1);
boolean valid=false;
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
for (String arrayName : receivers) {
ValueMapping m=in.get(new Location(arrayName + "String_Node_Str"));
if (m != null) {
ValueMapping value=new ValueMapping(m,false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
if (!valid) {
result.put(new Location(context.stackPtr - 1),new ValueMapping());
}
}
break;
case Constants.PUTFIELD:
{
PUTFIELD instr=(PUTFIELD)instruction;
int fieldSize=instr.getFieldType(context.constPool).getSize();
for (Location l : in.keySet()) {
if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - 1 - fieldSize) {
result.put(l,in.get(l));
}
}
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
for (String fieldName : receivers) {
String f=fieldName.substring(fieldName.lastIndexOf("String_Node_Str"),fieldName.length());
String strippedName;
if (fieldName.indexOf("String_Node_Str") >= 0) {
strippedName=fieldName.split("String_Node_Str")[0] + f;
}
 else {
strippedName=fieldName;
}
if (p.containsField(strippedName)) {
for (Location l : in.keySet()) {
if (l.stackLoc < 0 && !receivers.contains(l.heapLoc)) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(fieldName),new ValueMapping(in.get(l),false));
}
}
}
}
}
}
break;
case Constants.GETFIELD:
{
GETFIELD instr=(GETFIELD)instruction;
filterSet(in,result,context.stackPtr - 1);
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
Location location=new Location(context.stackPtr - 1);
boolean valid=false;
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
for (Iterator<String> i=receivers.iterator(); i.hasNext(); ) {
String fieldName=i.next();
String f=fieldName.substring(fieldName.lastIndexOf("String_Node_Str"),fieldName.length());
String strippedName;
if (fieldName.indexOf("String_Node_Str") >= 0) {
strippedName=fieldName.split("String_Node_Str")[0] + f;
}
 else {
strippedName=fieldName;
}
if (p.containsField(strippedName)) {
for (Iterator<Location> k=in.keySet().iterator(); k.hasNext(); ) {
Location l=k.next();
if (l.heapLoc.equals(fieldName)) {
ValueMapping value=new ValueMapping(in.get(l),false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
}
}
if (!valid && !(instr.getFieldType(context.constPool) instanceof ReferenceType)) {
result.put(new Location(context.stackPtr - 1),new ValueMapping());
}
}
break;
case Constants.PUTSTATIC:
{
PUTSTATIC instr=(PUTSTATIC)instruction;
int fieldSize=instr.getFieldType(context.constPool).getSize();
for (Iterator<Location> i=in.keySet().iterator(); i.hasNext(); ) {
Location l=i.next();
if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - fieldSize) {
result.put(l,in.get(l));
}
}
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
for (Iterator<String> i=receivers.iterator(); i.hasNext(); ) {
String fieldName=i.next();
if (p.containsField(fieldName)) {
for (Iterator<Location> k=in.keySet().iterator(); k.hasNext(); ) {
Location l=k.next();
if (l.stackLoc < 0 && !receivers.contains(l.heapLoc)) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(fieldName),new ValueMapping(in.get(l),false));
}
}
}
}
}
break;
case Constants.GETSTATIC:
{
GETSTATIC instr=(GETSTATIC)instruction;
result=new HashMap<Location,ValueMapping>(in);
retval.put(context.callString,result);
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
Location location=new Location(context.stackPtr);
boolean valid=false;
for (String fieldName : receivers) {
if (p.containsField(fieldName)) {
for (Location l : in.keySet()) {
if (l.heapLoc.equals(fieldName)) {
ValueMapping value=new ValueMapping(in.get(l),false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
}
if (!valid && !(instr.getFieldType(context.constPool) instanceof ReferenceType)) {
result.put(new Location(context.stackPtr),new ValueMapping());
}
}
break;
case Constants.IASTORE:
case Constants.CASTORE:
case Constants.SASTORE:
case Constants.BASTORE:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 3) {
result.put(l,in.get(l));
}
}
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
break;
}
for (String name : receivers) {
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
Location loc=new Location(name);
ValueMapping val=new ValueMapping(in.get(l),false);
val.join(in.get(loc));
result.put(loc,val);
}
}
}
}
break;
case Constants.AASTORE:
{
filterSet(in,result,context.stackPtr - 3);
}
break;
case Constants.IALOAD:
case Constants.CALOAD:
case Constants.SALOAD:
case Constants.BALOAD:
{
filterSet(in,result,context.stackPtr - 2);
DFATool p=interpreter.getProgram();
Location location=new Location(context.stackPtr - 2);
boolean valid=false;
Set<String> receivers=p.getReceivers(stmt,context.callString);
for (String name : receivers) {
for (Location l : in.keySet()) {
if (l.heapLoc.equals(name)) {
ValueMapping value=new ValueMapping(in.get(l),false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
if (!valid) {
result.put(new Location(context.stackPtr - 2),new ValueMapping(0));
}
}
break;
case Constants.AALOAD:
{
ValueMapping v=in.get(new Location(context.stackPtr - 1));
if (v == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
recordArrayIndex(stmt,context,v.assigned);
}
filterSet(in,result,context.stackPtr - 2);
}
break;
case Constants.DUP:
{
for (Location l : in.keySet()) {
result.put(l,in.get(l));
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(context.stackPtr),new ValueMapping(in.get(l),true));
}
}
}
break;
case Constants.DUP_X1:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(context.stackPtr - 2),new ValueMapping(in.get(l),true));
result.put(new Location(context.stackPtr),new ValueMapping(in.get(l),true));
}
if (l.stackLoc == context.stackPtr - 2) {
result.put(new Location(context.stackPtr - 1),new ValueMapping(in.get(l),true));
}
}
}
break;
case Constants.DUP2:
{
for (Location l : in.keySet()) {
result.put(l,in.get(l));
if (l.stackLoc == context.stackPtr - 2) {
result.put(new Location(context.stackPtr),new ValueMapping(in.get(l),true));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(context.stackPtr + 1),new ValueMapping(in.get(l),true));
}
}
}
break;
case Constants.POP:
{
filterSet(in,result,context.stackPtr - 1);
}
break;
case Constants.POP2:
{
filterSet(in,result,context.stackPtr - 2);
}
break;
case Constants.IINC:
{
IINC instr=(IINC)instruction;
int index=instr.getIndex();
int increment=instr.getIncrement();
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr) {
result.put(l,in.get(l));
}
if (l.stackLoc == index) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.add(increment);
m.constrained.add(increment);
Interval operand=new Interval(increment,increment);
if (m.increment != null && !m.softinc) {
m.increment.join(operand);
}
 else if (m.increment != null && m.softinc) {
if ((m.increment.getLb() < 0 && operand.getUb() > 0) || (m.increment.getUb() > 0 && operand.getLb() < 0)) {
m.increment.join(operand);
}
 else {
m.increment=operand;
}
m.softinc=false;
}
 else {
m.increment=operand;
m.softinc=false;
}
result.put(l,m);
}
}
}
break;
case Constants.IADD:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.add(operand);
m.constrained.add(operand);
if (m.increment != null && !m.softinc) {
m.increment.join(operand);
}
 else if (m.increment != null && m.softinc) {
if ((m.increment.getLb() < 0 && operand.getUb() > 0) || (m.increment.getUb() > 0 && operand.getLb() < 0)) {
m.increment.join(operand);
}
 else {
m.increment=operand;
}
m.softinc=false;
}
 else {
m.increment=operand;
m.softinc=false;
}
result.put(l,m);
}
}
}
break;
case Constants.ISUB:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.sub(operand);
m.constrained.sub(operand);
operand.neg();
if (m.increment != null && !m.softinc) {
m.increment.join(operand);
}
 else if (m.increment != null && m.softinc) {
if ((m.increment.getLb() < 0 && operand.getUb() > 0) || (m.increment.getUb() > 0 && operand.getLb() < 0)) {
m.increment.join(operand);
}
 else {
m.increment=operand;
}
m.softinc=false;
}
 else {
m.increment=operand;
m.softinc=false;
}
result.put(l,m);
}
}
}
break;
case Constants.INEG:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 1) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.neg();
m.constrained.neg();
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IUSHR:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.ushr(operand);
m.constrained.ushr(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.ISHR:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.shr(operand);
m.constrained.shr(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IMUL:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.mul(operand);
m.constrained.mul(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IDIV:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.div(operand);
m.constrained.div(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IAND:
case Constants.IOR:
case Constants.IXOR:
case Constants.IREM:
case Constants.ISHL:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping();
result.put(l,m);
}
}
}
break;
case Constants.I2B:
case Constants.I2C:
case Constants.I2S:
result=in;
retval.put(context.callString,result);
break;
case Constants.MONITORENTER:
result=in;
retval.put(context.callString,result);
context.syncLevel++;
break;
case Constants.MONITOREXIT:
result=in;
retval.put(context.callString,result);
context.syncLevel--;
if (context.syncLevel < 0) {
System.err.println("String_Node_Str");
System.exit(-1);
}
break;
case Constants.CHECKCAST:
result=in;
retval.put(context.callString,result);
break;
case Constants.INSTANCEOF:
{
filterSet(in,result,context.stackPtr - 1);
ValueMapping bool=new ValueMapping();
bool.assigned.setLb(0);
bool.assigned.setUb(1);
result.put(new Location(context.stackPtr - 1),bool);
}
break;
case Constants.NEW:
{
result=in;
retval.put(context.callString,result);
}
break;
case Constants.NEWARRAY:
{
NEWARRAY instr=(NEWARRAY)instruction;
String name=instr.getType().toString();
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
filterSet(in,result,context.stackPtr - 1);
boolean valid=false;
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(name + "String_Node_Str"),in.get(l));
recordSize(stmt,context,in.get(l).assigned);
valid=true;
}
}
if (!valid) {
ValueMapping v=new ValueMapping();
result.put(new Location(name + "String_Node_Str"),v);
recordSize(stmt,context,v.assigned);
}
}
break;
case Constants.ANEWARRAY:
{
ANEWARRAY instr=(ANEWARRAY)instruction;
String name=instr.getType(context.constPool).toString() + "String_Node_Str";
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
filterSet(in,result,context.stackPtr - 1);
boolean valid=false;
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(name + "String_Node_Str"),in.get(l));
recordSize(stmt,context,in.get(l).assigned);
valid=true;
}
}
if (!valid) {
ValueMapping v=new ValueMapping();
result.put(new Location(name + "String_Node_Str"),v);
recordSize(stmt,context,v.assigned);
}
}
break;
case Constants.MULTIANEWARRAY:
{
MULTIANEWARRAY instr=(MULTIANEWARRAY)instruction;
int dim=instr.getDimensions();
filterSet(in,result,context.stackPtr - dim);
String type=instr.getType(context.constPool).toString();
type=type.substring(0,type.indexOf("String_Node_Str"));
Interval[] size=new Interval[dim];
for (int i=1; i <= dim; i++) {
String name=type;
for (int k=0; k < i; k++) {
name+="String_Node_Str";
}
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
boolean valid=false;
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - i) {
result.put(new Location(name + "String_Node_Str"),in.get(l));
if (size[i - 1] != null) {
size[i - 1].join(in.get(l).assigned);
}
 else {
size[i - 1]=in.get(l).assigned;
}
valid=true;
}
}
if (!valid) {
ValueMapping v=new ValueMapping();
result.put(new Location(name + "String_Node_Str"),v);
size[i - 1]=v.assigned;
}
}
recordSize(stmt,context,size);
}
break;
case Constants.GOTO:
result=in;
retval.put(context.callString,result);
break;
case Constants.IFNULL:
case Constants.IFNONNULL:
{
checkScope(context,stmt);
filterSet(in,result,context.stackPtr - 1);
}
break;
case Constants.IF_ACMPEQ:
case Constants.IF_ACMPNE:
{
checkScope(context,stmt);
filterSet(in,result,context.stackPtr - 2);
}
break;
case Constants.IFEQ:
case Constants.IFNE:
case Constants.IFLT:
case Constants.IFGE:
case Constants.IFLE:
case Constants.IFGT:
checkScope(context,stmt);
result=doIf(stmt,edge,context,in,result);
retval.put(context.callString,result);
break;
case Constants.IF_ICMPEQ:
case Constants.IF_ICMPNE:
case Constants.IF_ICMPLT:
case Constants.IF_ICMPGE:
case Constants.IF_ICMPGT:
case Constants.IF_ICMPLE:
checkScope(context,stmt);
result=doIfIcmp(stmt,edge,context,in,result);
retval.put(context.callString,result);
break;
case Constants.LOOKUPSWITCH:
case Constants.TABLESWITCH:
result=in;
retval.put(context.callString,result);
break;
case Constants.INVOKEVIRTUAL:
case Constants.INVOKEINTERFACE:
case Constants.INVOKESTATIC:
case Constants.INVOKESPECIAL:
{
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
if (receivers == null) {
System.out.println(context.method + "String_Node_Str" + instruction.toString(context.constPool.getConstantPool())+ "String_Node_Str"+ stmt.toString(true)+ "String_Node_Str"+ "String_Node_Str");
result=in;
break;
}
for (String methodName : receivers) {
doInvoke(methodName,stmt,context,input,interpreter,state,retval);
}
}
break;
case Constants.ARETURN:
case Constants.RETURN:
{
filterSet(in,result,0);
}
break;
case Constants.IRETURN:
{
filterSet(in,result,0);
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(0),new ValueMapping(in.get(l),false));
}
}
}
break;
default :
result=in;
retval.put(context.callString,result);
break;
}
context.stackPtr+=instruction.produceStack(context.constPool) - instruction.consumeStack(context.constPool);
return retval;
}

Fixed version (ground truth):
public ContextMap<CallString,Map<Location,ValueMapping>> transfer(InstructionHandle stmt,FlowEdge edge,ContextMap<CallString,Map<Location,ValueMapping>> input,Interpreter<CallString,Map<Location,ValueMapping>> interpreter,Map<InstructionHandle,ContextMap<CallString,Map<Location,ValueMapping>>> state){
  Context context=new Context(input.getContext());
  Map<Location,ValueMapping> in=(Map<Location,ValueMapping>)input.get(context.callString);
  ContextMap<CallString,Map<Location,ValueMapping>> retval=new ContextMap<CallString,Map<Location,ValueMapping>>(context,new HashMap<CallString,Map<Location,ValueMapping>>());
  Instruction instruction=stmt.getInstruction();
  if (in == null) {
    context.stackPtr+=instruction.produceStack(context.constPool) - instruction.consumeStack(context.constPool);
    return retval;
  }
  Map<Location,ValueMapping> result=new HashMap<Location,ValueMapping>();
  retval.put(context.callString,result);
switch (instruction.getOpcode()) {
case Constants.ICONST_M1:
case Constants.ICONST_0:
case Constants.ICONST_1:
case Constants.ICONST_2:
case Constants.ICONST_3:
case Constants.ICONST_4:
case Constants.ICONST_5:
case Constants.BIPUSH:
case Constants.SIPUSH:
{
      ConstantPushInstruction instr=(ConstantPushInstruction)instruction;
      result=new HashMap<Location,ValueMapping>(in);
      retval.put(context.callString,result);
      int value=instr.getValue().intValue();
      result.put(new Location(context.stackPtr),new ValueMapping(value));
    }
  break;
case Constants.ACONST_NULL:
result=in;
retval.put(context.callString,result);
break;
case Constants.LDC:
case Constants.LDC_W:
{
LDC instr=(LDC)instruction;
result=new HashMap<Location,ValueMapping>(in);
retval.put(context.callString,result);
Type type=instr.getType(context.constPool);
if (type.equals(Type.INT)) {
Integer value=(Integer)instr.getValue(context.constPool);
result.put(new Location(context.stackPtr),new ValueMapping(value));
}
 else if (type.equals(Type.STRING)) {
String value=(String)instr.getValue(context.constPool);
String name="String_Node_Str";
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
result.put(new Location(name + "String_Node_Str"),new ValueMapping(value.length()));
}
}
break;
case Constants.LDC2_W:
result=in;
retval.put(context.callString,result);
break;
case Constants.ISTORE_0:
case Constants.ISTORE_1:
case Constants.ISTORE_2:
case Constants.ISTORE_3:
case Constants.ISTORE:
{
StoreInstruction instr=(StoreInstruction)instruction;
int index=instr.getIndex();
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1 && l.stackLoc != index) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
ValueMapping v=new ValueMapping(in.get(l),true);
if (in.get(l).source == null || in.get(l).source.stackLoc != index) {
v.defscope=ValueMapping.scope;
}
result.put(new Location(index),v);
}
}
}
break;
case Constants.ASTORE_0:
case Constants.ASTORE_1:
case Constants.ASTORE_2:
case Constants.ASTORE_3:
case Constants.ASTORE:
result=in;
retval.put(context.callString,result);
break;
case Constants.LSTORE_0:
case Constants.LSTORE_1:
case Constants.LSTORE_2:
case Constants.LSTORE_3:
case Constants.LSTORE:
filterSet(in,result,context.stackPtr - 2);
break;
case Constants.ILOAD_0:
case Constants.ILOAD_1:
case Constants.ILOAD_2:
case Constants.ILOAD_3:
case Constants.ILOAD:
{
LoadInstruction instr=(LoadInstruction)instruction;
filterSet(in,result,context.stackPtr);
int index=instr.getIndex();
for (Location l : in.keySet()) {
if (l.stackLoc == index) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.source=l;
result.put(new Location(context.stackPtr),m);
}
}
}
break;
case Constants.ALOAD_0:
case Constants.ALOAD_1:
case Constants.ALOAD_2:
case Constants.ALOAD_3:
case Constants.ALOAD:
result=in;
retval.put(context.callString,result);
break;
case Constants.ARRAYLENGTH:
{
filterSet(in,result,context.stackPtr - 1);
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
Location location=new Location(context.stackPtr - 1);
boolean valid=false;
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
for (String arrayName : receivers) {
ValueMapping m=in.get(new Location(arrayName + "String_Node_Str"));
if (m != null) {
ValueMapping value=new ValueMapping(m,false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
if (!valid) {
result.put(new Location(context.stackPtr - 1),new ValueMapping());
}
}
break;
case Constants.PUTFIELD:
{
PUTFIELD instr=(PUTFIELD)instruction;
int fieldSize=instr.getFieldType(context.constPool).getSize();
for (Location l : in.keySet()) {
if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - 1 - fieldSize) {
result.put(l,in.get(l));
}
}
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
for (String fieldName : receivers) {
String f=fieldName.substring(fieldName.lastIndexOf("String_Node_Str"),fieldName.length());
String strippedName;
if (fieldName.indexOf("String_Node_Str") >= 0) {
strippedName=fieldName.split("String_Node_Str")[0] + f;
}
 else {
strippedName=fieldName;
}
if (p.containsField(strippedName)) {
for (Location l : in.keySet()) {
if (l.stackLoc < 0 && !receivers.contains(l.heapLoc)) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(fieldName),new ValueMapping(in.get(l),false));
}
}
}
}
}
}
break;
case Constants.GETFIELD:
{
GETFIELD instr=(GETFIELD)instruction;
filterSet(in,result,context.stackPtr - 1);
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
Location location=new Location(context.stackPtr - 1);
boolean valid=false;
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
for (String fieldName : receivers) {
String f=fieldName.substring(fieldName.lastIndexOf("String_Node_Str"),fieldName.length());
String strippedName;
if (fieldName.indexOf("String_Node_Str") >= 0) {
strippedName=fieldName.split("String_Node_Str")[0] + f;
}
 else {
strippedName=fieldName;
}
if (p.containsField(strippedName)) {
for (Location l : in.keySet()) {
if (l.heapLoc.equals(fieldName)) {
ValueMapping value=new ValueMapping(in.get(l),false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
}
}
if (!valid && !(instr.getFieldType(context.constPool) instanceof ReferenceType)) {
result.put(new Location(context.stackPtr - 1),new ValueMapping());
}
}
break;
case Constants.PUTSTATIC:
{
PUTSTATIC instr=(PUTSTATIC)instruction;
int fieldSize=instr.getFieldType(context.constPool).getSize();
for (Location l : in.keySet()) {
if (l.stackLoc >= 0 && l.stackLoc < context.stackPtr - fieldSize) {
result.put(l,in.get(l));
}
}
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
for (String fieldName : receivers) {
if (p.containsField(fieldName)) {
for (Location l : in.keySet()) {
if (l.stackLoc < 0 && !receivers.contains(l.heapLoc)) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(fieldName),new ValueMapping(in.get(l),false));
}
}
}
}
}
break;
case Constants.GETSTATIC:
{
GETSTATIC instr=(GETSTATIC)instruction;
result=new HashMap<Location,ValueMapping>(in);
retval.put(context.callString,result);
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
Location location=new Location(context.stackPtr);
boolean valid=false;
for (String fieldName : receivers) {
if (p.containsField(fieldName)) {
for (Location l : in.keySet()) {
if (l.heapLoc.equals(fieldName)) {
ValueMapping value=new ValueMapping(in.get(l),false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
}
if (!valid && !(instr.getFieldType(context.constPool) instanceof ReferenceType)) {
result.put(new Location(context.stackPtr),new ValueMapping());
}
}
break;
case Constants.IASTORE:
case Constants.CASTORE:
case Constants.SASTORE:
case Constants.BASTORE:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 3) {
result.put(l,in.get(l));
}
}
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
if (receivers == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
break;
}
for (String name : receivers) {
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
Location loc=new Location(name);
ValueMapping val=new ValueMapping(in.get(l),false);
val.join(in.get(loc));
result.put(loc,val);
}
}
}
}
break;
case Constants.AASTORE:
{
filterSet(in,result,context.stackPtr - 3);
}
break;
case Constants.IALOAD:
case Constants.CALOAD:
case Constants.SALOAD:
case Constants.BALOAD:
{
filterSet(in,result,context.stackPtr - 2);
DFATool p=interpreter.getProgram();
Location location=new Location(context.stackPtr - 2);
boolean valid=false;
Set<String> receivers=p.getReceivers(stmt,context.callString);
for (String name : receivers) {
for (Location l : in.keySet()) {
if (l.heapLoc.equals(name)) {
ValueMapping value=new ValueMapping(in.get(l),false);
value.join(result.get(location));
result.put(location,value);
valid=true;
}
}
}
if (!valid) {
result.put(new Location(context.stackPtr - 2),new ValueMapping(0));
}
}
break;
case Constants.AALOAD:
{
ValueMapping v=in.get(new Location(context.stackPtr - 1));
if (v == null) {
System.out.println("String_Node_Str" + context.callString.toStringList() + context.method+ stmt);
}
 else {
recordArrayIndex(stmt,context,v.assigned);
}
filterSet(in,result,context.stackPtr - 2);
}
break;
case Constants.DUP:
{
for (Location l : in.keySet()) {
result.put(l,in.get(l));
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(context.stackPtr),new ValueMapping(in.get(l),true));
}
}
}
break;
case Constants.DUP_X1:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(context.stackPtr - 2),new ValueMapping(in.get(l),true));
result.put(new Location(context.stackPtr),new ValueMapping(in.get(l),true));
}
if (l.stackLoc == context.stackPtr - 2) {
result.put(new Location(context.stackPtr - 1),new ValueMapping(in.get(l),true));
}
}
}
break;
case Constants.DUP2:
{
for (Location l : in.keySet()) {
result.put(l,in.get(l));
if (l.stackLoc == context.stackPtr - 2) {
result.put(new Location(context.stackPtr),new ValueMapping(in.get(l),true));
}
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(context.stackPtr + 1),new ValueMapping(in.get(l),true));
}
}
}
break;
case Constants.POP:
{
filterSet(in,result,context.stackPtr - 1);
}
break;
case Constants.POP2:
{
filterSet(in,result,context.stackPtr - 2);
}
break;
case Constants.IINC:
{
IINC instr=(IINC)instruction;
int index=instr.getIndex();
int increment=instr.getIncrement();
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr) {
result.put(l,in.get(l));
}
if (l.stackLoc == index) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.add(increment);
m.constrained.add(increment);
Interval operand=new Interval(increment,increment);
if (m.increment != null && !m.softinc) {
m.increment.join(operand);
}
 else if (m.increment != null && m.softinc) {
if ((m.increment.getLb() < 0 && operand.getUb() > 0) || (m.increment.getUb() > 0 && operand.getLb() < 0)) {
m.increment.join(operand);
}
 else {
m.increment=operand;
}
m.softinc=false;
}
 else {
m.increment=operand;
m.softinc=false;
}
result.put(l,m);
}
}
}
break;
case Constants.IADD:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.add(operand);
m.constrained.add(operand);
if (m.increment != null && !m.softinc) {
m.increment.join(operand);
}
 else if (m.increment != null && m.softinc) {
if ((m.increment.getLb() < 0 && operand.getUb() > 0) || (m.increment.getUb() > 0 && operand.getLb() < 0)) {
m.increment.join(operand);
}
 else {
m.increment=operand;
}
m.softinc=false;
}
 else {
m.increment=operand;
m.softinc=false;
}
result.put(l,m);
}
}
}
break;
case Constants.ISUB:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.sub(operand);
m.constrained.sub(operand);
operand.neg();
if (m.increment != null && !m.softinc) {
m.increment.join(operand);
}
 else if (m.increment != null && m.softinc) {
if ((m.increment.getLb() < 0 && operand.getUb() > 0) || (m.increment.getUb() > 0 && operand.getLb() < 0)) {
m.increment.join(operand);
}
 else {
m.increment=operand;
}
m.softinc=false;
}
 else {
m.increment=operand;
m.softinc=false;
}
result.put(l,m);
}
}
}
break;
case Constants.INEG:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 1) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 1) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.neg();
m.constrained.neg();
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IUSHR:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.ushr(operand);
m.constrained.ushr(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.ISHR:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.shr(operand);
m.constrained.shr(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IMUL:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.mul(operand);
m.constrained.mul(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IDIV:
{
Interval operand=new Interval();
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
operand=in.get(l).assigned;
}
}
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping(in.get(l),true);
m.assigned.div(operand);
m.constrained.div(operand);
m.increment=new Interval();
result.put(l,m);
}
}
}
break;
case Constants.IAND:
case Constants.IOR:
case Constants.IXOR:
case Constants.IREM:
case Constants.ISHL:
{
for (Location l : in.keySet()) {
if (l.stackLoc < context.stackPtr - 2) {
result.put(l,in.get(l));
}
 else if (l.stackLoc == context.stackPtr - 2) {
ValueMapping m=new ValueMapping();
result.put(l,m);
}
}
}
break;
case Constants.I2B:
case Constants.I2C:
case Constants.I2S:
result=in;
retval.put(context.callString,result);
break;
case Constants.MONITORENTER:
result=in;
retval.put(context.callString,result);
context.syncLevel++;
break;
case Constants.MONITOREXIT:
result=in;
retval.put(context.callString,result);
context.syncLevel--;
if (context.syncLevel < 0) {
System.err.println("String_Node_Str");
System.exit(-1);
}
break;
case Constants.CHECKCAST:
result=in;
retval.put(context.callString,result);
break;
case Constants.INSTANCEOF:
{
filterSet(in,result,context.stackPtr - 1);
ValueMapping bool=new ValueMapping();
bool.assigned.setLb(0);
bool.assigned.setUb(1);
result.put(new Location(context.stackPtr - 1),bool);
}
break;
case Constants.NEW:
{
result=in;
retval.put(context.callString,result);
}
break;
case Constants.NEWARRAY:
{
NEWARRAY instr=(NEWARRAY)instruction;
String name=instr.getType().toString();
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
filterSet(in,result,context.stackPtr - 1);
boolean valid=false;
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(name + "String_Node_Str"),in.get(l));
recordSize(stmt,context,in.get(l).assigned);
valid=true;
}
}
if (!valid) {
ValueMapping v=new ValueMapping();
result.put(new Location(name + "String_Node_Str"),v);
recordSize(stmt,context,v.assigned);
}
}
break;
case Constants.ANEWARRAY:
{
ANEWARRAY instr=(ANEWARRAY)instruction;
String name=instr.getType(context.constPool).toString() + "String_Node_Str";
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
filterSet(in,result,context.stackPtr - 1);
boolean valid=false;
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(name + "String_Node_Str"),in.get(l));
recordSize(stmt,context,in.get(l).assigned);
valid=true;
}
}
if (!valid) {
ValueMapping v=new ValueMapping();
result.put(new Location(name + "String_Node_Str"),v);
recordSize(stmt,context,v.assigned);
}
}
break;
case Constants.MULTIANEWARRAY:
{
MULTIANEWARRAY instr=(MULTIANEWARRAY)instruction;
int dim=instr.getDimensions();
filterSet(in,result,context.stackPtr - dim);
String type=instr.getType(context.constPool).toString();
type=type.substring(0,type.indexOf("String_Node_Str"));
Interval[] size=new Interval[dim];
for (int i=1; i <= dim; i++) {
String name=type;
for (int k=0; k < i; k++) {
name+="String_Node_Str";
}
name+="String_Node_Str" + context.method + "String_Node_Str"+ stmt.getPosition();
boolean valid=false;
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - i) {
result.put(new Location(name + "String_Node_Str"),in.get(l));
if (size[i - 1] != null) {
size[i - 1].join(in.get(l).assigned);
}
 else {
size[i - 1]=in.get(l).assigned;
}
valid=true;
}
}
if (!valid) {
ValueMapping v=new ValueMapping();
result.put(new Location(name + "String_Node_Str"),v);
size[i - 1]=v.assigned;
}
}
recordSize(stmt,context,size);
}
break;
case Constants.GOTO:
result=in;
retval.put(context.callString,result);
break;
case Constants.IFNULL:
case Constants.IFNONNULL:
{
checkScope(context,stmt);
filterSet(in,result,context.stackPtr - 1);
}
break;
case Constants.IF_ACMPEQ:
case Constants.IF_ACMPNE:
{
checkScope(context,stmt);
filterSet(in,result,context.stackPtr - 2);
}
break;
case Constants.IFEQ:
case Constants.IFNE:
case Constants.IFLT:
case Constants.IFGE:
case Constants.IFLE:
case Constants.IFGT:
checkScope(context,stmt);
result=doIf(stmt,edge,context,in,result);
retval.put(context.callString,result);
break;
case Constants.IF_ICMPEQ:
case Constants.IF_ICMPNE:
case Constants.IF_ICMPLT:
case Constants.IF_ICMPGE:
case Constants.IF_ICMPGT:
case Constants.IF_ICMPLE:
checkScope(context,stmt);
result=doIfIcmp(stmt,edge,context,in,result);
retval.put(context.callString,result);
break;
case Constants.LOOKUPSWITCH:
case Constants.TABLESWITCH:
result=in;
retval.put(context.callString,result);
break;
case Constants.INVOKEVIRTUAL:
case Constants.INVOKEINTERFACE:
case Constants.INVOKESTATIC:
case Constants.INVOKESPECIAL:
{
DFATool p=interpreter.getProgram();
Set<String> receivers=p.getReceivers(stmt,context.callString);
if (receivers == null) {
System.out.println(context.method + "String_Node_Str" + instruction.toString(context.constPool.getConstantPool())+ "String_Node_Str"+ stmt.toString(true)+ "String_Node_Str"+ "String_Node_Str");
result=in;
break;
}
for (String methodName : receivers) {
doInvoke(methodName,stmt,context,input,interpreter,state,retval);
}
}
break;
case Constants.ARETURN:
case Constants.RETURN:
{
filterSet(in,result,0);
}
break;
case Constants.IRETURN:
{
filterSet(in,result,0);
for (Location l : in.keySet()) {
if (l.stackLoc == context.stackPtr - 1) {
result.put(new Location(0),new ValueMapping(in.get(l),false));
}
}
}
break;
default :
result=in;
retval.put(context.callString,result);
break;
}
context.stackPtr+=instruction.produceStack(context.constPool) - instruction.consumeStack(context.constPool);
return retval;
}