< prev index next >

src/hotspot/share/runtime/handshake.hpp

Print this page
rev 57079 : [mq]: handshake-logs


  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_RUNTIME_HANDSHAKE_HPP
  26 #define SHARE_RUNTIME_HANDSHAKE_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/flags/flagSetting.hpp"
  30 #include "runtime/semaphore.hpp"
  31 
  32 class ThreadClosure;
  33 class JavaThread;
  34 
  35 // A handshake operation is a callback that is executed for each JavaThread
  36 // while that thread is in a safepoint safe state. The callback is executed
  37 // either by the thread itself or by the VM thread while keeping the thread
  38 // in a blocked state. A handshake can be performed with a single
  39 // JavaThread as well.





















  40 class Handshake : public AllStatic {
  41  public:
  42   // Execution of handshake operation
  43   static void execute(ThreadClosure* thread_cl);
  44   static bool execute(ThreadClosure* thread_cl, JavaThread* target);
  45 };
  46 
  47 class HandshakeOperation;
  48 
  49 // The HandshakeState keep tracks of an ongoing handshake for one JavaThread.
  50 // VM thread and JavaThread are serialized with the semaphore making sure
  51 // the operation is only done by either VM thread on behalf of the JavaThread
  52 // or the JavaThread itself.
  53 class HandshakeState {
  54   HandshakeOperation* volatile _operation;
  55 
  56   Semaphore _semaphore;
  57   bool _thread_in_process_handshake;
  58 
  59   bool claim_handshake_for_vmthread();
  60   bool vmthread_can_process_handshake(JavaThread* target);
  61 
  62   void clear_handshake(JavaThread* thread);
  63 
  64   void process_self_inner(JavaThread* thread);
  65 public:
  66   HandshakeState();
  67 
  68   void set_operation(JavaThread* thread, HandshakeOperation* op);
  69 
  70   bool has_operation() const {
  71     return _operation != NULL;
  72   }
  73 
  74   void process_by_self(JavaThread* thread) {
  75     if (!_thread_in_process_handshake) {
  76       FlagSetting fs(_thread_in_process_handshake, true);
  77       process_self_inner(thread);
  78     }
  79   }
  80 
  81   void process_by_vmthread(JavaThread* target);
  82 };
  83 
  84 #endif // SHARE_RUNTIME_HANDSHAKE_HPP


  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_RUNTIME_HANDSHAKE_HPP
  26 #define SHARE_RUNTIME_HANDSHAKE_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/flags/flagSetting.hpp"
  30 #include "runtime/semaphore.hpp"
  31 

  32 class JavaThread;
  33 
  34 // A handshake operation is a callback that is executed for each JavaThread
  35 // while that thread is in a safepoint safe state. The callback is executed
  36 // either by the thread itself or by the VM thread while keeping the thread
  37 // in a blocked state. A handshake can be performed with a single
  38 // JavaThread as well.
  39 class HandshakeOperation: public StackObj {
  40   static Semaphore _done;
  41   bool _executed;
  42 public:
  43   HandshakeOperation() : _executed(false) {}
  44 
  45   void do_handshake(JavaThread* thread);
  46   bool thread_has_completed() { return _done.trywait(); }
  47   bool executed() const { return _executed; }
  48 
  49 #ifdef ASSERT
  50   void check_state() {
  51     assert(!_done.trywait(), "Must be zero");
  52   }
  53 #endif
  54 
  55   // Impl
  56   virtual void do_thread(JavaThread* thread) = 0;
  57   virtual const char* name() = 0;
  58 };
  59 
  60 class Handshake : public AllStatic {
  61  public:
  62   // Execution of handshake operation
  63   static void execute(HandshakeOperation* hs_op);
  64   static bool execute(HandshakeOperation* hs_op, JavaThread* target);
  65 };
  66 


  67 // The HandshakeState keep tracks of an ongoing handshake for one JavaThread.
  68 // VM thread and JavaThread are serialized with the semaphore making sure
  69 // the operation is only done by either VM thread on behalf of the JavaThread
  70 // or the JavaThread itself.
  71 class HandshakeState {
  72   HandshakeOperation* volatile _operation;
  73 
  74   Semaphore _semaphore;
  75   bool _thread_in_process_handshake;
  76 
  77   bool claim_handshake_for_vmthread();
  78   bool vmthread_can_process_handshake(JavaThread* target);
  79 
  80   void clear_handshake(JavaThread* thread);
  81 
  82   void process_self_inner(JavaThread* thread);
  83 public:
  84   HandshakeState();
  85 
  86   void set_operation(JavaThread* thread, HandshakeOperation* op);
  87 
  88   bool has_operation() const {
  89     return _operation != NULL;
  90   }
  91 
  92   void process_by_self(JavaThread* thread) {
  93     if (!_thread_in_process_handshake) {
  94       FlagSetting fs(_thread_in_process_handshake, true);
  95       process_self_inner(thread);
  96     }
  97   }
  98 
  99   bool process_by_vmthread(JavaThread* target);
 100 };
 101 
 102 #endif // SHARE_RUNTIME_HANDSHAKE_HPP
< prev index next >