Program: 6213
Project: 6213
Buggy source:
/** 
 * Analyze the number of references used in each scope. For the general technique, see   {@link com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis#analyzeBlockUsage()}<h2>Bytecodes using object references</h2> <ul> <li/> getfield (top of stack) <li/> putfield (second on stack) <li/> arraylen (top of stack) <li/> a*load (second on stack) <li/> a*store (third on stack) </ul> <h2>Reference Analysis</h2> For each scope, we do the following: <ol> <li/> Perform a local, symbolic points-to analysis <li/> Traverse all instructions, and collect for each reference the basic blocks it might be used in. Additionally, the cost of each basic block is set to the number of TOP references accessed. <li/> For each reference, add a decision variable denoting whether it is used at all, and add corresponding constraints. </ol>
 */
public void analyzeRefUsage(){
  usedReferences=new HashMap<CallGraphNode,Long>();
  CallString emptyCallString=new CallString();
  TopologicalOrderIterator<CallGraphNode,DefaultEdge> iter=project.getCallGraph().topDownIterator();
  while (iter.hasNext()) {
    try {
      CallGraphNode scope=iter.next();
      System.out.println("String_Node_Str" + scope.getMethodImpl().getFQMethodName());
      DFAAppInfo dfa=project.getDfaProgram();
      SymbolicPointsTo spt=new SymbolicPointsTo(MAX_SET_SIZE);
      dfa.runLocalAnalysis(spt,scope.getMethodImpl().getFQMethodName());
      HashMap<InstructionHandle,ContextMap<CallString,BoundedSet<SymbolicAddress>>> usedRefs=spt.getResult();
      SuperGraph sg=getScopeSuperGraph(scope);
      String key="String_Node_Str" + scope.toString();
      ILPModelBuilder imb=new ILPModelBuilder(new IpetConfig(project.getConfig()));
      Map<CFGNode,Long> costMap=new HashMap<CFGNode,Long>();
      HashMap<SymbolicAddress,Map<CFGNode,Integer>> accessSets=new HashMap<SymbolicAddress,Map<CFGNode,Integer>>();
      for (      CFGNode n : sg.vertexSet()) {
        BasicBlock bb=n.getBasicBlock();
        long topCost=0;
        if (bb == null)         continue;
        InstructionHandle ih=bb.getFirstInstruction();
        while (ih.getNext() != null) {
          BoundedSet<SymbolicAddress> refs;
          if (usedRefs.containsKey(ih)) {
            refs=usedRefs.get(ih).get(emptyCallString);
            if (refs.isSaturated() || countNonDistinct) {
              topCost+=1;
            }
 else {
              for (              SymbolicAddress ref : refs.getSet()) {
                addAccessSite(accessSets,ref,n);
              }
            }
          }
          ih=ih.getNext();
        }
        costMap.put(n,topCost);
      }
      MaxCostFlow<CFGNode,CFGEdge> maxCostFlow=imb.buildGlobalILPModel(key,sg,new MapCostProvider<CFGNode>(costMap,0));
      for (      Entry<SymbolicAddress,Map<CFGNode,Integer>> accessEntry : accessSets.entrySet()) {
        SymbolicAddress ref=accessEntry.getKey();
        Map<CFGNode,Integer> accessSet=accessEntry.getValue();
        DecisionVariable dvar=maxCostFlow.createDecisionVariable();
        decisionVariables.put(dvar,ref);
        maxCostFlow.addDecisionCost(dvar,1);
        LinearVector<CFGEdge> ub=new LinearVector<CFGEdge>();
        for (        Entry<CFGNode,Integer> entry : accessSet.entrySet()) {
          CFGNode node=entry.getKey();
          for (          CFGEdge edge : sg.incomingEdgesOf(node)) {
            ub.add(edge,1);
          }
        }
        maxCostFlow.addDecisionUpperBound(dvar,ub);
      }
      Map<CFGEdge,Long> flowMap=new HashMap<CFGEdge,Long>();
      Map<DecisionVariable,Boolean> cacheMissMap=new HashMap<DecisionVariable,Boolean>();
      double lpCost;
      try {
        lpCost=maxCostFlow.solve(flowMap,cacheMissMap);
      }
 catch (      Exception e) {
        throw new AssertionError("String_Node_Str" + scope);
      }
      long accessedReferences=(long)(lpCost + 0.5);
      this.usedReferences.put(scope,accessedReferences);
    }
 catch (    NullPointerException nullex) {
      nullex.printStackTrace();
    }
  }
}

