1 /*
   2  * Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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 #include "classfile/classLoaderDataGraph.hpp"
  27 #include "classfile/symbolTable.hpp"
  28 #include "classfile/stringTable.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "code/codeCache.hpp"
  31 #include "code/icBuffer.hpp"
  32 #include "compiler/oopMap.hpp"
  33 #include "gc/serial/defNewGeneration.hpp"
  34 #include "gc/shared/adaptiveSizePolicy.hpp"
  35 #include "gc/shared/cardTableBarrierSet.hpp"
  36 #include "gc/shared/cardTableRS.hpp"
  37 #include "gc/shared/collectedHeap.inline.hpp"
  38 #include "gc/shared/collectorCounters.hpp"
  39 #include "gc/shared/continuationGCSupport.inline.hpp"
  40 #include "gc/shared/gcId.hpp"
  41 #include "gc/shared/gcLocker.hpp"
  42 #include "gc/shared/gcPolicyCounters.hpp"
  43 #include "gc/shared/gcTrace.hpp"
  44 #include "gc/shared/gcTraceTime.inline.hpp"
  45 #include "gc/shared/genArguments.hpp"
  46 #include "gc/shared/gcVMOperations.hpp"
  47 #include "gc/shared/genCollectedHeap.hpp"
  48 #include "gc/shared/genOopClosures.inline.hpp"
  49 #include "gc/shared/generationSpec.hpp"
  50 #include "gc/shared/gcInitLogger.hpp"
  51 #include "gc/shared/locationPrinter.inline.hpp"
  52 #include "gc/shared/oopStorage.inline.hpp"
  53 #include "gc/shared/oopStorageSet.inline.hpp"
  54 #include "gc/shared/oopStorageParState.inline.hpp"
  55 #include "gc/shared/scavengableNMethods.hpp"
  56 #include "gc/shared/space.hpp"
  57 #include "gc/shared/strongRootsScope.hpp"
  58 #include "gc/shared/weakProcessor.hpp"
  59 #include "gc/shared/workerThread.hpp"
  60 #include "memory/iterator.hpp"
  61 #include "memory/metaspaceCounters.hpp"
  62 #include "memory/metaspaceUtils.hpp"
  63 #include "memory/resourceArea.hpp"
  64 #include "memory/universe.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "runtime/continuation.hpp"
  67 #include "runtime/handles.hpp"
  68 #include "runtime/handles.inline.hpp"
  69 #include "runtime/java.hpp"
  70 #include "runtime/threads.hpp"
  71 #include "runtime/vmThread.hpp"
  72 #include "services/memoryService.hpp"
  73 #include "utilities/autoRestore.hpp"
  74 #include "utilities/debug.hpp"
  75 #include "utilities/formatBuffer.hpp"
  76 #include "utilities/macros.hpp"
  77 #include "utilities/stack.inline.hpp"
  78 #include "utilities/vmError.hpp"
  79 #if INCLUDE_JVMCI
  80 #include "jvmci/jvmci.hpp"
  81 #endif
  82 
  83 GenCollectedHeap::GenCollectedHeap(Generation::Name young,
  84                                    Generation::Name old,
  85                                    const char* policy_counters_name) :
  86   CollectedHeap(),
  87   _young_gen(NULL),
  88   _old_gen(NULL),
  89   _young_gen_spec(new GenerationSpec(young,
  90                                      NewSize,
  91                                      MaxNewSize,
  92                                      GenAlignment)),
  93   _old_gen_spec(new GenerationSpec(old,
  94                                    OldSize,
  95                                    MaxOldSize,
  96                                    GenAlignment)),
  97   _rem_set(NULL),
  98   _soft_ref_gen_policy(),
  99   _size_policy(NULL),
 100   _gc_policy_counters(new GCPolicyCounters(policy_counters_name, 2, 2)),
 101   _incremental_collection_failed(false),
 102   _full_collections_completed(0),
 103   _young_manager(NULL),
 104   _old_manager(NULL) {
 105 }
 106 
 107 jint GenCollectedHeap::initialize() {
 108   // While there are no constraints in the GC code that HeapWordSize
 109   // be any particular value, there are multiple other areas in the
 110   // system which believe this to be true (e.g. oop->object_size in some
 111   // cases incorrectly returns the size in wordSize units rather than
 112   // HeapWordSize).
 113   guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
 114 
 115   // Allocate space for the heap.
 116 
 117   ReservedHeapSpace heap_rs = allocate(HeapAlignment);
 118 
 119   if (!heap_rs.is_reserved()) {
 120     vm_shutdown_during_initialization(
 121       "Could not reserve enough space for object heap");
 122     return JNI_ENOMEM;
 123   }
 124 
 125   initialize_reserved_region(heap_rs);
 126 
 127   _rem_set = create_rem_set(heap_rs.region());
 128   _rem_set->initialize();
 129   CardTableBarrierSet *bs = new CardTableBarrierSet(_rem_set);
 130   bs->initialize();
 131   BarrierSet::set_barrier_set(bs);
 132 
 133   ReservedSpace young_rs = heap_rs.first_part(_young_gen_spec->max_size());
 134   _young_gen = _young_gen_spec->init(young_rs, rem_set());
 135   ReservedSpace old_rs = heap_rs.last_part(_young_gen_spec->max_size());
 136 
 137   old_rs = old_rs.first_part(_old_gen_spec->max_size());
 138   _old_gen = _old_gen_spec->init(old_rs, rem_set());
 139 
 140   GCInitLogger::print();
 141 
 142   return JNI_OK;
 143 }
 144 
 145 CardTableRS* GenCollectedHeap::create_rem_set(const MemRegion& reserved_region) {
 146   return new CardTableRS(reserved_region);
 147 }
 148 
 149 void GenCollectedHeap::initialize_size_policy(size_t init_eden_size,
 150                                               size_t init_promo_size,
 151                                               size_t init_survivor_size) {
 152   const double max_gc_pause_sec = ((double) MaxGCPauseMillis) / 1000.0;
 153   _size_policy = new AdaptiveSizePolicy(init_eden_size,
 154                                         init_promo_size,
 155                                         init_survivor_size,
 156                                         max_gc_pause_sec,
 157                                         GCTimeRatio);
 158 }
 159 
 160 ReservedHeapSpace GenCollectedHeap::allocate(size_t alignment) {
 161   // Now figure out the total size.
 162   const size_t pageSize = UseLargePages ? os::large_page_size() : os::vm_page_size();
 163   assert(alignment % pageSize == 0, "Must be");
 164 
 165   // Check for overflow.
 166   size_t total_reserved = _young_gen_spec->max_size() + _old_gen_spec->max_size();
 167   if (total_reserved < _young_gen_spec->max_size()) {
 168     vm_exit_during_initialization("The size of the object heap + VM data exceeds "
 169                                   "the maximum representable size");
 170   }
 171   assert(total_reserved % alignment == 0,
 172          "Gen size; total_reserved=" SIZE_FORMAT ", alignment="
 173          SIZE_FORMAT, total_reserved, alignment);
 174 
 175   ReservedHeapSpace heap_rs = Universe::reserve_heap(total_reserved, alignment);
 176   size_t used_page_size = heap_rs.page_size();
 177 
 178   os::trace_page_sizes("Heap",
 179                        MinHeapSize,
 180                        total_reserved,
 181                        used_page_size,
 182                        heap_rs.base(),
 183                        heap_rs.size());
 184 
 185   return heap_rs;
 186 }
 187 
 188 class GenIsScavengable : public BoolObjectClosure {
 189 public:
 190   bool do_object_b(oop obj) {
 191     return GenCollectedHeap::heap()->is_in_young(obj);
 192   }
 193 };
 194 
 195 static GenIsScavengable _is_scavengable;
 196 
 197 void GenCollectedHeap::post_initialize() {
 198   CollectedHeap::post_initialize();
 199   ref_processing_init();
 200 
 201   DefNewGeneration* def_new_gen = (DefNewGeneration*)_young_gen;
 202 
 203   initialize_size_policy(def_new_gen->eden()->capacity(),
 204                          _old_gen->capacity(),
 205                          def_new_gen->from()->capacity());
 206 
 207   MarkSweep::initialize();
 208 
 209   ScavengableNMethods::initialize(&_is_scavengable);
 210 }
 211 
 212 void GenCollectedHeap::ref_processing_init() {
 213   _young_gen->ref_processor_init();
 214   _old_gen->ref_processor_init();
 215 }
 216 
 217 PreGenGCValues GenCollectedHeap::get_pre_gc_values() const {
 218   const DefNewGeneration* const def_new_gen = (DefNewGeneration*) young_gen();
 219 
 220   return PreGenGCValues(def_new_gen->used(),
 221                         def_new_gen->capacity(),
 222                         def_new_gen->eden()->used(),
 223                         def_new_gen->eden()->capacity(),
 224                         def_new_gen->from()->used(),
 225                         def_new_gen->from()->capacity(),
 226                         old_gen()->used(),
 227                         old_gen()->capacity());
 228 }
 229 
 230 GenerationSpec* GenCollectedHeap::young_gen_spec() const {
 231   return _young_gen_spec;
 232 }
 233 
 234 GenerationSpec* GenCollectedHeap::old_gen_spec() const {
 235   return _old_gen_spec;
 236 }
 237 
 238 size_t GenCollectedHeap::capacity() const {
 239   return _young_gen->capacity() + _old_gen->capacity();
 240 }
 241 
 242 size_t GenCollectedHeap::used() const {
 243   return _young_gen->used() + _old_gen->used();
 244 }
 245 
 246 void GenCollectedHeap::save_used_regions() {
 247   _old_gen->save_used_region();
 248   _young_gen->save_used_region();
 249 }
 250 
 251 size_t GenCollectedHeap::max_capacity() const {
 252   return _young_gen->max_capacity() + _old_gen->max_capacity();
 253 }
 254 
 255 // Update the _full_collections_completed counter
 256 // at the end of a stop-world full GC.
 257 unsigned int GenCollectedHeap::update_full_collections_completed() {
 258   assert(_full_collections_completed <= _total_full_collections,
 259          "Can't complete more collections than were started");
 260   _full_collections_completed = _total_full_collections;
 261   return _full_collections_completed;
 262 }
 263 
 264 // Return true if any of the following is true:
 265 // . the allocation won't fit into the current young gen heap
 266 // . gc locker is occupied (jni critical section)
 267 // . heap memory is tight -- the most recent previous collection
 268 //   was a full collection because a partial collection (would
 269 //   have) failed and is likely to fail again
 270 bool GenCollectedHeap::should_try_older_generation_allocation(size_t word_size) const {
 271   size_t young_capacity = _young_gen->capacity_before_gc();
 272   return    (word_size > heap_word_size(young_capacity))
 273          || GCLocker::is_active_and_needs_gc()
 274          || incremental_collection_failed();
 275 }
 276 
 277 HeapWord* GenCollectedHeap::expand_heap_and_allocate(size_t size, bool   is_tlab) {
 278   HeapWord* result = NULL;
 279   if (_old_gen->should_allocate(size, is_tlab)) {
 280     result = _old_gen->expand_and_allocate(size, is_tlab);
 281   }
 282   if (result == NULL) {
 283     if (_young_gen->should_allocate(size, is_tlab)) {
 284       result = _young_gen->expand_and_allocate(size, is_tlab);
 285     }
 286   }
 287   assert(result == NULL || is_in_reserved(result), "result not in heap");
 288   return result;
 289 }
 290 
 291 HeapWord* GenCollectedHeap::mem_allocate_work(size_t size,
 292                                               bool is_tlab,
 293                                               bool* gc_overhead_limit_was_exceeded) {
 294   // In general gc_overhead_limit_was_exceeded should be false so
 295   // set it so here and reset it to true only if the gc time
 296   // limit is being exceeded as checked below.
 297   *gc_overhead_limit_was_exceeded = false;
 298 
 299   HeapWord* result = NULL;
 300 
 301   // Loop until the allocation is satisfied, or unsatisfied after GC.
 302   for (uint try_count = 1, gclocker_stalled_count = 0; /* return or throw */; try_count += 1) {
 303 
 304     // First allocation attempt is lock-free.
 305     Generation *young = _young_gen;
 306     if (young->should_allocate(size, is_tlab)) {
 307       result = young->par_allocate(size, is_tlab);
 308       if (result != NULL) {
 309         assert(is_in_reserved(result), "result not in heap");
 310         return result;
 311       }
 312     }
 313     uint gc_count_before;  // Read inside the Heap_lock locked region.
 314     {
 315       MutexLocker ml(Heap_lock);
 316       log_trace(gc, alloc)("GenCollectedHeap::mem_allocate_work: attempting locked slow path allocation");
 317       // Note that only large objects get a shot at being
 318       // allocated in later generations.
 319       bool first_only = !should_try_older_generation_allocation(size);
 320 
 321       result = attempt_allocation(size, is_tlab, first_only);
 322       if (result != NULL) {
 323         assert(is_in_reserved(result), "result not in heap");
 324         return result;
 325       }
 326 
 327       if (GCLocker::is_active_and_needs_gc()) {
 328         if (is_tlab) {
 329           return NULL;  // Caller will retry allocating individual object.
 330         }
 331         if (!is_maximal_no_gc()) {
 332           // Try and expand heap to satisfy request.
 333           result = expand_heap_and_allocate(size, is_tlab);
 334           // Result could be null if we are out of space.
 335           if (result != NULL) {
 336             return result;
 337           }
 338         }
 339 
 340         if (gclocker_stalled_count > GCLockerRetryAllocationCount) {
 341           return NULL; // We didn't get to do a GC and we didn't get any memory.
 342         }
 343 
 344         // If this thread is not in a jni critical section, we stall
 345         // the requestor until the critical section has cleared and
 346         // GC allowed. When the critical section clears, a GC is
 347         // initiated by the last thread exiting the critical section; so
 348         // we retry the allocation sequence from the beginning of the loop,
 349         // rather than causing more, now probably unnecessary, GC attempts.
 350         JavaThread* jthr = JavaThread::current();
 351         if (!jthr->in_critical()) {
 352           MutexUnlocker mul(Heap_lock);
 353           // Wait for JNI critical section to be exited
 354           GCLocker::stall_until_clear();
 355           gclocker_stalled_count += 1;
 356           continue;
 357         } else {
 358           if (CheckJNICalls) {
 359             fatal("Possible deadlock due to allocating while"
 360                   " in jni critical section");
 361           }
 362           return NULL;
 363         }
 364       }
 365 
 366       // Read the gc count while the heap lock is held.
 367       gc_count_before = total_collections();
 368     }
 369 
 370     VM_GenCollectForAllocation op(size, is_tlab, gc_count_before);
 371     VMThread::execute(&op);
 372     if (op.prologue_succeeded()) {
 373       result = op.result();
 374       if (op.gc_locked()) {
 375          assert(result == NULL, "must be NULL if gc_locked() is true");
 376          continue;  // Retry and/or stall as necessary.
 377       }
 378 
 379       // Allocation has failed and a collection
 380       // has been done.  If the gc time limit was exceeded the
 381       // this time, return NULL so that an out-of-memory
 382       // will be thrown.  Clear gc_overhead_limit_exceeded
 383       // so that the overhead exceeded does not persist.
 384 
 385       const bool limit_exceeded = size_policy()->gc_overhead_limit_exceeded();
 386       const bool softrefs_clear = soft_ref_policy()->all_soft_refs_clear();
 387 
 388       if (limit_exceeded && softrefs_clear) {
 389         *gc_overhead_limit_was_exceeded = true;
 390         size_policy()->set_gc_overhead_limit_exceeded(false);
 391         if (op.result() != NULL) {
 392           CollectedHeap::fill_with_object(op.result(), size);
 393         }
 394         return NULL;
 395       }
 396       assert(result == NULL || is_in_reserved(result),
 397              "result not in heap");
 398       return result;
 399     }
 400 
 401     // Give a warning if we seem to be looping forever.
 402     if ((QueuedAllocationWarningCount > 0) &&
 403         (try_count % QueuedAllocationWarningCount == 0)) {
 404           log_warning(gc, ergo)("GenCollectedHeap::mem_allocate_work retries %d times,"
 405                                 " size=" SIZE_FORMAT " %s", try_count, size, is_tlab ? "(TLAB)" : "");
 406     }
 407   }
 408 }
 409 
 410 HeapWord* GenCollectedHeap::attempt_allocation(size_t size,
 411                                                bool is_tlab,
 412                                                bool first_only) {
 413   HeapWord* res = NULL;
 414 
 415   if (_young_gen->should_allocate(size, is_tlab)) {
 416     res = _young_gen->allocate(size, is_tlab);
 417     if (res != NULL || first_only) {
 418       return res;
 419     }
 420   }
 421 
 422   if (_old_gen->should_allocate(size, is_tlab)) {
 423     res = _old_gen->allocate(size, is_tlab);
 424   }
 425 
 426   return res;
 427 }
 428 
 429 HeapWord* GenCollectedHeap::mem_allocate(size_t size,
 430                                          bool* gc_overhead_limit_was_exceeded) {
 431   return mem_allocate_work(size,
 432                            false /* is_tlab */,
 433                            gc_overhead_limit_was_exceeded);
 434 }
 435 
 436 bool GenCollectedHeap::must_clear_all_soft_refs() {
 437   return _gc_cause == GCCause::_metadata_GC_clear_soft_refs ||
 438          _gc_cause == GCCause::_wb_full_gc;
 439 }
 440 
 441 void GenCollectedHeap::collect_generation(Generation* gen, bool full, size_t size,
 442                                           bool is_tlab, bool run_verification, bool clear_soft_refs) {
 443   FormatBuffer<> title("Collect gen: %s", gen->short_name());
 444   GCTraceTime(Trace, gc, phases) t1(title);
 445   TraceCollectorStats tcs(gen->counters());
 446   TraceMemoryManagerStats tmms(gen->gc_manager(), gc_cause());
 447 
 448   gen->stat_record()->invocations++;
 449   gen->stat_record()->accumulated_time.start();
 450 
 451   // Must be done anew before each collection because
 452   // a previous collection will do mangling and will
 453   // change top of some spaces.
 454   record_gen_tops_before_GC();
 455 
 456   log_trace(gc)("%s invoke=%d size=" SIZE_FORMAT, heap()->is_young_gen(gen) ? "Young" : "Old", gen->stat_record()->invocations, size * HeapWordSize);
 457 
 458   if (run_verification && VerifyBeforeGC) {
 459     Universe::verify("Before GC");
 460   }
 461   COMPILER2_OR_JVMCI_PRESENT(DerivedPointerTable::clear());
 462 
 463   // Do collection work
 464   {
 465     // Note on ref discovery: For what appear to be historical reasons,
 466     // GCH enables and disabled (by enqueuing) refs discovery.
 467     // In the future this should be moved into the generation's
 468     // collect method so that ref discovery and enqueueing concerns
 469     // are local to a generation. The collect method could return
 470     // an appropriate indication in the case that notification on
 471     // the ref lock was needed. This will make the treatment of
 472     // weak refs more uniform (and indeed remove such concerns
 473     // from GCH). XXX
 474 
 475     save_marks();   // save marks for all gens
 476     // We want to discover references, but not process them yet.
 477     // This mode is disabled in process_discovered_references if the
 478     // generation does some collection work, or in
 479     // enqueue_discovered_references if the generation returns
 480     // without doing any work.
 481     ReferenceProcessor* rp = gen->ref_processor();
 482     rp->start_discovery(clear_soft_refs);
 483 
 484     gen->collect(full, clear_soft_refs, size, is_tlab);
 485 
 486     rp->disable_discovery();
 487     rp->verify_no_references_recorded();
 488   }
 489 
 490   COMPILER2_OR_JVMCI_PRESENT(DerivedPointerTable::update_pointers());
 491 
 492   gen->stat_record()->accumulated_time.stop();
 493 
 494   update_gc_stats(gen, full);
 495 
 496   if (run_verification && VerifyAfterGC) {
 497     Universe::verify("After GC");
 498   }
 499 }
 500 
 501 void GenCollectedHeap::do_collection(bool           full,
 502                                      bool           clear_all_soft_refs,
 503                                      size_t         size,
 504                                      bool           is_tlab,
 505                                      GenerationType max_generation) {
 506   ResourceMark rm;
 507   DEBUG_ONLY(Thread* my_thread = Thread::current();)
 508 
 509   assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
 510   assert(my_thread->is_VM_thread(), "only VM thread");
 511   assert(Heap_lock->is_locked(),
 512          "the requesting thread should have the Heap_lock");
 513   guarantee(!is_gc_active(), "collection is not reentrant");
 514 
 515   if (GCLocker::check_active_before_gc()) {
 516     return; // GC is disabled (e.g. JNI GetXXXCritical operation)
 517   }
 518 
 519   const bool do_clear_all_soft_refs = clear_all_soft_refs ||
 520                           soft_ref_policy()->should_clear_all_soft_refs();
 521 
 522   ClearedAllSoftRefs casr(do_clear_all_soft_refs, soft_ref_policy());
 523 
 524   AutoModifyRestore<bool> temporarily(_is_gc_active, true);
 525 
 526   bool complete = full && (max_generation == OldGen);
 527   bool old_collects_young = complete && !ScavengeBeforeFullGC;
 528   bool do_young_collection = !old_collects_young && _young_gen->should_collect(full, size, is_tlab);
 529 
 530   const PreGenGCValues pre_gc_values = get_pre_gc_values();
 531 
 532   bool run_verification = total_collections() >= VerifyGCStartAt;
 533   bool prepared_for_verification = false;
 534   bool do_full_collection = false;
 535 
 536   if (do_young_collection) {
 537     GCIdMark gc_id_mark;
 538     GCTraceCPUTime tcpu;
 539     GCTraceTime(Info, gc) t("Pause Young", NULL, gc_cause(), true);
 540 
 541     print_heap_before_gc();
 542 
 543     if (run_verification && VerifyGCLevel <= 0 && VerifyBeforeGC) {
 544       prepare_for_verify();
 545       prepared_for_verification = true;
 546     }
 547 
 548     gc_prologue(complete);
 549     increment_total_collections(complete);
 550 
 551     collect_generation(_young_gen,
 552                        full,
 553                        size,
 554                        is_tlab,
 555                        run_verification && VerifyGCLevel <= 0,
 556                        do_clear_all_soft_refs);
 557 
 558     if (size > 0 && (!is_tlab || _young_gen->supports_tlab_allocation()) &&
 559         size * HeapWordSize <= _young_gen->unsafe_max_alloc_nogc()) {
 560       // Allocation request was met by young GC.
 561       size = 0;
 562     }
 563 
 564     // Ask if young collection is enough. If so, do the final steps for young collection,
 565     // and fallthrough to the end.
 566     do_full_collection = should_do_full_collection(size, full, is_tlab, max_generation);
 567     if (!do_full_collection) {
 568       // Adjust generation sizes.
 569       _young_gen->compute_new_size();
 570 
 571       print_heap_change(pre_gc_values);
 572 
 573       // Track memory usage and detect low memory after GC finishes
 574       MemoryService::track_memory_usage();
 575 
 576       gc_epilogue(complete);
 577     }
 578 
 579     print_heap_after_gc();
 580 
 581   } else {
 582     // No young collection, ask if we need to perform Full collection.
 583     do_full_collection = should_do_full_collection(size, full, is_tlab, max_generation);
 584   }
 585 
 586   if (do_full_collection) {
 587     GCIdMark gc_id_mark;
 588     GCTraceCPUTime tcpu;
 589     GCTraceTime(Info, gc) t("Pause Full", NULL, gc_cause(), true);
 590 
 591     print_heap_before_gc();
 592 
 593     if (!prepared_for_verification && run_verification &&
 594         VerifyGCLevel <= 1 && VerifyBeforeGC) {
 595       prepare_for_verify();
 596     }
 597 
 598     if (!do_young_collection) {
 599       gc_prologue(complete);
 600       increment_total_collections(complete);
 601     }
 602 
 603     // Accounting quirk: total full collections would be incremented when "complete"
 604     // is set, by calling increment_total_collections above. However, we also need to
 605     // account Full collections that had "complete" unset.
 606     if (!complete) {
 607       increment_total_full_collections();
 608     }
 609 
 610     Continuations::on_gc_marking_cycle_start();
 611     Continuations::arm_all_nmethods();
 612 
 613     collect_generation(_old_gen,
 614                        full,
 615                        size,
 616                        is_tlab,
 617                        run_verification && VerifyGCLevel <= 1,
 618                        do_clear_all_soft_refs);
 619 
 620     Continuations::on_gc_marking_cycle_finish();
 621     Continuations::arm_all_nmethods();
 622 
 623     // Adjust generation sizes.
 624     _old_gen->compute_new_size();
 625     _young_gen->compute_new_size();
 626 
 627     // Delete metaspaces for unloaded class loaders and clean up loader_data graph
 628     ClassLoaderDataGraph::purge(/*at_safepoint*/true);
 629     DEBUG_ONLY(MetaspaceUtils::verify();)
 630     // Resize the metaspace capacity after full collections
 631     MetaspaceGC::compute_new_size();
 632     update_full_collections_completed();
 633 
 634     print_heap_change(pre_gc_values);
 635 
 636     // Track memory usage and detect low memory after GC finishes
 637     MemoryService::track_memory_usage();
 638 
 639     // Need to tell the epilogue code we are done with Full GC, regardless what was
 640     // the initial value for "complete" flag.
 641     gc_epilogue(true);
 642 
 643     print_heap_after_gc();
 644   }
 645 }
 646 
 647 bool GenCollectedHeap::should_do_full_collection(size_t size, bool full, bool is_tlab,
 648                                                  GenCollectedHeap::GenerationType max_gen) const {
 649   return max_gen == OldGen && _old_gen->should_collect(full, size, is_tlab);
 650 }
 651 
 652 void GenCollectedHeap::register_nmethod(nmethod* nm) {
 653   ScavengableNMethods::register_nmethod(nm);
 654 }
 655 
 656 void GenCollectedHeap::unregister_nmethod(nmethod* nm) {
 657   ScavengableNMethods::unregister_nmethod(nm);
 658 }
 659 
 660 void GenCollectedHeap::verify_nmethod(nmethod* nm) {
 661   ScavengableNMethods::verify_nmethod(nm);
 662 }
 663 
 664 void GenCollectedHeap::flush_nmethod(nmethod* nm) {
 665   // Do nothing.
 666 }
 667 
 668 void GenCollectedHeap::prune_scavengable_nmethods() {
 669   ScavengableNMethods::prune_nmethods();
 670 }
 671 
 672 HeapWord* GenCollectedHeap::satisfy_failed_allocation(size_t size, bool is_tlab) {
 673   GCCauseSetter x(this, GCCause::_allocation_failure);
 674   HeapWord* result = NULL;
 675 
 676   assert(size != 0, "Precondition violated");
 677   if (GCLocker::is_active_and_needs_gc()) {
 678     // GC locker is active; instead of a collection we will attempt
 679     // to expand the heap, if there's room for expansion.
 680     if (!is_maximal_no_gc()) {
 681       result = expand_heap_and_allocate(size, is_tlab);
 682     }
 683     return result;   // Could be null if we are out of space.
 684   } else if (!incremental_collection_will_fail(false /* don't consult_young */)) {
 685     // Do an incremental collection.
 686     do_collection(false,                     // full
 687                   false,                     // clear_all_soft_refs
 688                   size,                      // size
 689                   is_tlab,                   // is_tlab
 690                   GenCollectedHeap::OldGen); // max_generation
 691   } else {
 692     log_trace(gc)(" :: Trying full because partial may fail :: ");
 693     // Try a full collection; see delta for bug id 6266275
 694     // for the original code and why this has been simplified
 695     // with from-space allocation criteria modified and
 696     // such allocation moved out of the safepoint path.
 697     do_collection(true,                      // full
 698                   false,                     // clear_all_soft_refs
 699                   size,                      // size
 700                   is_tlab,                   // is_tlab
 701                   GenCollectedHeap::OldGen); // max_generation
 702   }
 703 
 704   result = attempt_allocation(size, is_tlab, false /*first_only*/);
 705 
 706   if (result != NULL) {
 707     assert(is_in_reserved(result), "result not in heap");
 708     return result;
 709   }
 710 
 711   // OK, collection failed, try expansion.
 712   result = expand_heap_and_allocate(size, is_tlab);
 713   if (result != NULL) {
 714     return result;
 715   }
 716 
 717   // If we reach this point, we're really out of memory. Try every trick
 718   // we can to reclaim memory. Force collection of soft references. Force
 719   // a complete compaction of the heap. Any additional methods for finding
 720   // free memory should be here, especially if they are expensive. If this
 721   // attempt fails, an OOM exception will be thrown.
 722   {
 723     UIntFlagSetting flag_change(MarkSweepAlwaysCompactCount, 1); // Make sure the heap is fully compacted
 724 
 725     do_collection(true,                      // full
 726                   true,                      // clear_all_soft_refs
 727                   size,                      // size
 728                   is_tlab,                   // is_tlab
 729                   GenCollectedHeap::OldGen); // max_generation
 730   }
 731 
 732   result = attempt_allocation(size, is_tlab, false /* first_only */);
 733   if (result != NULL) {
 734     assert(is_in_reserved(result), "result not in heap");
 735     return result;
 736   }
 737 
 738   assert(!soft_ref_policy()->should_clear_all_soft_refs(),
 739     "Flag should have been handled and cleared prior to this point");
 740 
 741   // What else?  We might try synchronous finalization later.  If the total
 742   // space available is large enough for the allocation, then a more
 743   // complete compaction phase than we've tried so far might be
 744   // appropriate.
 745   return NULL;
 746 }
 747 
 748 #ifdef ASSERT
 749 class AssertNonScavengableClosure: public OopClosure {
 750 public:
 751   virtual void do_oop(oop* p) {
 752     assert(!GenCollectedHeap::heap()->is_in_partial_collection(*p),
 753       "Referent should not be scavengable.");  }
 754   virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); }
 755 };
 756 static AssertNonScavengableClosure assert_is_non_scavengable_closure;
 757 #endif
 758 
 759 void GenCollectedHeap::process_roots(ScanningOption so,
 760                                      OopClosure* strong_roots,
 761                                      CLDClosure* strong_cld_closure,
 762                                      CLDClosure* weak_cld_closure,
 763                                      CodeBlobToOopClosure* code_roots) {
 764   // General roots.
 765   assert(code_roots != NULL, "code root closure should always be set");
 766 
 767   ClassLoaderDataGraph::roots_cld_do(strong_cld_closure, weak_cld_closure);
 768 
 769   // Only process code roots from thread stacks if we aren't visiting the entire CodeCache anyway
 770   CodeBlobToOopClosure* roots_from_code_p = (so & SO_AllCodeCache) ? NULL : code_roots;
 771 
 772   Threads::oops_do(strong_roots, roots_from_code_p);
 773 
 774   OopStorageSet::strong_oops_do(strong_roots);
 775 
 776   if (so & SO_ScavengeCodeCache) {
 777     assert(code_roots != NULL, "must supply closure for code cache");
 778 
 779     // We only visit parts of the CodeCache when scavenging.
 780     ScavengableNMethods::nmethods_do(code_roots);
 781   }
 782   if (so & SO_AllCodeCache) {
 783     assert(code_roots != NULL, "must supply closure for code cache");
 784 
 785     // CMSCollector uses this to do intermediate-strength collections.
 786     // We scan the entire code cache, since CodeCache::do_unloading is not called.
 787     CodeCache::blobs_do(code_roots);
 788   }
 789   // Verify that the code cache contents are not subject to
 790   // movement by a scavenging collection.
 791   DEBUG_ONLY(CodeBlobToOopClosure assert_code_is_non_scavengable(&assert_is_non_scavengable_closure, !CodeBlobToOopClosure::FixRelocations));
 792   DEBUG_ONLY(ScavengableNMethods::asserted_non_scavengable_nmethods_do(&assert_code_is_non_scavengable));
 793 }
 794 
 795 void GenCollectedHeap::full_process_roots(bool is_adjust_phase,
 796                                           ScanningOption so,
 797                                           bool only_strong_roots,
 798                                           OopClosure* root_closure,
 799                                           CLDClosure* cld_closure) {
 800   // Called from either the marking phase or the adjust phase.
 801   const bool is_marking_phase = !is_adjust_phase;
 802 
 803   MarkingCodeBlobClosure mark_code_closure(root_closure, is_adjust_phase, is_marking_phase);
 804   CLDClosure* weak_cld_closure = only_strong_roots ? NULL : cld_closure;
 805 
 806   process_roots(so, root_closure, cld_closure, weak_cld_closure, &mark_code_closure);
 807 }
 808 
 809 void GenCollectedHeap::gen_process_weak_roots(OopClosure* root_closure) {
 810   WeakProcessor::oops_do(root_closure);
 811 }
 812 
 813 bool GenCollectedHeap::no_allocs_since_save_marks() {
 814   return _young_gen->no_allocs_since_save_marks() &&
 815          _old_gen->no_allocs_since_save_marks();
 816 }
 817 
 818 // public collection interfaces
 819 
 820 void GenCollectedHeap::collect(GCCause::Cause cause) {
 821   if ((cause == GCCause::_wb_young_gc) ||
 822       (cause == GCCause::_gc_locker)) {
 823     // Young collection for WhiteBox or GCLocker.
 824     collect(cause, YoungGen);
 825   } else {
 826 #ifdef ASSERT
 827   if (cause == GCCause::_scavenge_alot) {
 828     // Young collection only.
 829     collect(cause, YoungGen);
 830   } else {
 831     // Stop-the-world full collection.
 832     collect(cause, OldGen);
 833   }
 834 #else
 835     // Stop-the-world full collection.
 836     collect(cause, OldGen);
 837 #endif
 838   }
 839 }
 840 
 841 void GenCollectedHeap::collect(GCCause::Cause cause, GenerationType max_generation) {
 842   // The caller doesn't have the Heap_lock
 843   assert(!Heap_lock->owned_by_self(), "this thread should not own the Heap_lock");
 844 
 845   unsigned int gc_count_before;
 846   unsigned int full_gc_count_before;
 847 
 848   {
 849     MutexLocker ml(Heap_lock);
 850     // Read the GC count while holding the Heap_lock
 851     gc_count_before      = total_collections();
 852     full_gc_count_before = total_full_collections();
 853   }
 854 
 855   if (GCLocker::should_discard(cause, gc_count_before)) {
 856     return;
 857   }
 858 
 859   VM_GenCollectFull op(gc_count_before, full_gc_count_before,
 860                        cause, max_generation);
 861   VMThread::execute(&op);
 862 }
 863 
 864 void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs) {
 865    do_full_collection(clear_all_soft_refs, OldGen);
 866 }
 867 
 868 void GenCollectedHeap::do_full_collection(bool clear_all_soft_refs,
 869                                           GenerationType last_generation) {
 870   do_collection(true,                   // full
 871                 clear_all_soft_refs,    // clear_all_soft_refs
 872                 0,                      // size
 873                 false,                  // is_tlab
 874                 last_generation);       // last_generation
 875   // Hack XXX FIX ME !!!
 876   // A scavenge may not have been attempted, or may have
 877   // been attempted and failed, because the old gen was too full
 878   if (gc_cause() == GCCause::_gc_locker && incremental_collection_failed()) {
 879     log_debug(gc, jni)("GC locker: Trying a full collection because scavenge failed");
 880     // This time allow the old gen to be collected as well
 881     do_collection(true,                // full
 882                   clear_all_soft_refs, // clear_all_soft_refs
 883                   0,                   // size
 884                   false,               // is_tlab
 885                   OldGen);             // last_generation
 886   }
 887 }
 888 
 889 bool GenCollectedHeap::is_in_young(oop p) const {
 890   bool result = cast_from_oop<HeapWord*>(p) < _old_gen->reserved().start();
 891   assert(result == _young_gen->is_in_reserved(p),
 892          "incorrect test - result=%d, p=" INTPTR_FORMAT, result, p2i((void*)p));
 893   return result;
 894 }
 895 
 896 bool GenCollectedHeap::requires_barriers(stackChunkOop obj) const {
 897   return !is_in_young(obj);
 898 }
 899 
 900 // Returns "TRUE" iff "p" points into the committed areas of the heap.
 901 bool GenCollectedHeap::is_in(const void* p) const {
 902   return _young_gen->is_in(p) || _old_gen->is_in(p);
 903 }
 904 
 905 #ifdef ASSERT
 906 // Don't implement this by using is_in_young().  This method is used
 907 // in some cases to check that is_in_young() is correct.
 908 bool GenCollectedHeap::is_in_partial_collection(const void* p) {
 909   assert(is_in_reserved(p) || p == NULL,
 910     "Does not work if address is non-null and outside of the heap");
 911   return p < _young_gen->reserved().end() && p != NULL;
 912 }
 913 #endif
 914 
 915 void GenCollectedHeap::oop_iterate(OopIterateClosure* cl) {
 916   _young_gen->oop_iterate(cl);
 917   _old_gen->oop_iterate(cl);
 918 }
 919 
 920 void GenCollectedHeap::object_iterate(ObjectClosure* cl) {
 921   _young_gen->object_iterate(cl);
 922   _old_gen->object_iterate(cl);
 923 }
 924 
 925 Space* GenCollectedHeap::space_containing(const void* addr) const {
 926   Space* res = _young_gen->space_containing(addr);
 927   if (res != NULL) {
 928     return res;
 929   }
 930   res = _old_gen->space_containing(addr);
 931   assert(res != NULL, "Could not find containing space");
 932   return res;
 933 }
 934 
 935 HeapWord* GenCollectedHeap::block_start(const void* addr) const {
 936   assert(is_in_reserved(addr), "block_start of address outside of heap");
 937   if (_young_gen->is_in_reserved(addr)) {
 938     assert(_young_gen->is_in(addr), "addr should be in allocated part of generation");
 939     return _young_gen->block_start(addr);
 940   }
 941 
 942   assert(_old_gen->is_in_reserved(addr), "Some generation should contain the address");
 943   assert(_old_gen->is_in(addr), "addr should be in allocated part of generation");
 944   return _old_gen->block_start(addr);
 945 }
 946 
 947 bool GenCollectedHeap::block_is_obj(const HeapWord* addr) const {
 948   assert(is_in_reserved(addr), "block_is_obj of address outside of heap");
 949   assert(block_start(addr) == addr, "addr must be a block start");
 950   if (_young_gen->is_in_reserved(addr)) {
 951     return _young_gen->block_is_obj(addr);
 952   }
 953 
 954   assert(_old_gen->is_in_reserved(addr), "Some generation should contain the address");
 955   return _old_gen->block_is_obj(addr);
 956 }
 957 
 958 size_t GenCollectedHeap::tlab_capacity(Thread* thr) const {
 959   assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
 960   assert(_young_gen->supports_tlab_allocation(), "Young gen doesn't support TLAB allocation?!");
 961   return _young_gen->tlab_capacity();
 962 }
 963 
 964 size_t GenCollectedHeap::tlab_used(Thread* thr) const {
 965   assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
 966   assert(_young_gen->supports_tlab_allocation(), "Young gen doesn't support TLAB allocation?!");
 967   return _young_gen->tlab_used();
 968 }
 969 
 970 size_t GenCollectedHeap::unsafe_max_tlab_alloc(Thread* thr) const {
 971   assert(!_old_gen->supports_tlab_allocation(), "Old gen supports TLAB allocation?!");
 972   assert(_young_gen->supports_tlab_allocation(), "Young gen doesn't support TLAB allocation?!");
 973   return _young_gen->unsafe_max_tlab_alloc();
 974 }
 975 
 976 HeapWord* GenCollectedHeap::allocate_new_tlab(size_t min_size,
 977                                               size_t requested_size,
 978                                               size_t* actual_size) {
 979   bool gc_overhead_limit_was_exceeded;
 980   HeapWord* result = mem_allocate_work(requested_size /* size */,
 981                                        true /* is_tlab */,
 982                                        &gc_overhead_limit_was_exceeded);
 983   if (result != NULL) {
 984     *actual_size = requested_size;
 985   }
 986 
 987   return result;
 988 }
 989 
 990 // Requires "*prev_ptr" to be non-NULL.  Deletes and a block of minimal size
 991 // from the list headed by "*prev_ptr".
 992 static ScratchBlock *removeSmallestScratch(ScratchBlock **prev_ptr) {
 993   bool first = true;
 994   size_t min_size = 0;   // "first" makes this conceptually infinite.
 995   ScratchBlock **smallest_ptr, *smallest;
 996   ScratchBlock  *cur = *prev_ptr;
 997   while (cur) {
 998     assert(*prev_ptr == cur, "just checking");
 999     if (first || cur->num_words < min_size) {
1000       smallest_ptr = prev_ptr;
1001       smallest     = cur;
1002       min_size     = smallest->num_words;
1003       first        = false;
1004     }
1005     prev_ptr = &cur->next;
1006     cur     =  cur->next;
1007   }
1008   smallest      = *smallest_ptr;
1009   *smallest_ptr = smallest->next;
1010   return smallest;
1011 }
1012 
1013 // Sort the scratch block list headed by res into decreasing size order,
1014 // and set "res" to the result.
1015 static void sort_scratch_list(ScratchBlock*& list) {
1016   ScratchBlock* sorted = NULL;
1017   ScratchBlock* unsorted = list;
1018   while (unsorted) {
1019     ScratchBlock *smallest = removeSmallestScratch(&unsorted);
1020     smallest->next  = sorted;
1021     sorted          = smallest;
1022   }
1023   list = sorted;
1024 }
1025 
1026 ScratchBlock* GenCollectedHeap::gather_scratch(Generation* requestor,
1027                                                size_t max_alloc_words) {
1028   ScratchBlock* res = NULL;
1029   _young_gen->contribute_scratch(res, requestor, max_alloc_words);
1030   _old_gen->contribute_scratch(res, requestor, max_alloc_words);
1031   sort_scratch_list(res);
1032   return res;
1033 }
1034 
1035 void GenCollectedHeap::release_scratch() {
1036   _young_gen->reset_scratch();
1037   _old_gen->reset_scratch();
1038 }
1039 
1040 void GenCollectedHeap::prepare_for_verify() {
1041   ensure_parsability(false);        // no need to retire TLABs
1042 }
1043 
1044 void GenCollectedHeap::generation_iterate(GenClosure* cl,
1045                                           bool old_to_young) {
1046   if (old_to_young) {
1047     cl->do_generation(_old_gen);
1048     cl->do_generation(_young_gen);
1049   } else {
1050     cl->do_generation(_young_gen);
1051     cl->do_generation(_old_gen);
1052   }
1053 }
1054 
1055 bool GenCollectedHeap::is_maximal_no_gc() const {
1056   return _young_gen->is_maximal_no_gc() && _old_gen->is_maximal_no_gc();
1057 }
1058 
1059 void GenCollectedHeap::save_marks() {
1060   _young_gen->save_marks();
1061   _old_gen->save_marks();
1062 }
1063 
1064 GenCollectedHeap* GenCollectedHeap::heap() {
1065   // SerialHeap is the only subtype of GenCollectedHeap.
1066   return named_heap<GenCollectedHeap>(CollectedHeap::Serial);
1067 }
1068 
1069 #if INCLUDE_SERIALGC
1070 void GenCollectedHeap::prepare_for_compaction() {
1071   // Start by compacting into same gen.
1072   CompactPoint cp(_old_gen);
1073   _old_gen->prepare_for_compaction(&cp);
1074   _young_gen->prepare_for_compaction(&cp);
1075 }
1076 #endif // INCLUDE_SERIALGC
1077 
1078 void GenCollectedHeap::verify(VerifyOption option /* ignored */) {
1079   log_debug(gc, verify)("%s", _old_gen->name());
1080   _old_gen->verify();
1081 
1082   log_debug(gc, verify)("%s", _old_gen->name());
1083   _young_gen->verify();
1084 
1085   log_debug(gc, verify)("RemSet");
1086   rem_set()->verify();
1087 }
1088 
1089 void GenCollectedHeap::print_on(outputStream* st) const {
1090   if (_young_gen != NULL) {
1091     _young_gen->print_on(st);
1092   }
1093   if (_old_gen != NULL) {
1094     _old_gen->print_on(st);
1095   }
1096   MetaspaceUtils::print_on(st);
1097 }
1098 
1099 void GenCollectedHeap::gc_threads_do(ThreadClosure* tc) const {
1100 }
1101 
1102 bool GenCollectedHeap::print_location(outputStream* st, void* addr) const {
1103   return BlockLocationPrinter<GenCollectedHeap>::print_location(st, addr);
1104 }
1105 
1106 void GenCollectedHeap::print_tracing_info() const {
1107   if (log_is_enabled(Debug, gc, heap, exit)) {
1108     LogStreamHandle(Debug, gc, heap, exit) lsh;
1109     _young_gen->print_summary_info_on(&lsh);
1110     _old_gen->print_summary_info_on(&lsh);
1111   }
1112 }
1113 
1114 void GenCollectedHeap::print_heap_change(const PreGenGCValues& pre_gc_values) const {
1115   const DefNewGeneration* const def_new_gen = (DefNewGeneration*) young_gen();
1116 
1117   log_info(gc, heap)(HEAP_CHANGE_FORMAT" "
1118                      HEAP_CHANGE_FORMAT" "
1119                      HEAP_CHANGE_FORMAT,
1120                      HEAP_CHANGE_FORMAT_ARGS(def_new_gen->short_name(),
1121                                              pre_gc_values.young_gen_used(),
1122                                              pre_gc_values.young_gen_capacity(),
1123                                              def_new_gen->used(),
1124                                              def_new_gen->capacity()),
1125                      HEAP_CHANGE_FORMAT_ARGS("Eden",
1126                                              pre_gc_values.eden_used(),
1127                                              pre_gc_values.eden_capacity(),
1128                                              def_new_gen->eden()->used(),
1129                                              def_new_gen->eden()->capacity()),
1130                      HEAP_CHANGE_FORMAT_ARGS("From",
1131                                              pre_gc_values.from_used(),
1132                                              pre_gc_values.from_capacity(),
1133                                              def_new_gen->from()->used(),
1134                                              def_new_gen->from()->capacity()));
1135   log_info(gc, heap)(HEAP_CHANGE_FORMAT,
1136                      HEAP_CHANGE_FORMAT_ARGS(old_gen()->short_name(),
1137                                              pre_gc_values.old_gen_used(),
1138                                              pre_gc_values.old_gen_capacity(),
1139                                              old_gen()->used(),
1140                                              old_gen()->capacity()));
1141   MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());
1142 }
1143 
1144 class GenGCPrologueClosure: public GenCollectedHeap::GenClosure {
1145  private:
1146   bool _full;
1147  public:
1148   void do_generation(Generation* gen) {
1149     gen->gc_prologue(_full);
1150   }
1151   GenGCPrologueClosure(bool full) : _full(full) {};
1152 };
1153 
1154 void GenCollectedHeap::gc_prologue(bool full) {
1155   assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer");
1156 
1157   // Fill TLAB's and such
1158   ensure_parsability(true);   // retire TLABs
1159 
1160   // Walk generations
1161   GenGCPrologueClosure blk(full);
1162   generation_iterate(&blk, false);  // not old-to-young.
1163 };
1164 
1165 class GenGCEpilogueClosure: public GenCollectedHeap::GenClosure {
1166  private:
1167   bool _full;
1168  public:
1169   void do_generation(Generation* gen) {
1170     gen->gc_epilogue(_full);
1171   }
1172   GenGCEpilogueClosure(bool full) : _full(full) {};
1173 };
1174 
1175 void GenCollectedHeap::gc_epilogue(bool full) {
1176 #if COMPILER2_OR_JVMCI
1177   assert(DerivedPointerTable::is_empty(), "derived pointer present");
1178 #endif // COMPILER2_OR_JVMCI
1179 
1180   resize_all_tlabs();
1181 
1182   GenGCEpilogueClosure blk(full);
1183   generation_iterate(&blk, false);  // not old-to-young.
1184 
1185   MetaspaceCounters::update_performance_counters();
1186 };
1187 
1188 #ifndef PRODUCT
1189 class GenGCSaveTopsBeforeGCClosure: public GenCollectedHeap::GenClosure {
1190  private:
1191  public:
1192   void do_generation(Generation* gen) {
1193     gen->record_spaces_top();
1194   }
1195 };
1196 
1197 void GenCollectedHeap::record_gen_tops_before_GC() {
1198   if (ZapUnusedHeapArea) {
1199     GenGCSaveTopsBeforeGCClosure blk;
1200     generation_iterate(&blk, false);  // not old-to-young.
1201   }
1202 }
1203 #endif  // not PRODUCT
1204 
1205 class GenEnsureParsabilityClosure: public GenCollectedHeap::GenClosure {
1206  public:
1207   void do_generation(Generation* gen) {
1208     gen->ensure_parsability();
1209   }
1210 };
1211 
1212 void GenCollectedHeap::ensure_parsability(bool retire_tlabs) {
1213   CollectedHeap::ensure_parsability(retire_tlabs);
1214   GenEnsureParsabilityClosure ep_cl;
1215   generation_iterate(&ep_cl, false);
1216 }