src/hotspot/share/jfr/recorder/service/jfrPostBox.cpp
changeset 58863 c16ac7a2eba4
parent 54645 05aaccf7d558
child 59251 4cbfa5077d68
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "jfr/recorder/service/jfrPostBox.hpp"
    26 #include "jfr/recorder/service/jfrPostBox.hpp"
    27 #include "jfr/utilities/jfrTryLock.hpp"
    27 #include "jfr/utilities/jfrTryLock.hpp"
    28 #include "runtime/atomic.hpp"
    28 #include "runtime/atomic.hpp"
    29 #include "runtime/orderAccess.hpp"
       
    30 #include "runtime/thread.inline.hpp"
    29 #include "runtime/thread.inline.hpp"
    31 
    30 
    32 #define MSG_IS_SYNCHRONOUS ( (MSGBIT(MSG_ROTATE)) |          \
    31 #define MSG_IS_SYNCHRONOUS ( (MSGBIT(MSG_ROTATE)) |          \
    33                              (MSGBIT(MSG_STOP))   |          \
    32                              (MSGBIT(MSG_STOP))   |          \
    34                              (MSGBIT(MSG_START))  |          \
    33                              (MSGBIT(MSG_START))  |          \
    35                              (MSGBIT(MSG_CLONE_IN_MEMORY)) | \
    34                              (MSGBIT(MSG_CLONE_IN_MEMORY)) | \
    36                              (MSGBIT(MSG_VM_ERROR))          \
    35                              (MSGBIT(MSG_VM_ERROR))        | \
       
    36                              (MSGBIT(MSG_FLUSHPOINT))        \
    37                            )
    37                            )
    38 
    38 
    39 static JfrPostBox* _instance = NULL;
    39 static JfrPostBox* _instance = NULL;
    40 
    40 
    41 JfrPostBox& JfrPostBox::instance() {
    41 JfrPostBox& JfrPostBox::instance() {
    82   synchronous_post(the_message);
    82   synchronous_post(the_message);
    83 }
    83 }
    84 
    84 
    85 void JfrPostBox::deposit(int new_messages) {
    85 void JfrPostBox::deposit(int new_messages) {
    86   while (true) {
    86   while (true) {
    87     const int current_msgs = OrderAccess::load_acquire(&_messages);
    87     const int current_msgs = Atomic::load(&_messages);
    88     // OR the new message
    88     // OR the new message
    89     const int exchange_value = current_msgs | new_messages;
    89     const int exchange_value = current_msgs | new_messages;
    90     const int result = Atomic::cmpxchg(exchange_value, &_messages, current_msgs);
    90     const int result = Atomic::cmpxchg(exchange_value, &_messages, current_msgs);
    91     if (result == current_msgs) {
    91     if (result == current_msgs) {
    92       return;
    92       return;
   112   assert(!JfrMsg_lock->owned_by_self(), "should not hold JfrMsg_lock here!");
   112   assert(!JfrMsg_lock->owned_by_self(), "should not hold JfrMsg_lock here!");
   113   MonitorLocker msg_lock(JfrMsg_lock);
   113   MonitorLocker msg_lock(JfrMsg_lock);
   114   deposit(msg);
   114   deposit(msg);
   115   // serial_id is used to check when what we send in has been processed.
   115   // serial_id is used to check when what we send in has been processed.
   116   // _msg_read_serial is read under JfrMsg_lock protection.
   116   // _msg_read_serial is read under JfrMsg_lock protection.
   117   const uintptr_t serial_id = OrderAccess::load_acquire(&_msg_read_serial) + 1;
   117   const uintptr_t serial_id = Atomic::load(&_msg_read_serial) + 1;
   118   msg_lock.notify_all();
   118   msg_lock.notify_all();
   119   while (!is_message_processed(serial_id)) {
   119   while (!is_message_processed(serial_id)) {
   120     msg_lock.wait();
   120     msg_lock.wait();
   121   }
   121   }
   122 }
   122 }
   127  * that we are holding the JfrMsg_lock when checking
   127  * that we are holding the JfrMsg_lock when checking
   128  * completion status.
   128  * completion status.
   129  */
   129  */
   130 bool JfrPostBox::is_message_processed(uintptr_t serial_id) const {
   130 bool JfrPostBox::is_message_processed(uintptr_t serial_id) const {
   131   assert(JfrMsg_lock->owned_by_self(), "_msg_handled_serial must be read under JfrMsg_lock protection");
   131   assert(JfrMsg_lock->owned_by_self(), "_msg_handled_serial must be read under JfrMsg_lock protection");
   132   return serial_id <= OrderAccess::load_acquire(&_msg_handled_serial);
   132   return serial_id <= Atomic::load(&_msg_handled_serial);
   133 }
   133 }
   134 
   134 
   135 bool JfrPostBox::is_empty() const {
   135 bool JfrPostBox::is_empty() const {
   136   assert(JfrMsg_lock->owned_by_self(), "not holding JfrMsg_lock!");
   136   assert(JfrMsg_lock->owned_by_self(), "not holding JfrMsg_lock!");
   137   return OrderAccess::load_acquire(&_messages) == 0;
   137   return Atomic::load(&_messages) == 0;
   138 }
   138 }
   139 
   139 
   140 int JfrPostBox::collect() {
   140 int JfrPostBox::collect() {
   141   // get pending and reset to 0
   141   // get pending and reset to 0
   142   const int messages = Atomic::xchg(0, &_messages);
   142   const int messages = Atomic::xchg(0, &_messages);