52 assert(!lease(), "invariant"); |
52 assert(!lease(), "invariant"); |
53 assert(!retired(), "invariant"); |
53 assert(!retired(), "invariant"); |
54 return true; |
54 return true; |
55 } |
55 } |
56 |
56 |
57 void JfrBuffer::reinitialize() { |
57 void JfrBuffer::reinitialize(bool exclusion /* false */) { |
58 assert(!lease(), "invariant"); |
58 assert(!lease(), "invariant"); |
59 assert(!transient(), "invariant"); |
59 assert(!transient(), "invariant"); |
60 set_pos(start()); |
60 set_pos(start()); |
|
61 if (exclusion != excluded()) { |
|
62 // update |
|
63 if (exclusion) { |
|
64 set_excluded(); |
|
65 } else { |
|
66 clear_excluded(); |
|
67 } |
|
68 } |
61 clear_retired(); |
69 clear_retired(); |
62 set_top(start()); |
70 set_top(start()); |
63 } |
71 } |
64 |
72 |
65 void JfrBuffer::concurrent_reinitialization() { |
73 void JfrBuffer::concurrent_reinitialization() { |
105 void JfrBuffer::set_concurrent_top(const u1* new_top) { |
113 void JfrBuffer::set_concurrent_top(const u1* new_top) { |
106 assert(new_top != MUTEX_CLAIM, "invariant"); |
114 assert(new_top != MUTEX_CLAIM, "invariant"); |
107 assert(new_top <= end(), "invariant"); |
115 assert(new_top <= end(), "invariant"); |
108 assert(new_top >= start(), "invariant"); |
116 assert(new_top >= start(), "invariant"); |
109 assert(top() == MUTEX_CLAIM, "invariant"); |
117 assert(top() == MUTEX_CLAIM, "invariant"); |
110 OrderAccess::release_store(&_top, new_top); |
118 OrderAccess::storestore(); |
|
119 _top = new_top; |
111 } |
120 } |
112 |
121 |
113 size_t JfrBuffer::unflushed_size() const { |
122 size_t JfrBuffer::unflushed_size() const { |
114 return pos() - stable_top(); |
123 return pos() - stable_top(); |
115 } |
124 } |
116 |
125 |
117 void JfrBuffer::acquire(const void* id) { |
126 void JfrBuffer::acquire(const void* id) { |
118 assert(id != NULL, "invariant"); |
127 assert(id != NULL, "invariant"); |
119 const void* current_id; |
128 const void* current_id; |
120 do { |
129 do { |
121 current_id = OrderAccess::load_acquire(&_identity); |
130 current_id = Atomic::load(&_identity); |
122 } 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); |
123 } |
132 } |
124 |
133 |
125 bool JfrBuffer::try_acquire(const void* id) { |
134 bool JfrBuffer::try_acquire(const void* id) { |
126 assert(id != NULL, "invariant"); |
135 assert(id != NULL, "invariant"); |
127 const void* const current_id = OrderAccess::load_acquire(&_identity); |
136 const void* const current_id = Atomic::load(&_identity); |
128 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; |
129 } |
138 } |
130 |
139 |
131 void JfrBuffer::release() { |
140 void JfrBuffer::release() { |
132 OrderAccess::release_store(&_identity, (const void*)NULL); |
141 OrderAccess::storestore(); |
|
142 _identity = NULL; |
133 } |
143 } |
134 |
144 |
135 bool JfrBuffer::acquired_by(const void* id) const { |
145 bool JfrBuffer::acquired_by(const void* id) const { |
136 return identity() == id; |
146 return identity() == id; |
137 } |
147 } |
219 _flags ^= (u1)LEASE; |
230 _flags ^= (u1)LEASE; |
220 } |
231 } |
221 assert(!lease(), "invariant"); |
232 assert(!lease(), "invariant"); |
222 } |
233 } |
223 |
234 |
224 static u2 load_acquire_flags(const u2* const flags) { |
235 bool JfrBuffer::excluded() const { |
225 return OrderAccess::load_acquire(flags); |
236 return (u1)EXCLUDED == (_flags & (u1)EXCLUDED); |
226 } |
237 } |
227 |
238 |
228 static void release_store_flags(u2* const flags, u2 new_flags) { |
239 void JfrBuffer::set_excluded() { |
229 OrderAccess::release_store(flags, new_flags); |
240 _flags |= (u1)EXCLUDED; |
|
241 assert(excluded(), "invariant"); |
|
242 } |
|
243 |
|
244 void JfrBuffer::clear_excluded() { |
|
245 if (excluded()) { |
|
246 OrderAccess::storestore(); |
|
247 _flags ^= (u1)EXCLUDED; |
|
248 } |
|
249 assert(!excluded(), "invariant"); |
230 } |
250 } |
231 |
251 |
232 bool JfrBuffer::retired() const { |
252 bool JfrBuffer::retired() const { |
233 return (u1)RETIRED == (load_acquire_flags(&_flags) & (u1)RETIRED); |
253 return (_flags & (u1)RETIRED) == (u1)RETIRED; |
234 } |
254 } |
235 |
255 |
236 void JfrBuffer::set_retired() { |
256 void JfrBuffer::set_retired() { |
237 const u2 new_flags = load_acquire_flags(&_flags) | (u1)RETIRED; |
257 OrderAccess::storestore(); |
238 release_store_flags(&_flags, new_flags); |
258 _flags |= (u1)RETIRED; |
239 } |
259 } |
240 |
260 |
241 void JfrBuffer::clear_retired() { |
261 void JfrBuffer::clear_retired() { |
242 u2 new_flags = load_acquire_flags(&_flags); |
262 if (retired()) { |
243 if ((u1)RETIRED == (new_flags & (u1)RETIRED)) { |
263 OrderAccess::storestore(); |
244 new_flags ^= (u1)RETIRED; |
264 _flags ^= (u1)RETIRED; |
245 release_store_flags(&_flags, new_flags); |
265 } |
246 } |
266 } |
247 } |
|