author | dholmes |
Sat, 23 Jun 2018 01:32:41 -0400 | |
changeset 50735 | 2f2af62dfac7 |
parent 49956 | a87f2e7a527c |
child 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
1 |
/* |
49956
a87f2e7a527c
8191798: redo nested ThreadsListHandle to drop Threads_lock
dcubed
parents:
48382
diff
changeset
|
2 |
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
4 |
* |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
8 |
* |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
13 |
* accompanied this code). |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
14 |
* |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
18 |
* |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
21 |
* questions. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
22 |
* |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
23 |
*/ |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
24 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
25 |
#ifndef SHARE_VM_RUNTIME_THREADSMR_INLINE_HPP |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
26 |
#define SHARE_VM_RUNTIME_THREADSMR_INLINE_HPP |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
27 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
28 |
#include "runtime/atomic.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
29 |
#include "runtime/prefetch.inline.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
30 |
#include "runtime/thread.inline.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
31 |
#include "runtime/threadSMR.hpp" |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
32 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
33 |
// Devirtualize known thread closure types. |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
34 |
template <class T> |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
35 |
inline void ThreadsList::threads_do_dispatch(T *cl, JavaThread *const thread) const { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
36 |
cl->T::do_thread(thread); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
37 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
38 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
39 |
template <> |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
40 |
inline void ThreadsList::threads_do_dispatch<ThreadClosure>(ThreadClosure *cl, JavaThread *const thread) const { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
41 |
cl->do_thread(thread); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
42 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
43 |
|
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
44 |
template <class T> |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
45 |
inline void ThreadsList::threads_do(T *cl) const { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
46 |
const intx scan_interval = PrefetchScanIntervalInBytes; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
47 |
JavaThread *const *const end = _threads + _length; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
48 |
for (JavaThread *const *current_p = _threads; current_p != end; current_p++) { |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
49 |
Prefetch::read((void*)current_p, scan_interval); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
50 |
JavaThread *const current = *current_p; |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
51 |
threads_do_dispatch(cl, current); |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
52 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
53 |
} |
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
54 |
|
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
55 |
// These three inlines are private to ThreadsSMRSupport, but |
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
56 |
// they are called by public inline update_tlh_stats() below: |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
57 |
|
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
58 |
inline void ThreadsSMRSupport::add_tlh_times(uint add_value) { |
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
59 |
Atomic::add(add_value, &_tlh_times); |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
60 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
61 |
|
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
62 |
inline void ThreadsSMRSupport::inc_tlh_cnt() { |
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
63 |
Atomic::inc(&_tlh_cnt); |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
64 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
65 |
|
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
66 |
inline void ThreadsSMRSupport::update_tlh_time_max(uint new_value) { |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
67 |
while (true) { |
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
68 |
uint cur_value = _tlh_time_max; |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
69 |
if (new_value <= cur_value) { |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
70 |
// No need to update max value so we're done. |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
71 |
break; |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
72 |
} |
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
73 |
if (Atomic::cmpxchg(new_value, &_tlh_time_max, cur_value) == cur_value) { |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
74 |
// Updated max value so we're done. Otherwise try it all again. |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
75 |
break; |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
76 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
77 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
78 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
79 |
|
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
80 |
inline ThreadsList* ThreadsSMRSupport::get_java_thread_list() { |
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
81 |
return (ThreadsList*)OrderAccess::load_acquire(&_java_thread_list); |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
82 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
83 |
|
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
84 |
inline bool ThreadsSMRSupport::is_a_protected_JavaThread_with_lock(JavaThread *thread) { |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
85 |
MutexLockerEx ml(Threads_lock->owned_by_self() ? NULL : Threads_lock); |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
86 |
return is_a_protected_JavaThread(thread); |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
87 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
88 |
|
48382
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
89 |
inline void ThreadsSMRSupport::update_tlh_stats(uint millis) { |
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
90 |
ThreadsSMRSupport::inc_tlh_cnt(); |
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
91 |
ThreadsSMRSupport::add_tlh_times(millis); |
0997d6959851
8193135: get rid of redundant _smr_ prefix/infix in ThreadSMRSupport stuff
dcubed
parents:
48312
diff
changeset
|
92 |
ThreadsSMRSupport::update_tlh_time_max(millis); |
48312
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
93 |
} |
2a1413298af0
8191789: migrate more Thread-SMR stuff from thread.[ch]pp -> threadSMR.[ch]pp
dcubed
parents:
48105
diff
changeset
|
94 |
|
48105
8d15b1369c7a
8167108: inconsistent handling of SR_lock can lead to crashes
dcubed
parents:
diff
changeset
|
95 |
#endif // SHARE_VM_RUNTIME_THREADSMR_INLINE_HPP |