< prev index next >

src/hotspot/share/opto/callnode.cpp

Print this page

1939       } else {
1940         break;
1941       }
1942     } else {
1943       break; // found an interesting control
1944     }
1945   }
1946   return ctrl;
1947 }
1948 //
1949 // Given a control, see if it's the control projection of an Unlock which
1950 // operating on the same object as lock.
1951 //
1952 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1953                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1954   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : nullptr;
1955   if (ctrl_proj != nullptr && ctrl_proj->_con == TypeFunc::Control) {
1956     Node *n = ctrl_proj->in(0);
1957     if (n != nullptr && n->is_Unlock()) {
1958       UnlockNode *unlock = n->as_Unlock();
1959       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
1960       Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
1961       Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
1962       if (lock_obj->eqv_uncast(unlock_obj) &&
1963           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1964           !unlock->is_eliminated()) {
1965         lock_ops.append(unlock);
1966         return true;
1967       }
1968     }
1969   }
1970   return false;
1971 }
1972 
1973 //
1974 // Find the lock matching an unlock.  Returns null if a safepoint
1975 // or complicated control is encountered first.
1976 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1977   LockNode *lock_result = nullptr;
1978   // find the matching lock, or an intervening safepoint
1979   Node *ctrl = next_control(unlock->in(0));
1980   while (1) {
1981     assert(ctrl != nullptr, "invalid control graph");

1987     } else if (ctrl->is_Region()) {
1988       // Check for a simple diamond pattern.  Punt on anything more complicated
1989       if (ctrl->req() == 3 && ctrl->in(1) != nullptr && ctrl->in(2) != nullptr) {
1990         Node *in1 = next_control(ctrl->in(1));
1991         Node *in2 = next_control(ctrl->in(2));
1992         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1993              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1994           ctrl = next_control(in1->in(0)->in(0));
1995         } else {
1996           break;
1997         }
1998       } else {
1999         break;
2000       }
2001     } else {
2002       ctrl = next_control(ctrl->in(0));  // keep searching
2003     }
2004   }
2005   if (ctrl->is_Lock()) {
2006     LockNode *lock = ctrl->as_Lock();
2007     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2008     Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
2009     Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
2010     if (lock_obj->eqv_uncast(unlock_obj) &&
2011         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
2012       lock_result = lock;
2013     }
2014   }
2015   return lock_result;
2016 }
2017 
2018 // This code corresponds to case 3 above.
2019 
2020 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
2021                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
2022   Node* if_node = node->in(0);
2023   bool  if_true = node->is_IfTrue();
2024 
2025   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
2026     Node *lock_ctrl = next_control(if_node->in(0));
2027     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
2028       Node* lock1_node = nullptr;
2029       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
2030       if (if_true) {
2031         if (proj->is_IfFalse() && proj->outcnt() == 1) {
2032           lock1_node = proj->unique_out();
2033         }
2034       } else {
2035         if (proj->is_IfTrue() && proj->outcnt() == 1) {
2036           lock1_node = proj->unique_out();
2037         }
2038       }
2039       if (lock1_node != nullptr && lock1_node->is_Lock()) {
2040         LockNode *lock1 = lock1_node->as_Lock();
2041         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2042         Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
2043         Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
2044         if (lock_obj->eqv_uncast(lock1_obj) &&
2045             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
2046             !lock1->is_eliminated()) {
2047           lock_ops.append(lock1);
2048           return true;
2049         }
2050       }
2051     }
2052   }
2053 
2054   lock_ops.trunc_to(0);
2055   return false;
2056 }
2057 
2058 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
2059                                GrowableArray<AbstractLockNode*> &lock_ops) {
2060   // check each control merging at this point for a matching unlock.
2061   // in(0) should be self edge so skip it.
2062   for (int i = 1; i < (int)region->req(); i++) {
2063     Node *in_node = next_control(region->in(i));

2283       tty->print(" this: ");
2284       this->dump();
2285       tty->print(" box: ");
2286       box->dump();
2287       tty->print(" obj: ");
2288       obj->dump();
2289       if (unique_lock != nullptr) {
2290         tty->print(" unique_lock: ");
2291         unique_lock->dump();
2292       }
2293       if (bad_lock != nullptr) {
2294         tty->print(" bad_lock: ");
2295         bad_lock->dump();
2296       }
2297       tty->print_cr("===============");
2298     }
2299 #endif
2300     return false;
2301   }
2302 
2303   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2304   obj = bs->step_over_gc_barrier(obj);
2305   // Look for external lock for the same object.
2306   SafePointNode* sfn = this->as_SafePoint();
2307   JVMState* youngest_jvms = sfn->jvms();
2308   int max_depth = youngest_jvms->depth();
2309   for (int depth = 1; depth <= max_depth; depth++) {
2310     JVMState* jvms = youngest_jvms->of_depth(depth);
2311     int num_mon  = jvms->nof_monitors();
2312     // Loop over monitors
2313     for (int idx = 0; idx < num_mon; idx++) {
2314       Node* obj_node = sfn->monitor_obj(jvms, idx);
2315       obj_node = bs->step_over_gc_barrier(obj_node);
2316       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
2317       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
2318         box->set_nested();
2319         return true;
2320       }
2321     }
2322   }
2323 #ifdef ASSERT
2324   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
2325 #endif
2326   return false;
2327 }
2328 
2329 //=============================================================================
2330 uint UnlockNode::size_of() const { return sizeof(*this); }
2331 
2332 //=============================================================================
2333 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2334 
2335   // perform any generic optimizations first (returns 'this' or null)

