public void verify(String where, boolean checkCFG) {   { OPT_BasicBlock cur = cfg.firstInCodeOrder(); OPT_BasicBlock prev = null; while (cur != null) { if (cur.getPrev() != prev) { verror(where, "Prev link of "+cur+" does not point to "+prev); }   OPT_Instruction s = cur.start; OPT_Instruction e = cur.end; if (s == null) { verror(where, "Bblock "+cur+" has null start instruction"); } if (e == null) { verror(where, "Bblock "+cur+" has null end instruction"); }    if (!s.isBbFirst()) { verror(where, "Instr "+s+" is first instr of "+cur+" but is not BB_FIRST"); } if (s.getBasicBlock() != cur) { verror(where, "Instr "+s+" is first instr of "+cur+ " but points to BBlock "+s.getBasicBlock()); } if (!e.isBbLast()) { verror(where, "Instr "+e+" is last instr of "+cur+" but is not BB_LAST"); } if (e.getBasicBlock() != cur) { verror(where, "Instr "+e+" is last instr of "+cur+ " but points to BBlock "+e.getBasicBlock()); }   if (s.getPrev() != null) { verror(where, "Instr "+s+ " is the first instr of "+cur+" but has a predecessor " +s.getPrev()); } if (e.getNext() != null) { verror(where, "Instr "+s+ " is the last instr of "+cur+" but has a successor " +e.getNext()); } OPT_Instruction pp = s; OPT_Instruction p = s.getNext(); boolean foundBranch = false; while (p != e) { if (p == null) { verror(where, "Fell off the instruction list in " +cur+" before finding "+e); } if (p.getPrev() != pp) { verror(where, "Instr "+pp+" has next "+p +" but "+p+" has prev "+p.getPrev()); } if (!p.isBbInside()) { verror(where, "Instr "+p+ " should be inside "+cur+" but is not BBInside"); } if (foundBranch && !p.isBranch()) { printInstructions(); verror(where, "Non branch "+p+" after branch "+pp+" in "+cur); } if (p.isBranch() && p.operator() != LOWTABLESWITCH) { foundBranch = true; if (p.isUnconditionalBranch() && p.getNext() != e) { printInstructions(); verror(where, "Unconditional branch "+p+ " does not end its basic block "+cur); } } pp = p; p = p.getNext(); } if (p.getPrev() != pp) { verror(where, "Instr "+pp+" has next " +p+" but "+p+" has prev "+p.getPrev()); }   cur.scratch = 0;  prev = cur; cur = (OPT_BasicBlock)cur.getNext(); } }   final int inBBListMarker = 999; if (checkCFG) { final boolean VERIFY_CFG_EDGES = false; java.util.HashSet origOutSet = null; if (VERIFY_CFG_EDGES) origOutSet = new java.util.HashSet();  for (OPT_BasicBlock cur = cfg.firstInCodeOrder(); cur != null; cur = (OPT_BasicBlock)cur.getNext()) {   for (OPT_BasicBlockEnumeration e = cur.getIn(); e.hasMoreElements(); ) { OPT_BasicBlock pred = e.next(); if (!pred.pointsOut(cur)) { verror(where, pred+ " is an inEdge of "+cur+" but "+cur+ " is not an outEdge of "+pred); } }   for (OPT_BasicBlockEnumeration e =cur.getOut(); e.hasMoreElements(); ) { OPT_BasicBlock succ = e.next(); if (!succ.pointsIn(cur)) { verror(where, succ+ " is an outEdge of "+cur+" but "+cur+ " is not an inEdge of "+succ); }  if (VERIFY_CFG_EDGES && IRStage<=LIR) origOutSet.add(succ); }   if (VERIFY_CFG_EDGES && IRStage <= LIR) {     cur.recomputeNormalOut(this);   for (OPT_BasicBlockEnumeration e =cur.getOut(); e.hasMoreElements(); ) { OPT_BasicBlock succ = e.next(); if (!origOutSet.contains(succ) && !succ.isExit()   ) { cur.printExtended(); verror(where, "An edge in the cfg was incorrect.  " + succ+ " was not originally an out edge of " + cur + " but it was after calling recomputeNormalOut()" ); } origOutSet.remove(succ); }   if (!origOutSet.isEmpty()) { OPT_BasicBlock missing = (OPT_BasicBlock) origOutSet.iterator().next();  cur.printExtended(); verror(where, "An edge in the cfg was incorrect.  " + missing + " was originally an out edge of " + cur + " but not after calling recomputeNormalOut()"); } }   cur.scratch = inBBListMarker; }     for (OPT_BasicBlock cur = cfg.firstInCodeOrder(); cur != null; cur = (OPT_BasicBlock)cur.getNext()) { for (OPT_BasicBlockEnumeration e = cur.getIn(); e.hasMoreElements(); ) { OPT_BasicBlock pred = e.next(); if (pred.scratch != inBBListMarker) { verror(where, "In Method "+ method.getName() +", " + pred+" is an inEdge of "+cur+ " but it is not in the CFG!"); } } for (OPT_BasicBlockEnumeration e = cur.getOut(); e.hasMoreElements();) { OPT_BasicBlock succ = e.next(); if (succ.scratch != inBBListMarker) {  if (succ != cfg.exit()) { verror(where, "In Method "+ method.getName() +", "+ succ+ " is an outEdge of "+cur+" but it is not in the CFG!"); } } } } }  if (IRStage<MIR) { verifyRegisterDefs(where); verifyRegisterTypes(where); }
public void verify(String where) { verify(where, true);
  public void verify(String where, boolean checkCFG) {    // First, verify that the basic blocks are properly chained together    // and that each basic block's instruction list is properly constructed.    {      OPT_BasicBlock cur = cfg.firstInCodeOrder();      OPT_BasicBlock prev = null;      while (cur != null) {        if (cur.getPrev() != prev) {          verror(where,                  "Prev link of "+cur+" does not point to "+prev);        }        // Verify cur's start and end instructions        OPT_Instruction s = cur.start;        OPT_Instruction e = cur.end;        if (s == null) {          verror(where,                  "Bblock "+cur+" has null start instruction");        }        if (e == null) {          verror(where,                  "Bblock "+cur+" has null end instruction");        }                // cur has start and end instructions,         // make sure that they are locally ok.        if (!s.isBbFirst()) {          verror(where,                  "Instr "+s+" is first instr of "+cur+" but is not BB_FIRST");        }        if (s.getBasicBlock() != cur) {          verror(where,                  "Instr "+s+" is first instr of "+cur+                 " but points to BBlock "+s.getBasicBlock());        }        if (!e.isBbLast()) {          verror(where,                  "Instr "+e+" is last instr of "+cur+" but is not BB_LAST");        }        if (e.getBasicBlock() != cur) {          verror(where,                  "Instr "+e+" is last instr of "+cur+                 " but points to BBlock "+e.getBasicBlock());        }                // Now check the integrity of the block's instruction list        if (s.getPrev() != null) {          verror(where, "Instr "+s+                 " is the first instr of "+cur+" but has a predecessor "                 +s.getPrev());        }        if (e.getNext() != null) {          verror(where, "Instr "+s+                 " is the last instr of "+cur+" but has a successor "                 +e.getNext());        }        OPT_Instruction pp = s;        OPT_Instruction p = s.getNext();        boolean foundBranch = false;        while (p != e) {          if (p == null) {            verror(where, "Fell off the instruction list in "                   +cur+" before finding "+e);          }          if (p.getPrev() != pp) {            verror(where, "Instr "+pp+" has next "+p                   +" but "+p+" has prev "+p.getPrev());          }          if (!p.isBbInside()) {            verror(where, "Instr "+p+                   " should be inside "+cur+" but is not BBInside");          }          if (foundBranch && !p.isBranch()) {            printInstructions();            verror(where, "Non branch "+p+" after branch "+pp+" in "+cur);          }          if (p.isBranch() && p.operator() != LOWTABLESWITCH) {            foundBranch = true;            if (p.isUnconditionalBranch() && p.getNext() != e) {              printInstructions();              verror(where, "Unconditional branch "+p+                     " does not end its basic block "+cur);            }          }          pp = p;          p = p.getNext();        }               if (p.getPrev() != pp) {          verror(where, "Instr "+pp+" has next "                 +p+" but "+p+" has prev "+p.getPrev());        }        // initialize the mark bit for the bblist test below        cur.scratch = 0;        prev = cur;        cur = (OPT_BasicBlock)cur.getNext();      }    }    // Check that the CFG links are well formed    final int inBBListMarker = 999;  // actual number is insignificant    if (checkCFG) {      final boolean VERIFY_CFG_EDGES = false;      java.util.HashSet origOutSet = null;      if (VERIFY_CFG_EDGES) origOutSet = new java.util.HashSet();      for (OPT_BasicBlock cur = cfg.firstInCodeOrder();           cur != null;           cur = (OPT_BasicBlock)cur.getNext()) {        // Check incoming edges        for (OPT_BasicBlockEnumeration e = cur.getIn();              e.hasMoreElements(); ) {          OPT_BasicBlock pred = e.next();          if (!pred.pointsOut(cur)) {            verror(where, pred+                   " is an inEdge of "+cur+" but "+cur+                   " is not an outEdge of "+pred);          }        }        // Check outgoing edges        for (OPT_BasicBlockEnumeration e =cur.getOut();             e.hasMoreElements(); ) {          OPT_BasicBlock succ = e.next();          if (!succ.pointsIn(cur)) {            verror(where, succ+                   " is an outEdge of "+cur+" but "+cur+                   " is not an inEdge of "+succ);          }          // Remember the original out edges for CFG edge verification          if (VERIFY_CFG_EDGES && IRStage<=LIR) origOutSet.add(succ);        }        if (VERIFY_CFG_EDGES && IRStage <= LIR) {          // Next, check that the CFG links are semantically correct          // (ie that the CFG links and branch instructions agree)          // This done by calling recomputeNormalOut() and confirming          // that nothing changes.          cur.recomputeNormalOut(this);                    // Confirm outgoing edges didn't change          for (OPT_BasicBlockEnumeration e =cur.getOut();               e.hasMoreElements(); ) {            OPT_BasicBlock succ = e.next();            if (!origOutSet.contains(succ) &&                !succ.isExit() // Sometimes recomput is conservative in adding edge to exit                               // because it relies soley on the mayThrowUncaughtException                               // flag.                ) {              cur.printExtended();              verror(where, "An edge in the cfg was incorrect.  " +                      succ+ " was not originally an out edge of " + cur +                      " but it was after calling recomputeNormalOut()" );            }            origOutSet.remove(succ); // we saw it, so remove it          }          // See if there were any edges that we didn't see the second          // time around          if (!origOutSet.isEmpty()) {            OPT_BasicBlock missing =               (OPT_BasicBlock) origOutSet.iterator().next();            cur.printExtended();            verror(where, "An edge in the cfg was incorrect.  " +                   missing + " was originally an out edge of " + cur +                    " but not after calling recomputeNormalOut()");          }        }        // mark this block because it is the bblist        cur.scratch = inBBListMarker;      }            // Check to make sure that all blocks connected       // (via a CFG edge) to a block      // that is in the bblist are also in the bblist      for (OPT_BasicBlock cur = cfg.firstInCodeOrder();           cur != null;           cur = (OPT_BasicBlock)cur.getNext()) {        for (OPT_BasicBlockEnumeration e = cur.getIn();              e.hasMoreElements(); ) {          OPT_BasicBlock pred = e.next();          if (pred.scratch != inBBListMarker) {            verror(where, "In Method "+ method.getName() +", "                   + pred+" is an inEdge of "+cur+                   " but it is not in the CFG!");          }        }        for (OPT_BasicBlockEnumeration e = cur.getOut();              e.hasMoreElements();) {          OPT_BasicBlock succ = e.next();          if (succ.scratch != inBBListMarker) {            // the EXIT block is never in the BB list            if (succ != cfg.exit()) {               verror(where, "In Method "+ method.getName() +", "+ succ+                     " is an outEdge of "+cur+" but it is not in the CFG!");            }          }        }      }    } // end CFG sanity check    if (IRStage<MIR) {      verifyRegisterDefs(where);      verifyRegisterTypes(where);    }  }