author | coleenp |
Thu, 22 Aug 2019 09:51:36 -0400 | |
changeset 57840 | 4863a802a7c1 |
parent 57751 | 7284b00e6db3 |
child 58291 | a013100f7a35 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
2 |
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
26 |
#include "logging/log.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
48488
diff
changeset
|
27 |
#include "runtime/interfaceSupport.inline.hpp" |
7397 | 28 |
#include "runtime/mutex.hpp" |
29 |
#include "runtime/osThread.hpp" |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47634
diff
changeset
|
30 |
#include "runtime/safepointMechanism.inline.hpp" |
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
11636
diff
changeset
|
31 |
#include "runtime/thread.inline.hpp" |
7397 | 32 |
#include "utilities/events.hpp" |
40010 | 33 |
#include "utilities/macros.hpp" |
1 | 34 |
|
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
35 |
#ifdef ASSERT |
57840 | 36 |
void Mutex::check_safepoint_state(Thread* thread, bool do_safepoint_check) { |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
37 |
// If the JavaThread checks for safepoint, verify that the lock wasn't created with safepoint_check_never. |
57840 | 38 |
SafepointCheckRequired not_allowed = do_safepoint_check ? Mutex::_safepoint_check_never : |
39 |
Mutex::_safepoint_check_always; |
|
57699
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
40 |
assert(!thread->is_active_Java_thread() || _safepoint_check_required != not_allowed, |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
41 |
"This lock should %s have a safepoint check for Java threads: %s", |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
42 |
_safepoint_check_required ? "always" : "never", name()); |
57637
c38cca5ffb66
8229000: Fix lock and reenable assert in Monitor::check_safepoint_state
coleenp
parents:
57602
diff
changeset
|
43 |
|
c38cca5ffb66
8229000: Fix lock and reenable assert in Monitor::check_safepoint_state
coleenp
parents:
57602
diff
changeset
|
44 |
// If defined with safepoint_check_never, a NonJavaThread should never ask to safepoint check either. |
57840 | 45 |
assert(thread->is_Java_thread() || !do_safepoint_check || _safepoint_check_required != Mutex::_safepoint_check_never, |
57637
c38cca5ffb66
8229000: Fix lock and reenable assert in Monitor::check_safepoint_state
coleenp
parents:
57602
diff
changeset
|
46 |
"NonJavaThread should not check for safepoint"); |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
47 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
48 |
#endif // ASSERT |
1 | 49 |
|
57840 | 50 |
void Mutex::lock(Thread * self) { |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
51 |
check_safepoint_state(self, true); |
28163
322d55d167be
8047290: Make Mutex::_no_safepoint_check_flag locks verify that this lock never checks for safepoint
coleenp
parents:
26684
diff
changeset
|
52 |
|
57602
dbe471d2f8f8
8228673: Remove develop flag StrictSafepointChecks
coleenp
parents:
54665
diff
changeset
|
53 |
DEBUG_ONLY(check_prelock_state(self, true)); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
54 |
assert(_owner != self, "invariant"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
55 |
|
57840 | 56 |
Mutex* in_flight_mutex = NULL; |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
57 |
DEBUG_ONLY(int retry_cnt = 0;) |
57699
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
58 |
bool is_active_Java_thread = self->is_active_Java_thread(); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
59 |
while (!_lock.try_lock()) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
60 |
// The lock is contended |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
61 |
|
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
62 |
#ifdef ASSERT |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
63 |
check_block_state(self); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
64 |
if (retry_cnt++ > 3) { |
57840 | 65 |
log_trace(vmmutex)("JavaThread " INTPTR_FORMAT " on %d attempt trying to acquire vmmutex %s", p2i(self), retry_cnt, _name); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
66 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
67 |
#endif // ASSERT |
1 | 68 |
|
57699
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
69 |
// Is it a JavaThread participating in the safepoint protocol. |
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
70 |
if (is_active_Java_thread) { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
71 |
assert(rank() > Mutex::special, "Potential deadlock with special or lesser rank mutex"); |
57840 | 72 |
{ ThreadBlockInVMWithDeadlockCheck tbivmdc((JavaThread *) self, &in_flight_mutex); |
73 |
in_flight_mutex = this; // save for ~ThreadBlockInVMWithDeadlockCheck |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
74 |
_lock.lock(); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
75 |
} |
57840 | 76 |
if (in_flight_mutex != NULL) { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
77 |
// Not unlocked by ~ThreadBlockInVMWithDeadlockCheck |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
78 |
break; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
79 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
80 |
} else { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
81 |
_lock.lock(); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
82 |
break; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
83 |
} |
1 | 84 |
} |
85 |
||
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
86 |
assert_owner(NULL); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
87 |
set_owner(self); |
1 | 88 |
} |
89 |
||
57840 | 90 |
void Mutex::lock() { |
1 | 91 |
this->lock(Thread::current()); |
92 |
} |
|
93 |
||
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
94 |
// Lock without safepoint check - a degenerate variant of lock() for use by |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
95 |
// JavaThreads when it is known to be safe to not check for a safepoint when |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
96 |
// acquiring this lock. If the thread blocks acquiring the lock it is not |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
97 |
// safepoint-safe and so will prevent a safepoint from being reached. If used |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
98 |
// in the wrong way this can lead to a deadlock with the safepoint code. |
1 | 99 |
|
57840 | 100 |
void Mutex::lock_without_safepoint_check(Thread * self) { |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
101 |
check_safepoint_state(self, false); |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
102 |
assert(_owner != self, "invariant"); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
103 |
_lock.lock(); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
104 |
assert_owner(NULL); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
105 |
set_owner(self); |
1 | 106 |
} |
107 |
||
57840 | 108 |
void Mutex::lock_without_safepoint_check() { |
25069
c937c5e883c5
8047156: cleanup more non-indent white space issues prior to Contended Locking cleanup bucket
dcubed
parents:
24424
diff
changeset
|
109 |
lock_without_safepoint_check(Thread::current()); |
1 | 110 |
} |
111 |
||
112 |
||
22551 | 113 |
// Returns true if thread succeeds in grabbing the lock, otherwise false. |
1 | 114 |
|
57840 | 115 |
bool Mutex::try_lock() { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
116 |
Thread * const self = Thread::current(); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
117 |
DEBUG_ONLY(check_prelock_state(self, false);) |
1 | 118 |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
119 |
if (_lock.try_lock()) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
120 |
assert_owner(NULL); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
121 |
set_owner(self); |
1 | 122 |
return true; |
123 |
} |
|
124 |
return false; |
|
125 |
} |
|
126 |
||
57840 | 127 |
void Mutex::release_for_safepoint() { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
128 |
assert_owner(NULL); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
129 |
_lock.unlock(); |
1 | 130 |
} |
131 |
||
57840 | 132 |
void Mutex::unlock() { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
133 |
assert_owner(Thread::current()); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
134 |
set_owner(NULL); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
135 |
_lock.unlock(); |
1 | 136 |
} |
137 |
||
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
138 |
void Monitor::notify() { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
139 |
assert_owner(Thread::current()); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
140 |
_lock.notify(); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
141 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
142 |
|
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
143 |
void Monitor::notify_all() { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
144 |
assert_owner(Thread::current()); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
145 |
_lock.notify_all(); |
1 | 146 |
} |
147 |
||
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
53775
diff
changeset
|
148 |
#ifdef ASSERT |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
149 |
void Monitor::assert_wait_lock_state(Thread* self) { |
57840 | 150 |
Mutex* least = get_least_ranked_lock_besides_this(self->owned_locks()); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
151 |
assert(least != this, "Specification of get_least_... call above"); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
152 |
if (least != NULL && least->rank() <= special) { |
52913
bf2f2560dd53
8214315: G1: fatal error: acquiring lock SATB_Q_FL_lock/1 out of order with lock tty_lock/0
kbarrett
parents:
52581
diff
changeset
|
153 |
::tty->print("Attempting to wait on monitor %s/%d while holding" |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
154 |
" lock %s/%d -- possible deadlock", |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
155 |
name(), rank(), least->name(), least->rank()); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
156 |
assert(false, "Shouldn't block(wait) while holding a lock of rank special"); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
157 |
} |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
158 |
} |
54495
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
53775
diff
changeset
|
159 |
#endif // ASSERT |
941db9c0b5b5
8222231: Clean up interfaceSupport.inline.hpp duplicated code
coleenp
parents:
53775
diff
changeset
|
160 |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
161 |
bool Monitor::wait_without_safepoint_check(long timeout) { |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
162 |
Thread* const self = Thread::current(); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
163 |
check_safepoint_state(self, false); |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
164 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
165 |
// timeout is in milliseconds - with zero meaning never timeout |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
166 |
assert(timeout >= 0, "negative timeout"); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
167 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
168 |
assert_owner(self); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
169 |
assert_wait_lock_state(self); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
170 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
171 |
// conceptually set the owner to NULL in anticipation of |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
172 |
// abdicating the lock in wait |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
173 |
set_owner(NULL); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
174 |
int wait_status = _lock.wait(timeout); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
175 |
set_owner(self); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
176 |
return wait_status != 0; // return true IFF timeout |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
177 |
} |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
178 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
179 |
bool Monitor::wait(long timeout, bool as_suspend_equivalent) { |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
180 |
Thread* const self = Thread::current(); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
181 |
check_safepoint_state(self, true); |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
182 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
183 |
// timeout is in milliseconds - with zero meaning never timeout |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
184 |
assert(timeout >= 0, "negative timeout"); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
185 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
186 |
assert_owner(self); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
187 |
|
57699
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
188 |
// Safepoint checking logically implies an active JavaThread. |
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
189 |
guarantee(self->is_active_Java_thread(), "invariant"); |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
190 |
assert_wait_lock_state(self); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
191 |
|
25069
c937c5e883c5
8047156: cleanup more non-indent white space issues prior to Contended Locking cleanup bucket
dcubed
parents:
24424
diff
changeset
|
192 |
int wait_status; |
1 | 193 |
// conceptually set the owner to NULL in anticipation of |
194 |
// abdicating the lock in wait |
|
195 |
set_owner(NULL); |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
196 |
JavaThread *jt = (JavaThread *)self; |
57840 | 197 |
Mutex* in_flight_mutex = NULL; |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
198 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
199 |
{ |
57840 | 200 |
ThreadBlockInVMWithDeadlockCheck tbivmdc(jt, &in_flight_mutex); |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
201 |
OSThreadWaitState osts(self->osthread(), false /* not Object.wait() */); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
202 |
if (as_suspend_equivalent) { |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
203 |
jt->set_suspend_equivalent(); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
204 |
// cleared by handle_special_suspend_equivalent_condition() or |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
205 |
// java_suspend_self() |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
206 |
} |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
207 |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
208 |
wait_status = _lock.wait(timeout); |
57840 | 209 |
in_flight_mutex = this; // save for ~ThreadBlockInVMWithDeadlockCheck |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
210 |
|
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
211 |
// were we externally suspended while we were waiting? |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
212 |
if (as_suspend_equivalent && jt->handle_special_suspend_equivalent_condition()) { |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
213 |
// Our event wait has finished and we own the lock, but |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
214 |
// while we were waiting another thread suspended us. We don't |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
215 |
// want to hold the lock while suspended because that |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
216 |
// would surprise the thread that suspended us. |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
217 |
_lock.unlock(); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
218 |
jt->java_suspend_self(); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
219 |
_lock.lock(); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
220 |
} |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
221 |
} |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
222 |
|
57840 | 223 |
if (in_flight_mutex != NULL) { |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
224 |
// Not unlocked by ~ThreadBlockInVMWithDeadlockCheck |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
225 |
assert_owner(NULL); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
226 |
// Conceptually reestablish ownership of the lock. |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
227 |
set_owner(self); |
1 | 228 |
} else { |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
229 |
lock(self); |
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
54495
diff
changeset
|
230 |
} |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
231 |
|
25069
c937c5e883c5
8047156: cleanup more non-indent white space issues prior to Contended Locking cleanup bucket
dcubed
parents:
24424
diff
changeset
|
232 |
return wait_status != 0; // return true IFF timeout |
1 | 233 |
} |
234 |
||
57840 | 235 |
Mutex::~Mutex() { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
236 |
assert_owner(NULL); |
1 | 237 |
} |
238 |
||
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
239 |
// Only Threads_lock, Heap_lock and SR_lock may be safepoint_check_sometimes. |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
240 |
bool is_sometimes_ok(const char* name) { |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
241 |
return (strcmp(name, "Threads_lock") == 0 || strcmp(name, "Heap_lock") == 0 || strcmp(name, "SR_lock") == 0); |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
242 |
} |
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
243 |
|
57840 | 244 |
Mutex::Mutex(int Rank, const char * name, bool allow_vm_block, |
245 |
SafepointCheckRequired safepoint_check_required) : _owner(NULL) { |
|
52581
d402a406bbc3
8213723: More Monitor/mutex initialization management
dholmes
parents:
52555
diff
changeset
|
246 |
assert(os::mutex_init_done(), "Too early!"); |
57668 | 247 |
if (name == NULL) { |
248 |
strcpy(_name, "UNKNOWN"); |
|
249 |
} else { |
|
57840 | 250 |
strncpy(_name, name, MUTEX_NAME_LEN - 1); |
251 |
_name[MUTEX_NAME_LEN - 1] = '\0'; |
|
57668 | 252 |
} |
1 | 253 |
#ifdef ASSERT |
254 |
_allow_vm_block = allow_vm_block; |
|
25069
c937c5e883c5
8047156: cleanup more non-indent white space issues prior to Contended Locking cleanup bucket
dcubed
parents:
24424
diff
changeset
|
255 |
_rank = Rank; |
57668 | 256 |
_safepoint_check_required = safepoint_check_required; |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
257 |
|
57840 | 258 |
assert(_safepoint_check_required != Mutex::_safepoint_check_sometimes || is_sometimes_ok(name), |
54663
f03d5a093093
8074355: make MutexLocker smarter about non-JavaThreads
coleenp
parents:
54623
diff
changeset
|
259 |
"Lock has _safepoint_check_sometimes %s", name); |
1 | 260 |
#endif |
261 |
} |
|
262 |
||
57840 | 263 |
Monitor::Monitor(int Rank, const char * name, bool allow_vm_block, |
57668 | 264 |
SafepointCheckRequired safepoint_check_required) : |
57840 | 265 |
Mutex(Rank, name, allow_vm_block, safepoint_check_required) {} |
1 | 266 |
|
57840 | 267 |
bool Mutex::owned_by_self() const { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
268 |
return _owner == Thread::current(); |
1 | 269 |
} |
270 |
||
57840 | 271 |
void Mutex::print_on_error(outputStream* st) const { |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
272 |
st->print("[" PTR_FORMAT, p2i(this)); |
1 | 273 |
st->print("] %s", _name); |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
274 |
st->print(" - owner thread: " PTR_FORMAT, p2i(_owner)); |
1 | 275 |
} |
276 |
||
277 |
// ---------------------------------------------------------------------------------- |
|
278 |
// Non-product code |
|
279 |
||
280 |
#ifndef PRODUCT |
|
57840 | 281 |
void Mutex::print_on(outputStream* st) const { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
282 |
st->print_cr("Mutex: [" PTR_FORMAT "] %s - owner: " PTR_FORMAT, |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
283 |
p2i(this), _name, p2i(_owner)); |
1 | 284 |
} |
285 |
#endif |
|
286 |
||
287 |
#ifndef PRODUCT |
|
288 |
#ifdef ASSERT |
|
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
289 |
|
57840 | 290 |
void Mutex::assert_owner(Thread * expected) { |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
291 |
const char* msg = "invalid owner"; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
292 |
if (expected == NULL) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
293 |
msg = "should be un-owned"; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
294 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
295 |
else if (expected == Thread::current()) { |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
296 |
msg = "should be owned by current thread"; |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
297 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
298 |
assert(_owner == expected, |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
299 |
"%s: owner=" INTPTR_FORMAT ", should be=" INTPTR_FORMAT, |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
300 |
msg, p2i(_owner), p2i(expected)); |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
301 |
} |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
302 |
|
57840 | 303 |
Mutex* Mutex::get_least_ranked_lock(Mutex* locks) { |
304 |
Mutex *res, *tmp; |
|
1 | 305 |
for (res = tmp = locks; tmp != NULL; tmp = tmp->next()) { |
306 |
if (tmp->rank() < res->rank()) { |
|
307 |
res = tmp; |
|
308 |
} |
|
309 |
} |
|
310 |
if (!SafepointSynchronize::is_at_safepoint()) { |
|
311 |
// In this case, we expect the held locks to be |
|
312 |
// in increasing rank order (modulo any native ranks) |
|
313 |
for (tmp = locks; tmp != NULL; tmp = tmp->next()) { |
|
314 |
if (tmp->next() != NULL) { |
|
315 |
assert(tmp->rank() == Mutex::native || |
|
316 |
tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?"); |
|
317 |
} |
|
318 |
} |
|
319 |
} |
|
320 |
return res; |
|
321 |
} |
|
322 |
||
57840 | 323 |
Mutex* Mutex::get_least_ranked_lock_besides_this(Mutex* locks) { |
324 |
Mutex *res, *tmp; |
|
1 | 325 |
for (res = NULL, tmp = locks; tmp != NULL; tmp = tmp->next()) { |
326 |
if (tmp != this && (res == NULL || tmp->rank() < res->rank())) { |
|
327 |
res = tmp; |
|
328 |
} |
|
329 |
} |
|
330 |
if (!SafepointSynchronize::is_at_safepoint()) { |
|
331 |
// In this case, we expect the held locks to be |
|
332 |
// in increasing rank order (modulo any native ranks) |
|
333 |
for (tmp = locks; tmp != NULL; tmp = tmp->next()) { |
|
334 |
if (tmp->next() != NULL) { |
|
335 |
assert(tmp->rank() == Mutex::native || |
|
336 |
tmp->rank() <= tmp->next()->rank(), "mutex rank anomaly?"); |
|
337 |
} |
|
338 |
} |
|
339 |
} |
|
340 |
return res; |
|
341 |
} |
|
342 |
||
343 |
||
57840 | 344 |
bool Mutex::contains(Mutex* locks, Mutex* lock) { |
1 | 345 |
for (; locks != NULL; locks = locks->next()) { |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
346 |
if (locks == lock) { |
1 | 347 |
return true; |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
348 |
} |
1 | 349 |
} |
350 |
return false; |
|
351 |
} |
|
352 |
#endif |
|
353 |
||
354 |
// Called immediately after lock acquisition or release as a diagnostic |
|
355 |
// to track the lock-set of the thread and test for rank violations that |
|
356 |
// might indicate exposure to deadlock. |
|
357 |
// Rather like an EventListener for _owner (:>). |
|
358 |
||
57840 | 359 |
void Mutex::set_owner_implementation(Thread *new_owner) { |
1 | 360 |
// This function is solely responsible for maintaining |
361 |
// and checking the invariant that threads and locks |
|
362 |
// are in a 1/N relation, with some some locks unowned. |
|
363 |
// It uses the Mutex::_owner, Mutex::_next, and |
|
364 |
// Thread::_owned_locks fields, and no other function |
|
365 |
// changes those fields. |
|
366 |
// It is illegal to set the mutex from one non-NULL |
|
367 |
// owner to another--it must be owned by NULL as an |
|
368 |
// intermediate state. |
|
369 |
||
370 |
if (new_owner != NULL) { |
|
371 |
// the thread is acquiring this lock |
|
372 |
||
373 |
assert(new_owner == Thread::current(), "Should I be doing this?"); |
|
374 |
assert(_owner == NULL, "setting the owner thread of an already owned mutex"); |
|
375 |
_owner = new_owner; // set the owner |
|
376 |
||
377 |
// link "this" into the owned locks list |
|
378 |
||
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
379 |
#ifdef ASSERT // Thread::_owned_locks is under the same ifdef |
57840 | 380 |
Mutex* locks = get_least_ranked_lock(new_owner->owned_locks()); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
381 |
// Mutex::set_owner_implementation is a friend of Thread |
1 | 382 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
383 |
assert(this->rank() >= 0, "bad lock rank"); |
1 | 384 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
385 |
// Deadlock avoidance rules require us to acquire Mutexes only in |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
386 |
// a global total order. For example m1 is the lowest ranked mutex |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
387 |
// that the thread holds and m2 is the mutex the thread is trying |
53646
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
388 |
// to acquire, then deadlock avoidance rules require that the rank |
043ae846819f
8210832: Remove sneaky locking in class Monitor
pchilanomate
parents:
52913
diff
changeset
|
389 |
// of m2 be less than the rank of m1. |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
390 |
// The rank Mutex::native is an exception in that it is not subject |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
391 |
// to the verification rules. |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
392 |
if (this->rank() != Mutex::native && |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
393 |
this->rank() != Mutex::suspend_resume && |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
394 |
locks != NULL && locks->rank() <= this->rank() && |
53775 | 395 |
!SafepointSynchronize::is_at_safepoint()) { |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
396 |
new_owner->print_owned_locks(); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
28163
diff
changeset
|
397 |
fatal("acquiring lock %s/%d out of order with lock %s/%d -- " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
28163
diff
changeset
|
398 |
"possible deadlock", this->name(), this->rank(), |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
28163
diff
changeset
|
399 |
locks->name(), locks->rank()); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
400 |
} |
1 | 401 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
402 |
this->_next = new_owner->_owned_locks; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
403 |
new_owner->_owned_locks = this; |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
404 |
#endif |
1 | 405 |
|
406 |
} else { |
|
407 |
// the thread is releasing this lock |
|
408 |
||
409 |
Thread* old_owner = _owner; |
|
52555
3b2d22602c16
8213708: Different #ifdef guards cause incorrect use of Monitor::check_block_state()
pchilanomate
parents:
52450
diff
changeset
|
410 |
DEBUG_ONLY(_last_owner = old_owner;) |
1 | 411 |
|
412 |
assert(old_owner != NULL, "removing the owner thread of an unowned mutex"); |
|
413 |
assert(old_owner == Thread::current(), "removing the owner thread of an unowned mutex"); |
|
414 |
||
415 |
_owner = NULL; // set the owner |
|
416 |
||
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
417 |
#ifdef ASSERT |
57840 | 418 |
Mutex* locks = old_owner->owned_locks(); |
1 | 419 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
420 |
// remove "this" from the owned locks list |
1 | 421 |
|
57840 | 422 |
Mutex* prev = NULL; |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
423 |
bool found = false; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
424 |
for (; locks != NULL; prev = locks, locks = locks->next()) { |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
425 |
if (locks == this) { |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
426 |
found = true; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
427 |
break; |
1 | 428 |
} |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
429 |
} |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
430 |
assert(found, "Removing a lock not owned"); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
431 |
if (prev == NULL) { |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
432 |
old_owner->_owned_locks = _next; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
433 |
} else { |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
434 |
prev->_next = _next; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
435 |
} |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
436 |
_next = NULL; |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
437 |
#endif |
1 | 438 |
} |
439 |
} |
|
440 |
||
441 |
||
442 |
// Factored out common sanity checks for locking mutex'es. Used by lock() and try_lock() |
|
57840 | 443 |
void Mutex::check_prelock_state(Thread *thread, bool safepoint_check) { |
50280
5aaf3a471172
8203817: Monitor::try_lock() should not call check_prelock_state()
pliden
parents:
50203
diff
changeset
|
444 |
if (safepoint_check) { |
57699
4aea554692aa
8226228: Make Threads_lock an always safepoint checked lock.
rehn
parents:
57668
diff
changeset
|
445 |
assert((!thread->is_active_Java_thread() || ((JavaThread *)thread)->thread_state() == _thread_in_vm) |
50280
5aaf3a471172
8203817: Monitor::try_lock() should not call check_prelock_state()
pliden
parents:
50203
diff
changeset
|
446 |
|| rank() == Mutex::special, "wrong thread state for using locks"); |
1 | 447 |
if (thread->is_VM_thread() && !allow_vm_block()) { |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
28163
diff
changeset
|
448 |
fatal("VM thread using lock %s (not allowed to block on)", name()); |
1 | 449 |
} |
52555
3b2d22602c16
8213708: Different #ifdef guards cause incorrect use of Monitor::check_block_state()
pchilanomate
parents:
52450
diff
changeset
|
450 |
DEBUG_ONLY(if (rank() != Mutex::special) \ |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
451 |
thread->check_for_valid_safepoint_state(false);) |
1 | 452 |
} |
46644
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
41704
diff
changeset
|
453 |
assert(!os::ThreadCrashProtection::is_crash_protected(thread), |
a5813fb66270
8183925: Decouple crash protection from watcher thread
rehn
parents:
41704
diff
changeset
|
454 |
"locking not allowed when crash protection is set"); |
1 | 455 |
} |
456 |
||
57840 | 457 |
void Mutex::check_block_state(Thread *thread) { |
1 | 458 |
if (!_allow_vm_block && thread->is_VM_thread()) { |
459 |
warning("VM thread blocked on lock"); |
|
460 |
print(); |
|
461 |
BREAKPOINT; |
|
462 |
} |
|
57840 | 463 |
assert(_owner != thread, "deadlock: blocking on mutex owned by current thread"); |
1 | 464 |
} |
465 |
||
466 |
#endif // PRODUCT |