193 STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
194 Atomic::xchg(&_budget, (intptr_t)initial);
195 Atomic::store(&_tax_rate, tax_rate);
196 Atomic::inc(&_epoch);
197 }
198
199 bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) {
200 assert(ShenandoahPacing, "Only be here when pacing is enabled");
201
202 intptr_t tax = MAX2<intptr_t>(1, words * Atomic::load(&_tax_rate));
203
204 intptr_t cur = 0;
205 intptr_t new_val = 0;
206 do {
207 cur = Atomic::load(&_budget);
208 if (cur < tax && !force) {
209 // Progress depleted, alas.
210 return false;
211 }
212 new_val = cur - tax;
213 } while (Atomic::cmpxchg(new_val, &_budget, cur) != cur);
214 return true;
215 }
216
217 void ShenandoahPacer::unpace_for_alloc(intptr_t epoch, size_t words) {
218 assert(ShenandoahPacing, "Only be here when pacing is enabled");
219
220 if (_epoch != epoch) {
221 // Stale ticket, no need to unpace.
222 return;
223 }
224
225 intptr_t tax = MAX2<intptr_t>(1, words * Atomic::load(&_tax_rate));
226 Atomic::add(&_budget, tax);
227 }
228
229 intptr_t ShenandoahPacer::epoch() {
230 return Atomic::load(&_epoch);
231 }
232
233 void ShenandoahPacer::pace_for_alloc(size_t words) {
|
193 STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
194 Atomic::xchg(&_budget, (intptr_t)initial);
195 Atomic::store(&_tax_rate, tax_rate);
196 Atomic::inc(&_epoch);
197 }
198
199 bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) {
200 assert(ShenandoahPacing, "Only be here when pacing is enabled");
201
202 intptr_t tax = MAX2<intptr_t>(1, words * Atomic::load(&_tax_rate));
203
204 intptr_t cur = 0;
205 intptr_t new_val = 0;
206 do {
207 cur = Atomic::load(&_budget);
208 if (cur < tax && !force) {
209 // Progress depleted, alas.
210 return false;
211 }
212 new_val = cur - tax;
213 } while (Atomic::cmpxchg(&_budget, cur, new_val) != cur);
214 return true;
215 }
216
217 void ShenandoahPacer::unpace_for_alloc(intptr_t epoch, size_t words) {
218 assert(ShenandoahPacing, "Only be here when pacing is enabled");
219
220 if (_epoch != epoch) {
221 // Stale ticket, no need to unpace.
222 return;
223 }
224
225 intptr_t tax = MAX2<intptr_t>(1, words * Atomic::load(&_tax_rate));
226 Atomic::add(&_budget, tax);
227 }
228
229 intptr_t ShenandoahPacer::epoch() {
230 return Atomic::load(&_epoch);
231 }
232
233 void ShenandoahPacer::pace_for_alloc(size_t words) {
|