1939       } else {
1940         break;
1941       }
1942     } else {
1943       break; // found an interesting control
1944     }
1945   }
1946   return ctrl;
1947 }
1948 //
1949 // Given a control, see if it's the control projection of an Unlock which
1950 // operating on the same object as lock.
1951 //
1952 bool AbstractLockNode::find_matching_unlock(const Node* ctrl, LockNode* lock,
1953                                             GrowableArray<AbstractLockNode*> &lock_ops) {
1954   ProjNode *ctrl_proj = (ctrl->is_Proj()) ? ctrl->as_Proj() : nullptr;
1955   if (ctrl_proj != nullptr && ctrl_proj->_con == TypeFunc::Control) {
1956     Node *n = ctrl_proj->in(0);
1957     if (n != nullptr && n->is_Unlock()) {
1958       UnlockNode *unlock = n->as_Unlock();
1959       Node* lock_obj = lock->obj_node();
1960       Node* unlock_obj = unlock->obj_node();

1961       if (lock_obj->eqv_uncast(unlock_obj) &&
1962           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
1963           !unlock->is_eliminated()) {
1964         lock_ops.append(unlock);
1965         return true;
1966       }
1967     }
1968   }
1969   return false;
1970 }
1971 
1972 //
1973 // Find the lock matching an unlock.  Returns null if a safepoint
1974 // or complicated control is encountered first.
1975 LockNode *AbstractLockNode::find_matching_lock(UnlockNode* unlock) {
1976   LockNode *lock_result = nullptr;
1977   // find the matching lock, or an intervening safepoint
1978   Node *ctrl = next_control(unlock->in(0));
1979   while (1) {
1980     assert(ctrl != nullptr, "invalid control graph");

1986     } else if (ctrl->is_Region()) {
1987       // Check for a simple diamond pattern.  Punt on anything more complicated
1988       if (ctrl->req() == 3 && ctrl->in(1) != nullptr && ctrl->in(2) != nullptr) {
1989         Node *in1 = next_control(ctrl->in(1));
1990         Node *in2 = next_control(ctrl->in(2));
1991         if (((in1->is_IfTrue() && in2->is_IfFalse()) ||
1992              (in2->is_IfTrue() && in1->is_IfFalse())) && (in1->in(0) == in2->in(0))) {
1993           ctrl = next_control(in1->in(0)->in(0));
1994         } else {
1995           break;
1996         }
1997       } else {
1998         break;
1999       }
2000     } else {
2001       ctrl = next_control(ctrl->in(0));  // keep searching
2002     }
2003   }
2004   if (ctrl->is_Lock()) {
2005     LockNode *lock = ctrl->as_Lock();
2006     Node* lock_obj = lock->obj_node();
2007     Node* unlock_obj = unlock->obj_node();

2008     if (lock_obj->eqv_uncast(unlock_obj) &&
2009         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
2010       lock_result = lock;
2011     }
2012   }
2013   return lock_result;
2014 }
2015 
2016 // This code corresponds to case 3 above.
2017 
2018 bool AbstractLockNode::find_lock_and_unlock_through_if(Node* node, LockNode* lock,
2019                                                        GrowableArray<AbstractLockNode*> &lock_ops) {
2020   Node* if_node = node->in(0);
2021   bool  if_true = node->is_IfTrue();
2022 
2023   if (if_node->is_If() && if_node->outcnt() == 2 && (if_true || node->is_IfFalse())) {
2024     Node *lock_ctrl = next_control(if_node->in(0));
2025     if (find_matching_unlock(lock_ctrl, lock, lock_ops)) {
2026       Node* lock1_node = nullptr;
2027       ProjNode* proj = if_node->as_If()->proj_out(!if_true);
2028       if (if_true) {
2029         if (proj->is_IfFalse() && proj->outcnt() == 1) {
2030           lock1_node = proj->unique_out();
2031         }
2032       } else {
2033         if (proj->is_IfTrue() && proj->outcnt() == 1) {
2034           lock1_node = proj->unique_out();
2035         }
2036       }
2037       if (lock1_node != nullptr && lock1_node->is_Lock()) {
2038         LockNode *lock1 = lock1_node->as_Lock();
2039         Node* lock_obj = lock->obj_node();
2040         Node* lock1_obj = lock1->obj_node();

2041         if (lock_obj->eqv_uncast(lock1_obj) &&
2042             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
2043             !lock1->is_eliminated()) {
2044           lock_ops.append(lock1);
2045           return true;
2046         }
2047       }
2048     }
2049   }
2050 
2051   lock_ops.trunc_to(0);
2052   return false;
2053 }
2054 
2055 bool AbstractLockNode::find_unlocks_for_region(const RegionNode* region, LockNode* lock,
2056                                GrowableArray<AbstractLockNode*> &lock_ops) {
2057   // check each control merging at this point for a matching unlock.
2058   // in(0) should be self edge so skip it.
2059   for (int i = 1; i < (int)region->req(); i++) {
2060     Node *in_node = next_control(region->in(i));

2280       tty->print(" this: ");
2281       this->dump();
2282       tty->print(" box: ");
2283       box->dump();
2284       tty->print(" obj: ");
2285       obj->dump();
2286       if (unique_lock != nullptr) {
2287         tty->print(" unique_lock: ");
2288         unique_lock->dump();
2289       }
2290       if (bad_lock != nullptr) {
2291         tty->print(" bad_lock: ");
2292         bad_lock->dump();
2293       }
2294       tty->print_cr("===============");
2295     }
2296 #endif
2297     return false;
2298   }
2299 


2300   // Look for external lock for the same object.
2301   SafePointNode* sfn = this->as_SafePoint();
2302   JVMState* youngest_jvms = sfn->jvms();
2303   int max_depth = youngest_jvms->depth();
2304   for (int depth = 1; depth <= max_depth; depth++) {
2305     JVMState* jvms = youngest_jvms->of_depth(depth);
2306     int num_mon  = jvms->nof_monitors();
2307     // Loop over monitors
2308     for (int idx = 0; idx < num_mon; idx++) {
2309       Node* obj_node = sfn->monitor_obj(jvms, idx);

2310       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
2311       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
2312         box->set_nested();
2313         return true;
2314       }
2315     }
2316   }
2317 #ifdef ASSERT
2318   this->log_lock_optimization(c, "eliminate_lock_INLR_3");
2319 #endif
2320   return false;
2321 }
2322 
2323 //=============================================================================
2324 uint UnlockNode::size_of() const { return sizeof(*this); }
2325 
2326 //=============================================================================
2327 Node *UnlockNode::Ideal(PhaseGVN *phase, bool can_reshape) {
2328 
2329   // perform any generic optimizations first (returns 'this' or null)
< prev index next >