< prev index next >

src/share/vm/opto/macro.cpp

Print this page


   1 /*
   2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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  *


1882     return; // This BoxLock node was processed already.
1883 
1884   // New implementation (EliminateNestedLocks) has separate BoxLock
1885   // node for each locked region so mark all associated locks/unlocks as
1886   // eliminated even if different objects are referenced in one locked region
1887   // (for example, OSR compilation of nested loop inside locked scope).
1888   if (EliminateNestedLocks ||
1889       oldbox->as_BoxLock()->is_simple_lock_region(NULL, obj)) {
1890     // Box is used only in one lock region. Mark this box as eliminated.
1891     _igvn.hash_delete(oldbox);
1892     oldbox->as_BoxLock()->set_eliminated(); // This changes box's hash value
1893     _igvn.hash_insert(oldbox);
1894 
1895     for (uint i = 0; i < oldbox->outcnt(); i++) {
1896       Node* u = oldbox->raw_out(i);
1897       if (u->is_AbstractLock() && !u->as_AbstractLock()->is_non_esc_obj()) {
1898         AbstractLockNode* alock = u->as_AbstractLock();
1899         // Check lock's box since box could be referenced by Lock's debug info.
1900         if (alock->box_node() == oldbox) {
1901           // Mark eliminated all related locks and unlocks.



1902           alock->set_non_esc_obj();
1903         }
1904       }
1905     }
1906     return;
1907   }
1908 
1909   // Create new "eliminated" BoxLock node and use it in monitor debug info
1910   // instead of oldbox for the same object.
1911   BoxLockNode* newbox = oldbox->clone()->as_BoxLock();
1912 
1913   // Note: BoxLock node is marked eliminated only here and it is used
1914   // to indicate that all associated lock and unlock nodes are marked
1915   // for elimination.
1916   newbox->set_eliminated();
1917   transform_later(newbox);
1918 
1919   // Replace old box node with new box for all users of the same object.
1920   for (uint i = 0; i < oldbox->outcnt();) {
1921     bool next_edge = true;
1922 
1923     Node* u = oldbox->raw_out(i);
1924     if (u->is_AbstractLock()) {
1925       AbstractLockNode* alock = u->as_AbstractLock();
1926       if (alock->box_node() == oldbox && alock->obj_node()->eqv_uncast(obj)) {
1927         // Replace Box and mark eliminated all related locks and unlocks.



1928         alock->set_non_esc_obj();
1929         _igvn.rehash_node_delayed(alock);
1930         alock->set_box_node(newbox);
1931         next_edge = false;
1932       }
1933     }
1934     if (u->is_FastLock() && u->as_FastLock()->obj_node()->eqv_uncast(obj)) {
1935       FastLockNode* flock = u->as_FastLock();
1936       assert(flock->box_node() == oldbox, "sanity");
1937       _igvn.rehash_node_delayed(flock);
1938       flock->set_box_node(newbox);
1939       next_edge = false;
1940     }
1941 
1942     // Replace old box in monitor debug info.
1943     if (u->is_SafePoint() && u->as_SafePoint()->jvms()) {
1944       SafePointNode* sfn = u->as_SafePoint();
1945       JVMState* youngest_jvms = sfn->jvms();
1946       int max_depth = youngest_jvms->depth();
1947       for (int depth = 1; depth <= max_depth; depth++) {


1954           if (box_node == oldbox && obj_node->eqv_uncast(obj)) {
1955             int j = jvms->monitor_box_offset(idx);
1956             _igvn.replace_input_of(u, j, newbox);
1957             next_edge = false;
1958           }
1959         }
1960       }
1961     }
1962     if (next_edge) i++;
1963   }
1964 }
1965 
1966 //-----------------------mark_eliminated_locking_nodes-----------------------
1967 void PhaseMacroExpand::mark_eliminated_locking_nodes(AbstractLockNode *alock) {
1968   if (EliminateNestedLocks) {
1969     if (alock->is_nested()) {
1970        assert(alock->box_node()->as_BoxLock()->is_eliminated(), "sanity");
1971        return;
1972     } else if (!alock->is_non_esc_obj()) { // Not eliminated or coarsened
1973       // Only Lock node has JVMState needed here.
1974       if (alock->jvms() != NULL && alock->as_Lock()->is_nested_lock_region()) {


1975         // Mark eliminated related nested locks and unlocks.
1976         Node* obj = alock->obj_node();
1977         BoxLockNode* box_node = alock->box_node()->as_BoxLock();
1978         assert(!box_node->is_eliminated(), "should not be marked yet");
1979         // Note: BoxLock node is marked eliminated only here
1980         // and it is used to indicate that all associated lock
1981         // and unlock nodes are marked for elimination.
1982         box_node->set_eliminated(); // Box's hash is always NO_HASH here
1983         for (uint i = 0; i < box_node->outcnt(); i++) {
1984           Node* u = box_node->raw_out(i);
1985           if (u->is_AbstractLock()) {
1986             alock = u->as_AbstractLock();
1987             if (alock->box_node() == box_node) {
1988               // Verify that this Box is referenced only by related locks.
1989               assert(alock->obj_node()->eqv_uncast(obj), "");
1990               // Mark all related locks and unlocks.



1991               alock->set_nested();
1992             }
1993           }
1994         }






1995       }
1996       return;
1997     }
1998     // Process locks for non escaping object
1999     assert(alock->is_non_esc_obj(), "");
2000   } // EliminateNestedLocks
2001 
2002   if (alock->is_non_esc_obj()) { // Lock is used for non escaping object
2003     // Look for all locks of this object and mark them and
2004     // corresponding BoxLock nodes as eliminated.
2005     Node* obj = alock->obj_node();
2006     for (uint j = 0; j < obj->outcnt(); j++) {
2007       Node* o = obj->raw_out(j);
2008       if (o->is_AbstractLock() &&
2009           o->as_AbstractLock()->obj_node()->eqv_uncast(obj)) {
2010         alock = o->as_AbstractLock();
2011         Node* box = alock->box_node();
2012         // Replace old box node with new eliminated box for all users
2013         // of the same object and mark related locks as eliminated.
2014         mark_eliminated_box(box, obj);


2018 }
2019 
2020 // we have determined that this lock/unlock can be eliminated, we simply
2021 // eliminate the node without expanding it.
2022 //
2023 // Note:  The membar's associated with the lock/unlock are currently not
2024 //        eliminated.  This should be investigated as a future enhancement.
2025 //
2026 bool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
2027 
2028   if (!alock->is_eliminated()) {
2029     return false;
2030   }
2031 #ifdef ASSERT
2032   if (!alock->is_coarsened()) {
2033     // Check that new "eliminated" BoxLock node is created.
2034     BoxLockNode* oldbox = alock->box_node()->as_BoxLock();
2035     assert(oldbox->is_eliminated(), "should be done already");
2036   }
2037 #endif
2038   CompileLog* log = C->log();
2039   if (log != NULL) {
2040     log->head("eliminate_lock lock='%d'",
2041               alock->is_Lock());
2042     JVMState* p = alock->jvms();
2043     while (p != NULL) {
2044       log->elem("jvms bci='%d' method='%d'", p->bci(), log->identify(p->method()));
2045       p = p->caller();
2046     }
2047     log->tail("eliminate_lock");
2048   }
2049 
2050   #ifndef PRODUCT


2051   if (PrintEliminateLocks) {
2052     if (alock->is_Lock()) {
2053       tty->print_cr("++++ Eliminated: %d Lock", alock->_idx);
2054     } else {
2055       tty->print_cr("++++ Eliminated: %d Unlock", alock->_idx);
2056     }
2057   }
2058   #endif
2059 
2060   Node* mem  = alock->in(TypeFunc::Memory);
2061   Node* ctrl = alock->in(TypeFunc::Control);
2062 
2063   extract_call_projections(alock);
2064   // There are 2 projections from the lock.  The lock node will
2065   // be deleted when its last use is subsumed below.
2066   assert(alock->outcnt() == 2 &&
2067          _fallthroughproj != NULL &&
2068          _memproj_fallthrough != NULL,
2069          "Unexpected projections from Lock/Unlock");
2070 
2071   Node* fallthroughproj = _fallthroughproj;
2072   Node* memproj_fallthrough = _memproj_fallthrough;
2073 
2074   // The memory projection from a lock/unlock is RawMem
2075   // The input to a Lock is merged memory, so extract its RawMem input
2076   // (unless the MergeMem has been optimized away.)
2077   if (alock->is_Lock()) {
2078     // Seach for MemBarAcquireLock node and delete it also.


   1 /*
   2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   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  *


1882     return; // This BoxLock node was processed already.
1883 
1884   // New implementation (EliminateNestedLocks) has separate BoxLock
1885   // node for each locked region so mark all associated locks/unlocks as
1886   // eliminated even if different objects are referenced in one locked region
1887   // (for example, OSR compilation of nested loop inside locked scope).
1888   if (EliminateNestedLocks ||
1889       oldbox->as_BoxLock()->is_simple_lock_region(NULL, obj)) {
1890     // Box is used only in one lock region. Mark this box as eliminated.
1891     _igvn.hash_delete(oldbox);
1892     oldbox->as_BoxLock()->set_eliminated(); // This changes box's hash value
1893      _igvn.hash_insert(oldbox);
1894 
1895     for (uint i = 0; i < oldbox->outcnt(); i++) {
1896       Node* u = oldbox->raw_out(i);
1897       if (u->is_AbstractLock() && !u->as_AbstractLock()->is_non_esc_obj()) {
1898         AbstractLockNode* alock = u->as_AbstractLock();
1899         // Check lock's box since box could be referenced by Lock's debug info.
1900         if (alock->box_node() == oldbox) {
1901           // Mark eliminated all related locks and unlocks.
1902 #ifdef ASSERT
1903           alock->log_lock_optimization(C, "eliminate_lock_set_non_esc4");
1904 #endif
1905           alock->set_non_esc_obj();
1906         }
1907       }
1908     }
1909     return;
1910   }
1911 
1912   // Create new "eliminated" BoxLock node and use it in monitor debug info
1913   // instead of oldbox for the same object.
1914   BoxLockNode* newbox = oldbox->clone()->as_BoxLock();
1915 
1916   // Note: BoxLock node is marked eliminated only here and it is used
1917   // to indicate that all associated lock and unlock nodes are marked
1918   // for elimination.
1919   newbox->set_eliminated();
1920   transform_later(newbox);
1921 
1922   // Replace old box node with new box for all users of the same object.
1923   for (uint i = 0; i < oldbox->outcnt();) {
1924     bool next_edge = true;
1925 
1926     Node* u = oldbox->raw_out(i);
1927     if (u->is_AbstractLock()) {
1928       AbstractLockNode* alock = u->as_AbstractLock();
1929       if (alock->box_node() == oldbox && alock->obj_node()->eqv_uncast(obj)) {
1930         // Replace Box and mark eliminated all related locks and unlocks.
1931 #ifdef ASSERT
1932         alock->log_lock_optimization(C, "eliminate_lock_set_non_esc5");
1933 #endif
1934         alock->set_non_esc_obj();
1935         _igvn.rehash_node_delayed(alock);
1936         alock->set_box_node(newbox);
1937         next_edge = false;
1938       }
1939     }
1940     if (u->is_FastLock() && u->as_FastLock()->obj_node()->eqv_uncast(obj)) {
1941       FastLockNode* flock = u->as_FastLock();
1942       assert(flock->box_node() == oldbox, "sanity");
1943       _igvn.rehash_node_delayed(flock);
1944       flock->set_box_node(newbox);
1945       next_edge = false;
1946     }
1947 
1948     // Replace old box in monitor debug info.
1949     if (u->is_SafePoint() && u->as_SafePoint()->jvms()) {
1950       SafePointNode* sfn = u->as_SafePoint();
1951       JVMState* youngest_jvms = sfn->jvms();
1952       int max_depth = youngest_jvms->depth();
1953       for (int depth = 1; depth <= max_depth; depth++) {


1960           if (box_node == oldbox && obj_node->eqv_uncast(obj)) {
1961             int j = jvms->monitor_box_offset(idx);
1962             _igvn.replace_input_of(u, j, newbox);
1963             next_edge = false;
1964           }
1965         }
1966       }
1967     }
1968     if (next_edge) i++;
1969   }
1970 }
1971 
1972 //-----------------------mark_eliminated_locking_nodes-----------------------
1973 void PhaseMacroExpand::mark_eliminated_locking_nodes(AbstractLockNode *alock) {
1974   if (EliminateNestedLocks) {
1975     if (alock->is_nested()) {
1976        assert(alock->box_node()->as_BoxLock()->is_eliminated(), "sanity");
1977        return;
1978     } else if (!alock->is_non_esc_obj()) { // Not eliminated or coarsened
1979       // Only Lock node has JVMState needed here.
1980       // Not that preceding claim is documented anywhere else.
1981       if (alock->jvms() != NULL) {
1982         if (alock->as_Lock()->is_nested_lock_region()) {
1983           // Mark eliminated related nested locks and unlocks.
1984           Node* obj = alock->obj_node();
1985           BoxLockNode* box_node = alock->box_node()->as_BoxLock();
1986           assert(!box_node->is_eliminated(), "should not be marked yet");
1987           // Note: BoxLock node is marked eliminated only here
1988           // and it is used to indicate that all associated lock
1989           // and unlock nodes are marked for elimination.
1990           box_node->set_eliminated(); // Box's hash is always NO_HASH here
1991           for (uint i = 0; i < box_node->outcnt(); i++) {
1992             Node* u = box_node->raw_out(i);
1993             if (u->is_AbstractLock()) {
1994               alock = u->as_AbstractLock();
1995               if (alock->box_node() == box_node) {
1996                 // Verify that this Box is referenced only by related locks.
1997                 assert(alock->obj_node()->eqv_uncast(obj), "");
1998                 // Mark all related locks and unlocks.
1999 #ifdef ASSERT
2000                 alock->log_lock_optimization(C, "eliminate_lock_set_nested");
2001 #endif
2002                 alock->set_nested();
2003               }
2004             }
2005           }
2006         } else {
2007 #ifdef ASSERT
2008           alock->log_lock_optimization(C, "eliminate_lock_NOT_nested_lock_region");
2009           alock->as_Lock()->is_nested_lock_region_debug(C);
2010 #endif
2011         }
2012       }
2013       return;
2014     }
2015     // Process locks for non escaping object
2016     assert(alock->is_non_esc_obj(), "");
2017   } // EliminateNestedLocks
2018 
2019   if (alock->is_non_esc_obj()) { // Lock is used for non escaping object
2020     // Look for all locks of this object and mark them and
2021     // corresponding BoxLock nodes as eliminated.
2022     Node* obj = alock->obj_node();
2023     for (uint j = 0; j < obj->outcnt(); j++) {
2024       Node* o = obj->raw_out(j);
2025       if (o->is_AbstractLock() &&
2026           o->as_AbstractLock()->obj_node()->eqv_uncast(obj)) {
2027         alock = o->as_AbstractLock();
2028         Node* box = alock->box_node();
2029         // Replace old box node with new eliminated box for all users
2030         // of the same object and mark related locks as eliminated.
2031         mark_eliminated_box(box, obj);


2035 }
2036 
2037 // we have determined that this lock/unlock can be eliminated, we simply
2038 // eliminate the node without expanding it.
2039 //
2040 // Note:  The membar's associated with the lock/unlock are currently not
2041 //        eliminated.  This should be investigated as a future enhancement.
2042 //
2043 bool PhaseMacroExpand::eliminate_locking_node(AbstractLockNode *alock) {
2044 
2045   if (!alock->is_eliminated()) {
2046     return false;
2047   }
2048 #ifdef ASSERT
2049   if (!alock->is_coarsened()) {
2050     // Check that new "eliminated" BoxLock node is created.
2051     BoxLockNode* oldbox = alock->box_node()->as_BoxLock();
2052     assert(oldbox->is_eliminated(), "should be done already");
2053   }
2054 #endif











2055 
2056   alock->log_lock_optimization(C, "eliminate_lock");
2057 
2058 #ifndef PRODUCT
2059   if (PrintEliminateLocks) {
2060     if (alock->is_Lock()) {
2061       tty->print_cr("++++ Eliminated: %d Lock", alock->_idx);
2062     } else {
2063       tty->print_cr("++++ Eliminated: %d Unlock", alock->_idx);
2064     }
2065   }
2066 #endif
2067 
2068   Node* mem  = alock->in(TypeFunc::Memory);
2069   Node* ctrl = alock->in(TypeFunc::Control);
2070 
2071   extract_call_projections(alock);
2072   // There are 2 projections from the lock.  The lock node will
2073   // be deleted when its last use is subsumed below.
2074   assert(alock->outcnt() == 2 &&
2075          _fallthroughproj != NULL &&
2076          _memproj_fallthrough != NULL,
2077          "Unexpected projections from Lock/Unlock");
2078 
2079   Node* fallthroughproj = _fallthroughproj;
2080   Node* memproj_fallthrough = _memproj_fallthrough;
2081 
2082   // The memory projection from a lock/unlock is RawMem
2083   // The input to a Lock is merged memory, so extract its RawMem input
2084   // (unless the MergeMem has been optimized away.)
2085   if (alock->is_Lock()) {
2086     // Seach for MemBarAcquireLock node and delete it also.


< prev index next >