< prev index next >

src/hotspot/share/runtime/mutex.cpp

Print this page
rev 47589 : Introduce SafepointMechanism
rev 47591 : Add Thread Local handshakes and thread local polling


  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 "runtime/atomic.hpp"
  27 #include "runtime/interfaceSupport.hpp"
  28 #include "runtime/mutex.hpp"
  29 #include "runtime/orderAccess.inline.hpp"
  30 #include "runtime/osThread.hpp"

  31 #include "runtime/thread.inline.hpp"
  32 #include "utilities/events.hpp"
  33 #include "utilities/macros.hpp"
  34 
  35 // 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
  36 //
  37 // Native Monitor-Mutex locking - theory of operations
  38 //
  39 // * Native Monitors are completely unrelated to Java-level monitors,
  40 //   although the "back-end" slow-path implementations share a common lineage.
  41 //   See objectMonitor:: in synchronizer.cpp.
  42 //   Native Monitors do *not* support nesting or recursion but otherwise
  43 //   they're basically Hoare-flavor monitors.
  44 //
  45 // * A thread acquires ownership of a Monitor/Mutex by CASing the LockByte
  46 //   in the _LockWord from zero to non-zero.  Note that the _Owner field
  47 //   is advisory and is used only to verify that the thread calling unlock()
  48 //   is indeed the last thread to have acquired the lock.
  49 //
  50 // * Contending threads "push" themselves onto the front of the contention


 377 
 378     // Consider checking _owner's schedctl state, if OFFPROC abort spin.
 379     // If the owner is OFFPROC then it's unlike that the lock will be dropped
 380     // in a timely fashion, which suggests that spinning would not be fruitful
 381     // or profitable.
 382 
 383     // Stall for "Delay" time units - iterations in the current implementation.
 384     // Avoid generating coherency traffic while stalled.
 385     // Possible ways to delay:
 386     //   PAUSE, SLEEP, MEMBAR #sync, MEMBAR #halt,
 387     //   wr %g0,%asi, gethrtime, rdstick, rdtick, rdtsc, etc. ...
 388     // Note that on Niagara-class systems we want to minimize STs in the
 389     // spin loop.  N1 and brethren write-around the L1$ over the xbar into the L2$.
 390     // Furthermore, they don't have a W$ like traditional SPARC processors.
 391     // We currently use a Marsaglia Shift-Xor RNG loop.
 392     Steps += Delay;
 393     if (Self != NULL) {
 394       jint rv = Self->rng[0];
 395       for (int k = Delay; --k >= 0;) {
 396         rv = MarsagliaXORV(rv);
 397         if ((flgs & 4) == 0 && SafepointSynchronize::do_call_back()) return 0;
 398       }
 399       Self->rng[0] = rv;
 400     } else {
 401       Stall(Delay);
 402     }
 403   }
 404 }
 405 
 406 static int ParkCommon(ParkEvent * ev, jlong timo) {
 407   // Diagnostic support - periodically unwedge blocked threads
 408   intx nmt = NativeMonitorTimeout;
 409   if (nmt > 0 && (nmt < timo || timo <= 0)) {
 410     timo = nmt;
 411   }
 412   int err = OS_OK;
 413   if (0 == timo) {
 414     ev->park();
 415   } else {
 416     err = ev->park(timo);
 417   }




  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 "runtime/atomic.hpp"
  27 #include "runtime/interfaceSupport.hpp"
  28 #include "runtime/mutex.hpp"
  29 #include "runtime/orderAccess.inline.hpp"
  30 #include "runtime/osThread.hpp"
  31 #include "runtime/safepointMechanism.inline.hpp"
  32 #include "runtime/thread.inline.hpp"
  33 #include "utilities/events.hpp"
  34 #include "utilities/macros.hpp"
  35 
  36 // 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
  37 //
  38 // Native Monitor-Mutex locking - theory of operations
  39 //
  40 // * Native Monitors are completely unrelated to Java-level monitors,
  41 //   although the "back-end" slow-path implementations share a common lineage.
  42 //   See objectMonitor:: in synchronizer.cpp.
  43 //   Native Monitors do *not* support nesting or recursion but otherwise
  44 //   they're basically Hoare-flavor monitors.
  45 //
  46 // * A thread acquires ownership of a Monitor/Mutex by CASing the LockByte
  47 //   in the _LockWord from zero to non-zero.  Note that the _Owner field
  48 //   is advisory and is used only to verify that the thread calling unlock()
  49 //   is indeed the last thread to have acquired the lock.
  50 //
  51 // * Contending threads "push" themselves onto the front of the contention


 378 
 379     // Consider checking _owner's schedctl state, if OFFPROC abort spin.
 380     // If the owner is OFFPROC then it's unlike that the lock will be dropped
 381     // in a timely fashion, which suggests that spinning would not be fruitful
 382     // or profitable.
 383 
 384     // Stall for "Delay" time units - iterations in the current implementation.
 385     // Avoid generating coherency traffic while stalled.
 386     // Possible ways to delay:
 387     //   PAUSE, SLEEP, MEMBAR #sync, MEMBAR #halt,
 388     //   wr %g0,%asi, gethrtime, rdstick, rdtick, rdtsc, etc. ...
 389     // Note that on Niagara-class systems we want to minimize STs in the
 390     // spin loop.  N1 and brethren write-around the L1$ over the xbar into the L2$.
 391     // Furthermore, they don't have a W$ like traditional SPARC processors.
 392     // We currently use a Marsaglia Shift-Xor RNG loop.
 393     Steps += Delay;
 394     if (Self != NULL) {
 395       jint rv = Self->rng[0];
 396       for (int k = Delay; --k >= 0;) {
 397         rv = MarsagliaXORV(rv);
 398         if ((flgs & 4) == 0 && SafepointMechanism::poll(Self)) return 0;
 399       }
 400       Self->rng[0] = rv;
 401     } else {
 402       Stall(Delay);
 403     }
 404   }
 405 }
 406 
 407 static int ParkCommon(ParkEvent * ev, jlong timo) {
 408   // Diagnostic support - periodically unwedge blocked threads
 409   intx nmt = NativeMonitorTimeout;
 410   if (nmt > 0 && (nmt < timo || timo <= 0)) {
 411     timo = nmt;
 412   }
 413   int err = OS_OK;
 414   if (0 == timo) {
 415     ev->park();
 416   } else {
 417     err = ev->park(timo);
 418   }


< prev index next >