113 void JfrBuffer::set_concurrent_top(const u1* new_top) { |
113 void JfrBuffer::set_concurrent_top(const u1* new_top) { |
114 assert(new_top != MUTEX_CLAIM, "invariant"); |
114 assert(new_top != MUTEX_CLAIM, "invariant"); |
115 assert(new_top <= end(), "invariant"); |
115 assert(new_top <= end(), "invariant"); |
116 assert(new_top >= start(), "invariant"); |
116 assert(new_top >= start(), "invariant"); |
117 assert(top() == MUTEX_CLAIM, "invariant"); |
117 assert(top() == MUTEX_CLAIM, "invariant"); |
118 OrderAccess::release_store(&_top, new_top); |
118 OrderAccess::storestore(); |
|
119 _top = new_top; |
119 } |
120 } |
120 |
121 |
121 size_t JfrBuffer::unflushed_size() const { |
122 size_t JfrBuffer::unflushed_size() const { |
122 return pos() - stable_top(); |
123 return pos() - stable_top(); |
123 } |
124 } |
124 |
125 |
125 void JfrBuffer::acquire(const void* id) { |
126 void JfrBuffer::acquire(const void* id) { |
126 assert(id != NULL, "invariant"); |
127 assert(id != NULL, "invariant"); |
127 const void* current_id; |
128 const void* current_id; |
128 do { |
129 do { |
129 current_id = OrderAccess::load_acquire(&_identity); |
130 current_id = Atomic::load(&_identity); |
130 } while (current_id != NULL || Atomic::cmpxchg(id, &_identity, current_id) != current_id); |
131 } while (current_id != NULL || Atomic::cmpxchg(id, &_identity, current_id) != current_id); |
131 } |
132 } |
132 |
133 |
133 bool JfrBuffer::try_acquire(const void* id) { |
134 bool JfrBuffer::try_acquire(const void* id) { |
134 assert(id != NULL, "invariant"); |
135 assert(id != NULL, "invariant"); |
135 const void* const current_id = OrderAccess::load_acquire(&_identity); |
136 const void* const current_id = Atomic::load(&_identity); |
136 return current_id == NULL && Atomic::cmpxchg(id, &_identity, current_id) == current_id; |
137 return current_id == NULL && Atomic::cmpxchg(id, &_identity, current_id) == current_id; |
137 } |
138 } |
138 |
139 |
139 void JfrBuffer::release() { |
140 void JfrBuffer::release() { |
140 OrderAccess::release_store(&_identity, (const void*)NULL); |
141 OrderAccess::storestore(); |
|
142 _identity = NULL; |
141 } |
143 } |
142 |
144 |
143 bool JfrBuffer::acquired_by(const void* id) const { |
145 bool JfrBuffer::acquired_by(const void* id) const { |
144 return identity() == id; |
146 return identity() == id; |
145 } |
147 } |
239 assert(excluded(), "invariant"); |
241 assert(excluded(), "invariant"); |
240 } |
242 } |
241 |
243 |
242 void JfrBuffer::clear_excluded() { |
244 void JfrBuffer::clear_excluded() { |
243 if (excluded()) { |
245 if (excluded()) { |
|
246 OrderAccess::storestore(); |
244 _flags ^= (u1)EXCLUDED; |
247 _flags ^= (u1)EXCLUDED; |
245 } |
248 } |
246 assert(!excluded(), "invariant"); |
249 assert(!excluded(), "invariant"); |
247 } |
250 } |
248 |
251 |
249 static u2 load_acquire_flags(const u2* const flags) { |
|
250 return OrderAccess::load_acquire(flags); |
|
251 } |
|
252 |
|
253 static void release_store_flags(u2* const flags, u2 new_flags) { |
|
254 OrderAccess::release_store(flags, new_flags); |
|
255 } |
|
256 |
|
257 bool JfrBuffer::retired() const { |
252 bool JfrBuffer::retired() const { |
258 return (u1)RETIRED == (load_acquire_flags(&_flags) & (u1)RETIRED); |
253 return (_flags & (u1)RETIRED) == (u1)RETIRED; |
259 } |
254 } |
260 |
255 |
261 void JfrBuffer::set_retired() { |
256 void JfrBuffer::set_retired() { |
262 const u2 new_flags = load_acquire_flags(&_flags) | (u1)RETIRED; |
257 OrderAccess::storestore(); |
263 release_store_flags(&_flags, new_flags); |
258 _flags |= (u1)RETIRED; |
264 } |
259 } |
265 |
260 |
266 void JfrBuffer::clear_retired() { |
261 void JfrBuffer::clear_retired() { |
267 u2 new_flags = load_acquire_flags(&_flags); |
262 if (retired()) { |
268 if ((u1)RETIRED == (new_flags & (u1)RETIRED)) { |
263 OrderAccess::storestore(); |
269 new_flags ^= (u1)RETIRED; |
264 _flags ^= (u1)RETIRED; |
270 release_store_flags(&_flags, new_flags); |
265 } |
271 } |
266 } |
272 } |
|