src/share/vm/runtime/mutex.cpp

Print this page


   1 
   2 /*
   3  * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 # include "incls/_precompiled.incl"
  27 # include "incls/_mutex.cpp.incl"














  28 
  29 // o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
  30 //
  31 // Native Monitor-Mutex locking - theory of operations
  32 //
  33 // * Native Monitors are completely unrelated to Java-level monitors,
  34 //   although the "back-end" slow-path implementations share a common lineage.
  35 //   See objectMonitor:: in synchronizer.cpp.
  36 //   Native Monitors do *not* support nesting or recursion but otherwise
  37 //   they're basically Hoare-flavor monitors.
  38 //
  39 // * A thread acquires ownership of a Monitor/Mutex by CASing the LockByte
  40 //   in the _LockWord from zero to non-zero.  Note that the _Owner field
  41 //   is advisory and is used only to verify that the thread calling unlock()
  42 //   is indeed the last thread to have acquired the lock.
  43 //
  44 // * Contending threads "push" themselves onto the front of the contention
  45 //   queue -- called the cxq -- with CAS and then spin/park.
  46 //   The _LockWord contains the LockByte as well as the pointer to the head
  47 //   of the cxq.  Colocating the LockByte with the cxq precludes certain races.


   1 
   2 /*
   3  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "runtime/mutex.hpp"
  28 #include "runtime/osThread.hpp"
  29 #include "utilities/events.hpp"
  30 #ifdef TARGET_OS_FAMILY_linux
  31 # include "mutex_linux.inline.hpp"
  32 # include "thread_linux.inline.hpp"
  33 #endif
  34 #ifdef TARGET_OS_FAMILY_solaris
  35 # include "mutex_solaris.inline.hpp"
  36 # include "thread_solaris.inline.hpp"
  37 #endif
  38 #ifdef TARGET_OS_FAMILY_windows
  39 # include "mutex_windows.inline.hpp"
  40 # include "thread_windows.inline.hpp"
  41 #endif
  42 
  43 // o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
  44 //
  45 // Native Monitor-Mutex locking - theory of operations
  46 //
  47 // * Native Monitors are completely unrelated to Java-level monitors,
  48 //   although the "back-end" slow-path implementations share a common lineage.
  49 //   See objectMonitor:: in synchronizer.cpp.
  50 //   Native Monitors do *not* support nesting or recursion but otherwise
  51 //   they're basically Hoare-flavor monitors.
  52 //
  53 // * A thread acquires ownership of a Monitor/Mutex by CASing the LockByte
  54 //   in the _LockWord from zero to non-zero.  Note that the _Owner field
  55 //   is advisory and is used only to verify that the thread calling unlock()
  56 //   is indeed the last thread to have acquired the lock.
  57 //
  58 // * Contending threads "push" themselves onto the front of the contention
  59 //   queue -- called the cxq -- with CAS and then spin/park.
  60 //   The _LockWord contains the LockByte as well as the pointer to the head
  61 //   of the cxq.  Colocating the LockByte with the cxq precludes certain races.