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/heuristics/shenandoahGlobalHeuristics.hpp"
28 #include "gc/shenandoah/shenandoahFreeSet.hpp"
29 #include "gc/shenandoah/shenandoahGlobalGeneration.hpp"
30 #include "gc/shenandoah/shenandoahHeap.hpp"
31 #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp"
32 #include "gc/shenandoah/shenandoahUtils.hpp"
33 #include "gc/shenandoah/shenandoahVerifier.hpp"
34
35
36 const char* ShenandoahGlobalGeneration::name() const {
37 return type() == NON_GEN ? "" : "Global";
38 }
39
40 size_t ShenandoahGlobalGeneration::max_capacity() const {
41 return ShenandoahHeap::heap()->max_capacity();
42 }
43
44 size_t ShenandoahGlobalGeneration::used_regions() const {
45 ShenandoahGenerationalHeap* heap = ShenandoahGenerationalHeap::heap();
46 assert(heap->mode()->is_generational(), "Region usage accounting is only for generational mode");
47 return heap->old_generation()->used_regions() + heap->young_generation()->used_regions();
48 }
49
50 size_t ShenandoahGlobalGeneration::used_regions_size() const {
51 return ShenandoahHeap::heap()->capacity();
52 }
53
54 size_t ShenandoahGlobalGeneration::available() const {
55 return ShenandoahHeap::heap()->free_set()->available();
56 }
57
58 size_t ShenandoahGlobalGeneration::soft_available() const {
59 size_t available = this->available();
60
61 // Make sure the code below treats available without the soft tail.
62 assert(max_capacity() >= ShenandoahHeap::heap()->soft_max_capacity(), "Max capacity must be greater than soft max capacity.");
63 size_t soft_tail = max_capacity() - ShenandoahHeap::heap()->soft_max_capacity();
64 return (available > soft_tail) ? (available - soft_tail) : 0;
65 }
66
67 void ShenandoahGlobalGeneration::set_concurrent_mark_in_progress(bool in_progress) {
68 ShenandoahHeap* heap = ShenandoahHeap::heap();
69 if (in_progress && heap->mode()->is_generational()) {
70 // Global collection has preempted an old generation mark. This is fine
71 // because the global generation includes the old generation, but we
72 // want the global collect to start from a clean slate and we don't want
73 // any stale state in the old generation.
74 assert(!heap->is_concurrent_old_mark_in_progress(), "Old cycle should not be running.");
75 }
76
77 heap->set_concurrent_young_mark_in_progress(in_progress);
78 }
79
80 bool ShenandoahGlobalGeneration::contains(ShenandoahAffiliation affiliation) const {
81 return true;
82 }
83
84 bool ShenandoahGlobalGeneration::contains(ShenandoahHeapRegion* region) const {
85 return true;
86 }
87
88 void ShenandoahGlobalGeneration::parallel_heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
89 ShenandoahHeap::heap()->parallel_heap_region_iterate(cl);
90 }
91
92 void ShenandoahGlobalGeneration::heap_region_iterate(ShenandoahHeapRegionClosure* cl) {
93 ShenandoahHeap::heap()->heap_region_iterate(cl);
94 }
95
96 bool ShenandoahGlobalGeneration::is_concurrent_mark_in_progress() {
97 ShenandoahHeap* heap = ShenandoahHeap::heap();
98 return heap->is_concurrent_mark_in_progress();
99 }
100
101 ShenandoahHeuristics* ShenandoahGlobalGeneration::initialize_heuristics(ShenandoahMode* gc_mode) {
102 if (gc_mode->is_generational()) {
103 _heuristics = new ShenandoahGlobalHeuristics(this);
104 } else {
105 _heuristics = gc_mode->initialize_heuristics(this);
106 }
107
108 _heuristics->set_guaranteed_gc_interval(ShenandoahGuaranteedGCInterval);
109 confirm_heuristics_mode();
110 return _heuristics;
111 }
112
113 void ShenandoahGlobalGeneration::set_mark_complete() {
114 ShenandoahGeneration::set_mark_complete();
115 if (ShenandoahHeap::heap()->mode()->is_generational()) {
116 ShenandoahGenerationalHeap* heap = ShenandoahGenerationalHeap::heap();
117 heap->young_generation()->set_mark_complete();
118 heap->old_generation()->set_mark_complete();
119 }
120 }
121
122 void ShenandoahGlobalGeneration::set_mark_incomplete() {
123 ShenandoahGeneration::set_mark_incomplete();
124 if (ShenandoahHeap::heap()->mode()->is_generational()) {
125 ShenandoahGenerationalHeap* heap = ShenandoahGenerationalHeap::heap();
126 heap->young_generation()->set_mark_incomplete();
127 heap->old_generation()->set_mark_incomplete();
128 }
129 }
130
131 void ShenandoahGlobalGeneration::prepare_gc() {
132 ShenandoahGeneration::prepare_gc();
133
134 if (ShenandoahHeap::heap()->mode()->is_generational()) {
135 assert(type() == GLOBAL, "Unexpected generation type");
136 // Clear any stale/partial local census data before the start of a
137 // new marking cycle
138 ShenandoahGenerationalHeap::heap()->age_census()->reset_local();
139 } else {
140 assert(type() == NON_GEN, "Unexpected generation type");
141 }
142 }