< prev index next >

src/hotspot/share/opto/callnode.cpp

Print this page

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

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

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

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

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

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


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

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