< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahPacer.cpp

Print this page




 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(tax, &_budget);
 227 }
 228 
 229 intptr_t ShenandoahPacer::epoch() {
 230   return Atomic::load(&_epoch);
 231 }
 232 
 233 void ShenandoahPacer::pace_for_alloc(size_t words) {
 234   assert(ShenandoahPacing, "Only be here when pacing is enabled");
 235 
 236   // Fast path: try to allocate right away
 237   if (claim_for_alloc(words, false)) {
 238     return;
 239   }
 240 
 241   // Threads that are attaching should not block at all: they are not
 242   // fully initialized yet. Calling sleep() on them would be awkward.
 243   // This is probably the path that allocates the thread oop itself.
 244   // Forcefully claim without waiting.
 245   if (JavaThread::current()->is_attaching_via_jni()) {
 246     claim_for_alloc(words, true);




 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) {
 234   assert(ShenandoahPacing, "Only be here when pacing is enabled");
 235 
 236   // Fast path: try to allocate right away
 237   if (claim_for_alloc(words, false)) {
 238     return;
 239   }
 240 
 241   // Threads that are attaching should not block at all: they are not
 242   // fully initialized yet. Calling sleep() on them would be awkward.
 243   // This is probably the path that allocates the thread oop itself.
 244   // Forcefully claim without waiting.
 245   if (JavaThread::current()->is_attaching_via_jni()) {
 246     claim_for_alloc(words, true);


< prev index next >