< prev index next >

src/hotspot/share/jfr/recorder/service/jfrPostBox.cpp

Print this page




  70 }
  71 
  72 void JfrPostBox::post(JFR_Msg msg) {
  73   const int the_message = MSGBIT(msg);
  74   if (is_thread_lock_aversive()) {
  75     deposit(the_message);
  76     return;
  77   }
  78   if (!is_synchronous(the_message)) {
  79     asynchronous_post(the_message);
  80     return;
  81   }
  82   synchronous_post(the_message);
  83 }
  84 
  85 void JfrPostBox::deposit(int new_messages) {
  86   while (true) {
  87     const int current_msgs = Atomic::load(&_messages);
  88     // OR the new message
  89     const int exchange_value = current_msgs | new_messages;
  90     const int result = Atomic::cmpxchg(exchange_value, &_messages, current_msgs);
  91     if (result == current_msgs) {
  92       return;
  93     }
  94     /* Some other thread just set exactly what this thread wanted */
  95     if ((result & new_messages) == new_messages) {
  96       return;
  97     }
  98   }
  99 }
 100 
 101 void JfrPostBox::asynchronous_post(int msg) {
 102   assert(!is_synchronous(msg), "invariant");
 103   deposit(msg);
 104   JfrMonitorTryLock try_msg_lock(JfrMsg_lock);
 105   if (try_msg_lock.acquired()) {
 106     JfrMsg_lock->notify_all();
 107   }
 108 }
 109 
 110 void JfrPostBox::synchronous_post(int msg) {


 122 }
 123 
 124 /*
 125  * Check if a synchronous message has been processed.
 126  * We avoid racing on _msg_handled_serial by ensuring
 127  * that we are holding the JfrMsg_lock when checking
 128  * completion status.
 129  */
 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");
 132   return serial_id <= Atomic::load(&_msg_handled_serial);
 133 }
 134 
 135 bool JfrPostBox::is_empty() const {
 136   assert(JfrMsg_lock->owned_by_self(), "not holding JfrMsg_lock!");
 137   return Atomic::load(&_messages) == 0;
 138 }
 139 
 140 int JfrPostBox::collect() {
 141   // get pending and reset to 0
 142   const int messages = Atomic::xchg(0, &_messages);
 143   if (check_waiters(messages)) {
 144     _has_waiters = true;
 145     assert(JfrMsg_lock->owned_by_self(), "incrementing _msg_read_serial is protected by JfrMsg_lock");
 146     // Update made visible on release of JfrMsg_lock via fence instruction in Monitor::IUnlock.
 147     ++_msg_read_serial;
 148   }
 149   return messages;
 150 }
 151 
 152 bool JfrPostBox::check_waiters(int messages) const {
 153   assert(JfrMsg_lock->owned_by_self(), "not holding JfrMsg_lock!");
 154   assert(!_has_waiters, "invariant");
 155   return is_synchronous(messages);
 156 }
 157 
 158 void JfrPostBox::notify_waiters() {
 159   if (!_has_waiters) {
 160     return;
 161   }
 162   _has_waiters = false;


  70 }
  71 
  72 void JfrPostBox::post(JFR_Msg msg) {
  73   const int the_message = MSGBIT(msg);
  74   if (is_thread_lock_aversive()) {
  75     deposit(the_message);
  76     return;
  77   }
  78   if (!is_synchronous(the_message)) {
  79     asynchronous_post(the_message);
  80     return;
  81   }
  82   synchronous_post(the_message);
  83 }
  84 
  85 void JfrPostBox::deposit(int new_messages) {
  86   while (true) {
  87     const int current_msgs = Atomic::load(&_messages);
  88     // OR the new message
  89     const int exchange_value = current_msgs | new_messages;
  90     const int result = Atomic::cmpxchg(&_messages, current_msgs, exchange_value);
  91     if (result == current_msgs) {
  92       return;
  93     }
  94     /* Some other thread just set exactly what this thread wanted */
  95     if ((result & new_messages) == new_messages) {
  96       return;
  97     }
  98   }
  99 }
 100 
 101 void JfrPostBox::asynchronous_post(int msg) {
 102   assert(!is_synchronous(msg), "invariant");
 103   deposit(msg);
 104   JfrMonitorTryLock try_msg_lock(JfrMsg_lock);
 105   if (try_msg_lock.acquired()) {
 106     JfrMsg_lock->notify_all();
 107   }
 108 }
 109 
 110 void JfrPostBox::synchronous_post(int msg) {


 122 }
 123 
 124 /*
 125  * Check if a synchronous message has been processed.
 126  * We avoid racing on _msg_handled_serial by ensuring
 127  * that we are holding the JfrMsg_lock when checking
 128  * completion status.
 129  */
 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");
 132   return serial_id <= Atomic::load(&_msg_handled_serial);
 133 }
 134 
 135 bool JfrPostBox::is_empty() const {
 136   assert(JfrMsg_lock->owned_by_self(), "not holding JfrMsg_lock!");
 137   return Atomic::load(&_messages) == 0;
 138 }
 139 
 140 int JfrPostBox::collect() {
 141   // get pending and reset to 0
 142   const int messages = Atomic::xchg(&_messages, 0);
 143   if (check_waiters(messages)) {
 144     _has_waiters = true;
 145     assert(JfrMsg_lock->owned_by_self(), "incrementing _msg_read_serial is protected by JfrMsg_lock");
 146     // Update made visible on release of JfrMsg_lock via fence instruction in Monitor::IUnlock.
 147     ++_msg_read_serial;
 148   }
 149   return messages;
 150 }
 151 
 152 bool JfrPostBox::check_waiters(int messages) const {
 153   assert(JfrMsg_lock->owned_by_self(), "not holding JfrMsg_lock!");
 154   assert(!_has_waiters, "invariant");
 155   return is_synchronous(messages);
 156 }
 157 
 158 void JfrPostBox::notify_waiters() {
 159   if (!_has_waiters) {
 160     return;
 161   }
 162   _has_waiters = false;
< prev index next >