< prev index next >

src/hotspot/share/opto/callnode.cpp

Print this page




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "ci/bcEscapeAnalyzer.hpp"
  28 #include "compiler/oopMap.hpp"

  29 #include "interpreter/interpreter.hpp"
  30 #include "opto/callGenerator.hpp"
  31 #include "opto/callnode.hpp"
  32 #include "opto/castnode.hpp"
  33 #include "opto/convertnode.hpp"
  34 #include "opto/escape.hpp"
  35 #include "opto/locknode.hpp"
  36 #include "opto/machnode.hpp"
  37 #include "opto/matcher.hpp"
  38 #include "opto/parse.hpp"
  39 #include "opto/regalloc.hpp"
  40 #include "opto/regmask.hpp"
  41 #include "opto/rootnode.hpp"
  42 #include "opto/runtime.hpp"
  43 
  44 // Portions of code courtesy of Clifford Click
  45 
  46 // Optimization - Graph Style
  47 
  48 //=============================================================================


1080 #endif
1081 
1082 //------------------------------calling_convention-----------------------------
1083 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1084   Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
1085 }
1086 
1087 //=============================================================================
1088 //------------------------------calling_convention-----------------------------
1089 
1090 
1091 //=============================================================================
1092 #ifndef PRODUCT
1093 void CallLeafNode::dump_spec(outputStream *st) const {
1094   st->print("# ");
1095   st->print("%s", _name);
1096   CallNode::dump_spec(st);
1097 }
1098 #endif
1099 








