src/share/vm/runtime/mutex.hpp

Print this page


   1 /*
   2  * Copyright (c) 1998, 2008, 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  *
  23  */
  24 







  25 // The SplitWord construct allows us to colocate the contention queue
  26 // (cxq) with the lock-byte.  The queue elements are ParkEvents, which are
  27 // always aligned on 256-byte addresses - the least significant byte of
  28 // a ParkEvent is always 0.  Colocating the lock-byte with the queue
  29 // allows us to easily avoid what would otherwise be a race in lock()
  30 // if we were to use two completely separate fields for the contention queue
  31 // and the lock indicator.  Specifically, colocation renders us immune
  32 // from the race where a thread might enqueue itself in the lock() slow-path
  33 // immediately after the lock holder drops the outer lock in the unlock()
  34 // fast-path.
  35 //
  36 // Colocation allows us to use a fast-path unlock() form that uses
  37 // A MEMBAR instead of a CAS.  MEMBAR has lower local latency than CAS
  38 // on many platforms.
  39 //
  40 // See:
  41 // +  http://blogs.sun.com/dave/entry/biased_locking_in_hotspot
  42 // +  http://blogs.sun.com/dave/resource/synchronization-public2.pdf
  43 //
  44 // Note that we're *not* using word-tearing the classic sense.


 248 // there may have been some benefit to having distinct mutexes and monitors, but that time
 249 // has past.
 250 //
 251 // The Mutex/Monitor design parallels that of Java-monitors, being based on
 252 // thread-specific park-unpark platform-specific primitives.
 253 
 254 
 255 class Mutex : public Monitor {      // degenerate Monitor
 256  public:
 257    Mutex (int rank, const char *name, bool allow_vm_block=false);
 258    ~Mutex () ;
 259  private:
 260    bool notify ()    { ShouldNotReachHere(); return false; }
 261    bool notify_all() { ShouldNotReachHere(); return false; }
 262    bool wait (bool no_safepoint_check, long timeout, bool as_suspend_equivalent) {
 263      ShouldNotReachHere() ;
 264      return false ;
 265    }
 266 };
 267 


   1 /*
   2  * Copyright (c) 1998, 2010, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_MUTEX_HPP
  26 #define SHARE_VM_RUNTIME_MUTEX_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/os.hpp"
  30 #include "utilities/histogram.hpp"
  31 
  32 // The SplitWord construct allows us to colocate the contention queue
  33 // (cxq) with the lock-byte.  The queue elements are ParkEvents, which are
  34 // always aligned on 256-byte addresses - the least significant byte of
  35 // a ParkEvent is always 0.  Colocating the lock-byte with the queue
  36 // allows us to easily avoid what would otherwise be a race in lock()
  37 // if we were to use two completely separate fields for the contention queue
  38 // and the lock indicator.  Specifically, colocation renders us immune
  39 // from the race where a thread might enqueue itself in the lock() slow-path
  40 // immediately after the lock holder drops the outer lock in the unlock()
  41 // fast-path.
  42 //
  43 // Colocation allows us to use a fast-path unlock() form that uses
  44 // A MEMBAR instead of a CAS.  MEMBAR has lower local latency than CAS
  45 // on many platforms.
  46 //
  47 // See:
  48 // +  http://blogs.sun.com/dave/entry/biased_locking_in_hotspot
  49 // +  http://blogs.sun.com/dave/resource/synchronization-public2.pdf
  50 //
  51 // Note that we're *not* using word-tearing the classic sense.


 255 // there may have been some benefit to having distinct mutexes and monitors, but that time
 256 // has past.
 257 //
 258 // The Mutex/Monitor design parallels that of Java-monitors, being based on
 259 // thread-specific park-unpark platform-specific primitives.
 260 
 261 
 262 class Mutex : public Monitor {      // degenerate Monitor
 263  public:
 264    Mutex (int rank, const char *name, bool allow_vm_block=false);
 265    ~Mutex () ;
 266  private:
 267    bool notify ()    { ShouldNotReachHere(); return false; }
 268    bool notify_all() { ShouldNotReachHere(); return false; }
 269    bool wait (bool no_safepoint_check, long timeout, bool as_suspend_equivalent) {
 270      ShouldNotReachHere() ;
 271      return false ;
 272    }
 273 };
 274 
 275 
 276 #endif // SHARE_VM_RUNTIME_MUTEX_HPP