1 /*
2 * Copyright (c) 2018, 2022, 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
25 #include "precompiled.hpp"
26 #include "gc/shared/gcArguments.hpp"
27 #include "gc/shared/tlab_globals.hpp"
28 #include "gc/shared/workerPolicy.hpp"
29 #include "gc/shenandoah/shenandoahArguments.hpp"
30 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
31 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
32 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
33 #include "runtime/globals_extension.hpp"
34 #include "runtime/java.hpp"
35 #include "utilities/defaultStream.hpp"
36
37 void ShenandoahArguments::initialize() {
38 #if !(defined AARCH64 || defined AMD64 || defined IA32 || defined PPC64 || defined RISCV64)
39 vm_exit_during_initialization("Shenandoah GC is not supported on this platform.");
40 #endif
41
42 #if 0 // leave this block as stepping stone for future platforms
43 log_warning(gc)("Shenandoah GC is not fully supported on this platform:");
44 log_warning(gc)(" concurrent modes are not supported, only STW cycles are enabled;");
45 log_warning(gc)(" arch-specific barrier code is not implemented, disabling barriers;");
46
47 FLAG_SET_DEFAULT(ShenandoahGCHeuristics, "passive");
48
49 FLAG_SET_DEFAULT(ShenandoahSATBBarrier, false);
50 FLAG_SET_DEFAULT(ShenandoahLoadRefBarrier, false);
51 FLAG_SET_DEFAULT(ShenandoahIUBarrier, false);
52 FLAG_SET_DEFAULT(ShenandoahCASBarrier, false);
53 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false);
54
55 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
56 #endif
57 if (UseLargePages) {
58 size_t large_page_size = os::large_page_size();
59 if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
60 warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
61 os::large_page_size() / K);
62 FLAG_SET_DEFAULT(ShenandoahUncommit, false);
63 }
64 }
65
66 // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes
67 // storage allocation code NUMA-aware.
68 if (FLAG_IS_DEFAULT(UseNUMA)) {
69 FLAG_SET_DEFAULT(UseNUMA, true);
70 }
71
72 // Set up default number of concurrent threads. We want to have cycles complete fast
73 // enough, but we also do not want to steal too much CPU from the concurrently running
74 // application. Using 1/4 of available threads for concurrent GC seems a good
75 // compromise here.
76 bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);
77 if (ergo_conc) {
78 FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4));
79 }
80
81 if (ConcGCThreads == 0) {
82 vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#");
83 }
84
85 // Set up default number of parallel threads. We want to have decent pauses performance
86 // which would use parallel threads, but we also do not want to do too many threads
87 // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair
88 // compromise here. Due to implementation constraints, it should not be lower than
89 // the number of concurrent threads.
90 bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);
91 if (ergo_parallel) {
137 FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);
138 }
139 }
140 #ifdef ASSERT
141 // C2 barrier verification is only reliable when all default barriers are enabled
142 if (ShenandoahVerifyOptoBarriers &&
143 (!FLAG_IS_DEFAULT(ShenandoahSATBBarrier) ||
144 !FLAG_IS_DEFAULT(ShenandoahLoadRefBarrier) ||
145 !FLAG_IS_DEFAULT(ShenandoahIUBarrier) ||
146 !FLAG_IS_DEFAULT(ShenandoahCASBarrier) ||
147 !FLAG_IS_DEFAULT(ShenandoahCloneBarrier)
148 )) {
149 warning("Unusual barrier configuration, disabling C2 barrier verification");
150 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
151 }
152 #else
153 guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled");
154 #endif // ASSERT
155 #endif // COMPILER2
156
157 // Record more information about previous cycles for improved debugging pleasure
158 if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) {
159 FLAG_SET_DEFAULT(LogEventsBufferEntries, 250);
160 }
161
162 if ((InitialHeapSize == MaxHeapSize) && ShenandoahUncommit) {
163 log_info(gc)("Min heap equals to max heap, disabling ShenandoahUncommit");
164 FLAG_SET_DEFAULT(ShenandoahUncommit, false);
165 }
166
167 // If class unloading is disabled, no unloading for concurrent cycles as well.
168 if (!ClassUnloading) {
169 FLAG_SET_DEFAULT(ClassUnloadingWithConcurrentMark, false);
170 }
171
172 // TLAB sizing policy makes resizing decisions before each GC cycle. It averages
173 // historical data, assigning more recent data the weight according to TLABAllocationWeight.
174 // Current default is good for generational collectors that run frequent young GCs.
175 // With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy
176 // to converge faster over smaller number of resizing decisions.
177 if (FLAG_IS_DEFAULT(TLABAllocationWeight)) {
178 FLAG_SET_DEFAULT(TLABAllocationWeight, 90);
179 }
180 }
181
182 size_t ShenandoahArguments::conservative_max_heap_alignment() {
183 size_t align = ShenandoahMaxRegionSize;
184 if (UseLargePages) {
185 align = MAX2(align, os::large_page_size());
186 }
187 return align;
188 }
189
190 void ShenandoahArguments::initialize_alignments() {
191 // Need to setup sizes early to get correct alignments.
192 MaxHeapSize = ShenandoahHeapRegion::setup_sizes(MaxHeapSize);
193
194 // This is expected by our algorithm for ShenandoahHeap::heap_region_containing().
195 size_t align = ShenandoahHeapRegion::region_size_bytes();
196 if (UseLargePages) {
197 align = MAX2(align, os::large_page_size());
198 }
199 SpaceAlignment = align;
200 HeapAlignment = align;
201 }
202
203 CollectedHeap* ShenandoahArguments::create_heap() {
204 return new ShenandoahHeap(new ShenandoahCollectorPolicy());
205 }
|
1 /*
2 * Copyright (c) 2018, 2022, Red Hat, Inc. All rights reserved.
3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "gc/shared/gcArguments.hpp"
28 #include "gc/shared/tlab_globals.hpp"
29 #include "gc/shared/workerPolicy.hpp"
30 #include "gc/shenandoah/shenandoahArguments.hpp"
31 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp"
32 #include "gc/shenandoah/shenandoahGenerationalHeap.hpp"
33 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
34 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
35 #include "runtime/globals_extension.hpp"
36 #include "runtime/java.hpp"
37 #include "utilities/defaultStream.hpp"
38
39 void ShenandoahArguments::initialize() {
40 #if !(defined AARCH64 || defined AMD64 || defined IA32 || defined PPC64 || defined RISCV64)
41 vm_exit_during_initialization("Shenandoah GC is not supported on this platform.");
42 #endif
43
44 #if 0 // leave this block as stepping stone for future platforms
45 log_warning(gc)("Shenandoah GC is not fully supported on this platform:");
46 log_warning(gc)(" concurrent modes are not supported, only STW cycles are enabled;");
47 log_warning(gc)(" arch-specific barrier code is not implemented, disabling barriers;");
48
49 FLAG_SET_DEFAULT(ShenandoahGCHeuristics, "passive");
50
51 FLAG_SET_DEFAULT(ShenandoahSATBBarrier, false);
52 FLAG_SET_DEFAULT(ShenandoahLoadRefBarrier, false);
53 FLAG_SET_DEFAULT(ShenandoahIUBarrier, false);
54 FLAG_SET_DEFAULT(ShenandoahCASBarrier, false);
55 FLAG_SET_DEFAULT(ShenandoahCardBarrier, false);
56 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false);
57
58 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
59 #endif
60 if (UseLargePages) {
61 size_t large_page_size = os::large_page_size();
62 if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
63 warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
64 os::large_page_size() / K);
65 FLAG_SET_DEFAULT(ShenandoahUncommit, false);
66 }
67 }
68
69 // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes
70 // storage allocation code NUMA-aware.
71 if (FLAG_IS_DEFAULT(UseNUMA)) {
72 FLAG_SET_DEFAULT(UseNUMA, true);
73 }
74
75 // We use this as the time period for tracking minimum mutator utilization (MMU).
76 // In generational mode, the MMU is used as a signal to adjust the size of the
77 // young generation.
78 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
79 FLAG_SET_DEFAULT(GCPauseIntervalMillis, 5000);
80 }
81
82 // Set up default number of concurrent threads. We want to have cycles complete fast
83 // enough, but we also do not want to steal too much CPU from the concurrently running
84 // application. Using 1/4 of available threads for concurrent GC seems a good
85 // compromise here.
86 bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);
87 if (ergo_conc) {
88 FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4));
89 }
90
91 if (ConcGCThreads == 0) {
92 vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#");
93 }
94
95 // Set up default number of parallel threads. We want to have decent pauses performance
96 // which would use parallel threads, but we also do not want to do too many threads
97 // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair
98 // compromise here. Due to implementation constraints, it should not be lower than
99 // the number of concurrent threads.
100 bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);
101 if (ergo_parallel) {
147 FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);
148 }
149 }
150 #ifdef ASSERT
151 // C2 barrier verification is only reliable when all default barriers are enabled
152 if (ShenandoahVerifyOptoBarriers &&
153 (!FLAG_IS_DEFAULT(ShenandoahSATBBarrier) ||
154 !FLAG_IS_DEFAULT(ShenandoahLoadRefBarrier) ||
155 !FLAG_IS_DEFAULT(ShenandoahIUBarrier) ||
156 !FLAG_IS_DEFAULT(ShenandoahCASBarrier) ||
157 !FLAG_IS_DEFAULT(ShenandoahCloneBarrier)
158 )) {
159 warning("Unusual barrier configuration, disabling C2 barrier verification");
160 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
161 }
162 #else
163 guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled");
164 #endif // ASSERT
165 #endif // COMPILER2
166
167 if (ShenandoahIUBarrier) {
168 assert(strcmp(ShenandoahGCMode, "generational"), "Generational mode does not support IU barrier");
169 }
170
171 // Record more information about previous cycles for improved debugging pleasure
172 if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) {
173 FLAG_SET_DEFAULT(LogEventsBufferEntries, 250);
174 }
175
176 if ((InitialHeapSize == MaxHeapSize) && ShenandoahUncommit) {
177 log_info(gc)("Min heap equals to max heap, disabling ShenandoahUncommit");
178 FLAG_SET_DEFAULT(ShenandoahUncommit, false);
179 }
180
181 // If class unloading is disabled, no unloading for concurrent cycles as well.
182 if (!ClassUnloading) {
183 FLAG_SET_DEFAULT(ClassUnloadingWithConcurrentMark, false);
184 }
185
186 // TLAB sizing policy makes resizing decisions before each GC cycle. It averages
187 // historical data, assigning more recent data the weight according to TLABAllocationWeight.
188 // Current default is good for generational collectors that run frequent young GCs.
189 // With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy
190 // to converge faster over smaller number of resizing decisions.
191 if (FLAG_IS_DEFAULT(TLABAllocationWeight)) {
192 FLAG_SET_DEFAULT(TLABAllocationWeight, 90);
193 }
194 }
195
196 size_t ShenandoahArguments::conservative_max_heap_alignment() {
197 size_t align = ShenandoahMaxRegionSize;
198 if (UseLargePages) {
199 align = MAX2(align, os::large_page_size());
200 }
201 return align;
202 }
203
204 void ShenandoahArguments::initialize_alignments() {
205 CardTable::initialize_card_size();
206
207 // Need to setup sizes early to get correct alignments.
208 MaxHeapSize = ShenandoahHeapRegion::setup_sizes(MaxHeapSize);
209
210 // This is expected by our algorithm for ShenandoahHeap::heap_region_containing().
211 size_t align = ShenandoahHeapRegion::region_size_bytes();
212 if (UseLargePages) {
213 align = MAX2(align, os::large_page_size());
214 }
215 SpaceAlignment = align;
216 HeapAlignment = align;
217 }
218
219 CollectedHeap* ShenandoahArguments::create_heap() {
220 if (strcmp(ShenandoahGCMode, "generational") != 0) {
221 // Not generational
222 return new ShenandoahHeap(new ShenandoahCollectorPolicy());
223 } else {
224 return new ShenandoahGenerationalHeap(new ShenandoahCollectorPolicy());
225 }
226 }
|