< prev index next >

src/hotspot/share/opto/callnode.cpp

Print this page




1606       } else {
1607         break;
1608       }
1609     } else {
1610       break; // found an interesting control
1611     }
1612   }
1613   return ctrl;
1614 }
1615 //
1616 // Given a control, see if it's the control projection of an Unlock which
1617 // operating on the same object as lock.
1618 //
1619 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1620                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1621   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
1622   if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
1623     Node *n = ctrl_proj->in(0);
1624     if (n != NULL && n->is_Unlock()) {
1625       UnlockNode *unlock = n->as_Unlock();
1626       if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&



1627           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1628           !unlock->is_eliminated()) {
1629         lock_ops.append(unlock);
1630         return true;
1631       }
1632     }
1633   }
1634   return false;
1635 }
1636 
1637 //
1638 // Find the lock matching an unlock.  Returns null if a safepoint
1639 // or complicated control is encountered first.
1640 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1641   LockNode *lock_result = NULL;
1642   // find the matching lock, or an intervening safepoint
1643   Node *ctrl = next_control(unlock->in(0));
1644   while (1) {
1645     assert(ctrl != NULL, "invalid control graph");
1646     assert(!ctrl->is_Start(), "missing lock for unlock");


1651     } else if (ctrl->is_Region()) {
1652       // Check for a simple diamond pattern.  Punt on anything more complicated
1653       if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
1654         Node *in1 = next_control(ctrl->in(1));
1655         Node *in2 = next_control(ctrl->in(2));
1656         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1657              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1658           ctrl = next_control(in1->in(0)->in(0));
1659         } else {
1660           break;
1661         }
1662       } else {
1663         break;
1664       }
1665     } else {
1666       ctrl = next_control(ctrl->in(0));  // keep searching
1667     }
1668   }
1669   if (ctrl->is_Lock()) {
1670     LockNode *lock = ctrl->as_Lock();
1671     if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&



1672         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
1673       lock_result = lock;
1674     }
1675   }
1676   return lock_result;
1677 }
1678 
1679 // This code corresponds to case 3 above.
1680 
1681 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
1682                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
1683   Node* if_node = node->in(0);
1684   bool  if_true = node->is_IfTrue();
1685 
1686   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
1687     Node *lock_ctrl = next_control(if_node->in(0));
1688     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
1689       Node* lock1_node = NULL;
1690       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
1691       if (if_true) {
1692         if (proj->is_IfFalse() && proj->outcnt() == 1) {
1693           lock1_node = proj->unique_out();
1694         }
1695       } else {
1696         if (proj->is_IfTrue() && proj->outcnt() == 1) {
1697           lock1_node = proj->unique_out();
1698         }
1699       }
1700       if (lock1_node != NULL && lock1_node->is_Lock()) {
1701         LockNode *lock1 = lock1_node->as_Lock();
1702         if (lock->obj_node()->eqv_uncast(lock1->obj_node()) &&



1703             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
1704             !lock1->is_eliminated()) {
1705           lock_ops.append(lock1);
1706           return true;
1707         }
1708       }
1709     }
1710   }
1711 
1712   lock_ops.trunc_to(0);
1713   return false;
1714 }
1715 
1716 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
1717                                GrowableArray<AbstractLockNode*> &lock_ops) {
1718   // check each control merging at this point for a matching unlock.
1719   // in(0) should be self edge so skip it.
1720   for (int i = 1; i < (int)region->req(); i++) {
1721     Node *in_node = next_control(region->in(i));
1722     if (in_node != NULL) {


1899 #endif
1900     return false; // External lock or it is not Box (Phi node).
1901   }
1902 
1903   // Ignore complex cases: merged locks or multiple locks.
1904   Node* obj = obj_node();
1905   LockNode* unique_lock = NULL;
1906   if (!box->is_simple_lock_region(&unique_lock, obj)) {
1907 #ifdef ASSERT
1908     this->log_lock_optimization(c, "eliminate_lock_INLR_2a");
1909 #endif
1910     return false;
1911   }
1912   if (unique_lock != this) {
1913 #ifdef ASSERT
1914     this->log_lock_optimization(c, "eliminate_lock_INLR_2b");
1915 #endif
1916     return false;
1917   }
1918 


1919   // Look for external lock for the same object.
1920   SafePointNode* sfn = this->as_SafePoint();
1921   JVMState* youngest_jvms = sfn->jvms();
1922   int max_depth = youngest_jvms->depth();
1923   for (int depth = 1; depth <= max_depth; depth++) {
1924     JVMState* jvms = youngest_jvms->of_depth(depth);
1925     int num_mon  = jvms->nof_monitors();
1926     // Loop over monitors
1927     for (int idx = 0; idx < num_mon; idx++) {
1928       Node* obj_node = sfn->monitor_obj(jvms, idx);

1929       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
1930       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
1931         return true;
1932       }
1933     }
1934   }
1935 #ifdef ASSERT
1936   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
1937 #endif
1938   return false;
1939 }
1940 
1941 //=============================================================================
1942 uint UnlockNode::size_of() const { return sizeof(*this); }
1943 
1944 //=============================================================================
1945 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1946 
1947   // perform any generic optimizations first (returns 'this' or NULL)
1948   Node *result = SafePointNode::Ideal(phase, can_reshape);




