24 */
25
26 #ifndef SHARE_RUNTIME_JAVATHREAD_HPP
27 #define SHARE_RUNTIME_JAVATHREAD_HPP
28
29 #include "jni.h"
30 #include "memory/allocation.hpp"
31 #include "oops/oop.hpp"
32 #include "oops/oopHandle.hpp"
33 #include "runtime/frame.hpp"
34 #include "runtime/globals.hpp"
35 #include "runtime/handshake.hpp"
36 #include "runtime/javaFrameAnchor.hpp"
37 #include "runtime/lockStack.hpp"
38 #include "runtime/park.hpp"
39 #include "runtime/safepointMechanism.hpp"
40 #include "runtime/stackWatermarkSet.hpp"
41 #include "runtime/stackOverflow.hpp"
42 #include "runtime/thread.hpp"
43 #include "runtime/threadHeapSampler.hpp"
44 #include "runtime/threadStatisticalInfo.hpp"
45 #include "utilities/exceptions.hpp"
46 #include "utilities/globalDefinitions.hpp"
47 #include "utilities/macros.hpp"
48 #if INCLUDE_JFR
49 #include "jfr/support/jfrThreadExtension.hpp"
50 #endif
51
52 class AsyncExceptionHandshake;
53 class ContinuationEntry;
54 class DeoptResourceMark;
55 class InternalOOMEMark;
56 class JNIHandleBlock;
57 class JVMCIRuntime;
58
59 class JvmtiDeferredUpdates;
60 class JvmtiSampledObjectAllocEventCollector;
61 class JvmtiThreadState;
62
63 class Metadata;
141
142 // Used to pass back results to the interpreter or generated code running Java code.
143 oop _vm_result; // oop result is GC-preserved
144 Metadata* _vm_result_2; // non-oop result
145
146 // See ReduceInitialCardMarks: this holds the precise space interval of
147 // the most recent slow path allocation for which compiled code has
148 // elided card-marks for performance along the fast-path.
149 MemRegion _deferred_card_mark;
150
151 ObjectMonitor* volatile _current_pending_monitor; // ObjectMonitor this thread is waiting to lock
152 bool _current_pending_monitor_is_from_java; // locking is from Java code
153 ObjectMonitor* volatile _current_waiting_monitor; // ObjectMonitor on which this thread called Object.wait()
154
155 // Active_handles points to a block of handles
156 JNIHandleBlock* _active_handles;
157
158 // One-element thread local free list
159 JNIHandleBlock* _free_handle_block;
160
161 public:
162 // For tracking the heavyweight monitor the thread is pending on.
163 ObjectMonitor* current_pending_monitor() {
164 // Use Atomic::load() to prevent data race between concurrent modification and
165 // concurrent readers, e.g. ThreadService::get_current_contended_monitor().
166 // Especially, reloading pointer from thread after null check must be prevented.
167 return Atomic::load(&_current_pending_monitor);
168 }
169 void set_current_pending_monitor(ObjectMonitor* monitor) {
170 Atomic::store(&_current_pending_monitor, monitor);
171 }
172 void set_current_pending_monitor_is_from_java(bool from_java) {
173 _current_pending_monitor_is_from_java = from_java;
174 }
175 bool current_pending_monitor_is_from_java() {
176 return _current_pending_monitor_is_from_java;
177 }
178 ObjectMonitor* current_waiting_monitor() {
179 // See the comment in current_pending_monitor() above.
180 return Atomic::load(&_current_waiting_monitor);
181 }
298 //
299 // _vm_exited is a special value to cover the case of a JavaThread
300 // executing native code after the VM itself is terminated.
301 //
302 // A JavaThread that fails to JNI attach has these _terminated field transitions:
303 // _not_terminated => _thread_terminated
304 //
305 volatile TerminatedTypes _terminated;
306
307 jint _in_deopt_handler; // count of deoptimization
308 // handlers thread is in
309 volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access
310 bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was
311 // never locked) when throwing an exception. Used by interpreter only.
312 #if INCLUDE_JVMTI
313 volatile bool _carrier_thread_suspended; // Carrier thread is externally suspended
314 bool _is_in_VTMS_transition; // thread is in virtual thread mount state transition
315 bool _is_in_tmp_VTMS_transition; // thread is in temporary virtual thread mount state transition
316 bool _is_disable_suspend; // JVMTI suspend is temporarily disabled; used on current thread only
317 bool _VTMS_transition_mark; // used for sync between VTMS transitions and disablers
318 #ifdef ASSERT
319 bool _is_VTMS_transition_disabler; // thread currently disabled VTMS transitions
320 #endif
321 #endif
322
323 // JNI attach states:
324 enum JNIAttachStates {
325 _not_attaching_via_jni = 1, // thread is not attaching via JNI
326 _attaching_via_jni, // thread is attaching via JNI
327 _attached_via_jni // thread has attached via JNI
328 };
329
330 // A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
331 // A native thread that is attaching via JNI starts with a value
332 // of _attaching_via_jni and transitions to _attached_via_jni.
333 volatile JNIAttachStates _jni_attach_state;
334
335 // In scope of an InternalOOMEMark?
336 bool _is_in_internal_oome_mark;
337
446 int _depth_first_number;
447
448 // JVMTI PopFrame support
449 // This is set to popframe_pending to signal that top Java frame should be popped immediately
450 int _popframe_condition;
451
452 // If reallocation of scalar replaced objects fails, we throw OOM
453 // and during exception propagation, pop the top
454 // _frames_to_pop_failed_realloc frames, the ones that reference
455 // failed reallocations.
456 int _frames_to_pop_failed_realloc;
457
458 ContinuationEntry* _cont_entry;
459 intptr_t* _cont_fastpath; // the sp of the oldest known interpreted/call_stub frame inside the
460 // continuation that we know about
461 int _cont_fastpath_thread_state; // whether global thread state allows continuation fastpath (JVMTI)
462
463 // It's signed for error detection.
464 intx _held_monitor_count; // used by continuations for fast lock detection
465 intx _jni_monitor_count;
466
467 private:
468
469 friend class VMThread;
470 friend class ThreadWaitTransition;
471 friend class VM_Exit;
472
473 // Stack watermark barriers.
474 StackWatermarks _stack_watermarks;
475
476 public:
477 inline StackWatermarks* stack_watermarks() { return &_stack_watermarks; }
478
479 public:
480 // Constructor
481 JavaThread(MEMFLAGS flags = mtThread); // delegating constructor
482 JavaThread(ThreadFunction entry_point, size_t stack_size = 0, MEMFLAGS flags = mtThread);
483 ~JavaThread();
484
485 // Factory method to create a new JavaThread whose attach state is "is attaching"
592 void set_doing_unsafe_access(bool val) { _doing_unsafe_access = val; }
593
594 bool do_not_unlock_if_synchronized() { return _do_not_unlock_if_synchronized; }
595 void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
596
597 SafepointMechanism::ThreadData* poll_data() { return &_poll_data; }
598
599 void set_requires_cross_modify_fence(bool val) PRODUCT_RETURN NOT_PRODUCT({ _requires_cross_modify_fence = val; })
600
601 // Continuation support
602 ContinuationEntry* last_continuation() const { return _cont_entry; }
603 void set_cont_fastpath(intptr_t* x) { _cont_fastpath = x; }
604 void push_cont_fastpath(intptr_t* sp) { if (sp > _cont_fastpath) _cont_fastpath = sp; }
605 void set_cont_fastpath_thread_state(bool x) { _cont_fastpath_thread_state = (int)x; }
606 intptr_t* raw_cont_fastpath() const { return _cont_fastpath; }
607 bool cont_fastpath() const { return _cont_fastpath == nullptr && _cont_fastpath_thread_state != 0; }
608 bool cont_fastpath_thread_state() const { return _cont_fastpath_thread_state != 0; }
609
610 void inc_held_monitor_count(intx i = 1, bool jni = false);
611 void dec_held_monitor_count(intx i = 1, bool jni = false);
612
613 intx held_monitor_count() { return _held_monitor_count; }
614 intx jni_monitor_count() { return _jni_monitor_count; }
615 void clear_jni_monitor_count() { _jni_monitor_count = 0; }
616
617 inline bool is_vthread_mounted() const;
618 inline const ContinuationEntry* vthread_continuation() const;
619
620 private:
621 DEBUG_ONLY(void verify_frame_info();)
622
623 // Support for thread handshake operations
624 HandshakeState _handshake;
625 public:
626 HandshakeState* handshake_state() { return &_handshake; }
627
628 // A JavaThread can always safely operate on it self and other threads
629 // can do it safely if they are the active handshaker.
630 bool is_handshake_safe_for(Thread* th) const {
631 return _handshake.active_handshaker() == th || this == th;
632 }
633
634 // Suspend/resume support for JavaThread
635 // higher-level suspension/resume logic called by the public APIs
636 bool java_suspend();
637 bool java_resume();
638 bool is_suspended() { return _handshake.is_suspended(); }
639
648 inline void set_carrier_thread_suspended();
649 inline void clear_carrier_thread_suspended();
650
651 bool is_carrier_thread_suspended() const {
652 return _carrier_thread_suspended;
653 }
654
655 bool is_in_VTMS_transition() const { return _is_in_VTMS_transition; }
656 bool is_in_tmp_VTMS_transition() const { return _is_in_tmp_VTMS_transition; }
657 bool is_in_any_VTMS_transition() const { return _is_in_VTMS_transition || _is_in_tmp_VTMS_transition; }
658
659 void set_is_in_VTMS_transition(bool val);
660 void toggle_is_in_tmp_VTMS_transition() { _is_in_tmp_VTMS_transition = !_is_in_tmp_VTMS_transition; };
661
662 bool is_disable_suspend() const { return _is_disable_suspend; }
663 void toggle_is_disable_suspend() { _is_disable_suspend = !_is_disable_suspend; };
664
665 bool VTMS_transition_mark() const { return Atomic::load(&_VTMS_transition_mark); }
666 void set_VTMS_transition_mark(bool val) { Atomic::store(&_VTMS_transition_mark, val); }
667
668 #ifdef ASSERT
669 bool is_VTMS_transition_disabler() const { return _is_VTMS_transition_disabler; }
670 void set_is_VTMS_transition_disabler(bool val);
671 #endif
672 #endif
673
674 // Support for object deoptimization and JFR suspension
675 void handle_special_runtime_exit_condition();
676 bool has_special_runtime_exit_condition() {
677 return (_suspend_flags & (_obj_deopt JFR_ONLY(| _trace_flag))) != 0;
678 }
679
680 // Stack-locking support (not for LM_LIGHTWEIGHT)
681 bool is_lock_owned(address adr) const;
682
683 // Accessors for vframe array top
684 // The linked list of vframe arrays are sorted on sp. This means when we
685 // unpack the head must contain the vframe array to unpack.
686 void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
687 vframeArray* vframe_array_head() const { return _vframe_array_head; }
688
689 // Side structure for deferring update of java frame locals until deopt occurs
690 JvmtiDeferredUpdates* deferred_updates() const { return _jvmti_deferred_updates; }
691 void set_deferred_updates(JvmtiDeferredUpdates* du) { _jvmti_deferred_updates = du; }
692
693 // These only really exist to make debugging deopt problems simpler
806 }
807 static ByteSize reserved_stack_activation_offset() {
808 return byte_offset_of(JavaThread, _stack_overflow_state._reserved_stack_activation);
809 }
810 static ByteSize shadow_zone_safe_limit() {
811 return byte_offset_of(JavaThread, _stack_overflow_state._shadow_zone_safe_limit);
812 }
813 static ByteSize shadow_zone_growth_watermark() {
814 return byte_offset_of(JavaThread, _stack_overflow_state._shadow_zone_growth_watermark);
815 }
816
817 static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags); }
818
819 static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
820 static ByteSize should_post_on_exceptions_flag_offset() {
821 return byte_offset_of(JavaThread, _should_post_on_exceptions_flag);
822 }
823 static ByteSize doing_unsafe_access_offset() { return byte_offset_of(JavaThread, _doing_unsafe_access); }
824 NOT_PRODUCT(static ByteSize requires_cross_modify_fence_offset() { return byte_offset_of(JavaThread, _requires_cross_modify_fence); })
825
826 static ByteSize cont_entry_offset() { return byte_offset_of(JavaThread, _cont_entry); }
827 static ByteSize cont_fastpath_offset() { return byte_offset_of(JavaThread, _cont_fastpath); }
828 static ByteSize held_monitor_count_offset() { return byte_offset_of(JavaThread, _held_monitor_count); }
829 static ByteSize jni_monitor_count_offset() { return byte_offset_of(JavaThread, _jni_monitor_count); }
830
831 #if INCLUDE_JVMTI
832 static ByteSize is_in_VTMS_transition_offset() { return byte_offset_of(JavaThread, _is_in_VTMS_transition); }
833 static ByteSize is_in_tmp_VTMS_transition_offset() { return byte_offset_of(JavaThread, _is_in_tmp_VTMS_transition); }
834 static ByteSize is_disable_suspend_offset() { return byte_offset_of(JavaThread, _is_disable_suspend); }
835 #endif
836
837 // Returns the jni environment for this thread
838 JNIEnv* jni_environment() { return &_jni_environment; }
839
840 // Returns the current thread as indicated by the given JNIEnv.
841 // We don't assert it is Thread::current here as that is done at the
842 // external JNI entry points where the JNIEnv is passed into the VM.
843 static JavaThread* thread_from_jni_environment(JNIEnv* env) {
844 JavaThread* current = reinterpret_cast<JavaThread*>(((intptr_t)env - in_bytes(jni_environment_offset())));
845 // We can't normally get here in a thread that has completed its
846 // execution and so "is_terminated", except when the call is from
847 // AsyncGetCallTrace, which can be triggered by a signal at any point in
848 // a thread's lifecycle. A thread is also considered terminated if the VM
849 // has exited, so we have to check this and block in case this is a daemon
1221 public:
1222 UnlockFlagSaver(JavaThread* t) {
1223 _thread = t;
1224 _do_not_unlock = t->do_not_unlock_if_synchronized();
1225 t->set_do_not_unlock_if_synchronized(false);
1226 }
1227 ~UnlockFlagSaver() {
1228 _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
1229 }
1230 };
1231
1232 class JNIHandleMark : public StackObj {
1233 JavaThread* _thread;
1234 public:
1235 JNIHandleMark(JavaThread* thread) : _thread(thread) {
1236 thread->push_jni_handle_block();
1237 }
1238 ~JNIHandleMark() { _thread->pop_jni_handle_block(); }
1239 };
1240
1241 #endif // SHARE_RUNTIME_JAVATHREAD_HPP
|
24 */
25
26 #ifndef SHARE_RUNTIME_JAVATHREAD_HPP
27 #define SHARE_RUNTIME_JAVATHREAD_HPP
28
29 #include "jni.h"
30 #include "memory/allocation.hpp"
31 #include "oops/oop.hpp"
32 #include "oops/oopHandle.hpp"
33 #include "runtime/frame.hpp"
34 #include "runtime/globals.hpp"
35 #include "runtime/handshake.hpp"
36 #include "runtime/javaFrameAnchor.hpp"
37 #include "runtime/lockStack.hpp"
38 #include "runtime/park.hpp"
39 #include "runtime/safepointMechanism.hpp"
40 #include "runtime/stackWatermarkSet.hpp"
41 #include "runtime/stackOverflow.hpp"
42 #include "runtime/thread.hpp"
43 #include "runtime/threadHeapSampler.hpp"
44 #include "runtime/threadIdentifier.hpp"
45 #include "runtime/threadStatisticalInfo.hpp"
46 #include "utilities/exceptions.hpp"
47 #include "utilities/globalDefinitions.hpp"
48 #include "utilities/macros.hpp"
49 #if INCLUDE_JFR
50 #include "jfr/support/jfrThreadExtension.hpp"
51 #endif
52
53 class AsyncExceptionHandshake;
54 class ContinuationEntry;
55 class DeoptResourceMark;
56 class InternalOOMEMark;
57 class JNIHandleBlock;
58 class JVMCIRuntime;
59
60 class JvmtiDeferredUpdates;
61 class JvmtiSampledObjectAllocEventCollector;
62 class JvmtiThreadState;
63
64 class Metadata;
142
143 // Used to pass back results to the interpreter or generated code running Java code.
144 oop _vm_result; // oop result is GC-preserved
145 Metadata* _vm_result_2; // non-oop result
146
147 // See ReduceInitialCardMarks: this holds the precise space interval of
148 // the most recent slow path allocation for which compiled code has
149 // elided card-marks for performance along the fast-path.
150 MemRegion _deferred_card_mark;
151
152 ObjectMonitor* volatile _current_pending_monitor; // ObjectMonitor this thread is waiting to lock
153 bool _current_pending_monitor_is_from_java; // locking is from Java code
154 ObjectMonitor* volatile _current_waiting_monitor; // ObjectMonitor on which this thread called Object.wait()
155
156 // Active_handles points to a block of handles
157 JNIHandleBlock* _active_handles;
158
159 // One-element thread local free list
160 JNIHandleBlock* _free_handle_block;
161
162 // ID used as owner for inflated monitors. Same as the tidĀ field of the current
163 // _vthread object, except during creation of the primordial and JNI attached
164 // thread cases where this field can have a temporal value.
165 int64_t _lock_id;
166
167 public:
168 bool _on_monitorenter;
169
170 bool is_on_monitorenter() { return _on_monitorenter; }
171 void set_on_monitorenter(bool val) { _on_monitorenter = val; }
172
173 void set_lock_id(int64_t tid) {
174 assert(tid >= ThreadIdentifier::initial() && tid < ThreadIdentifier::current(), "invalid tid");
175 _lock_id = tid;
176 }
177 int64_t lock_id() const { return _lock_id; }
178
179 // For tracking the heavyweight monitor the thread is pending on.
180 ObjectMonitor* current_pending_monitor() {
181 // Use Atomic::load() to prevent data race between concurrent modification and
182 // concurrent readers, e.g. ThreadService::get_current_contended_monitor().
183 // Especially, reloading pointer from thread after null check must be prevented.
184 return Atomic::load(&_current_pending_monitor);
185 }
186 void set_current_pending_monitor(ObjectMonitor* monitor) {
187 Atomic::store(&_current_pending_monitor, monitor);
188 }
189 void set_current_pending_monitor_is_from_java(bool from_java) {
190 _current_pending_monitor_is_from_java = from_java;
191 }
192 bool current_pending_monitor_is_from_java() {
193 return _current_pending_monitor_is_from_java;
194 }
195 ObjectMonitor* current_waiting_monitor() {
196 // See the comment in current_pending_monitor() above.
197 return Atomic::load(&_current_waiting_monitor);
198 }
315 //
316 // _vm_exited is a special value to cover the case of a JavaThread
317 // executing native code after the VM itself is terminated.
318 //
319 // A JavaThread that fails to JNI attach has these _terminated field transitions:
320 // _not_terminated => _thread_terminated
321 //
322 volatile TerminatedTypes _terminated;
323
324 jint _in_deopt_handler; // count of deoptimization
325 // handlers thread is in
326 volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access
327 bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was
328 // never locked) when throwing an exception. Used by interpreter only.
329 #if INCLUDE_JVMTI
330 volatile bool _carrier_thread_suspended; // Carrier thread is externally suspended
331 bool _is_in_VTMS_transition; // thread is in virtual thread mount state transition
332 bool _is_in_tmp_VTMS_transition; // thread is in temporary virtual thread mount state transition
333 bool _is_disable_suspend; // JVMTI suspend is temporarily disabled; used on current thread only
334 bool _VTMS_transition_mark; // used for sync between VTMS transitions and disablers
335 bool _pending_jvmti_unmount_event; // When preempting we post unmount event at unmount end rather than start
336 ObjectMonitor* _contended_entered_monitor; // Monitor por pending monitor_contended_entered callback
337 #ifdef ASSERT
338 bool _is_VTMS_transition_disabler; // thread currently disabled VTMS transitions
339 #endif
340 #endif
341
342 // JNI attach states:
343 enum JNIAttachStates {
344 _not_attaching_via_jni = 1, // thread is not attaching via JNI
345 _attaching_via_jni, // thread is attaching via JNI
346 _attached_via_jni // thread has attached via JNI
347 };
348
349 // A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
350 // A native thread that is attaching via JNI starts with a value
351 // of _attaching_via_jni and transitions to _attached_via_jni.
352 volatile JNIAttachStates _jni_attach_state;
353
354 // In scope of an InternalOOMEMark?
355 bool _is_in_internal_oome_mark;
356
465 int _depth_first_number;
466
467 // JVMTI PopFrame support
468 // This is set to popframe_pending to signal that top Java frame should be popped immediately
469 int _popframe_condition;
470
471 // If reallocation of scalar replaced objects fails, we throw OOM
472 // and during exception propagation, pop the top
473 // _frames_to_pop_failed_realloc frames, the ones that reference
474 // failed reallocations.
475 int _frames_to_pop_failed_realloc;
476
477 ContinuationEntry* _cont_entry;
478 intptr_t* _cont_fastpath; // the sp of the oldest known interpreted/call_stub frame inside the
479 // continuation that we know about
480 int _cont_fastpath_thread_state; // whether global thread state allows continuation fastpath (JVMTI)
481
482 // It's signed for error detection.
483 intx _held_monitor_count; // used by continuations for fast lock detection
484 intx _jni_monitor_count;
485 bool _preempting;
486 bool _preemption_cancelled;
487 bool _pending_interrupted_exception;
488 address _preempt_alternate_return; // used when preempting a thread
489
490 #ifdef ASSERT
491 intx _obj_locker_count;
492
493 public:
494 intx obj_locker_count() { return _obj_locker_count; }
495 void inc_obj_locker_count() {
496 assert(_obj_locker_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _obj_locker_count);
497 _obj_locker_count++;
498 }
499 void dec_obj_locker_count() {
500 _obj_locker_count--;
501 assert(_obj_locker_count >= 0, "Must always be greater than 0: " INTX_FORMAT, _obj_locker_count);
502 }
503 #endif // ASSERT
504
505 private:
506
507 friend class VMThread;
508 friend class ThreadWaitTransition;
509 friend class VM_Exit;
510
511 // Stack watermark barriers.
512 StackWatermarks _stack_watermarks;
513
514 public:
515 inline StackWatermarks* stack_watermarks() { return &_stack_watermarks; }
516
517 public:
518 // Constructor
519 JavaThread(MEMFLAGS flags = mtThread); // delegating constructor
520 JavaThread(ThreadFunction entry_point, size_t stack_size = 0, MEMFLAGS flags = mtThread);
521 ~JavaThread();
522
523 // Factory method to create a new JavaThread whose attach state is "is attaching"
630 void set_doing_unsafe_access(bool val) { _doing_unsafe_access = val; }
631
632 bool do_not_unlock_if_synchronized() { return _do_not_unlock_if_synchronized; }
633 void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; }
634
635 SafepointMechanism::ThreadData* poll_data() { return &_poll_data; }
636
637 void set_requires_cross_modify_fence(bool val) PRODUCT_RETURN NOT_PRODUCT({ _requires_cross_modify_fence = val; })
638
639 // Continuation support
640 ContinuationEntry* last_continuation() const { return _cont_entry; }
641 void set_cont_fastpath(intptr_t* x) { _cont_fastpath = x; }
642 void push_cont_fastpath(intptr_t* sp) { if (sp > _cont_fastpath) _cont_fastpath = sp; }
643 void set_cont_fastpath_thread_state(bool x) { _cont_fastpath_thread_state = (int)x; }
644 intptr_t* raw_cont_fastpath() const { return _cont_fastpath; }
645 bool cont_fastpath() const { return _cont_fastpath == nullptr && _cont_fastpath_thread_state != 0; }
646 bool cont_fastpath_thread_state() const { return _cont_fastpath_thread_state != 0; }
647
648 void inc_held_monitor_count(intx i = 1, bool jni = false);
649 void dec_held_monitor_count(intx i = 1, bool jni = false);
650 intx held_monitor_count() { return _held_monitor_count; }
651
652 intx jni_monitor_count() { return _jni_monitor_count; }
653 void clear_jni_monitor_count() { _jni_monitor_count = 0; }
654
655 inline bool is_vthread_mounted() const;
656 inline const ContinuationEntry* vthread_continuation() const;
657
658 bool preempting() { return _preempting; }
659 void set_preempting(bool b) { _preempting = b; }
660
661 bool preemption_cancelled() { return _preemption_cancelled; }
662 void set_preemption_cancelled(bool b) { _preemption_cancelled = b; }
663
664 bool pending_interrupted_exception() { return _pending_interrupted_exception; }
665 void set_pending_interrupted_exception(bool b) { _pending_interrupted_exception = b; }
666
667 void set_preempt_alternate_return(address val) { _preempt_alternate_return = val; }
668
669 private:
670 DEBUG_ONLY(void verify_frame_info();)
671
672 // Support for thread handshake operations
673 HandshakeState _handshake;
674 public:
675 HandshakeState* handshake_state() { return &_handshake; }
676
677 // A JavaThread can always safely operate on it self and other threads
678 // can do it safely if they are the active handshaker.
679 bool is_handshake_safe_for(Thread* th) const {
680 return _handshake.active_handshaker() == th || this == th;
681 }
682
683 // Suspend/resume support for JavaThread
684 // higher-level suspension/resume logic called by the public APIs
685 bool java_suspend();
686 bool java_resume();
687 bool is_suspended() { return _handshake.is_suspended(); }
688
697 inline void set_carrier_thread_suspended();
698 inline void clear_carrier_thread_suspended();
699
700 bool is_carrier_thread_suspended() const {
701 return _carrier_thread_suspended;
702 }
703
704 bool is_in_VTMS_transition() const { return _is_in_VTMS_transition; }
705 bool is_in_tmp_VTMS_transition() const { return _is_in_tmp_VTMS_transition; }
706 bool is_in_any_VTMS_transition() const { return _is_in_VTMS_transition || _is_in_tmp_VTMS_transition; }
707
708 void set_is_in_VTMS_transition(bool val);
709 void toggle_is_in_tmp_VTMS_transition() { _is_in_tmp_VTMS_transition = !_is_in_tmp_VTMS_transition; };
710
711 bool is_disable_suspend() const { return _is_disable_suspend; }
712 void toggle_is_disable_suspend() { _is_disable_suspend = !_is_disable_suspend; };
713
714 bool VTMS_transition_mark() const { return Atomic::load(&_VTMS_transition_mark); }
715 void set_VTMS_transition_mark(bool val) { Atomic::store(&_VTMS_transition_mark, val); }
716
717 bool pending_jvmti_unmount_event() { return _pending_jvmti_unmount_event; }
718 void set_pending_jvmti_unmount_event(bool val) { _pending_jvmti_unmount_event = val; }
719
720 bool pending_contended_entered_event() { return _contended_entered_monitor != nullptr; }
721 ObjectMonitor* contended_entered_monitor() { return _contended_entered_monitor; }
722 #ifdef ASSERT
723 bool is_VTMS_transition_disabler() const { return _is_VTMS_transition_disabler; }
724 void set_is_VTMS_transition_disabler(bool val);
725 #endif
726 #endif
727
728 void set_contended_entered_monitor(ObjectMonitor* val) NOT_JVMTI_RETURN JVMTI_ONLY({ _contended_entered_monitor = val; })
729
730 // Support for object deoptimization and JFR suspension
731 void handle_special_runtime_exit_condition();
732 bool has_special_runtime_exit_condition() {
733 return (_suspend_flags & (_obj_deopt JFR_ONLY(| _trace_flag))) != 0;
734 }
735
736 // Stack-locking support (not for LM_LIGHTWEIGHT)
737 bool is_lock_owned(address adr) const;
738
739 // Accessors for vframe array top
740 // The linked list of vframe arrays are sorted on sp. This means when we
741 // unpack the head must contain the vframe array to unpack.
742 void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
743 vframeArray* vframe_array_head() const { return _vframe_array_head; }
744
745 // Side structure for deferring update of java frame locals until deopt occurs
746 JvmtiDeferredUpdates* deferred_updates() const { return _jvmti_deferred_updates; }
747 void set_deferred_updates(JvmtiDeferredUpdates* du) { _jvmti_deferred_updates = du; }
748
749 // These only really exist to make debugging deopt problems simpler
862 }
863 static ByteSize reserved_stack_activation_offset() {
864 return byte_offset_of(JavaThread, _stack_overflow_state._reserved_stack_activation);
865 }
866 static ByteSize shadow_zone_safe_limit() {
867 return byte_offset_of(JavaThread, _stack_overflow_state._shadow_zone_safe_limit);
868 }
869 static ByteSize shadow_zone_growth_watermark() {
870 return byte_offset_of(JavaThread, _stack_overflow_state._shadow_zone_growth_watermark);
871 }
872
873 static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags); }
874
875 static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
876 static ByteSize should_post_on_exceptions_flag_offset() {
877 return byte_offset_of(JavaThread, _should_post_on_exceptions_flag);
878 }
879 static ByteSize doing_unsafe_access_offset() { return byte_offset_of(JavaThread, _doing_unsafe_access); }
880 NOT_PRODUCT(static ByteSize requires_cross_modify_fence_offset() { return byte_offset_of(JavaThread, _requires_cross_modify_fence); })
881
882 static ByteSize lock_id_offset() { return byte_offset_of(JavaThread, _lock_id); }
883
884 static ByteSize cont_entry_offset() { return byte_offset_of(JavaThread, _cont_entry); }
885 static ByteSize cont_fastpath_offset() { return byte_offset_of(JavaThread, _cont_fastpath); }
886 static ByteSize held_monitor_count_offset() { return byte_offset_of(JavaThread, _held_monitor_count); }
887 static ByteSize jni_monitor_count_offset() { return byte_offset_of(JavaThread, _jni_monitor_count); }
888 static ByteSize preempting_offset() { return byte_offset_of(JavaThread, _preempting); }
889 static ByteSize preemption_cancelled_offset() { return byte_offset_of(JavaThread, _preemption_cancelled); }
890 static ByteSize preempt_alternate_return_offset() { return byte_offset_of(JavaThread, _preempt_alternate_return); }
891
892 #if INCLUDE_JVMTI
893 static ByteSize is_in_VTMS_transition_offset() { return byte_offset_of(JavaThread, _is_in_VTMS_transition); }
894 static ByteSize is_in_tmp_VTMS_transition_offset() { return byte_offset_of(JavaThread, _is_in_tmp_VTMS_transition); }
895 static ByteSize is_disable_suspend_offset() { return byte_offset_of(JavaThread, _is_disable_suspend); }
896 #endif
897
898 // Returns the jni environment for this thread
899 JNIEnv* jni_environment() { return &_jni_environment; }
900
901 // Returns the current thread as indicated by the given JNIEnv.
902 // We don't assert it is Thread::current here as that is done at the
903 // external JNI entry points where the JNIEnv is passed into the VM.
904 static JavaThread* thread_from_jni_environment(JNIEnv* env) {
905 JavaThread* current = reinterpret_cast<JavaThread*>(((intptr_t)env - in_bytes(jni_environment_offset())));
906 // We can't normally get here in a thread that has completed its
907 // execution and so "is_terminated", except when the call is from
908 // AsyncGetCallTrace, which can be triggered by a signal at any point in
909 // a thread's lifecycle. A thread is also considered terminated if the VM
910 // has exited, so we have to check this and block in case this is a daemon
1282 public:
1283 UnlockFlagSaver(JavaThread* t) {
1284 _thread = t;
1285 _do_not_unlock = t->do_not_unlock_if_synchronized();
1286 t->set_do_not_unlock_if_synchronized(false);
1287 }
1288 ~UnlockFlagSaver() {
1289 _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
1290 }
1291 };
1292
1293 class JNIHandleMark : public StackObj {
1294 JavaThread* _thread;
1295 public:
1296 JNIHandleMark(JavaThread* thread) : _thread(thread) {
1297 thread->push_jni_handle_block();
1298 }
1299 ~JNIHandleMark() { _thread->pop_jni_handle_block(); }
1300 };
1301
1302 class ThreadOnMonitorEnter {
1303 JavaThread* _thread;
1304 public:
1305 ThreadOnMonitorEnter(JavaThread* thread) : _thread(thread) {
1306 _thread->set_on_monitorenter(true);
1307 }
1308 ~ThreadOnMonitorEnter() { _thread->set_on_monitorenter(false); }
1309 };
1310
1311 #endif // SHARE_RUNTIME_JAVATHREAD_HPP
|