< prev index next >

src/hotspot/share/prims/jvmtiThreadState.hpp

Print this page
*** 25,10 ***
--- 25,11 ---
  #ifndef SHARE_PRIMS_JVMTITHREADSTATE_HPP
  #define SHARE_PRIMS_JVMTITHREADSTATE_HPP
  
  #include "jvmtifiles/jvmti.h"
  #include "memory/allocation.hpp"
+ #include "oops/oopHandle.hpp"
  #include "prims/jvmtiEventController.hpp"
  #include "prims/jvmtiExport.hpp"
  #include "runtime/thread.hpp"
  #include "utilities/growableArray.hpp"
  

*** 66,10 ***
--- 67,83 ---
    ~JvmtiEnvThreadStateIterator();
    JvmtiEnvThreadState* first();
    JvmtiEnvThreadState* next(JvmtiEnvThreadState* ets);
  };
  
+ ///////////////////////////////////////////////////////////////
+ //
+ // class JvmtiVTMTDisabler
+ //
+ // Virtual Threads Mount Transition (VTMT) mechanism
+ //
+ class JvmtiVTMTDisabler {
+  private:
+ #ifdef ASSERT
+   static volatile unsigned short _suspend_count;
+ #endif
+   static volatile unsigned short _VTMT_count;
+   static volatile unsigned short _VTMT_disable_count; // VTMT is disabled while it is non-zero
+ 
+   static void disable_VTMT();
+   static void enable_VTMT();
+   bool _is_suspender;
+   bool _self_suspend;
+ 
+   DEBUG_ONLY(static void print_info();)
+  public:
+   JvmtiVTMTDisabler(bool is_suspender = false);
+   ~JvmtiVTMTDisabler();
+ 
+   void set_self_suspend();
+   static void start_VTMT(jthread vthread, int callsite_tag);
+   static void finish_VTMT(jthread vthread, int callsite_tag);
+   static int  VTMT_disable_count();
+   static int  VTMT_count();
+ };
+ 
+ ///////////////////////////////////////////////////////////////
+ //
+ // class VThreadList
+ //
+ // Used for Virtual Threads Suspend/Resume management
+ //
+ class VThreadList : public GrowableArrayCHeap<OopHandle, mtServiceability> {
+  public:
+   VThreadList() : GrowableArrayCHeap<OopHandle, mtServiceability>(0) {}
+   void append(oop vt);
+   void remove(oop vt);
+   int  find(oop vt) const;
+   bool contains(oop vt) const;
+   void invalidate();
+ };
+ 
+ ///////////////////////////////////////////////////////////////
+ //
+ // class JvmtiVTSuspender
+ //
+ // Virtual Threads Suspend/Resume management
+ //
+ class JvmtiVTSuspender : AllStatic {
+  private:
+   // Suspend modes for virtual threads
+   typedef enum VThreadSuspendMode {
+     vthread_suspend_none = 0,
+     vthread_suspend_ind  = 1,
+     vthread_suspend_all  = 2
+   } VThreadSuspendMode;
+ 
+   static VThreadSuspendMode _vthread_suspend_mode;
+   static VThreadList* _vthread_suspend_list;
+   static VThreadList* _vthread_resume_list;
+ 
+  public:
+   static void register_all_vthreads_suspend();
+   static void register_all_vthreads_resume();
+   static bool register_vthread_suspend(oop vt);
+   static bool register_vthread_resume(oop vt);
+   static bool is_vthread_suspended(oop vt);
+ };
  
  ///////////////////////////////////////////////////////////////
  //
  // class JvmtiThreadState
  //

