1 /* 2 * Copyright (c) 2018, 2019, 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/workerPolicy.hpp" 28 #include "gc/shenandoah/shenandoahArguments.hpp" 29 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp" 30 #include "gc/shenandoah/shenandoahHeap.inline.hpp" 31 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 32 #include "utilities/defaultStream.hpp" 33 34 void ShenandoahArguments::initialize() { 35 #if !(defined AARCH64 || defined AMD64 || defined IA32) 36 vm_exit_during_initialization("Shenandoah GC is not supported on this platform."); 37 #endif 38 39 #if 0 // leave this block as stepping stone for future platforms 40 log_warning(gc)("Shenandoah GC is not fully supported on this platform:"); 41 log_warning(gc)(" concurrent modes are not supported, only STW cycles are enabled;"); 42 log_warning(gc)(" arch-specific barrier code is not implemented, disabling barriers;"); 43 44 FLAG_SET_DEFAULT(ShenandoahGCHeuristics, "passive"); 45 46 FLAG_SET_DEFAULT(ShenandoahSATBBarrier, false); 47 FLAG_SET_DEFAULT(ShenandoahLoadRefBarrier, false); 48 FLAG_SET_DEFAULT(ShenandoahKeepAliveBarrier, false); 49 FLAG_SET_DEFAULT(ShenandoahStoreValEnqueueBarrier, false); 50 FLAG_SET_DEFAULT(ShenandoahCASBarrier, false); 51 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false); 52 53 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false); 54 #endif 55 56 if (UseLargePages && (MaxHeapSize / os::large_page_size()) < ShenandoahHeapRegion::MIN_NUM_REGIONS) { 57 warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit", 58 os::large_page_size() / K); 59 FLAG_SET_DEFAULT(ShenandoahUncommit, false); 60 } 61 62 // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes 63 // storage allocation code NUMA-aware. 64 if (FLAG_IS_DEFAULT(UseNUMA)) { 65 FLAG_SET_DEFAULT(UseNUMA, true); 66 } 67 68 // Set up default number of concurrent threads. We want to have cycles complete fast 69 // enough, but we also do not want to steal too much CPU from the concurrently running 70 // application. Using 1/4 of available threads for concurrent GC seems a good 71 // compromise here. 72 bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads); 73 if (ergo_conc) { 74 FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::initial_active_processor_count() / 4)); 75 } 76 77 if (ConcGCThreads == 0) { 78 vm_exit_during_initialization("Shenandoah expects ConcGCThreads > 0, check -XX:ConcGCThreads=#"); 79 } 80 81 // Set up default number of parallel threads. We want to have decent pauses performance 82 // which would use parallel threads, but we also do not want to do too many threads 83 // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair 84 // compromise here. Due to implementation constraints, it should not be lower than 85 // the number of concurrent threads. 86 bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads); 87 if (ergo_parallel) { 88 FLAG_SET_DEFAULT(ParallelGCThreads, MAX2(1, os::initial_active_processor_count() / 2)); 89 } 90 91 if (ParallelGCThreads == 0) { 92 vm_exit_during_initialization("Shenandoah expects ParallelGCThreads > 0, check -XX:ParallelGCThreads=#"); 93 } 94 95 // Make sure ergonomic decisions do not break the thread count invariants. 96 // This may happen when user overrides one of the flags, but not the other. 97 // When that happens, we want to adjust the setting that was set ergonomically. 98 if (ParallelGCThreads < ConcGCThreads) { 99 if (ergo_conc && !ergo_parallel) { 100 FLAG_SET_DEFAULT(ConcGCThreads, ParallelGCThreads); 101 } else if (!ergo_conc && ergo_parallel) { 102 FLAG_SET_DEFAULT(ParallelGCThreads, ConcGCThreads); 103 } else if (ergo_conc && ergo_parallel) { 104 // Should not happen, check the ergonomic computation above. Fail with relevant error. 105 vm_exit_during_initialization("Shenandoah thread count ergonomic error"); 106 } else { 107 // User settings error, report and ask user to rectify. 108 vm_exit_during_initialization("Shenandoah expects ConcGCThreads <= ParallelGCThreads, check -XX:ParallelGCThreads, -XX:ConcGCThreads"); 109 } 110 } 111 112 if (FLAG_IS_DEFAULT(ParallelRefProcEnabled)) { 113 FLAG_SET_DEFAULT(ParallelRefProcEnabled, true); 114 } 115 116 if (ShenandoahRegionSampling && FLAG_IS_DEFAULT(PerfDataMemorySize)) { 117 // When sampling is enabled, max out the PerfData memory to get more 118 // Shenandoah data in, including Matrix. 119 FLAG_SET_DEFAULT(PerfDataMemorySize, 2048*K); 120 } 121 122 #ifdef COMPILER2 123 // Shenandoah cares more about pause times, rather than raw throughput. 124 if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) { 125 FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true); 126 if (FLAG_IS_DEFAULT(LoopStripMiningIter)) { 127 FLAG_SET_DEFAULT(LoopStripMiningIter, 1000); 128 } 129 } 130 #ifdef ASSERT 131 // C2 barrier verification is only reliable when all default barriers are enabled 132 if (ShenandoahVerifyOptoBarriers && 133 (!FLAG_IS_DEFAULT(ShenandoahSATBBarrier) || 134 !FLAG_IS_DEFAULT(ShenandoahLoadRefBarrier) || 135 !FLAG_IS_DEFAULT(ShenandoahKeepAliveBarrier) || 136 !FLAG_IS_DEFAULT(ShenandoahStoreValEnqueueBarrier) || 137 !FLAG_IS_DEFAULT(ShenandoahCASBarrier) || 138 !FLAG_IS_DEFAULT(ShenandoahCloneBarrier) 139 )) { 140 warning("Unusual barrier configuration, disabling C2 barrier verification"); 141 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false); 142 } 143 #else 144 guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled"); 145 #endif // ASSERT 146 #endif // COMPILER2 147 148 if (AlwaysPreTouch) { 149 // Shenandoah handles pre-touch on its own. It does not let the 150 // generic storage code to do the pre-touch before Shenandoah has 151 // a chance to do it on its own. 152 FLAG_SET_DEFAULT(AlwaysPreTouch, false); 153 FLAG_SET_DEFAULT(ShenandoahAlwaysPreTouch, true); 154 } 155 156 // Record more information about previous cycles for improved debugging pleasure 157 if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) { 158 FLAG_SET_DEFAULT(LogEventsBufferEntries, 250); 159 } 160 161 if (ShenandoahAlwaysPreTouch) { 162 if (!FLAG_IS_DEFAULT(ShenandoahUncommit)) { 163 warning("AlwaysPreTouch is enabled, disabling ShenandoahUncommit"); 164 } 165 FLAG_SET_DEFAULT(ShenandoahUncommit, false); 166 } 167 168 if ((InitialHeapSize == MaxHeapSize) && ShenandoahUncommit) { 169 log_info(gc)("Min heap equals to max heap, disabling ShenandoahUncommit"); 170 FLAG_SET_DEFAULT(ShenandoahUncommit, false); 171 } 172 173 // If class unloading is disabled, no unloading for concurrent cycles as well. 174 if (!ClassUnloading) { 175 FLAG_SET_DEFAULT(ClassUnloadingWithConcurrentMark, false); 176 } 177 178 // AOT is not supported yet 179 if (UseAOT) { 180 if (!FLAG_IS_DEFAULT(UseAOT)) { 181 warning("Shenandoah does not support AOT at this moment, disabling UseAOT"); 182 } 183 FLAG_SET_DEFAULT(UseAOT, 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 // Need to setup sizes early to get correct alignments. 206 ShenandoahHeapRegion::setup_sizes(MaxHeapSize); 207 208 // This is expected by our algorithm for ShenandoahHeap::heap_region_containing(). 209 size_t align = ShenandoahHeapRegion::region_size_bytes(); 210 if (UseLargePages) { 211 align = MAX2(align, os::large_page_size()); 212 } 213 SpaceAlignment = align; 214 HeapAlignment = align; 215 } 216 217 CollectedHeap* ShenandoahArguments::create_heap() { 218 return new ShenandoahHeap(new ShenandoahCollectorPolicy()); 219 }