< prev index next >

src/hotspot/share/runtime/synchronizer.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 "classfile/vmSymbols.hpp"
  27 #include "gc/shared/suspendibleThreadSet.hpp"
  28 #include "jfr/jfrEvents.hpp"

  29 #include "logging/log.hpp"
  30 #include "logging/logStream.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/padded.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/markWord.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "runtime/atomic.hpp"
  38 #include "runtime/frame.inline.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/handshake.hpp"
  41 #include "runtime/interfaceSupport.inline.hpp"
  42 #include "runtime/javaThread.hpp"
  43 #include "runtime/lockStack.inline.hpp"
  44 #include "runtime/mutexLocker.hpp"
  45 #include "runtime/objectMonitor.hpp"
  46 #include "runtime/objectMonitor.inline.hpp"
  47 #include "runtime/os.inline.hpp"
  48 #include "runtime/osThread.hpp"

 885     value = 1;            // for sensitivity testing
 886   } else if (hashCode == 3) {
 887     value = ++GVars.hc_sequence;
 888   } else if (hashCode == 4) {
 889     value = cast_from_oop<intptr_t>(obj);
 890   } else {
 891     // Marsaglia's xor-shift scheme with thread-specific state
 892     // This is probably the best overall implementation -- we'll
 893     // likely make this the default in future releases.
 894     unsigned t = current->_hashStateX;
 895     t ^= (t << 11);
 896     current->_hashStateX = current->_hashStateY;
 897     current->_hashStateY = current->_hashStateZ;
 898     current->_hashStateZ = current->_hashStateW;
 899     unsigned v = current->_hashStateW;
 900     v = (v ^ (v >> 19)) ^ (t ^ (t >> 8));
 901     current->_hashStateW = v;
 902     value = v;
 903   }
 904 
 905   value &= markWord::hash_mask;
 906   if (value == 0) value = 0xBAD;
 907   assert(value != markWord::no_hash, "invariant");
 908   return value;
 909 }
 910 
 911 // Can be called from non JavaThreads (e.g., VMThread) for FastHashCode
 912 // calculations as part of JVM/TI tagging.
 913 static bool is_lock_owned(Thread* thread, oop obj) {
 914   assert(LockingMode == LM_LIGHTWEIGHT, "only call this with new lightweight locking enabled");
 915   return thread->is_Java_thread() ? JavaThread::cast(thread)->lock_stack().contains(obj) : false;
 916 }
 917 
 918 intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) {
 919 
 920   while (true) {
 921     ObjectMonitor* monitor = nullptr;
 922     markWord temp, test;
 923     intptr_t hash;
 924     markWord mark = read_stable_mark(obj);
 925     if (VerifyHeavyMonitors) {

1692     // final audit and all the remaining ObjectMonitors have been
1693     // deflated, BUT the MonitorDeflationThread blocked for the final
1694     // safepoint during unlinking.
1695 
1696     // Unlink deflated ObjectMonitors from the in-use list.
1697     ResourceMark rm;
1698     GrowableArray<ObjectMonitor*> delete_list((int)deflated_count);
1699     unlinked_count = _in_use_list.unlink_deflated(current, ls, &timer, &delete_list);
1700     if (current->is_monitor_deflation_thread()) {
1701       if (ls != nullptr) {
1702         timer.stop();
1703         ls->print_cr("before handshaking: unlinked_count=" SIZE_FORMAT
1704                      ", in_use_list stats: ceiling=" SIZE_FORMAT ", count="
1705                      SIZE_FORMAT ", max=" SIZE_FORMAT,
1706                      unlinked_count, in_use_list_ceiling(),
1707                      _in_use_list.count(), _in_use_list.max());
1708       }
1709 
1710       // A JavaThread needs to handshake in order to safely free the
1711       // ObjectMonitors that were deflated in this cycle.



1712       HandshakeForDeflation hfd_hc;
1713       Handshake::execute(&hfd_hc);
1714       // Also, we sync and desync GC threads around the handshake, so that they can
1715       // safely read the mark-word and look-through to the object-monitor, without
1716       // being afraid that the object-monitor is going away.
1717       VM_RendezvousGCThreads sync_gc;
1718       VMThread::execute(&sync_gc);
1719 
1720       if (ls != nullptr) {
1721         ls->print_cr("after handshaking: in_use_list stats: ceiling="
1722                      SIZE_FORMAT ", count=" SIZE_FORMAT ", max=" SIZE_FORMAT,
1723                      in_use_list_ceiling(), _in_use_list.count(), _in_use_list.max());
1724         timer.start();
1725       }
1726     } else {
1727       // This is not a monitor deflation thread.
1728       // No handshake or rendezvous is needed when we are already at safepoint.
1729       assert_at_safepoint();
1730     }
1731 

   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 "classfile/vmSymbols.hpp"
  27 #include "gc/shared/suspendibleThreadSet.hpp"
  28 #include "jfr/jfrEvents.hpp"
  29 #include "gc/shared/suspendibleThreadSet.hpp"
  30 #include "logging/log.hpp"
  31 #include "logging/logStream.hpp"
  32 #include "memory/allocation.inline.hpp"
  33 #include "memory/padded.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/markWord.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/atomic.hpp"
  39 #include "runtime/frame.inline.hpp"
  40 #include "runtime/handles.inline.hpp"
  41 #include "runtime/handshake.hpp"
  42 #include "runtime/interfaceSupport.inline.hpp"
  43 #include "runtime/javaThread.hpp"
  44 #include "runtime/lockStack.inline.hpp"
  45 #include "runtime/mutexLocker.hpp"
  46 #include "runtime/objectMonitor.hpp"
  47 #include "runtime/objectMonitor.inline.hpp"
  48 #include "runtime/os.inline.hpp"
  49 #include "runtime/osThread.hpp"

 886     value = 1;            // for sensitivity testing
 887   } else if (hashCode == 3) {
 888     value = ++GVars.hc_sequence;
 889   } else if (hashCode == 4) {
 890     value = cast_from_oop<intptr_t>(obj);
 891   } else {
 892     // Marsaglia's xor-shift scheme with thread-specific state
 893     // This is probably the best overall implementation -- we'll
 894     // likely make this the default in future releases.
 895     unsigned t = current->_hashStateX;
 896     t ^= (t << 11);
 897     current->_hashStateX = current->_hashStateY;
 898     current->_hashStateY = current->_hashStateZ;
 899     current->_hashStateZ = current->_hashStateW;
 900     unsigned v = current->_hashStateW;
 901     v = (v ^ (v >> 19)) ^ (t ^ (t >> 8));
 902     current->_hashStateW = v;
 903     value = v;
 904   }
 905 
 906   value &= UseCompactObjectHeaders ? markWord::hash_mask_compact : markWord::hash_mask;
 907   if (value == 0) value = 0xBAD;
 908   assert(value != markWord::no_hash, "invariant");
 909   return value;
 910 }
 911 
 912 // Can be called from non JavaThreads (e.g., VMThread) for FastHashCode
 913 // calculations as part of JVM/TI tagging.
 914 static bool is_lock_owned(Thread* thread, oop obj) {
 915   assert(LockingMode == LM_LIGHTWEIGHT, "only call this with new lightweight locking enabled");
 916   return thread->is_Java_thread() ? JavaThread::cast(thread)->lock_stack().contains(obj) : false;
 917 }
 918 
 919 intptr_t ObjectSynchronizer::FastHashCode(Thread* current, oop obj) {
 920 
 921   while (true) {
 922     ObjectMonitor* monitor = nullptr;
 923     markWord temp, test;
 924     intptr_t hash;
 925     markWord mark = read_stable_mark(obj);
 926     if (VerifyHeavyMonitors) {

1693     // final audit and all the remaining ObjectMonitors have been
1694     // deflated, BUT the MonitorDeflationThread blocked for the final
1695     // safepoint during unlinking.
1696 
1697     // Unlink deflated ObjectMonitors from the in-use list.
1698     ResourceMark rm;
1699     GrowableArray<ObjectMonitor*> delete_list((int)deflated_count);
1700     unlinked_count = _in_use_list.unlink_deflated(current, ls, &timer, &delete_list);
1701     if (current->is_monitor_deflation_thread()) {
1702       if (ls != nullptr) {
1703         timer.stop();
1704         ls->print_cr("before handshaking: unlinked_count=" SIZE_FORMAT
1705                      ", in_use_list stats: ceiling=" SIZE_FORMAT ", count="
1706                      SIZE_FORMAT ", max=" SIZE_FORMAT,
1707                      unlinked_count, in_use_list_ceiling(),
1708                      _in_use_list.count(), _in_use_list.max());
1709       }
1710 
1711       // A JavaThread needs to handshake in order to safely free the
1712       // ObjectMonitors that were deflated in this cycle.
1713       // Also, we sync and desync GC threads around the handshake, so that they can
1714       // safely read the mark-word and look-through to the object-monitor, without
1715       // being afraid that the object-monitor is going away.
1716       HandshakeForDeflation hfd_hc;
1717       Handshake::execute(&hfd_hc);
1718       // Also, we sync and desync GC threads around the handshake, so that they can
1719       // safely read the mark-word and look-through to the object-monitor, without
1720       // being afraid that the object-monitor is going away.
1721       VM_RendezvousGCThreads sync_gc;
1722       VMThread::execute(&sync_gc);
1723 
1724       if (ls != nullptr) {
1725         ls->print_cr("after handshaking: in_use_list stats: ceiling="
1726                      SIZE_FORMAT ", count=" SIZE_FORMAT ", max=" SIZE_FORMAT,
1727                      in_use_list_ceiling(), _in_use_list.count(), _in_use_list.max());
1728         timer.start();
1729       }
1730     } else {
1731       // This is not a monitor deflation thread.
1732       // No handshake or rendezvous is needed when we are already at safepoint.
1733       assert_at_safepoint();
1734     }
1735 
< prev index next >