< prev index next >

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

Print this page
@@ -1,7 +1,8 @@
  /*
   * Copyright (c) 2014, 2021, Red Hat, Inc. All rights reserved.
+  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -29,17 +30,22 @@
  #include "gc/shared/gcTraceTime.inline.hpp"
  #include "gc/shared/preservedMarks.inline.hpp"
  #include "gc/shared/tlab_globals.hpp"
  #include "gc/shared/workerThread.hpp"
  #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
+ #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  #include "gc/shenandoah/shenandoahConcurrentGC.hpp"
  #include "gc/shenandoah/shenandoahCollectionSet.hpp"
+ #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
  #include "gc/shenandoah/shenandoahFreeSet.hpp"
  #include "gc/shenandoah/shenandoahFullGC.hpp"
+ #include "gc/shenandoah/shenandoahGenerationalFullGC.hpp"
+ #include "gc/shenandoah/shenandoahGlobalGeneration.hpp"
  #include "gc/shenandoah/shenandoahPhaseTimings.hpp"
  #include "gc/shenandoah/shenandoahMark.inline.hpp"
  #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
+ #include "gc/shenandoah/shenandoahHeapRegionClosures.hpp"
  #include "gc/shenandoah/shenandoahHeapRegionSet.hpp"
  #include "gc/shenandoah/shenandoahHeap.inline.hpp"
  #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
  #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
  #include "gc/shenandoah/shenandoahMetrics.hpp"

@@ -53,11 +59,10 @@
  #include "gc/shenandoah/shenandoahWorkerPolicy.hpp"
  #include "memory/metaspaceUtils.hpp"
  #include "memory/universe.hpp"
  #include "oops/compressedOops.inline.hpp"
  #include "oops/oop.inline.hpp"
- #include "runtime/javaThread.hpp"
  #include "runtime/orderAccess.hpp"
  #include "runtime/vmThread.hpp"
  #include "utilities/copy.hpp"
  #include "utilities/events.hpp"
  #include "utilities/growableArray.hpp"

@@ -103,24 +108,38 @@
    metrics.snap_before();
  
    // Perform full GC
    do_it(cause);
  
+   ShenandoahHeap* const heap = ShenandoahHeap::heap();
+ 
+   if (heap->mode()->is_generational()) {
+     ShenandoahGenerationalFullGC::handle_completion(heap);
+   }
+ 
    metrics.snap_after();
  
    if (metrics.is_good_progress()) {
-     ShenandoahHeap::heap()->notify_gc_progress();
+     heap->notify_gc_progress();
    } else {
      // Nothing to do. Tell the allocation path that we have failed to make
      // progress, and it can finally fail.
-     ShenandoahHeap::heap()->notify_gc_no_progress();
+     heap->notify_gc_no_progress();
    }
+ 
+   // Regardless if progress was made, we record that we completed a "successful" full GC.
+   heap->global_generation()->heuristics()->record_success_full();
+   heap->shenandoah_policy()->record_success_full();
  }
  
  void ShenandoahFullGC::do_it(GCCause::Cause gc_cause) {
    ShenandoahHeap* heap = ShenandoahHeap::heap();
  
+   if (heap->mode()->is_generational()) {
+     ShenandoahGenerationalFullGC::prepare();
+   }
+ 
    if (ShenandoahVerify) {
      heap->verifier()->verify_before_fullgc();
    }
  
    if (VerifyBeforeGC) {

@@ -159,41 +178,45 @@
      if (heap->is_update_refs_in_progress()) {
        heap->set_update_refs_in_progress(false);
      }
      assert(!heap->is_update_refs_in_progress(), "sanity");
  
-     // b. Cancel concurrent mark, if in progress
+     // b. Cancel all concurrent marks, if in progress
      if (heap->is_concurrent_mark_in_progress()) {
-       ShenandoahConcurrentGC::cancel();
-       heap->set_concurrent_mark_in_progress(false);
+       heap->cancel_concurrent_mark();
      }
      assert(!heap->is_concurrent_mark_in_progress(), "sanity");
  
      // c. Update roots if this full GC is due to evac-oom, which may carry from-space pointers in roots.
      if (has_forwarded_objects) {
        update_roots(true /*full_gc*/);
      }
  
      // d. Reset the bitmaps for new marking
