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