1606       } else {
1607         break;
1608       }
1609     } else {
1610       break; // found an interesting control
1611     }
1612   }
1613   return ctrl;
1614 }
1615 //
1616 // Given a control, see if it's the control projection of an Unlock which
1617 // operating on the same object as lock.
1618 //
1619 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1620                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1621   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
1622   if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
1623     Node *n = ctrl_proj->in(0);
1624     if (n != NULL && n->is_Unlock()) {
1625       UnlockNode *unlock = n->as_Unlock();
1626       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1627       Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1628       Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1629       if (lock_obj->eqv_uncast(unlock_obj) &&
1630           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1631           !unlock->is_eliminated()) {
1632         lock_ops.append(unlock);
1633         return true;
1634       }
1635     }
1636   }
1637   return false;
1638 }
1639 
1640 //
1641 // Find the lock matching an unlock.  Returns null if a safepoint
1642 // or complicated control is encountered first.
1643 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1644   LockNode *lock_result = NULL;
1645   // find the matching lock, or an intervening safepoint
1646   Node *ctrl = next_control(unlock->in(0));
1647   while (1) {
1648     assert(ctrl != NULL, "invalid control graph");
1649     assert(!ctrl->is_Start(), "missing lock for unlock");


1654     } else if (ctrl->is_Region()) {
1655       // Check for a simple diamond pattern.  Punt on anything more complicated
1656       if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
1657         Node *in1 = next_control(ctrl->in(1));
1658         Node *in2 = next_control(ctrl->in(2));
1659         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1660              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1661           ctrl = next_control(in1->in(0)->in(0));
1662         } else {
1663           break;
1664         }
1665       } else {
1666         break;
1667       }
1668     } else {
1669       ctrl = next_control(ctrl->in(0));  // keep searching
1670     }
1671   }
1672   if (ctrl->is_Lock()) {
1673     LockNode *lock = ctrl->as_Lock();
1674     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1675     Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1676     Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1677     if (lock_obj->eqv_uncast(unlock_obj) &&
1678         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
1679       lock_result = lock;
1680     }
1681   }
1682   return lock_result;
1683 }
1684 
1685 // This code corresponds to case 3 above.
1686 
1687 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
1688                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
1689   Node* if_node = node->in(0);
1690   bool  if_true = node->is_IfTrue();
1691 
1692   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
1693     Node *lock_ctrl = next_control(if_node->in(0));
1694     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
1695       Node* lock1_node = NULL;
1696       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
1697       if (if_true) {
1698         if (proj->is_IfFalse() && proj->outcnt() == 1) {
1699           lock1_node = proj->unique_out();
1700         }
1701       } else {
1702         if (proj->is_IfTrue() && proj->outcnt() == 1) {
1703           lock1_node = proj->unique_out();
1704         }
1705       }
1706       if (lock1_node != NULL && lock1_node->is_Lock()) {
1707         LockNode *lock1 = lock1_node->as_Lock();
1708         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1709         Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1710         Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
1711         if (lock_obj->eqv_uncast(lock1_obj) &&
1712             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
1713             !lock1->is_eliminated()) {
1714           lock_ops.append(lock1);
1715           return true;
1716         }
1717       }
1718     }
1719   }
1720 
1721   lock_ops.trunc_to(0);
1722   return false;
1723 }
1724 
1725 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
1726                                GrowableArray<AbstractLockNode*> &lock_ops) {
1727   // check each control merging at this point for a matching unlock.
1728   // in(0) should be self edge so skip it.
1729   for (int i = 1; i < (int)region->req(); i++) {
1730     Node *in_node = next_control(region->in(i));
1731     if (in_node != NULL) {


1908 #endif
1909     return false; // External lock or it is not Box (Phi node).
1910   }
1911 
1912   // Ignore complex cases: merged locks or multiple locks.
1913   Node* obj = obj_node();
1914   LockNode* unique_lock = NULL;
1915   if (!box->is_simple_lock_region(&unique_lock, obj)) {
1916 #ifdef ASSERT
1917     this->log_lock_optimization(c, "eliminate_lock_INLR_2a");
1918 #endif
1919     return false;
1920   }
1921   if (unique_lock != this) {
1922 #ifdef ASSERT
1923     this->log_lock_optimization(c, "eliminate_lock_INLR_2b");
1924 #endif
1925     return false;
1926   }
1927 
1928   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1929   obj = bs->step_over_gc_barrier(obj);
1930   // Look for external lock for the same object.
1931   SafePointNode* sfn = this->as_SafePoint();
1932   JVMState* youngest_jvms = sfn->jvms();
1933   int max_depth = youngest_jvms->depth();
1934   for (int depth = 1; depth <= max_depth; depth++) {
1935     JVMState* jvms = youngest_jvms->of_depth(depth);
1936     int num_mon  = jvms->nof_monitors();
1937     // Loop over monitors
1938     for (int idx = 0; idx < num_mon; idx++) {
1939       Node* obj_node = sfn->monitor_obj(jvms, idx);
1940       obj_node = bs->step_over_gc_barrier(obj_node);
1941       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
1942       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
1943         return true;
1944       }
1945     }
1946   }
1947 #ifdef ASSERT
1948   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
1949 #endif
1950   return false;
1951 }
1952 
1953 //=============================================================================
1954 uint UnlockNode::size_of() const { return sizeof(*this); }
1955 
1956 //=============================================================================
1957 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1958 
1959   // perform any generic optimizations first (returns 'this' or NULL)
1960   Node *result = SafePointNode::Ideal(phase, can_reshape);


< prev index next >