1 /*
  2  * Copyright (c) 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 #include "precompiled.hpp"
 25 
 26 #include "gc/shenandoah/shenandoahFreeSet.hpp"
 27 #include "gc/shenandoah/shenandoahGlobalGeneration.hpp"
 28 #include "gc/shenandoah/shenandoahHeap.hpp"
 29 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
 30 #include "gc/shenandoah/shenandoahUtils.hpp"
 31 #include "gc/shenandoah/shenandoahVerifier.hpp"
 32 #include "gc/shenandoah/shenandoahYoungGeneration.hpp"
 33 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
 34 
 35 const char* ShenandoahGlobalGeneration::name() const {
 36   return "GLOBAL";
 37 }
 38 
 39 size_t ShenandoahGlobalGeneration::max_capacity() const {
 40   return ShenandoahHeap::heap()->max_capacity();
 41 }
 42 
 43 size_t ShenandoahGlobalGeneration::used_regions_size() const {
 44   return ShenandoahHeap::heap()->capacity();
 45 }
 46 
 47 size_t ShenandoahGlobalGeneration::soft_max_capacity() const {
 48   return ShenandoahHeap::heap()->soft_max_capacity();
 49 }
 50 
 51 size_t ShenandoahGlobalGeneration::used() const {
 52   return ShenandoahHeap::heap()->used();
 53 }
 54 
 55 size_t ShenandoahGlobalGeneration::available() const {
 56   return ShenandoahHeap::heap()->free_set()->available();
 57 }
 58 
 59 void ShenandoahGlobalGeneration::set_concurrent_mark_in_progress(bool in_progress) {
 60   ShenandoahHeap* heap = ShenandoahHeap::heap();
 61   if (in_progress && heap->is_concurrent_old_mark_in_progress()) {
 62     // Global collection has preempted an old generation mark. This is fine
 63     // because the global generation includes the old generation, but we
 64     // want the global collect to start from a clean slate and we don't want
 65     // any stale state in the old generation.
 66     heap->purge_old_satb_buffers(true /* abandon */);
 67     heap->old_generation()->cancel_marking();
 68     heap->young_generation()->set_old_gen_task_queues(nullptr);
 69   }
 70 
 71   heap->set_concurrent_young_mark_in_progress(in_progress);
 72   heap->set_concurrent_old_mark_in_progress(in_progress);
 73 }
 74 
 75 bool ShenandoahGlobalGeneration::contains(ShenandoahHeapRegion* region) const {
 76   return true;
 77 }
 78 
 79 void ShenandoahGlobalGeneration::parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
 80   ShenandoahHeap::heap()->parallel_heap_region_iterate(cl);
 81 }
 82 
 83 void ShenandoahGlobalGeneration::heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
 84   ShenandoahHeap::heap()->heap_region_iterate(cl);
 85 }
 86 
 87 bool ShenandoahGlobalGeneration::is_concurrent_mark_in_progress() {
 88   ShenandoahHeap* heap = ShenandoahHeap::heap();
 89   return heap->is_concurrent_mark_in_progress();
 90 }
 91 
 92 void ShenandoahGlobalGeneration::prepare_gc(bool do_old_gc_bootstrap) {
 93   ShenandoahGeneration::prepare_gc(do_old_gc_bootstrap);
 94 
 95   ShenandoahHeap* heap = ShenandoahHeap::heap();
 96   if (heap->mode()->is_generational()) {
 97     heap->cancel_mixed_collections();
 98   }
 99 }
100