Fixed version (ground truth):
/** 
 * Analyze the number of references used in each scope. For the general technique, see   {@link com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis#analyzeBlockUsage()}<h2>Bytecodes using object references</h2> <ul> <li/> getfield (top of stack) <li/> putfield (second on stack) <li/> arraylen (top of stack) <li/> a*load (second on stack) <li/> a*store (third on stack) </ul> <h2>Reference Analysis</h2> For each scope, we do the following: <ol> <li/> Perform a local, symbolic points-to analysis <li/> Traverse all instructions, and collect for each reference the basic blocks it might be used in. Additionally, the cost of each basic block is set to the number of TOP references accessed. <li/> For each reference, add a decision variable denoting whether it is used at all, and add corresponding constraints. </ol>
 */
public void analyzeRefUsage(){
  usedReferences=new HashMap<CallGraphNode,Long>();
  CallString emptyCallString=new CallString();
  TopologicalOrderIterator<CallGraphNode,DefaultEdge> iter=project.getCallGraph().topDownIterator();
  while (iter.hasNext()) {
    CallGraphNode scope=iter.next();
    System.out.println("String_Node_Str" + scope.getMethodImpl().getFQMethodName());
    DFAAppInfo dfa=project.getDfaProgram();
    SymbolicPointsTo spt=new SymbolicPointsTo(MAX_SET_SIZE);
    dfa.runLocalAnalysis(spt,scope.getMethodImpl().getFQMethodName());
    HashMap<InstructionHandle,ContextMap<CallString,BoundedSet<SymbolicAddress>>> usedRefs=spt.getResult();
    SuperGraph sg=getScopeSuperGraph(scope);
    String key="String_Node_Str" + scope.toString();
    ILPModelBuilder imb=new ILPModelBuilder(new IpetConfig(project.getConfig()));
    Map<CFGNode,Long> costMap=new HashMap<CFGNode,Long>();
    HashMap<SymbolicAddress,Map<CFGNode,Integer>> accessSets=new HashMap<SymbolicAddress,Map<CFGNode,Integer>>();
    for (    CFGNode n : sg.vertexSet()) {
      BasicBlock bb=n.getBasicBlock();
      long topCost=0;
      if (bb == null)       continue;
      InstructionHandle ih=bb.getFirstInstruction();
      while (ih.getNext() != null) {
        BoundedSet<SymbolicAddress> refs;
        if (usedRefs.containsKey(ih)) {
          refs=usedRefs.get(ih).get(emptyCallString);
          if (refs.isSaturated() || countNonDistinct) {
            topCost+=1;
          }
 else {
            for (            SymbolicAddress ref : refs.getSet()) {
              addAccessSite(accessSets,ref,n);
            }
          }
        }
        ih=ih.getNext();
      }
      costMap.put(n,topCost);
    }
    MaxCostFlow<CFGNode,CFGEdge> maxCostFlow=imb.buildGlobalILPModel(key,sg,new MapCostProvider<CFGNode>(costMap,0));
    for (    Entry<SymbolicAddress,Map<CFGNode,Integer>> accessEntry : accessSets.entrySet()) {
      SymbolicAddress ref=accessEntry.getKey();
      Map<CFGNode,Integer> accessSet=accessEntry.getValue();
      DecisionVariable dvar=maxCostFlow.createDecisionVariable();
      decisionVariables.put(dvar,ref);
      maxCostFlow.addDecisionCost(dvar,1);
      LinearVector<CFGEdge> ub=new LinearVector<CFGEdge>();
      for (      Entry<CFGNode,Integer> entry : accessSet.entrySet()) {
        CFGNode node=entry.getKey();
        for (        CFGEdge edge : sg.incomingEdgesOf(node)) {
          ub.add(edge,1);
        }
      }
      maxCostFlow.addDecisionUpperBound(dvar,ub);
    }
    Map<CFGEdge,Long> flowMap=new HashMap<CFGEdge,Long>();
    Map<DecisionVariable,Boolean> cacheMissMap=new HashMap<DecisionVariable,Boolean>();
    double lpCost;
    try {
      lpCost=maxCostFlow.solve(flowMap,cacheMissMap);
    }
 catch (    Exception e) {
      throw new AssertionError("String_Node_Str" + scope);
    }
    long accessedReferences=(long)(lpCost + 0.5);
    this.usedReferences.put(scope,accessedReferences);
  }
}