hotspot/src/share/vm/opto/gcm.cpp
changeset 1070 e03de091796e
parent 781 e1baa9c8f16f
child 1498 346bf226078e
--- a/hotspot/src/share/vm/opto/gcm.cpp	Wed Aug 27 16:33:34 2008 -0700
+++ b/hotspot/src/share/vm/opto/gcm.cpp	Thu Aug 28 10:22:12 2008 -0700
@@ -1609,7 +1609,30 @@
 float Block::succ_prob(uint i) {
   int eidx = end_idx();
   Node *n = _nodes[eidx];  // Get ending Node
-  int op = n->is_Mach() ? n->as_Mach()->ideal_Opcode() : n->Opcode();
+
+  int op = n->Opcode();
+  if (n->is_Mach()) {
+    if (n->is_MachNullCheck()) {
+      // Can only reach here if called after lcm. The original Op_If is gone,
+      // so we attempt to infer the probability from one or both of the
+      // successor blocks.
+      assert(_num_succs == 2, "expecting 2 successors of a null check");
+      // If either successor has only one predecessor, then the
+      // probabiltity estimate can be derived using the
+      // relative frequency of the successor and this block.
+      if (_succs[i]->num_preds() == 2) {
+        return _succs[i]->_freq / _freq;
+      } else if (_succs[1-i]->num_preds() == 2) {
+        return 1 - (_succs[1-i]->_freq / _freq);
+      } else {
+        // Estimate using both successor frequencies
+        float freq = _succs[i]->_freq;
+        return freq / (freq + _succs[1-i]->_freq);
+      }
+    }
+    op = n->as_Mach()->ideal_Opcode();
+  }
+
 
   // Switch on branch type
   switch( op ) {