-     heap->reset_mark_bitmap();
+     heap->global_generation()->reset_mark_bitmap();
      assert(heap->marking_context()->is_bitmap_clear(), "sanity");
-     assert(!heap->marking_context()->is_complete(), "sanity");
+     assert(!heap->global_generation()->is_mark_complete(), "sanity");
  
      // e. Abandon reference discovery and clear all discovered references.
-     ShenandoahReferenceProcessor* rp = heap->ref_processor();
+     ShenandoahReferenceProcessor* rp = heap->global_generation()->ref_processor();
      rp->abandon_partial_discovery();
  
      // f. Sync pinned region status from the CP marks
      heap->sync_pinned_region_status();
  
+     if (heap->mode()->is_generational()) {
+       ShenandoahGenerationalFullGC::restore_top_before_promote(heap);
+     }
+ 
      // The rest of prologue:
      _preserved_marks->init(heap->workers()->active_workers());
  
      assert(heap->has_forwarded_objects() == has_forwarded_objects, "This should not change");
    }
  
    if (UseTLAB) {
+     // Note: PLABs are also retired with GCLABs in generational mode.
      heap->gclabs_retire(ResizeTLAB);
      heap->tlabs_retire(ResizeTLAB);
    }
  
    OrderAccess::fence();

@@ -226,16 +249,12 @@
      OrderAccess::fence();
  
      phase3_update_references();
  
      phase4_compact_objects(worker_slices);
-   }
  
-   {
-     // Epilogue
-     _preserved_marks->restore(heap->workers());
-     _preserved_marks->reclaim();
+     phase5_epilog();
    }
  
    // Resize metaspace
    MetaspaceGC::compute_new_size();
  

@@ -267,34 +286,41 @@
    ShenandoahMarkingContext* const _ctx;
  
  public:
    ShenandoahPrepareForMarkClosure() : _ctx(ShenandoahHeap::heap()->marking_context()) {}
  