1100 //=============================================================================
1101 
1102 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1103   assert(verify_jvms(jvms), "jvms must match");
1104   int loc = jvms->locoff() + idx;
1105   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1106     // If current local idx is top then local idx - 1 could
1107     // be a long/double that needs to be killed since top could
1108     // represent the 2nd half ofthe long/double.
1109     uint ideal = in(loc -1)->ideal_reg();
1110     if (ideal == Op_RegD || ideal == Op_RegL) {
1111       // set other (low index) half to top
1112       set_req(loc - 1, in(loc));
1113     }
1114   }
1115   set_req(loc, c);
1116 }
1117 
1118 uint SafePointNode::size_of() const { return sizeof(*this); }
1119 uint SafePointNode::cmp( const Node &n ) const {


1621       } else {
1622         break;
1623       }
1624     } else {
1625       break; // found an interesting control
1626     }
1627   }
1628   return ctrl;
1629 }
1630 //
1631 // Given a control, see if it's the control projection of an Unlock which
1632 // operating on the same object as lock.
1633 //
1634 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1635                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1636   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
1637   if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
1638     Node *n = ctrl_proj->in(0);
1639     if (n != NULL && n->is_Unlock()) {
1640       UnlockNode *unlock = n->as_Unlock();
1641       if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&







1642           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1643           !unlock->is_eliminated()) {
1644         lock_ops.append(unlock);
1645         return true;
1646       }
1647     }
1648   }
1649   return false;
1650 }
1651 
1652 //
1653 // Find the lock matching an unlock.  Returns null if a safepoint
1654 // or complicated control is encountered first.
1655 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1656   LockNode *lock_result = NULL;
1657   // find the matching lock, or an intervening safepoint
1658   Node *ctrl = next_control(unlock->in(0));
1659   while (1) {
1660     assert(ctrl != NULL, "invalid control graph");
1661     assert(!ctrl->is_Start(), "missing lock for unlock");


1666     } else if (ctrl->is_Region()) {
1667       // Check for a simple diamond pattern.  Punt on anything more complicated
1668       if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
1669         Node *in1 = next_control(ctrl->in(1));
1670         Node *in2 = next_control(ctrl->in(2));
1671         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1672              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1673           ctrl = next_control(in1->in(0)->in(0));
1674         } else {
1675           break;
1676         }
1677       } else {
1678         break;
1679       }
1680     } else {
1681       ctrl = next_control(ctrl->in(0));  // keep searching
1682     }
1683   }
1684   if (ctrl->is_Lock()) {
1685     LockNode *lock = ctrl->as_Lock();
1686     if (lock->obj_node()->eqv_uncast(unlock->obj_node()) &&







1687         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
1688       lock_result = lock;
1689     }
1690   }
1691   return lock_result;
1692 }
1693 
1694 // This code corresponds to case 3 above.
1695 
1696 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
1697                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
1698   Node* if_node = node->in(0);
1699   bool  if_true = node->is_IfTrue();
1700 
1701   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
1702     Node *lock_ctrl = next_control(if_node->in(0));
1703     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
1704       Node* lock1_node = NULL;
1705       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
1706       if (if_true) {
1707         if (proj->is_IfFalse() && proj->outcnt() == 1) {
1708           lock1_node = proj->unique_out();
1709         }
1710       } else {
1711         if (proj->is_IfTrue() && proj->outcnt() == 1) {
1712           lock1_node = proj->unique_out();
1713         }
1714       }
1715       if (lock1_node != NULL && lock1_node->is_Lock()) {
1716         LockNode *lock1 = lock1_node->as_Lock();
1717         if (lock->obj_node()->eqv_uncast(lock1->obj_node()) &&







1718             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
1719             !lock1->is_eliminated()) {
1720           lock_ops.append(lock1);
1721           return true;
1722         }
1723       }
1724     }
1725   }
1726 
1727   lock_ops.trunc_to(0);
1728   return false;
1729 }
1730 
1731 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
1732                                GrowableArray<AbstractLockNode*> &lock_ops) {
1733   // check each control merging at this point for a matching unlock.
1734   // in(0) should be self edge so skip it.
1735   for (int i = 1; i < (int)region->req(); i++) {
1736     Node *in_node = next_control(region->in(i));
1737     if (in_node != NULL) {


1914 #endif
1915     return false; // External lock or it is not Box (Phi node).
1916   }
1917 
1918   // Ignore complex cases: merged locks or multiple locks.
1919   Node* obj = obj_node();
1920   LockNode* unique_lock = NULL;
1921   if (!box->is_simple_lock_region(&unique_lock, obj)) {
1922 #ifdef ASSERT
1923     this->log_lock_optimization(c, "eliminate_lock_INLR_2a");
1924 #endif
1925     return false;
1926   }
1927   if (unique_lock != this) {
1928 #ifdef ASSERT
1929     this->log_lock_optimization(c, "eliminate_lock_INLR_2b");
1930 #endif
1931     return false;
1932   }
1933 




1934   // Look for external lock for the same object.
1935   SafePointNode* sfn = this->as_SafePoint();
1936   JVMState* youngest_jvms = sfn->jvms();
1937   int max_depth = youngest_jvms->depth();
1938   for (int depth = 1; depth <= max_depth; depth++) {
1939     JVMState* jvms = youngest_jvms->of_depth(depth);
1940     int num_mon  = jvms->nof_monitors();
1941     // Loop over monitors
1942     for (int idx = 0; idx < num_mon; idx++) {
1943       Node* obj_node = sfn->monitor_obj(jvms, idx);



1944       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
1945       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
1946         return true;
1947       }
1948     }
1949   }
1950 #ifdef ASSERT
1951   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
1952 #endif
1953   return false;
1954 }
1955 
1956 //=============================================================================
1957 uint UnlockNode::size_of() const { return sizeof(*this); }
1958 
1959 //=============================================================================
1960 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1961 
1962   // perform any generic optimizations first (returns 'this' or NULL)
1963   Node *result = SafePointNode::Ideal(phase, can_reshape);




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "compiler/compileLog.hpp"
  27 #include "ci/bcEscapeAnalyzer.hpp"
  28 #include "compiler/oopMap.hpp"
  29 #include "gc/shared/barrierSet.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "opto/callGenerator.hpp"
  32 #include "opto/callnode.hpp"
  33 #include "opto/castnode.hpp"
  34 #include "opto/convertnode.hpp"
  35 #include "opto/escape.hpp"
  36 #include "opto/locknode.hpp"
  37 #include "opto/machnode.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/parse.hpp"
  40 #include "opto/regalloc.hpp"
  41 #include "opto/regmask.hpp"
  42 #include "opto/rootnode.hpp"
  43 #include "opto/runtime.hpp"
  44 
  45 // Portions of code courtesy of Clifford Click
  46 
  47 // Optimization - Graph Style
  48 
  49 //=============================================================================


