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;
|
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;
|