< 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 //=============================================================================


1065 #endif
1066 
1067 //------------------------------calling_convention-----------------------------
1068 void CallRuntimeNode::calling_convention( BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt ) const {
1069   Matcher::c_calling_convention( sig_bt, parm_regs, argcnt );
1070 }
1071 
1072 //=============================================================================
1073 //------------------------------calling_convention-----------------------------
1074 
1075 
1076 //=============================================================================
1077 #ifndef PRODUCT
1078 void CallLeafNode::dump_spec(outputStream *st) const {
1079   st->print("# ");
1080   st->print("%s", _name);
1081   CallNode::dump_spec(st);
1082 }
1083 #endif
1084 








1085 //=============================================================================
1086 
1087 void SafePointNode::set_local(JVMState* jvms, uint idx, Node *c) {
1088   assert(verify_jvms(jvms), "jvms must match");
1089   int loc = jvms->locoff() + idx;
1090   if (in(loc)->is_top() && idx > 0 && !c->is_top() ) {
1091     // If current local idx is top then local idx - 1 could
1092     // be a long/double that needs to be killed since top could
1093     // represent the 2nd half ofthe long/double.
1094     uint ideal = in(loc -1)->ideal_reg();
1095     if (ideal == Op_RegD || ideal == Op_RegL) {
1096       // set other (low index) half to top
1097       set_req(loc - 1, in(loc));
1098     }
1099   }
1100   set_req(loc, c);
1101 }
1102 
1103 uint SafePointNode::size_of() const { return sizeof(*this); }
1104 uint SafePointNode::cmp( const Node &n ) const {


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);




   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 //=============================================================================


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


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


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


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


< prev index next >