13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_RUNTIME_JAVATHREAD_INLINE_HPP
27 #define SHARE_RUNTIME_JAVATHREAD_INLINE_HPP
28
29 #include "runtime/javaThread.hpp"
30
31 #include "classfile/javaClasses.hpp"
32 #include "gc/shared/tlab_globals.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/instanceKlass.hpp"
35 #include "oops/oopHandle.inline.hpp"
36 #include "runtime/atomic.hpp"
37 #include "runtime/continuation.hpp"
38 #include "runtime/continuationEntry.inline.hpp"
39 #include "runtime/nonJavaThread.hpp"
40 #include "runtime/orderAccess.hpp"
41 #include "runtime/safepoint.hpp"
42
43 inline void JavaThread::set_suspend_flag(SuspendFlags f) {
44 uint32_t flags;
45 do {
46 flags = _suspend_flags;
47 }
48 while (Atomic::cmpxchg(&_suspend_flags, flags, (flags | f)) != flags);
49 }
50 inline void JavaThread::clear_suspend_flag(SuspendFlags f) {
51 uint32_t flags;
52 do {
53 flags = _suspend_flags;
54 }
55 while (Atomic::cmpxchg(&_suspend_flags, flags, (flags & ~f)) != flags);
56 }
57
58 inline void JavaThread::set_trace_flag() {
59 set_suspend_flag(_trace_flag);
60 }
61 inline void JavaThread::clear_trace_flag() {
222 inline void JavaThread::set_terminated(TerminatedTypes t) {
223 Atomic::release_store(&_terminated, t);
224 }
225
226 inline bool JavaThread::is_active_Java_thread() const {
227 return on_thread_list() && !is_terminated();
228 }
229
230 // Allow tracking of class initialization monitor use
231 inline void JavaThread::set_class_to_be_initialized(InstanceKlass* k) {
232 assert((k == nullptr && _class_to_be_initialized != nullptr) ||
233 (k != nullptr && _class_to_be_initialized == nullptr), "incorrect usage");
234 assert(this == Thread::current(), "Only the current thread can set this field");
235 _class_to_be_initialized = k;
236 }
237
238 inline InstanceKlass* JavaThread::class_to_be_initialized() const {
239 return _class_to_be_initialized;
240 }
241
242 #endif // SHARE_RUNTIME_JAVATHREAD_INLINE_HPP
|
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_RUNTIME_JAVATHREAD_INLINE_HPP
27 #define SHARE_RUNTIME_JAVATHREAD_INLINE_HPP
28
29 #include "runtime/javaThread.hpp"
30
31 #include "classfile/javaClasses.hpp"
32 #include "gc/shared/tlab_globals.hpp"
33 #include "logging/log.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "memory/universe.hpp"
36 #include "oops/instanceKlass.hpp"
37 #include "oops/oopHandle.inline.hpp"
38 #include "runtime/atomic.hpp"
39 #include "runtime/continuation.hpp"
40 #include "runtime/continuationEntry.inline.hpp"
41 #include "runtime/nonJavaThread.hpp"
42 #include "runtime/objectMonitor.inline.hpp"
43 #include "runtime/orderAccess.hpp"
44 #include "runtime/safepoint.hpp"
45 #include "runtime/synchronizer.hpp"
46 #include "utilities/globalDefinitions.hpp"
47 #include "utilities/sizes.hpp"
48
49 inline void JavaThread::set_suspend_flag(SuspendFlags f) {
50 uint32_t flags;
51 do {
52 flags = _suspend_flags;
53 }
54 while (Atomic::cmpxchg(&_suspend_flags, flags, (flags | f)) != flags);
55 }
56 inline void JavaThread::clear_suspend_flag(SuspendFlags f) {
57 uint32_t flags;
58 do {
59 flags = _suspend_flags;
60 }
61 while (Atomic::cmpxchg(&_suspend_flags, flags, (flags & ~f)) != flags);
62 }
63
64 inline void JavaThread::set_trace_flag() {
65 set_suspend_flag(_trace_flag);
66 }
67 inline void JavaThread::clear_trace_flag() {
228 inline void JavaThread::set_terminated(TerminatedTypes t) {
229 Atomic::release_store(&_terminated, t);
230 }
231
232 inline bool JavaThread::is_active_Java_thread() const {
233 return on_thread_list() && !is_terminated();
234 }
235
236 // Allow tracking of class initialization monitor use
237 inline void JavaThread::set_class_to_be_initialized(InstanceKlass* k) {
238 assert((k == nullptr && _class_to_be_initialized != nullptr) ||
239 (k != nullptr && _class_to_be_initialized == nullptr), "incorrect usage");
240 assert(this == Thread::current(), "Only the current thread can set this field");
241 _class_to_be_initialized = k;
242 }
243
244 inline InstanceKlass* JavaThread::class_to_be_initialized() const {
245 return _class_to_be_initialized;
246 }
247
248 inline void JavaThread::om_set_monitor_cache(ObjectMonitor* monitor) {
249 assert(LockingMode == LM_LIGHTWEIGHT, "must be");
250 assert(monitor != nullptr, "use om_clear_monitor_cache to clear");
251 assert(this == current() || monitor->owner_raw() == this, "only add owned monitors for other threads");
252 assert(this == current() || is_obj_deopt_suspend(), "thread must not run concurrently");
253
254 _om_cache.set_monitor(monitor);
255 }
256
257 inline void JavaThread::om_clear_monitor_cache() {
258 if (LockingMode != LM_LIGHTWEIGHT) {
259 return;
260 }
261
262 _om_cache.clear();
263
264 LogTarget(Info, monitorinflation, thread) lt;
265 if (!lt.is_enabled()) {
266 return;
267 }
268
269 ResourceMark rm;
270
271 if (_unlocked_inflation != 0 ||
272 _recursive_inflation != 0 ||
273 _contended_recursive_inflation != 0 ||
274 _contended_inflation != 0 ||
275 _wait_inflation != 0 ||
276 _lock_stack_inflation != 0) {
277 lt.print("Mon: %8zu Rec: %8zu CRec: %8zu Cont: %8zu Wait: %8zu Stack: %8zu Thread: %s",
278 _unlocked_inflation,
279 _recursive_inflation,
280 _contended_recursive_inflation,
281 _contended_inflation,
282 _wait_inflation,
283 _lock_stack_inflation,
284 name());
285 }
286 _unlocked_inflation = 0;
287 _recursive_inflation = 0;
288 _contended_recursive_inflation = 0;
289 _contended_inflation = 0;
290 _wait_inflation = 0;
291 _lock_stack_inflation = 0;
292
293 if (_lock_lookup != 0 ||
294 _unlock_lookup != 0) {
295 const double lock_hit_rate = (double)_lock_hit / (double)_lock_lookup * 100;
296 const double unlock_hit_rate = (double)_unlock_hit / (double)_unlock_lookup * 100;
297 lt.print("Lock: %3.2lf %% [%6zu / %6zu] Unlock: %3.2lf %% [%6zu / %6zu] Thread: %s",
298 lock_hit_rate, _lock_hit, _lock_lookup,
299 unlock_hit_rate, _unlock_hit, _unlock_lookup,
300 name());
301 }
302 _lock_hit = 0;
303 _lock_lookup = 0;
304 _unlock_hit = 0;
305 _unlock_lookup = 0;
306 }
307
308 inline ObjectMonitor* JavaThread::om_get_from_monitor_cache(oop obj) {
309 assert(obj != nullptr, "do not look for null objects");
310 assert(this == current(), "only get own thread locals");
311 return _om_cache.get_monitor(obj);
312 }
313
314 #endif // SHARE_RUNTIME_JAVATHREAD_INLINE_HPP
|