rev 60421 : [mq]: 8248401-stefank-review

   1 /*
   2  * Copyright (c) 2013, 2020, Red Hat, Inc. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 
  27 #include "gc/shenandoah/shenandoahConcurrentMark.inline.hpp"
  28 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  29 #include "gc/shenandoah/shenandoahControlThread.hpp"
  30 #include "gc/shenandoah/shenandoahFreeSet.hpp"
  31 #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  32 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  33 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
  34 #include "gc/shenandoah/shenandoahRootProcessor.inline.hpp"
  35 #include "gc/shenandoah/shenandoahUtils.hpp"
  36 #include "gc/shenandoah/shenandoahVMOperations.hpp"
  37 #include "gc/shenandoah/shenandoahWorkerPolicy.hpp"
  38 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
  39 #include "memory/iterator.hpp"
  40 #include "memory/universe.hpp"
  41 #include "runtime/atomic.hpp"
  42 
  43 ShenandoahControlThread::ShenandoahControlThread() :
  44   ConcurrentGCThread(),
  45   _alloc_failure_waiters_lock(Mutex::leaf, "ShenandoahAllocFailureGC_lock", true, Monitor::_safepoint_check_always),
  46   _gc_waiters_lock(Mutex::leaf, "ShenandoahRequestedGC_lock", true, Monitor::_safepoint_check_always),
  47   _periodic_task(this),
  48   _requested_gc_cause(GCCause::_no_cause_specified),
  49   _degen_point(ShenandoahHeap::_degenerated_outside_cycle),
  50   _allocs_seen(0) {
  51 
  52   reset_gc_id();
  53   create_and_start(ShenandoahCriticalControlThreadPriority ? CriticalPriority : NearMaxPriority);
  54   _periodic_task.enroll();
  55   _periodic_satb_flush_task.enroll();
  56   if (ShenandoahPacing) {
  57     _periodic_pacer_notify_task.enroll();
  58   }
  59 }
  60 
  61 ShenandoahControlThread::~ShenandoahControlThread() {
  62   // This is here so that super is called.
  63 }
  64 
  65 void ShenandoahPeriodicTask::task() {
  66   _thread->handle_force_counters_update();
  67   _thread->handle_counters_update();
  68 }
  69 
  70 void ShenandoahPeriodicSATBFlushTask::task() {
  71   ShenandoahHeap::heap()->force_satb_flush_all_threads();
  72 }
  73 
  74 void ShenandoahPeriodicPacerNotify::task() {
  75   assert(ShenandoahPacing, "Should not be here otherwise");
  76   ShenandoahHeap::heap()->pacer()->notify_waiters();
  77 }
  78 
  79 void ShenandoahControlThread::run_service() {
  80   ShenandoahHeap* heap = ShenandoahHeap::heap();
  81 
  82   GCMode default_mode = concurrent_normal;
  83   GCCause::Cause default_cause = GCCause::_shenandoah_concurrent_gc;
  84   int sleep = ShenandoahControlIntervalMin;
  85 
  86   double last_shrink_time = os::elapsedTime();
  87   double last_sleep_adjust_time = os::elapsedTime();
  88 
  89   // Shrink period avoids constantly polling regions for shrinking.
  90   // Having a period 10x lower than the delay would mean we hit the
  91   // shrinking with lag of less than 1/10-th of true delay.
  92   // ShenandoahUncommitDelay is in msecs, but shrink_period is in seconds.
  93   double shrink_period = (double)ShenandoahUncommitDelay / 1000 / 10;
  94 
  95   ShenandoahCollectorPolicy* policy = heap->shenandoah_policy();
  96   ShenandoahHeuristics* heuristics = heap->heuristics();
  97   while (!in_graceful_shutdown() && !should_terminate()) {
  98     // Figure out if we have pending requests.
  99     bool alloc_failure_pending = _alloc_failure_gc.is_set();
 100     bool explicit_gc_requested = _gc_requested.is_set() &&  is_explicit_gc(_requested_gc_cause);
 101     bool implicit_gc_requested = _gc_requested.is_set() && !is_explicit_gc(_requested_gc_cause);
 102 
 103     // This control loop iteration have seen this much allocations.
 104     size_t allocs_seen = Atomic::xchg(&_allocs_seen, (size_t)0);
 105 
 106     // Choose which GC mode to run in. The block below should select a single mode.
 107     GCMode mode = none;
 108     GCCause::Cause cause = GCCause::_last_gc_cause;
 109     ShenandoahHeap::ShenandoahDegenPoint degen_point = ShenandoahHeap::_degenerated_unset;
 110 
 111     if (alloc_failure_pending) {
 112       // Allocation failure takes precedence: we have to deal with it first thing
 113       log_info(gc)("Trigger: Handle Allocation Failure");
 114 
 115       cause = GCCause::_allocation_failure;
 116 
 117       // Consume the degen point, and seed it with default value
 118       degen_point = _degen_point;
 119       _degen_point = ShenandoahHeap::_degenerated_outside_cycle;
 120 
 121       if (ShenandoahDegeneratedGC && heuristics->should_degenerate_cycle()) {
 122         heuristics->record_allocation_failure_gc();
 123         policy->record_alloc_failure_to_degenerated(degen_point);
 124         mode = stw_degenerated;
 125       } else {
 126         heuristics->record_allocation_failure_gc();
 127         policy->record_alloc_failure_to_full();
 128         mode = stw_full;
 129       }
 130 
 131     } else if (explicit_gc_requested) {
 132       cause = _requested_gc_cause;
 133       log_info(gc)("Trigger: Explicit GC request (%s)", GCCause::to_string(cause));
 134 
 135       heuristics->record_requested_gc();
 136 
 137       if (ExplicitGCInvokesConcurrent) {
 138         policy->record_explicit_to_concurrent();
 139         mode = default_mode;
 140         // Unload and clean up everything
 141         heap->set_process_references(heuristics->can_process_references());
 142         heap->set_unload_classes(heuristics->can_unload_classes());
 143       } else {
 144         policy->record_explicit_to_full();
 145         mode = stw_full;
 146       }
 147     } else if (implicit_gc_requested) {
 148       cause = _requested_gc_cause;
 149       log_info(gc)("Trigger: Implicit GC request (%s)", GCCause::to_string(cause));
 150 
 151       heuristics->record_requested_gc();
 152 
 153       if (ShenandoahImplicitGCInvokesConcurrent) {
 154         policy->record_implicit_to_concurrent();
 155         mode = default_mode;
 156 
 157         // Unload and clean up everything
 158         heap->set_process_references(heuristics->can_process_references());
 159         heap->set_unload_classes(heuristics->can_unload_classes());
 160       } else {
 161         policy->record_implicit_to_full();
 162         mode = stw_full;
 163       }
 164     } else {
 165       // Potential normal cycle: ask heuristics if it wants to act
 166       if (heuristics->should_start_gc()) {
 167         mode = default_mode;
 168         cause = default_cause;
 169       }
 170 
 171       // Ask policy if this cycle wants to process references or unload classes
 172       heap->set_process_references(heuristics->should_process_references());
 173       heap->set_unload_classes(heuristics->should_unload_classes());
 174     }
 175 
 176     // Blow all soft references on this cycle, if handling allocation failure,
 177     // either implicit or explicit GC request,  or we are requested to do so unconditionally.
 178     if (alloc_failure_pending || implicit_gc_requested || explicit_gc_requested || ShenandoahAlwaysClearSoftRefs) {
 179       heap->soft_ref_policy()->set_should_clear_all_soft_refs(true);
 180     }
 181 
 182     bool gc_requested = (mode != none);
 183     assert (!gc_requested || cause != GCCause::_last_gc_cause, "GC cause should be set");
 184 
 185     if (gc_requested) {
 186       // GC is starting, bump the internal ID
 187       update_gc_id();
 188 
 189       heap->reset_bytes_allocated_since_gc_start();
 190 
 191       // Use default constructor to snapshot the Metaspace state before GC.
 192       metaspace::MetaspaceSizesSnapshot meta_sizes;
 193 
 194       // If GC was requested, we are sampling the counters even without actual triggers
 195       // from allocation machinery. This captures GC phases more accurately.
 196       set_forced_counters_update(true);
 197 
 198       // If GC was requested, we better dump freeset data for performance debugging
 199       {
 200         ShenandoahHeapLocker locker(heap->lock());
 201         heap->free_set()->log_status();
 202       }
 203 
 204       switch (mode) {
 205         case concurrent_normal:
 206           service_concurrent_normal_cycle(cause);
 207           break;
 208         case stw_degenerated:
 209           service_stw_degenerated_cycle(cause, degen_point);
 210           break;
 211         case stw_full:
 212           service_stw_full_cycle(cause);
 213           break;
 214         default:
 215           ShouldNotReachHere();
 216       }
 217 
 218       // If this was the requested GC cycle, notify waiters about it
 219       if (explicit_gc_requested || implicit_gc_requested) {
 220         notify_gc_waiters();
 221       }
 222 
 223       // If this was the allocation failure GC cycle, notify waiters about it
 224       if (alloc_failure_pending) {
 225         notify_alloc_failure_waiters();
 226       }
 227 
 228       // Report current free set state at the end of cycle, whether
 229       // it is a normal completion, or the abort.
 230       {
 231         ShenandoahHeapLocker locker(heap->lock());
 232         heap->free_set()->log_status();
 233 
 234         // Notify Universe about new heap usage. This has implications for
 235         // global soft refs policy, and we better report it every time heap
 236         // usage goes down.
 237         Universe::update_heap_info_at_gc();
 238 
 239         // Signal that we have completed a visit to all live objects.
 240         Universe::heap()->next_whole_heap_examined();
 241       }
 242 
 243       // Disable forced counters update, and update counters one more time
 244       // to capture the state at the end of GC session.
 245       handle_force_counters_update();
 246       set_forced_counters_update(false);
 247 
 248       // Retract forceful part of soft refs policy
 249       heap->soft_ref_policy()->set_should_clear_all_soft_refs(false);
 250 
 251       // Clear metaspace oom flag, if current cycle unloaded classes
 252       if (heap->unload_classes()) {
 253         heuristics->clear_metaspace_oom();
 254       }
 255 
 256       // Commit worker statistics to cycle data
 257       heap->phase_timings()->flush_par_workers_to_cycle();
 258       if (ShenandoahPacing) {
 259         heap->pacer()->flush_stats_to_cycle();
 260       }
 261 
 262       // Print GC stats for current cycle
 263       {
 264         LogTarget(Info, gc, stats) lt;
 265         if (lt.is_enabled()) {
 266           ResourceMark rm;
 267           LogStream ls(lt);
 268           heap->phase_timings()->print_cycle_on(&ls);
 269           if (ShenandoahPacing) {
 270             heap->pacer()->print_cycle_on(&ls);
 271           }
 272         }
 273       }
 274 
 275       // Commit statistics to globals
 276       heap->phase_timings()->flush_cycle_to_global();
 277 
 278       // Print Metaspace change following GC (if logging is enabled).
 279       MetaspaceUtils::print_metaspace_change(meta_sizes);


 280 
 281       // GC is over, we are at idle now
 282       if (ShenandoahPacing) {
 283         heap->pacer()->setup_for_idle();
 284       }
 285     } else {
 286       // Allow allocators to know we have seen this much regions
 287       if (ShenandoahPacing && (allocs_seen > 0)) {
 288         heap->pacer()->report_alloc(allocs_seen);
 289       }
 290     }
 291 
 292     double current = os::elapsedTime();
 293 
 294     if (ShenandoahUncommit && (explicit_gc_requested || (current - last_shrink_time > shrink_period))) {
 295       // Try to uncommit enough stale regions. Explicit GC tries to uncommit everything.
 296       // Regular paths uncommit only occasionally.
 297       double shrink_before = explicit_gc_requested ?
 298                              current :
 299                              current - (ShenandoahUncommitDelay / 1000.0);
 300       service_uncommit(shrink_before);
 301       heap->phase_timings()->flush_cycle_to_global();
 302       last_shrink_time = current;
 303     }
 304 
 305     // Wait before performing the next action. If allocation happened during this wait,
 306     // we exit sooner, to let heuristics re-evaluate new conditions. If we are at idle,
 307     // back off exponentially.
 308     if (_heap_changed.try_unset()) {
 309       sleep = ShenandoahControlIntervalMin;
 310     } else if ((current - last_sleep_adjust_time) * 1000 > ShenandoahControlIntervalAdjustPeriod){
 311       sleep = MIN2<int>(ShenandoahControlIntervalMax, MAX2(1, sleep * 2));
 312       last_sleep_adjust_time = current;
 313     }
 314     os::naked_short_sleep(sleep);
 315   }
 316 
 317   // Wait for the actual stop(), can't leave run_service() earlier.
 318   while (!should_terminate()) {
 319     os::naked_short_sleep(ShenandoahControlIntervalMin);
 320   }
 321 }
 322 
 323 void ShenandoahControlThread::service_concurrent_normal_cycle(GCCause::Cause cause) {
 324   // Normal cycle goes via all concurrent phases. If allocation failure (af) happens during
 325   // any of the concurrent phases, it first degrades to Degenerated GC and completes GC there.
 326   // If second allocation failure happens during Degenerated GC cycle (for example, when GC
 327   // tries to evac something and no memory is available), cycle degrades to Full GC.
 328   //
 329   // There are also a shortcut through the normal cycle: immediate garbage shortcut, when
 330   // heuristics says there are no regions to compact, and all the collection comes from immediately
 331   // reclaimable regions.
 332   //
 333   // ................................................................................................
 334   //
 335   //                                    (immediate garbage shortcut)                Concurrent GC
 336   //                             /-------------------------------------------\
 337   //                             |                                           |
 338   //                             |                                           |
 339   //                             |                                           |
 340   //                             |                                           v
 341   // [START] ----> Conc Mark ----o----> Conc Evac --o--> Conc Update-Refs ---o----> [END]
 342   //                   |                    |                 |              ^
 343   //                   | (af)               | (af)            | (af)         |
 344   // ..................|....................|.................|..............|.......................
 345   //                   |                    |                 |              |
 346   //                   |                    |                 |              |      Degenerated GC
 347   //                   v                    v                 v              |
 348   //               STW Mark ----------> STW Evac ----> STW Update-Refs ----->o
 349   //                   |                    |                 |              ^
 350   //                   | (af)               | (af)            | (af)         |
 351   // ..................|....................|.................|..............|.......................
 352   //                   |                    |                 |              |
 353   //                   |                    v                 |              |      Full GC
 354   //                   \------------------->o<----------------/              |
 355   //                                        |                                |
 356   //                                        v                                |
 357   //                                      Full GC  --------------------------/
 358   //
 359   ShenandoahHeap* heap = ShenandoahHeap::heap();
 360 
 361   if (check_cancellation_or_degen(ShenandoahHeap::_degenerated_outside_cycle)) return;
 362 
 363   GCIdMark gc_id_mark;
 364   ShenandoahGCSession session(cause);
 365 
 366   TraceCollectorStats tcs(heap->monitoring_support()->concurrent_collection_counters());
 367 
 368   // Reset for upcoming marking
 369   heap->entry_reset();
 370 
 371   // Start initial mark under STW
 372   heap->vmop_entry_init_mark();
 373 
 374   // Continue concurrent mark
 375   heap->entry_mark();
 376   if (check_cancellation_or_degen(ShenandoahHeap::_degenerated_mark)) return;
 377 
 378   // If not cancelled, can try to concurrently pre-clean
 379   heap->entry_preclean();
 380 
 381   // Complete marking under STW, and start evacuation
 382   heap->vmop_entry_final_mark();
 383 
 384   // Process weak roots that might still point to regions that would be broken by cleanup
 385   if (heap->is_concurrent_weak_root_in_progress()) {
 386     heap->entry_weak_roots();
 387   }
 388 
 389   // Final mark might have reclaimed some immediate garbage, kick cleanup to reclaim
 390   // the space. This would be the last action if there is nothing to evacuate.
 391   heap->entry_cleanup_early();
 392 
 393   {
 394     ShenandoahHeapLocker locker(heap->lock());
 395     heap->free_set()->log_status();
 396   }
 397 
 398   // Perform concurrent class unloading
 399   if (heap->is_concurrent_weak_root_in_progress()) {
 400     heap->entry_class_unloading();
 401   }
 402 
 403   // Processing strong roots
 404   // This may be skipped if there is nothing to update/evacuate.
 405   // If so, strong_root_in_progress would be unset.
 406   if (heap->is_concurrent_strong_root_in_progress()) {
 407     heap->entry_strong_roots();
 408   }
 409 
 410   // Continue the cycle with evacuation and optional update-refs.
 411   // This may be skipped if there is nothing to evacuate.
 412   // If so, evac_in_progress would be unset by collection set preparation code.
 413   if (heap->is_evacuation_in_progress()) {
 414     // Concurrently evacuate
 415     heap->entry_evac();
 416     if (check_cancellation_or_degen(ShenandoahHeap::_degenerated_evac)) return;
 417 
 418     // Perform update-refs phase.
 419     heap->vmop_entry_init_updaterefs();
 420     heap->entry_updaterefs();
 421     if (check_cancellation_or_degen(ShenandoahHeap::_degenerated_updaterefs)) return;
 422 
 423     heap->vmop_entry_final_updaterefs();
 424 
 425     // Update references freed up collection set, kick the cleanup to reclaim the space.
 426     heap->entry_cleanup_complete();
 427   }
 428 
 429   // Cycle is complete
 430   heap->heuristics()->record_success_concurrent();
 431   heap->shenandoah_policy()->record_success_concurrent();
 432 }
 433 
 434 bool ShenandoahControlThread::check_cancellation_or_degen(ShenandoahHeap::ShenandoahDegenPoint point) {
 435   ShenandoahHeap* heap = ShenandoahHeap::heap();
 436   if (heap->cancelled_gc()) {
 437     assert (is_alloc_failure_gc() || in_graceful_shutdown(), "Cancel GC either for alloc failure GC, or gracefully exiting");
 438     if (!in_graceful_shutdown()) {
 439       assert (_degen_point == ShenandoahHeap::_degenerated_outside_cycle,
 440               "Should not be set yet: %s", ShenandoahHeap::degen_point_to_string(_degen_point));
 441       _degen_point = point;
 442     }
 443     return true;
 444   }
 445   return false;
 446 }
 447 
 448 void ShenandoahControlThread::stop_service() {
 449   // Nothing to do here.
 450 }
 451 
 452 void ShenandoahControlThread::service_stw_full_cycle(GCCause::Cause cause) {
 453   GCIdMark gc_id_mark;
 454   ShenandoahGCSession session(cause);
 455 
 456   ShenandoahHeap* heap = ShenandoahHeap::heap();
 457   heap->vmop_entry_full(cause);
 458 
 459   heap->heuristics()->record_success_full();
 460   heap->shenandoah_policy()->record_success_full();
 461 }
 462 
 463 void ShenandoahControlThread::service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahHeap::ShenandoahDegenPoint point) {
 464   assert (point != ShenandoahHeap::_degenerated_unset, "Degenerated point should be set");
 465 
 466   GCIdMark gc_id_mark;
 467   ShenandoahGCSession session(cause);
 468 
 469   ShenandoahHeap* heap = ShenandoahHeap::heap();
 470   heap->vmop_degenerated(point);
 471 
 472   heap->heuristics()->record_success_degenerated();
 473   heap->shenandoah_policy()->record_success_degenerated();
 474 }
 475 
 476 void ShenandoahControlThread::service_uncommit(double shrink_before) {
 477   ShenandoahHeap* heap = ShenandoahHeap::heap();
 478 
 479   // Determine if there is work to do. This avoids taking heap lock if there is
 480   // no work available, avoids spamming logs with superfluous logging messages,
 481   // and minimises the amount of work while locks are taken.
 482 
 483   if (heap->committed() <= heap->min_capacity()) return;
 484 
 485   bool has_work = false;
 486   for (size_t i = 0; i < heap->num_regions(); i++) {
 487     ShenandoahHeapRegion *r = heap->get_region(i);
 488     if (r->is_empty_committed() && (r->empty_time() < shrink_before)) {
 489       has_work = true;
 490       break;
 491     }
 492   }
 493 
 494   if (has_work) {
 495     heap->entry_uncommit(shrink_before);
 496   }
 497 }
 498 
 499 bool ShenandoahControlThread::is_explicit_gc(GCCause::Cause cause) const {
 500   return GCCause::is_user_requested_gc(cause) ||
 501          GCCause::is_serviceability_requested_gc(cause);
 502 }
 503 
 504 void ShenandoahControlThread::request_gc(GCCause::Cause cause) {
 505   assert(GCCause::is_user_requested_gc(cause) ||
 506          GCCause::is_serviceability_requested_gc(cause) ||
 507          cause == GCCause::_metadata_GC_clear_soft_refs ||
 508          cause == GCCause::_full_gc_alot ||
 509          cause == GCCause::_wb_full_gc ||
 510          cause == GCCause::_scavenge_alot,
 511          "only requested GCs here");
 512 
 513   if (is_explicit_gc(cause)) {
 514     if (!DisableExplicitGC) {
 515       handle_requested_gc(cause);
 516     }
 517   } else {
 518     handle_requested_gc(cause);
 519   }
 520 }
 521 
 522 void ShenandoahControlThread::handle_requested_gc(GCCause::Cause cause) {
 523   // Make sure we have at least one complete GC cycle before unblocking
 524   // from the explicit GC request.
 525   //
 526   // This is especially important for weak references cleanup and/or native
 527   // resources (e.g. DirectByteBuffers) machinery: when explicit GC request
 528   // comes very late in the already running cycle, it would miss lots of new
 529   // opportunities for cleanup that were made available before the caller
 530   // requested the GC.
 531 
 532   MonitorLocker ml(&_gc_waiters_lock);
 533   size_t current_gc_id = get_gc_id();
 534   size_t required_gc_id = current_gc_id + 1;
 535   while (current_gc_id < required_gc_id) {
 536     _gc_requested.set();
 537     _requested_gc_cause = cause;
 538     ml.wait();
 539     current_gc_id = get_gc_id();
 540   }
 541 }
 542 
 543 void ShenandoahControlThread::handle_alloc_failure(ShenandoahAllocRequest& req) {
 544   ShenandoahHeap* heap = ShenandoahHeap::heap();
 545 
 546   assert(current()->is_Java_thread(), "expect Java thread here");
 547 
 548   if (try_set_alloc_failure_gc()) {
 549     // Only report the first allocation failure
 550     log_info(gc)("Failed to allocate %s, " SIZE_FORMAT "%s",
 551                  req.type_string(),
 552                  byte_size_in_proper_unit(req.size() * HeapWordSize), proper_unit_for_byte_size(req.size() * HeapWordSize));
 553 
 554     // Now that alloc failure GC is scheduled, we can abort everything else
 555     heap->cancel_gc(GCCause::_allocation_failure);
 556   }
 557 
 558   MonitorLocker ml(&_alloc_failure_waiters_lock);
 559   while (is_alloc_failure_gc()) {
 560     ml.wait();
 561   }
 562 }
 563 
 564 void ShenandoahControlThread::handle_alloc_failure_evac(size_t words) {
 565   ShenandoahHeap* heap = ShenandoahHeap::heap();
 566 
 567   if (try_set_alloc_failure_gc()) {
 568     // Only report the first allocation failure
 569     log_info(gc)("Failed to allocate " SIZE_FORMAT "%s for evacuation",
 570                  byte_size_in_proper_unit(words * HeapWordSize), proper_unit_for_byte_size(words * HeapWordSize));
 571   }
 572 
 573   // Forcefully report allocation failure
 574   heap->cancel_gc(GCCause::_shenandoah_allocation_failure_evac);
 575 }
 576 
 577 void ShenandoahControlThread::notify_alloc_failure_waiters() {
 578   _alloc_failure_gc.unset();
 579   MonitorLocker ml(&_alloc_failure_waiters_lock);
 580   ml.notify_all();
 581 }
 582 
 583 bool ShenandoahControlThread::try_set_alloc_failure_gc() {
 584   return _alloc_failure_gc.try_set();
 585 }
 586 
 587 bool ShenandoahControlThread::is_alloc_failure_gc() {
 588   return _alloc_failure_gc.is_set();
 589 }
 590 
 591 void ShenandoahControlThread::notify_gc_waiters() {
 592   _gc_requested.unset();
 593   MonitorLocker ml(&_gc_waiters_lock);
 594   ml.notify_all();
 595 }
 596 
 597 void ShenandoahControlThread::handle_counters_update() {
 598   if (_do_counters_update.is_set()) {
 599     _do_counters_update.unset();
 600     ShenandoahHeap::heap()->monitoring_support()->update_counters();
 601   }
 602 }
 603 
 604 void ShenandoahControlThread::handle_force_counters_update() {
 605   if (_force_counters_update.is_set()) {
 606     _do_counters_update.unset(); // reset these too, we do update now!
 607     ShenandoahHeap::heap()->monitoring_support()->update_counters();
 608   }
 609 }
 610 
 611 void ShenandoahControlThread::notify_heap_changed() {
 612   // This is called from allocation path, and thus should be fast.
 613 
 614   // Update monitoring counters when we took a new region. This amortizes the
 615   // update costs on slow path.
 616   if (_do_counters_update.is_unset()) {
 617     _do_counters_update.set();
 618   }
 619   // Notify that something had changed.
 620   if (_heap_changed.is_unset()) {
 621     _heap_changed.set();
 622   }
 623 }
 624 
 625 void ShenandoahControlThread::pacing_notify_alloc(size_t words) {
 626   assert(ShenandoahPacing, "should only call when pacing is enabled");
 627   Atomic::add(&_allocs_seen, words);
 628 }
 629 
 630 void ShenandoahControlThread::set_forced_counters_update(bool value) {
 631   _force_counters_update.set_cond(value);
 632 }
 633 
 634 void ShenandoahControlThread::reset_gc_id() {
 635   Atomic::store(&_gc_id, (size_t)0);
 636 }
 637 
 638 void ShenandoahControlThread::update_gc_id() {
 639   Atomic::inc(&_gc_id);
 640 }
 641 
 642 size_t ShenandoahControlThread::get_gc_id() {
 643   return Atomic::load(&_gc_id);
 644 }
 645 
 646 void ShenandoahControlThread::print() const {
 647   print_on(tty);
 648 }
 649 
 650 void ShenandoahControlThread::print_on(outputStream* st) const {
 651   st->print("Shenandoah Concurrent Thread");
 652   Thread::print_on(st);
 653   st->cr();
 654 }
 655 
 656 void ShenandoahControlThread::start() {
 657   create_and_start();
 658 }
 659 
 660 void ShenandoahControlThread::prepare_for_graceful_shutdown() {
 661   _graceful_shutdown.set();
 662 }
 663 
 664 bool ShenandoahControlThread::in_graceful_shutdown() {
 665   return _graceful_shutdown.is_set();
 666 }
--- EOF ---