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(ShenandoahCASBarrier, false);
52 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false);
53
54 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
55 #endif
56 if (UseLargePages) {
57 size_t large_page_size = os::large_page_size();
58 if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
59 warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
60 os::large_page_size() / K);
61 FLAG_SET_DEFAULT(ShenandoahUncommit, false);
62 }
63 }
64
65 // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes
66 // storage allocation code NUMA-aware.
67 if (FLAG_IS_DEFAULT(UseNUMA)) {
68 FLAG_SET_DEFAULT(UseNUMA, true);
69 }
70
71 // Set up default number of concurrent threads. We want to have cycles complete fast
72 // enough, but we also do not want to steal too much CPU from the concurrently running
73 // application. Using 1/4 of available threads for concurrent GC seems a good
74 // compromise here.
75 bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);
76 if (ergo_conc) {
77 FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4));
78 }
79
80 if (ConcGCThreads == 0) {
81 vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#");
82 }
83
84 // Set up default number of parallel threads. We want to have decent pauses performance
85 // which would use parallel threads, but we also do not want to do too many threads
86 // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair
87 // compromise here. Due to implementation constraints, it should not be lower than
88 // the number of concurrent threads.
89 bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);
90 if (ergo_parallel) {
169
170 // TLAB sizing policy makes resizing decisions before each GC cycle. It averages
171 // historical data, assigning more recent data the weight according to TLABAllocationWeight.
172 // Current default is good for generational collectors that run frequent young GCs.
173 // With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy
174 // to converge faster over smaller number of resizing decisions.
175 if (FLAG_IS_DEFAULT(TLABAllocationWeight)) {
176 FLAG_SET_DEFAULT(TLABAllocationWeight, 90);
177 }
178 }
179
180 size_t ShenandoahArguments::conservative_max_heap_alignment() {
181 size_t align = ShenandoahMaxRegionSize;
182 if (UseLargePages) {
183 align = MAX2(align, os::large_page_size());
184 }
185 return align;
186 }
187
188 void ShenandoahArguments::initialize_alignments() {
189 // Need to setup sizes early to get correct alignments.
190 MaxHeapSize = ShenandoahHeapRegion::setup_sizes(MaxHeapSize);
191
192 // This is expected by our algorithm for ShenandoahHeap::heap_region_containing().
193 size_t align = ShenandoahHeapRegion::region_size_bytes();
194 if (UseLargePages) {
195 align = MAX2(align, os::large_page_size());
196 }
197 SpaceAlignment = align;
198 HeapAlignment = align;
199 }
200
201 CollectedHeap* ShenandoahArguments::create_heap() {
202 return new ShenandoahHeap(new ShenandoahCollectorPolicy());
203 }
|
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(ShenandoahCASBarrier, false);
54 FLAG_SET_DEFAULT(ShenandoahCardBarrier, false);
55 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false);
56
57 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
58 #endif
59 if (UseLargePages) {
60 size_t large_page_size = os::large_page_size();
61 if ((align_up(MaxHeapSize, large_page_size) / large_page_size) < ShenandoahHeapRegion::MIN_NUM_REGIONS) {
62 warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit",
63 os::large_page_size() / K);
64 FLAG_SET_DEFAULT(ShenandoahUncommit, false);
65 }
66 }
67
68 // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes
69 // storage allocation code NUMA-aware.
70 if (FLAG_IS_DEFAULT(UseNUMA)) {
71 FLAG_SET_DEFAULT(UseNUMA, true);
72 }
73
74 // We use this as the time period for tracking minimum mutator utilization (MMU).
75 // In generational mode, the MMU is used as a signal to adjust the size of the
76 // young generation.
77 if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
78 FLAG_SET_DEFAULT(GCPauseIntervalMillis, 5000);
79 }
80
81 // Set up default number of concurrent threads. We want to have cycles complete fast
82 // enough, but we also do not want to steal too much CPU from the concurrently running
83 // application. Using 1/4 of available threads for concurrent GC seems a good
84 // compromise here.
85 bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);
86 if (ergo_conc) {
87 FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4));
88 }
89
90 if (ConcGCThreads == 0) {
91 vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#");
92 }
93
94 // Set up default number of parallel threads. We want to have decent pauses performance
95 // which would use parallel threads, but we also do not want to do too many threads
96 // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair
97 // compromise here. Due to implementation constraints, it should not be lower than
98 // the number of concurrent threads.
99 bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);
100 if (ergo_parallel) {
179
180 // TLAB sizing policy makes resizing decisions before each GC cycle. It averages
181 // historical data, assigning more recent data the weight according to TLABAllocationWeight.
182 // Current default is good for generational collectors that run frequent young GCs.
183 // With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy
184 // to converge faster over smaller number of resizing decisions.
185 if (FLAG_IS_DEFAULT(TLABAllocationWeight)) {
186 FLAG_SET_DEFAULT(TLABAllocationWeight, 90);
187 }
188 }
189
190 size_t ShenandoahArguments::conservative_max_heap_alignment() {
191 size_t align = ShenandoahMaxRegionSize;
192 if (UseLargePages) {
193 align = MAX2(align, os::large_page_size());
194 }
195 return align;
196 }
197
198 void ShenandoahArguments::initialize_alignments() {
199 CardTable::initialize_card_size();
200
201 // Need to setup sizes early to get correct alignments.
202 MaxHeapSize = ShenandoahHeapRegion::setup_sizes(MaxHeapSize);
203
204 // This is expected by our algorithm for ShenandoahHeap::heap_region_containing().
205 size_t align = ShenandoahHeapRegion::region_size_bytes();
206 if (UseLargePages) {
207 align = MAX2(align, os::large_page_size());
208 }
209 SpaceAlignment = align;
210 HeapAlignment = align;
211 }
212
213 CollectedHeap* ShenandoahArguments::create_heap() {
214 if (strcmp(ShenandoahGCMode, "generational") != 0) {
215 // Not generational
216 return new ShenandoahHeap(new ShenandoahCollectorPolicy());
217 } else {
218 return new ShenandoahGenerationalHeap(new ShenandoahCollectorPolicy());
219 }
220 }
|