Program: 186657
Project: 186657
Buggy source:
/** 
 * @param modification the modifications which will be done
 * @return the number of cache miss cycles due to the code size change
 */
public long getDeltaCacheMissCosts(CodeModification modification){
  int deltaBytes=modification.getDeltaLocalCodesize();
  MethodInfo method=modification.getMethod();
  if (deltaBytes == 0)   return 0;
  if (analysisType == AnalysisType.ALWAYS_HIT)   return 0;
  WCETProcessorModel pm=analyses.getJCopter().getWCETProcessorModel();
  int size=getMethodSize(method);
  int oldWords=MiscUtils.bytesToWords(size);
  int newWords=MiscUtils.bytesToWords(size + deltaBytes);
  int deltaBlocks=cache.requiredNumberOfBlocks(newWords) - cache.requiredNumberOfBlocks(oldWords);
  int newBlocks=getRequiredBlocks(method) + deltaBlocks;
  long costs=0;
  if (analysisType == AnalysisType.ALWAYS_MISS || !cache.allFit(newBlocks)) {
    long oldCycles=pm.getMethodCacheMissPenalty(oldWords,true);
    long newCycles=pm.getMethodCacheMissPenalty(newWords,true);
    costs=analyses.getExecCountAnalysis().getExecCount(method) * (newCycles - oldCycles);
    oldCycles=pm.getMethodCacheMissPenalty(oldWords,false);
    newCycles=pm.getMethodCacheMissPenalty(newWords,false);
    for (    InvokeSite invokeSite : method.getCode().getInvokeSites()) {
      costs+=analyses.getExecCountAnalysis().getExecCount(invokeSite) * (newCycles - oldCycles);
    }
  }
  if (analysisType == AnalysisType.ALWAYS_MISS) {
    return costs;
  }
  Set<ExecutionContext> changes=findClassificationChanges(method,deltaBytes,modification.getRemovedInvokees(),false);
  long deltaCosts=0;
  for (  ExecutionContext node : changes) {
    for (    InvokeSite invokeSite : node.getMethodInfo().getCode().getInvokeSites()) {
      int sizeWords=0;
      for (      MethodInfo invokee : callGraph.findImplementations(node.getCallString().push(invokeSite))) {
        sizeWords=Math.max(sizeWords,invokee.getCode().getNumberOfWords());
      }
      long count=analyses.getExecCountAnalysis().getExecCount(node,invokeSite.getInstructionHandle());
      deltaCosts+=count * pm.getMethodCacheMissPenalty(sizeWords,true);
      deltaCosts+=count * pm.getMethodCacheMissPenalty(oldWords,false);
    }
  }
  if (deltaBytes > 0) {
    costs+=deltaCosts;
  }
 else {
    costs-=deltaCosts;
  }
  if (analysisType == AnalysisType.ALL_FIT_REGIONS) {
  }
  return costs;
}

Fixed version (ground truth):
/** 
 * @param modification the modifications which will be done
 * @return the number of cache miss cycles due to the code size change
 */
public long getDeltaCacheMissCosts(CodeModification modification){
  int deltaBytes=modification.getDeltaLocalCodesize();
  MethodInfo method=modification.getMethod();
  if (deltaBytes == 0)   return 0;
  if (analysisType == AnalysisType.ALWAYS_HIT)   return 0;
  WCETProcessorModel pm=analyses.getJCopter().getWCETProcessorModel();
  int size=getMethodSize(method);
  int oldWords=MiscUtils.bytesToWords(size);
  int newWords=MiscUtils.bytesToWords(size + deltaBytes);
  int deltaBlocks=cache.requiredNumberOfBlocks(newWords) - cache.requiredNumberOfBlocks(oldWords);
  int newBlocks=getRequiredBlocks(method) + deltaBlocks;
  long costs=0;
  if (analysisType == AnalysisType.ALWAYS_MISS || !cache.allFit(newBlocks)) {
    long oldCycles=pm.getMethodCacheMissPenalty(oldWords,true);
    long newCycles=pm.getMethodCacheMissPenalty(newWords,true);
    costs=analyses.getExecCountAnalysis().getExecCount(method) * (newCycles - oldCycles);
    oldCycles=pm.getMethodCacheMissPenalty(oldWords,false);
    newCycles=pm.getMethodCacheMissPenalty(newWords,false);
    int startPos=modification.getStart().getPosition();
    int endPos=modification.getEnd().getPosition();
    for (    InvokeSite invokeSite : method.getCode().getInvokeSites()) {
      int pos=invokeSite.getInstructionHandle().getPosition();
      if (pos >= startPos && pos <= endPos)       continue;
      costs+=analyses.getExecCountAnalysis().getExecCount(invokeSite) * (newCycles - oldCycles);
    }
  }
  if (analysisType == AnalysisType.ALWAYS_MISS) {
    return costs;
  }
  Set<ExecutionContext> changes=findClassificationChanges(method,deltaBytes,modification.getRemovedInvokees(),false);
  AppInfo appInfo=AppInfo.getSingleton();
  long deltaCosts=0;
  for (  ExecutionContext node : changes) {
    for (    InvokeSite invokeSite : node.getMethodInfo().getCode().getInvokeSites()) {
      int sizeWords=0;
      for (      MethodInfo invokee : appInfo.findImplementations(node.getCallString().push(invokeSite))) {
        sizeWords=Math.max(sizeWords,invokee.getCode().getNumberOfWords());
      }
      long count=analyses.getExecCountAnalysis().getExecCount(node,invokeSite.getInstructionHandle());
      deltaCosts+=count * pm.getMethodCacheMissPenalty(sizeWords,true);
      deltaCosts+=count * pm.getMethodCacheMissPenalty(oldWords,false);
    }
  }
  if (deltaBytes > 0) {
    costs+=deltaCosts;
  }
 else {
    costs-=deltaCosts;
  }
  if (analysisType == AnalysisType.ALL_FIT_REGIONS) {
  }
  return costs;
}