1 /*
  2  * Copyright Amazon.com Inc. 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 #include "precompiled.hpp"
 25 
 26 #include "gc/shenandoah/shenandoahAgeCensus.hpp"
 27 #include "gc/shenandoah/shenandoahFreeSet.hpp"
 28 #include "gc/shenandoah/shenandoahHeap.hpp"
 29 #include "gc/shenandoah/shenandoahHeapRegionClosures.hpp"
 30 #include "gc/shenandoah/shenandoahUtils.hpp"
 31 #include "gc/shenandoah/shenandoahYoungGeneration.hpp"
 32 #include "gc/shenandoah/heuristics/shenandoahYoungHeuristics.hpp"
 33 
 34 ShenandoahYoungGeneration::ShenandoahYoungGeneration(uint max_queues, size_t max_capacity, size_t soft_max_capacity) :
 35   ShenandoahGeneration(YOUNG, max_queues, max_capacity, soft_max_capacity),
 36   _old_gen_task_queues(nullptr) {
 37 }
 38 
 39 void ShenandoahYoungGeneration::set_concurrent_mark_in_progress(bool in_progress) {
 40   ShenandoahHeap* heap = ShenandoahHeap::heap();
 41   heap->set_concurrent_young_mark_in_progress(in_progress);
 42   if (is_bootstrap_cycle() && in_progress && !heap->is_prepare_for_old_mark_in_progress()) {
 43     // This is not a bug. When the bootstrapping marking phase is complete,
 44     // the old generation marking is still in progress, unless it's not.
 45     // In the case that old-gen preparation for mixed evacuation has been
 46     // preempted, we do not want to set concurrent old mark to be in progress.
 47     heap->set_concurrent_old_mark_in_progress(in_progress);
 48   }
 49 }
 50 
 51 bool ShenandoahYoungGeneration::contains(ShenandoahAffiliation affiliation) const {
 52   return affiliation == YOUNG_GENERATION;
 53 }
 54 
 55 bool ShenandoahYoungGeneration::contains(ShenandoahHeapRegion* region) const {
 56   return region->is_young();
 57 }
 58 
 59 void ShenandoahYoungGeneration::parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
 60   // Just iterate over the young generation here.
 61   ShenandoahIncludeRegionClosure<YOUNG_GENERATION> young_regions_cl(cl);
 62   ShenandoahHeap::heap()->parallel_heap_region_iterate(&young_regions_cl);
 63 }
 64 
 65 void ShenandoahYoungGeneration::heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
 66   ShenandoahIncludeRegionClosure<YOUNG_GENERATION> young_regions_cl(cl);
 67   ShenandoahHeap::heap()->heap_region_iterate(&young_regions_cl);
 68 }
 69 
 70 void ShenandoahYoungGeneration::parallel_region_iterate_free(ShenandoahHeapRegionClosure* cl) {
 71   ShenandoahExcludeRegionClosure<OLD_GENERATION> exclude_cl(cl);
 72   ShenandoahHeap::heap()->parallel_heap_region_iterate(&exclude_cl);
 73 }
 74 
 75 bool ShenandoahYoungGeneration::is_concurrent_mark_in_progress() {
 76   return ShenandoahHeap::heap()->is_concurrent_young_mark_in_progress();
 77 }
 78 
 79 void ShenandoahYoungGeneration::reserve_task_queues(uint workers) {
 80   ShenandoahGeneration::reserve_task_queues(workers);
 81   if (is_bootstrap_cycle()) {
 82     _old_gen_task_queues->reserve(workers);
 83   }
 84 }
 85 
 86 bool ShenandoahYoungGeneration::contains(oop obj) const {
 87   return ShenandoahHeap::heap()->is_in_young(obj);
 88 }
 89 
 90 ShenandoahHeuristics* ShenandoahYoungGeneration::initialize_heuristics(ShenandoahMode* gc_mode) {
 91   _young_heuristics = new ShenandoahYoungHeuristics(this);
 92   _heuristics = _young_heuristics;
 93   _heuristics->set_guaranteed_gc_interval(ShenandoahGuaranteedYoungGCInterval);
 94   confirm_heuristics_mode();
 95   return _heuristics;
 96 }
 97 
 98 size_t ShenandoahYoungGeneration::available() const {
 99   // The collector reserve may eat into what the mutator is allowed to use. Make sure we are looking
100   // at what is available to the mutator when reporting how much memory is available.
101   size_t available = this->ShenandoahGeneration::available();
102   return MIN2(available, ShenandoahHeap::heap()->free_set()->available());
103 }
104 
105 size_t ShenandoahYoungGeneration::soft_available() const {
106   size_t available = this->ShenandoahGeneration::soft_available();
107   return MIN2(available, ShenandoahHeap::heap()->free_set()->available());
108 }
109 
110 void ShenandoahYoungGeneration::prepare_gc() {
111 
112   ShenandoahGeneration::prepare_gc();
113 
114   assert(type() == YOUNG, "Error?");
115   // Clear any stale/partial local census data before the start of a
116   // new marking cycle
117   ShenandoahGenerationalHeap::heap()->age_census()->reset_local();
118 }