1081 #endif
1082 
1083 //------------------------------calling_convention-----------------------------
1084 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1085   Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
1086 }
1087 
1088 //=============================================================================
1089 //------------------------------calling_convention-----------------------------
1090 
1091 
1092 //=============================================================================
1093 #ifndef PRODUCT
1094 void CallLeafNode::dump_spec(outputStream *st) const {
1095   st->print("# ");
1096   st->print("%s", _name);
1097   CallNode::dump_spec(st);
1098 }
1099 #endif
1100 
1101 Node *CallLeafNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1102   Node* ideal = BarrierSet::barrier_set()->barrier_set_c2()->ideal_node(phase, this, can_reshape);
1103   if (ideal != NULL) {
1104     return ideal;
1105   }
1106   return CallNode::Ideal(phase, can_reshape);
1107 }
1108 
1109 //=============================================================================
1110 
1111 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1112   assert(verify_jvms(jvms), "jvms must match");
1113   int loc = jvms->locoff() + idx;
1114   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1115     // If current local idx is top then local idx - 1 could
1116     // be a long/double that needs to be killed since top could
1117     // represent the 2nd half ofthe long/double.
1118     uint ideal = in(loc -1)->ideal_reg();
1119     if (ideal == Op_RegD || ideal == Op_RegL) {
1120       // set other (low index) half to top
1121       set_req(loc - 1, in(loc));
1122     }
1123   }
1124   set_req(loc, c);
1125 }
1126 
1127 uint SafePointNode::size_of() const { return sizeof(*this); }
1128 uint SafePointNode::cmp( const Node &n ) const {


1630       } else {
1631         break;
1632       }
1633     } else {
1634       break; // found an interesting control
1635     }
1636   }
1637   return ctrl;
1638 }
1639 //
1640 // Given a control, see if it's the control projection of an Unlock which
1641 // operating on the same object as lock.
1642 //
1643 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1644                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1645   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : NULL;
1646   if (ctrl_proj != NULL && ctrl_proj->_con == TypeFunc::Control) {
1647     Node *n = ctrl_proj->in(0);
1648     if (n != NULL && n->is_Unlock()) {
1649       UnlockNode *unlock = n->as_Unlock();
1650       Node* lock_obj = lock->obj_node();
1651       Node* unlock_obj = unlock->obj_node();
1652       if (UseShenandoahGC) {
1653         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1654         lock_obj = bs->step_over_gc_barrier(lock_obj);
1655         unlock_obj = bs->step_over_gc_barrier(unlock_obj);
1656       }
1657       if (lock_obj->eqv_uncast(unlock_obj) &&
1658           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1659           !unlock->is_eliminated()) {
1660         lock_ops.append(unlock);
1661         return true;
1662       }
1663     }
1664   }
1665   return false;
1666 }
1667 
1668 //
1669 // Find the lock matching an unlock.  Returns null if a safepoint
1670 // or complicated control is encountered first.
1671 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1672   LockNode *lock_result = NULL;
1673   // find the matching lock, or an intervening safepoint
1674   Node *ctrl = next_control(unlock->in(0));
1675   while (1) {
1676     assert(ctrl != NULL, "invalid control graph");
1677     assert(!ctrl->is_Start(), "missing lock for unlock");


1682     } else if (ctrl->is_Region()) {
1683       // Check for a simple diamond pattern.  Punt on anything more complicated
1684       if (ctrl->req() == 3 && ctrl->in(1) != NULL && ctrl->in(2) != NULL) {
1685         Node *in1 = next_control(ctrl->in(1));
1686         Node *in2 = next_control(ctrl->in(2));
1687         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1688              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1689           ctrl = next_control(in1->in(0)->in(0));
1690         } else {
1691           break;
1692         }
1693       } else {
1694         break;
1695       }
1696     } else {
1697       ctrl = next_control(ctrl->in(0));  // keep searching
1698     }
1699   }
1700   if (ctrl->is_Lock()) {
1701     LockNode *lock = ctrl->as_Lock();
1702     Node* lock_obj = lock->obj_node();
1703     Node* unlock_obj = unlock->obj_node();
1704     if (UseShenandoahGC) {
1705       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1706       lock_obj = bs->step_over_gc_barrier(lock_obj);
1707       unlock_obj = bs->step_over_gc_barrier(unlock_obj);
1708     }
1709     if (lock_obj->eqv_uncast(unlock_obj) &&
1710         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
1711       lock_result = lock;
1712     }
1713   }
1714   return lock_result;
1715 }
1716 
1717 // This code corresponds to case 3 above.
1718 
1719 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
1720                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
1721   Node* if_node = node->in(0);
1722   bool  if_true = node->is_IfTrue();
1723 
1724   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
1725     Node *lock_ctrl = next_control(if_node->in(0));
1726     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
1727       Node* lock1_node = NULL;
1728       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
1729       if (if_true) {
1730         if (proj->is_IfFalse() && proj->outcnt() == 1) {
1731           lock1_node = proj->unique_out();
1732         }
1733       } else {
1734         if (proj->is_IfTrue() && proj->outcnt() == 1) {
1735           lock1_node = proj->unique_out();
1736         }
1737       }
1738       if (lock1_node != NULL && lock1_node->is_Lock()) {
1739         LockNode *lock1 = lock1_node->as_Lock();
1740         Node* lock_obj = lock->obj_node();
1741         Node* lock1_obj = lock1->obj_node();
1742         if (UseShenandoahGC) {
1743           BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1744           lock_obj = bs->step_over_gc_barrier(lock_obj);
1745           lock1_obj = bs->step_over_gc_barrier(lock1_obj);
1746         }
1747         if (lock_obj->eqv_uncast(lock1_obj) &&
1748             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
1749             !lock1->is_eliminated()) {
1750           lock_ops.append(lock1);
1751           return true;
1752         }
1753       }
1754     }
1755   }
1756 
1757   lock_ops.trunc_to(0);
1758   return false;
1759 }
1760 
1761 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
1762                                GrowableArray<AbstractLockNode*> &lock_ops) {
1763   // check each control merging at this point for a matching unlock.
1764   // in(0) should be self edge so skip it.
1765   for (int i = 1; i < (int)region->req(); i++) {
1766     Node *in_node = next_control(region->in(i));
1767     if (in_node != NULL) {


1944 #endif
1945     return false; // External lock or it is not Box (Phi node).
1946   }
1947 
1948   // Ignore complex cases: merged locks or multiple locks.
1949   Node* obj = obj_node();
1950   LockNode* unique_lock = NULL;
1951   if (!box->is_simple_lock_region(&unique_lock, obj)) {
1952 #ifdef ASSERT
1953     this->log_lock_optimization(c, "eliminate_lock_INLR_2a");
1954 #endif
1955     return false;
1956   }
1957   if (unique_lock != this) {
1958 #ifdef ASSERT
1959     this->log_lock_optimization(c, "eliminate_lock_INLR_2b");
1960 #endif
1961     return false;
1962   }
1963 
1964   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1965   if (UseShenandoahGC) {
1966     obj = bs->step_over_gc_barrier(obj);
1967   }
1968   // Look for external lock for the same object.
1969   SafePointNode* sfn = this->as_SafePoint();
1970   JVMState* youngest_jvms = sfn->jvms();
1971   int max_depth = youngest_jvms->depth();
1972   for (int depth = 1; depth <= max_depth; depth++) {
1973     JVMState* jvms = youngest_jvms->of_depth(depth);
1974     int num_mon  = jvms->nof_monitors();
1975     // Loop over monitors
1976     for (int idx = 0; idx < num_mon; idx++) {
1977       Node* obj_node = sfn->monitor_obj(jvms, idx);
1978       if (UseShenandoahGC) {
1979         obj_node = bs->step_over_gc_barrier(obj_node);
1980       }
1981       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
1982       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
1983         return true;
1984       }
1985     }
1986   }
1987 #ifdef ASSERT
1988   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
1989 #endif
1990   return false;
1991 }
1992 
1993 //=============================================================================
1994 uint UnlockNode::size_of() const { return sizeof(*this); }
1995 
1996 //=============================================================================
1997 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
1998 
1999   // perform any generic optimizations first (returns 'this' or NULL)
2000   Node *result = SafePointNode::Ideal(phase, can_reshape);


< prev index next >