-   void heap_region_do(ShenandoahHeapRegion *r) {
+   void heap_region_do(ShenandoahHeapRegion *r) override {
      _ctx->capture_top_at_mark_start(r);
      r->clear_live_data();
    }
+ 
+   bool is_thread_safe() override { return true; }
  };
  
  void ShenandoahFullGC::phase1_mark_heap() {
    GCTraceTime(Info, gc, phases) time("Phase 1: Mark live objects", _gc_timer);
    ShenandoahGCPhase mark_phase(ShenandoahPhaseTimings::full_gc_mark);
  
    ShenandoahHeap* heap = ShenandoahHeap::heap();
  
-   ShenandoahPrepareForMarkClosure cl;
-   heap->heap_region_iterate(&cl);
+   ShenandoahPrepareForMarkClosure prepare_for_mark;
+   ShenandoahExcludeRegionClosure<FREE> cl(&prepare_for_mark);
+   heap->parallel_heap_region_iterate(&cl);
  
-   heap->set_unload_classes(heap->heuristics()->can_unload_classes());
+   heap->set_unload_classes(heap->global_generation()->heuristics()->can_unload_classes());
  
-   ShenandoahReferenceProcessor* rp = heap->ref_processor();
+   ShenandoahReferenceProcessor* rp = heap->global_generation()->ref_processor();
    // enable ("weak") refs discovery
    rp->set_soft_reference_policy(true); // forcefully purge all soft references
  
-   ShenandoahSTWMark mark(true /*full_gc*/);
+   ShenandoahSTWMark mark(heap->global_generation(), true /*full_gc*/);
    mark.mark();
    heap->parallel_cleaning(true /* full_gc */);
+ 
+   if (ShenandoahHeap::heap()->mode()->is_generational()) {
+     ShenandoahGenerationalFullGC::log_live_in_old(heap);
+   }
  }
  
  class ShenandoahPrepareForCompactionObjectClosure : public ObjectClosure {
  private:
    PreservedMarks*          const _preserved_marks;

@@ -319,11 +345,11 @@
  
    void set_from_region(ShenandoahHeapRegion* from_region) {
      _from_region = from_region;
    }
  
-   void finish_region() {
+   void finish() {
      assert(_to_region != nullptr, "should not happen");
      _to_region->set_new_top(_compact_point);
    }
  
    bool is_compact_same_region() {

@@ -339,11 +365,11 @@
      assert(_heap->complete_marking_context()->is_marked(p), "must be marked");
      assert(!_heap->complete_marking_context()->allocated_after_mark_start(p), "must be truly marked");
  
      size_t obj_size = p->size();
      if (_compact_point + obj_size > _to_region->end()) {
-       finish_region();
+       finish();
  
        // Object doesn't fit. Pick next empty region and start compacting there.
        ShenandoahHeapRegion* new_to_region;
        if (_empty_regions_pos < _empty_regions.length()) {
          new_to_region = _empty_regions.at(_empty_regions_pos);

@@ -393,51 +419,71 @@
      // Can move the region, and this is not the humongous region. Humongous
      // moves are special cased here, because their moves are handled separately.
      return r->is_stw_move_allowed() && !r->is_humongous();
    }
  
-   void work(uint worker_id) {
-     ShenandoahParallelWorkerSession worker_session(worker_id);
-     ShenandoahHeapRegionSet* slice = _worker_slices[worker_id];
-     ShenandoahHeapRegionSetIterator it(slice);
-     ShenandoahHeapRegion* from_region = it.next();
-     // No work?
-     if (from_region == nullptr) {
-        return;
-     }
- 
-     // Sliding compaction. Walk all regions in the slice, and compact them.
-     // Remember empty regions and reuse them as needed.
-     ResourceMark rm;
+   void work(uint worker_id) override;
+ private:
+   template<typename ClosureType>
+   void prepare_for_compaction(ClosureType& cl,
+                               GrowableArray<ShenandoahHeapRegion*>& empty_regions,
+                               ShenandoahHeapRegionSetIterator& it,
+                               ShenandoahHeapRegion* from_region);
+ };
  
-     GrowableArray<ShenandoahHeapRegion*> empty_regions((int)_heap->num_regions());
+ void ShenandoahPrepareForCompactionTask::work(uint worker_id) {
+   ShenandoahParallelWorkerSession worker_session(worker_id);
+   ShenandoahHeapRegionSet* slice = _worker_slices[worker_id];
+   ShenandoahHeapRegionSetIterator it(slice);
+   ShenandoahHeapRegion* from_region = it.next();
+   // No work?
+   if (from_region == nullptr) {
+     return;
+   }
  
-     ShenandoahPrepareForCompactionObjectClosure cl(_preserved_marks->get(worker_id), empty_regions, from_region);
+   // Sliding compaction. Walk all regions in the slice, and compact them.
+   // Remember empty regions and reuse them as needed.
+   ResourceMark rm;
  
-     while (from_region != nullptr) {
-       assert(is_candidate_region(from_region), "Sanity");
+   GrowableArray<ShenandoahHeapRegion*> empty_regions((int)_heap->num_regions());
  
-       cl.set_from_region(from_region);
-       if (from_region->has_live()) {
-         _heap->marked_object_iterate(from_region, &cl);
-       }
+   if (_heap->mode()->is_generational()) {
+     ShenandoahPrepareForGenerationalCompactionObjectClosure cl(_preserved_marks->get(worker_id),
+                                                                empty_regions, from_region, worker_id);
+     prepare_for_compaction(cl, empty_regions, it, from_region);
+   } else {
+     ShenandoahPrepareForCompactionObjectClosure cl(_preserved_marks->get(worker_id), empty_regions, from_region);
+     prepare_for_compaction(cl, empty_regions, it, from_region);
+   }
+ }
  
-       // Compacted the region to somewhere else? From-region is empty then.
-       if (!cl.is_compact_same_region()) {
-         empty_regions.append(from_region);
-       }
-       from_region = it.next();
+ template<typename ClosureType>
+ void ShenandoahPrepareForCompactionTask::prepare_for_compaction(ClosureType& cl,
+                                                                 GrowableArray<ShenandoahHeapRegion*>& empty_regions,
+                                                                 ShenandoahHeapRegionSetIterator& it,
+                                                                 ShenandoahHeapRegion* from_region) {
+   while (from_region != nullptr) {
+     assert(is_candidate_region(from_region), "Sanity");
+     cl.set_from_region(from_region);
+     if (from_region->has_live()) {
+       _heap->marked_object_iterate(from_region, &cl);
      }
-     cl.finish_region();
  
-     // Mark all remaining regions as empty
-     for (int pos = cl.empty_regions_pos(); pos < empty_regions.length(); ++pos) {
-       ShenandoahHeapRegion* r = empty_regions.at(pos);
-       r->set_new_top(r->bottom());
+     // Compacted the region to somewhere else? From-region is empty then.
+     if (!cl.is_compact_same_region()) {
+       empty_regions.append(from_region);
      }
+     from_region = it.next();
    }
- };
+   cl.finish();
+ 
+   // Mark all remaining regions as empty
+   for (int pos = cl.empty_regions_pos(); pos < empty_regions.length(); ++pos) {
+     ShenandoahHeapRegion* r = empty_regions.at(pos);
+     r->set_new_top(r->bottom());
+   }
+ }
  
  void ShenandoahFullGC::calculate_target_humongous_objects() {
    ShenandoahHeap* heap = ShenandoahHeap::heap();
  
    // Compute the new addresses for humongous objects. We need to do this after addresses

@@ -452,10 +498,11 @@
    // detected, then sliding restarts towards that non-movable region.
  
    size_t to_begin = heap->num_regions();
    size_t to_end = heap->num_regions();
  
+   log_debug(gc)("Full GC calculating target humongous objects from end " SIZE_FORMAT, to_end);
    for (size_t c = heap->num_regions(); c > 0; c--) {
      ShenandoahHeapRegion *r = heap->get_region(c - 1);
      if (r->is_humongous_continuation() || (r->new_top() == r->bottom())) {
        // To-region candidate: record this, and continue scan
        to_begin = r->index();

@@ -494,10 +541,11 @@
    void heap_region_do(ShenandoahHeapRegion* r) {
      if (r->is_trash()) {
        r->recycle();
      }
      if (r->is_cset()) {
+       // Leave affiliation unchanged
        r->make_regular_bypass();
      }
      if (r->is_empty_uncommitted()) {
        r->make_committed_bypass();
      }

@@ -517,25 +565,22 @@
  public:
    ShenandoahTrashImmediateGarbageClosure() :
      _heap(ShenandoahHeap::heap()),
      _ctx(ShenandoahHeap::heap()->complete_marking_context()) {}
  
-   void heap_region_do(ShenandoahHeapRegion* r) {
+   void heap_region_do(ShenandoahHeapRegion* r) override {
      if (r->is_humongous_start()) {
        oop humongous_obj = cast_to_oop(r->bottom());
        if (!_ctx->is_marked(humongous_obj)) {
-         assert(!r->has_live(),
-                "Region " SIZE_FORMAT " is not marked, should not have live", r->index());
+         assert(!r->has_live(), "Region " SIZE_FORMAT " is not marked, should not have live", r->index());
          _heap->trash_humongous_region_at(r);
        } else {
-         assert(r->has_live(),
-                "Region " SIZE_FORMAT " should have live", r->index());
+         assert(r->has_live(), "Region " SIZE_FORMAT " should have live", r->index());
        }
      } else if (r->is_humongous_continuation()) {
        // If we hit continuation, the non-live humongous starts should have been trashed already
-       assert(r->humongous_start_region()->has_live(),
-              "Region " SIZE_FORMAT " should have live", r->index());
+       assert(r->humongous_start_region()->has_live(), "Region " SIZE_FORMAT " should have live", r->index());
      } else if (r->is_regular()) {
        if (!r->has_live()) {
          r->make_trash_immediate();
        }
      }

@@ -694,12 +739,13 @@
    // had been updated in GC prologue.
    heap->assert_pinned_region_status();
  
    {
      // Trash the immediately collectible regions before computing addresses
-     ShenandoahTrashImmediateGarbageClosure tigcl;
-     heap->heap_region_iterate(&tigcl);
+     ShenandoahTrashImmediateGarbageClosure trash_immediate_garbage;
+     ShenandoahExcludeRegionClosure<FREE> cl(&trash_immediate_garbage);
+     heap->heap_region_iterate(&cl);
  
      // Make sure regions are in good state: committed, active, clean.
      // This is needed because we are potentially sliding the data through them.
      ShenandoahEnsureHeapActiveClosure ecl;
      heap->heap_region_iterate(&ecl);

@@ -783,10 +829,13 @@
      ShenandoahHeapRegion* r = _regions.next();
      while (r != nullptr) {
        if (!r->is_humongous_continuation() && r->has_live()) {
          _heap->marked_object_iterate(r, &obj_cl);
        }
+       if (_heap->mode()->is_generational()) {
+         ShenandoahGenerationalFullGC::maybe_coalesce_and_fill_region(r);
+       }
        r = _regions.next();
      }
    }
  };
  

@@ -887,14 +936,24 @@
  };
  
  class ShenandoahPostCompactClosure : public ShenandoahHeapRegionClosure {
  private:
    ShenandoahHeap* const _heap;
-   size_t _live;
+   bool _is_generational;
+   size_t _young_regions, _young_usage, _young_humongous_waste;
+   size_t _old_regions, _old_usage, _old_humongous_waste;
  
  public:
-   ShenandoahPostCompactClosure() : _heap(ShenandoahHeap::heap()), _live(0) {
+   ShenandoahPostCompactClosure() : _heap(ShenandoahHeap::heap()),
+                                    _is_generational(_heap->mode()->is_generational()),
+                                    _young_regions(0),
+                                    _young_usage(0),
+                                    _young_humongous_waste(0),
+                                    _old_regions(0),
+                                    _old_usage(0),
+                                    _old_humongous_waste(0)
+   {
      _heap->free_set()->clear();
    }
  
    void heap_region_do(ShenandoahHeapRegion* r) {
      assert (!r->is_cset(), "cset regions should have been demoted already");

@@ -910,10 +969,14 @@
  
      size_t live = r->used();
  
      // Make empty regions that have been allocated into regular
      if (r->is_empty() && live > 0) {
+       if (!_is_generational) {
+         r->make_affiliated_maybe();
+       }
+       // else, generational mode compaction has already established affiliation.
        r->make_regular_bypass();
        if (ZapUnusedHeapArea) {
          SpaceMangler::mangle_region(MemRegion(r->top(), r->end()));
        }
      }

@@ -925,28 +988,45 @@
  
      // Recycle all trash regions
      if (r->is_trash()) {
        live = 0;
        r->recycle();
+     } else {
+       if (r->is_old()) {
+         ShenandoahGenerationalFullGC::account_for_region(r, _old_regions, _old_usage, _old_humongous_waste);
+       } else if (r->is_young()) {
+         ShenandoahGenerationalFullGC::account_for_region(r, _young_regions, _young_usage, _young_humongous_waste);
+       }
      }
- 
      r->set_live_data(live);
      r->reset_alloc_metadata();
-     _live += live;
    }
  
-   size_t get_live() {
-     return _live;
+   void update_generation_usage() {
+     if (_is_generational) {
+       _heap->old_generation()->establish_usage(_old_regions, _old_usage, _old_humongous_waste);
+       _heap->young_generation()->establish_usage(_young_regions, _young_usage, _young_humongous_waste);
+     } else {
+       assert(_old_regions == 0, "Old regions only expected in generational mode");
+       assert(_old_usage == 0, "Old usage only expected in generational mode");
+       assert(_old_humongous_waste == 0, "Old humongous waste only expected in generational mode");
+     }
+ 
+     // In generational mode, global usage should be the sum of young and old. This is also true
+     // for non-generational modes except that there are no old regions.
+     _heap->global_generation()->establish_usage(_old_regions + _young_regions,
+                                                 _old_usage + _young_usage,
+                                                 _old_humongous_waste + _young_humongous_waste);
    }
  };
  
  void ShenandoahFullGC::compact_humongous_objects() {
    // Compact humongous regions, based on their fwdptr objects.
    //
    // This code is serial, because doing the in-slice parallel sliding is tricky. In most cases,
    // humongous regions are already compacted, and do not require further moves, which alleviates
-   // sliding costs. We may consider doing this in parallel in future.
+   // sliding costs. We may consider doing this in parallel in the future.
  
    ShenandoahHeap* heap = ShenandoahHeap::heap();
  
    for (size_t c = heap->num_regions(); c > 0; c--) {
      ShenandoahHeapRegion* r = heap->get_region(c - 1);

@@ -964,29 +1044,32 @@
        size_t new_start = heap->heap_region_index_containing(old_obj->forwardee());
        size_t new_end   = new_start + num_regions - 1;
        assert(old_start != new_start, "must be real move");
        assert(r->is_stw_move_allowed(), "Region " SIZE_FORMAT " should be movable", r->index());
  
+       log_debug(gc)("Full GC compaction moves humongous object from region " SIZE_FORMAT " to region " SIZE_FORMAT, old_start, new_start);
        Copy::aligned_conjoint_words(r->bottom(), heap->get_region(new_start)->bottom(), words_size);
        ContinuationGCSupport::relativize_stack_chunk(cast_to_oop<HeapWord*>(r->bottom()));
  
        oop new_obj = cast_to_oop(heap->get_region(new_start)->bottom());
        new_obj->init_mark();
  
        {
+         ShenandoahAffiliation original_affiliation = r->affiliation();
          for (size_t c = old_start; c <= old_end; c++) {
            ShenandoahHeapRegion* r = heap->get_region(c);
+           // Leave humongous region affiliation unchanged.
            r->make_regular_bypass();
            r->set_top(r->bottom());
          }
  
          for (size_t c = new_start; c <= new_end; c++) {
            ShenandoahHeapRegion* r = heap->get_region(c);
            if (c == new_start) {
-             r->make_humongous_start_bypass();
+             r->make_humongous_start_bypass(original_affiliation);
            } else {
-             r->make_humongous_cont_bypass();
+             r->make_humongous_cont_bypass(original_affiliation);
            }
  
            // Trailing region may be non-full, record the remainder there
            size_t remainder = words_size & ShenandoahHeapRegion::region_size_words_mask();
            if ((c == new_end) && (remainder != 0)) {

@@ -1048,10 +1131,15 @@
    // Compact humongous objects after regular object moves
    {
      ShenandoahGCPhase phase(ShenandoahPhaseTimings::full_gc_copy_objects_humong);
      compact_humongous_objects();
    }
+ }
+ 
+ void ShenandoahFullGC::phase5_epilog() {
+   GCTraceTime(Info, gc, phases) time("Phase 5: Full GC epilog", _gc_timer);
+   ShenandoahHeap* heap = ShenandoahHeap::heap();
  
    // Reset complete bitmap. We're about to reset the complete-top-at-mark-start pointer
    // and must ensure the bitmap is in sync.
    {
      ShenandoahGCPhase phase(ShenandoahPhaseTimings::full_gc_copy_objects_reset_complete);

@@ -1060,16 +1148,39 @@
    }
  
    // Bring regions in proper states after the collection, and set heap properties.
    {
      ShenandoahGCPhase phase(ShenandoahPhaseTimings::full_gc_copy_objects_rebuild);
- 
      ShenandoahPostCompactClosure post_compact;
      heap->heap_region_iterate(&post_compact);
-     heap->set_used(post_compact.get_live());
+     post_compact.update_generation_usage();
+ 
+     if (heap->mode()->is_generational()) {
+       ShenandoahGenerationalFullGC::balance_generations_after_gc(heap);
+     }
  
      heap->collection_set()->clear();
-     heap->free_set()->rebuild();
+     size_t young_cset_regions, old_cset_regions;
+     size_t first_old, last_old, num_old;
+     heap->free_set()->prepare_to_rebuild(young_cset_regions, old_cset_regions, first_old, last_old, num_old);
+ 
+     // We also do not expand old generation size following Full GC because we have scrambled age populations and
+     // no longer have objects separated by age into distinct regions.
+     if (heap->mode()->is_generational()) {
+       ShenandoahGenerationalFullGC::compute_balances();
+     }
+ 
+     heap->free_set()->finish_rebuild(young_cset_regions, old_cset_regions, num_old);
+ 
+     heap->clear_cancelled_gc(true /* clear oom handler */);
    }
  
-   heap->clear_cancelled_gc();
+   _preserved_marks->restore(heap->workers());
+   _preserved_marks->reclaim();
+ 
+   // We defer generation resizing actions until after cset regions have been recycled.  We do this even following an
+   // abbreviated cycle.
+   if (heap->mode()->is_generational()) {
+     ShenandoahGenerationalFullGC::balance_generations_after_rebuilding_free_set();
+     ShenandoahGenerationalFullGC::rebuild_remembered_set(heap);
+   }
  }
< prev index next >