*** 77,12 ***
--- 151,16 ---
  // 1. Local table of enabled events.
  class JvmtiThreadState : public CHeapObj<mtInternal> {
   private:
    friend class JvmtiEnv;
    JavaThread        *_thread;
+   JavaThread        *_thread_saved;
+   OopHandle         _thread_oop_h;
    // Jvmti Events that cannot be posted in their current context.
    JvmtiDeferredEventQueue* _jvmti_event_queue;
+   bool              _is_in_VTMT; // saved JavaThread.is_in_VTMT()
+   bool              _is_virtual; // state belongs to a virtual thread
    bool              _hide_single_stepping;
    bool              _pending_step_for_popframe;
    bool              _pending_step_for_earlyret;
    int               _hide_level;
  

*** 102,10 ***
--- 180,11 ---
    JvmtiClassLoadKind    _class_load_kind;
    GrowableArray<Klass*>* _classes_being_redefined;
  
    // This is only valid when is_interp_only_mode() returns true
    int               _cur_stack_depth;
+   int               _saved_interp_only_mode;
  
    JvmtiThreadEventEnable _thread_event_enable;
  
    // for support of JvmtiEnvThreadState
    JvmtiEnvThreadState*   _head_env_thread_state;

*** 122,11 ***
    JvmtiVMObjectAllocEventCollector* _vm_object_alloc_event_collector;
    // holds the current sampled object alloc event collector, NULL if no event collector in use
    JvmtiSampledObjectAllocEventCollector* _sampled_object_alloc_event_collector;
  
    // Should only be created by factory methods
!   JvmtiThreadState(JavaThread *thread);
  
    friend class JvmtiEnvThreadStateIterator;
    inline JvmtiEnvThreadState* head_env_thread_state();
    inline void set_head_env_thread_state(JvmtiEnvThreadState* ets);
  
--- 201,11 ---
    JvmtiVMObjectAllocEventCollector* _vm_object_alloc_event_collector;
    // holds the current sampled object alloc event collector, NULL if no event collector in use
    JvmtiSampledObjectAllocEventCollector* _sampled_object_alloc_event_collector;
  
    // Should only be created by factory methods
!   JvmtiThreadState(JavaThread *thread, oop thread_oop);
  
    friend class JvmtiEnvThreadStateIterator;
    inline JvmtiEnvThreadState* head_env_thread_state();
    inline void set_head_env_thread_state(JvmtiEnvThreadState* ets);
  

*** 149,12 ***
  
    static void periodic_clean_up();
  
    void add_env(JvmtiEnvBase *env);
  
    // Used by the interpreter for fullspeed debugging support
!   bool is_interp_only_mode()                { return _thread->is_interp_only_mode(); }
    void enter_interp_only_mode();
    void leave_interp_only_mode();
  
    // access to the linked list of all JVMTI thread states
    static JvmtiThreadState *first() {
--- 228,17 ---
  
    static void periodic_clean_up();
  
    void add_env(JvmtiEnvBase *env);
  
+   void unbind_from(JavaThread* thread);
+   void bind_to(JavaThread* thread);
+ 
    // Used by the interpreter for fullspeed debugging support
!   bool is_interp_only_mode()                {
+      return _thread == NULL ?  _saved_interp_only_mode != 0 : _thread->is_interp_only_mode();
+   }
    void enter_interp_only_mode();
    void leave_interp_only_mode();
  
    // access to the linked list of all JVMTI thread states
    static JvmtiThreadState *first() {

*** 175,10 ***
--- 259,21 ---
    void decr_cur_stack_depth();
  
    int count_frames();
  
    inline JavaThread *get_thread()      { return _thread;              }
+   inline JavaThread *get_thread_or_saved(); // return _thread_saved if _thread is NULL
+ 
+   // Needed for virtual threads as they can migrate to different JavaThread's.
+   // Also used for carrier threads to clear/restore _thread.
+   void set_thread(JavaThread* thread);
+   oop get_thread_oop();
+ 
+   // The JavaThread is_in_VTMT() bit saved at unmount to restore at mount.
+   inline bool is_in_VTMT() { return _is_in_VTMT; }
+   inline void set_is_in_VTMT(bool val) { _is_in_VTMT = val; }
+   inline bool is_virtual() { return _is_virtual; } // the _thread is virtual
  
    inline bool is_exception_detected()  { return _exception_state == ES_DETECTED;  }
    inline bool is_exception_caught()    { return _exception_state == ES_CAUGHT;  }
  
    inline void set_exception_detected() { _exception_state = ES_DETECTED; }

*** 344,14 ***
  
    void update_for_pop_top_frame();
  
    // already holding JvmtiThreadState_lock - retrieve or create JvmtiThreadState
    // Can return NULL if JavaThread is exiting.
!   static JvmtiThreadState *state_for_while_locked(JavaThread *thread);
    // retrieve or create JvmtiThreadState
    // Can return NULL if JavaThread is exiting.
!   static JvmtiThreadState *state_for(JavaThread *thread);
  
    // JVMTI ForceEarlyReturn support
  
    // This is set to earlyret_pending to signal that top Java frame
    // should be returned immediately
--- 439,14 ---
  
    void update_for_pop_top_frame();
  
    // already holding JvmtiThreadState_lock - retrieve or create JvmtiThreadState
    // Can return NULL if JavaThread is exiting.
!   static JvmtiThreadState *state_for_while_locked(JavaThread *thread, oop thread_oop = NULL);
    // retrieve or create JvmtiThreadState
    // Can return NULL if JavaThread is exiting.
!   static JvmtiThreadState *state_for(JavaThread *thread, Handle thread_handle = Handle());
  
    // JVMTI ForceEarlyReturn support
  
    // This is set to earlyret_pending to signal that top Java frame
    // should be returned immediately

*** 389,11 ***
  
    void oops_do(OopClosure* f, CodeBlobClosure* cf) NOT_JVMTI_RETURN; // GC support
    void nmethods_do(CodeBlobClosure* cf) NOT_JVMTI_RETURN;
  
  public:
!   void set_should_post_on_exceptions(bool val) { _thread->set_should_post_on_exceptions_flag(val ? JNI_TRUE : JNI_FALSE); }
  
    // Thread local event queue, which doesn't require taking the Service_lock.
    void enqueue_event(JvmtiDeferredEvent* event) NOT_JVMTI_RETURN;
    void post_events(JvmtiEnv* env);
    void run_nmethod_entry_barriers();
--- 484,11 ---
  
    void oops_do(OopClosure* f, CodeBlobClosure* cf) NOT_JVMTI_RETURN; // GC support
    void nmethods_do(CodeBlobClosure* cf) NOT_JVMTI_RETURN;
  
  public:
!   void set_should_post_on_exceptions(bool val);
  
    // Thread local event queue, which doesn't require taking the Service_lock.
    void enqueue_event(JvmtiDeferredEvent* event) NOT_JVMTI_RETURN;
    void post_events(JvmtiEnv* env);
    void run_nmethod_entry_barriers();
< prev index next >