Ejemplo n.º 1
0
  private void findNonCanonicalRegions(RPST rpst, Region region) {
    Set<Region> childrenBefore = new HashSet<>(rpst.getChildren(region));
    if (rpst.getChildCount(region) > 1) {
      boolean found = true;
      while (found) {
        found = false;

        // children ordered by dominance
        List<Region> children = new ArrayList<>(rpst.getChildren(region));
        Collections.sort(
            children,
            new Comparator<Region>() {
              @Override
              public int compare(Region region1, Region region2) {
                return getDomInfo().dominates(region1.getEntry(), region2.getEntry()) ? 1 : -1;
              }
            });

        for (Region child1 : children) {
          for (Region child2 : children) {
            if (!child1.equals(child2)) {
              if (isNonCanonicalRegion(rpst, child1, child2)) {
                Region newRegion =
                    new RegionImpl(child1.getEntry(), child2.getExit(), ParentType.UNDEFINED);
                LOGGER.debug("New non canonical region {}", newRegion);
                rpst.addRegion(newRegion, region);
                rpst.setNewParent(child1, newRegion);
                rpst.setNewParent(child2, newRegion);
                found = true;
                break;
              }
            }
          }
          if (found) {
            break;
          }
        }
      }
    }
    for (Region child : childrenBefore) {
      findNonCanonicalRegions(rpst, child);
    }
  }
Ejemplo n.º 2
0
 /** Test if two canonical regions could be merge in one non canonical region. */
 private boolean isNonCanonicalRegion(RPST rpst, Region region1, Region region2) {
   if (!region1.getExit().equals(region2.getEntry())) {
     return false;
   }
   if (rpst.getChildCount(region2) == 0) {
     return false;
   }
   // basic blocks of merged region
   Set<BasicBlock> basicBlocks = new HashSet<>();
   basicBlocks.addAll(rpst.getBasicBlocks(region1));
   basicBlocks.addAll(rpst.getBasicBlocks(region2));
   basicBlocks.add(region2.getExit());
   if (!basicBlocks.containsAll(cfg.getSuccessorsOf(region1.getExit()))) {
     return false;
   }
   if (!basicBlocks.containsAll(cfg.getPredecessorsOf(region1.getExit()))) {
     return false;
   }
   return true;
 }
Ejemplo n.º 3
0
  /**
   * Given a List of QueryObjects known to be inconsistent as determined by validation, log where
   * the suspect objects are found by checking for it in 1) the expected List 2) the CQ history of
   * events 3) the select results 4) the localRegion
   *
   * @param inconsistencies A List of suspect QueryObjects to check in each location.
   * @param expected The expected List of objects for a query.
   * @param history The CQHistory for the query
   * @returns
   */
  private String getLocationString(List inconsistencies, List expected, CQHistory history) {
    StringBuffer aStr = new StringBuffer();
    for (int i = 0; i < inconsistencies.size(); i++) {
      QueryObject suspect = (QueryObject) (inconsistencies.get(i));

      // check the local region
      boolean found = false;
      Iterator it = aRegion.keySet().iterator();
      while (it.hasNext()) {
        Object key = it.next();
        Region.Entry entry = aRegion.getEntry(key);
        QueryObject qo = (QueryObject) (entry.getValue());
        if ((qo != null) && (qo.equals(suspect))) {
          found = true;
          aStr.append(
              qo.toStringAbbreviated()
                  + " was found in "
                  + aRegion.getFullPath()
                  + " at key "
                  + key
                  + "\n");
        }
      }
      if (!found) {
        aStr.append(
            suspect.toStringAbbreviated() + " was NOT found in " + aRegion.getFullPath() + "\n");
      }

      // seach for all occurrences in expected list
      found = false;
      it = expected.iterator();
      while (it.hasNext()) {
        QueryObject qo = (QueryObject) (it.next());
        if (qo.equals(suspect)) {
          found = true;
          aStr.append(qo.toStringAbbreviated() + " was found in expected results\n");
        }
      }
      if (!found) {
        aStr.append(suspect.toStringAbbreviated() + " was NOT found in expected results\n");
      }

      // seach for all occurrences in selectResults
      SelectResults selResults = history.getSelectResults();
      found = false;
      it = selResults.iterator();
      while (it.hasNext()) {
        QueryObject qo = (QueryObject) (it.next());
        if (qo.equals(suspect)) {
          found = true;
          aStr.append(qo.toStringAbbreviated() + " was found in SelectResults\n");
        }
      }
      if (!found) {
        aStr.append(suspect.toStringAbbreviated() + " was NOT found in SelectResults\n");
      }

      // seach for all occurrences in history
      found = false;
      List eventList = history.getEvents();
      for (int j = 0; j < eventList.size(); j++) {
        CqEvent event = (CqEvent) (eventList.get(j));
        QueryObject qo = (QueryObject) (event.getNewValue());
        if ((qo != null) && (qo.equals(suspect))) {
          found = true;
          aStr.append(
              qo.toStringAbbreviated()
                  + " was found in event history as new value "
                  + event
                  + "\n");
        }
      }
      if (!found) {
        aStr.append(suspect.toStringAbbreviated() + " was NOT found in CqEvent history\n");
      }
    }
    return aStr.toString();
  }