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->mode()->is_generational()) {
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->cancel_old_gc();
67   }
68 
69   heap->set_concurrent_young_mark_in_progress(in_progress);
70 }
71 
72 bool ShenandoahGlobalGeneration::contains(ShenandoahHeapRegion* region) const {
73   return true;
74 }
75 
76 void ShenandoahGlobalGeneration::parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
77   ShenandoahHeap::heap()->parallel_heap_region_iterate(cl);
78 }
79 
80 void ShenandoahGlobalGeneration::heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
81   ShenandoahHeap::heap()->heap_region_iterate(cl);
82 }
83 
84 bool ShenandoahGlobalGeneration::is_concurrent_mark_in_progress() {
85   ShenandoahHeap* heap = ShenandoahHeap::heap();
86   return heap->is_concurrent_mark_in_progress();
87 }