1 /* 2 * Copyright (c) 2018, 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.inline.hpp" 27 #include "gc/shenandoah/shenandoahArguments.hpp" 28 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp" 29 #include "gc/shenandoah/shenandoahHeap.hpp" 30 #include "gc/shenandoah/shenandoahHeapRegion.hpp" 31 #include "gc/shenandoah/shenandoahTaskqueue.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 #ifdef IA32 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(ShenandoahKeepAliveBarrier, false); 48 FLAG_SET_DEFAULT(ShenandoahWriteBarrier, false); 49 FLAG_SET_DEFAULT(ShenandoahReadBarrier, false); 50 FLAG_SET_DEFAULT(ShenandoahStoreValEnqueueBarrier, false); 51 FLAG_SET_DEFAULT(ShenandoahStoreValReadBarrier, false); 52 FLAG_SET_DEFAULT(ShenandoahCASBarrier, false); 53 FLAG_SET_DEFAULT(ShenandoahAcmpBarrier, false); 54 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false); 55 #endif 56 57 #ifdef _LP64 58 // The optimized ObjArrayChunkedTask takes some bits away from the full 64 addressable 59 // bits, fail if we ever attempt to address more than we can. Only valid on 64bit. 60 if (MaxHeapSize >= ObjArrayChunkedTask::max_addressable()) { 61 jio_fprintf(defaultStream::error_stream(), 62 "Shenandoah GC cannot address more than " SIZE_FORMAT " bytes, and " SIZE_FORMAT " bytes heap requested.", 63 ObjArrayChunkedTask::max_addressable(), MaxHeapSize); 64 vm_exit(1); 65 } 66 #endif 67 68 if (UseLargePages && (MaxHeapSize / os::large_page_size()) < ShenandoahHeapRegion::MIN_NUM_REGIONS) { 69 warning("Large pages size (" SIZE_FORMAT "K) is too large to afford page-sized regions, disabling uncommit", 70 os::large_page_size() / K); 71 FLAG_SET_DEFAULT(ShenandoahUncommit, false); 72 } 73 74 // Enable NUMA by default. While Shenandoah is not NUMA-aware, enabling NUMA makes 75 // storage allocation code NUMA-aware, and NUMA interleaving makes the storage 76 // allocated in consistent manner (interleaving) to minimize run-to-run variance. 77 if (FLAG_IS_DEFAULT(UseNUMA)) { 78 FLAG_SET_DEFAULT(UseNUMA, true); 79 FLAG_SET_DEFAULT(UseNUMAInterleaving, true); 80 } 81 82 FLAG_SET_DEFAULT(ParallelGCThreads, 83 Abstract_VM_Version::parallel_worker_threads()); 84 85 if (FLAG_IS_DEFAULT(ConcGCThreads)) { 86 uint conc_threads = MAX2((uint) 1, ParallelGCThreads); 87 FLAG_SET_DEFAULT(ConcGCThreads, conc_threads); 88 } 89 90 if (FLAG_IS_DEFAULT(ParallelRefProcEnabled)) { 91 FLAG_SET_DEFAULT(ParallelRefProcEnabled, true); 92 } 93 94 if (ShenandoahRegionSampling && FLAG_IS_DEFAULT(PerfDataMemorySize)) { 95 // When sampling is enabled, max out the PerfData memory to get more 96 // Shenandoah data in, including Matrix. 97 FLAG_SET_DEFAULT(PerfDataMemorySize, 2048*K); 98 } 99 100 #ifdef COMPILER2 101 // Shenandoah cares more about pause times, rather than raw throughput. 102 if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) { 103 FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true); 104 if (FLAG_IS_DEFAULT(LoopStripMiningIter)) { 105 FLAG_SET_DEFAULT(LoopStripMiningIter, 1000); 106 } 107 } 108 #ifdef ASSERT 109 // C2 barrier verification is only reliable when all default barriers are enabled 110 if (ShenandoahVerifyOptoBarriers && 111 (!FLAG_IS_DEFAULT(ShenandoahSATBBarrier) || 112 !FLAG_IS_DEFAULT(ShenandoahKeepAliveBarrier) || 113 !FLAG_IS_DEFAULT(ShenandoahWriteBarrier) || 114 !FLAG_IS_DEFAULT(ShenandoahReadBarrier) || 115 !FLAG_IS_DEFAULT(ShenandoahStoreValEnqueueBarrier) || 116 !FLAG_IS_DEFAULT(ShenandoahStoreValReadBarrier) || 117 !FLAG_IS_DEFAULT(ShenandoahCASBarrier) || 118 !FLAG_IS_DEFAULT(ShenandoahAcmpBarrier) || 119 !FLAG_IS_DEFAULT(ShenandoahCloneBarrier) 120 )) { 121 warning("Unusual barrier configuration, disabling C2 barrier verification"); 122 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false); 123 } 124 #else 125 guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled"); 126 #endif // ASSERT 127 #endif // COMPILER2 128 129 if (AlwaysPreTouch) { 130 // Shenandoah handles pre-touch on its own. It does not let the 131 // generic storage code to do the pre-touch before Shenandoah has 132 // a chance to do it on its own. 133 FLAG_SET_DEFAULT(AlwaysPreTouch, false); 134 FLAG_SET_DEFAULT(ShenandoahAlwaysPreTouch, true); 135 } 136 137 // Shenandoah C2 optimizations apparently dislike the shape of thread-local handshakes. 138 // Disable it by default, unless we enable it specifically for debugging. 139 if (FLAG_IS_DEFAULT(ThreadLocalHandshakes)) { 140 if (ThreadLocalHandshakes) { 141 FLAG_SET_DEFAULT(ThreadLocalHandshakes, false); 142 } 143 } else { 144 if (ThreadLocalHandshakes) { 145 warning("Thread-local handshakes are not working correctly with Shenandoah at the moment. Enable at your own risk."); 146 } 147 } 148 149 // Record more information about previous cycles for improved debugging pleasure 150 if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) { 151 FLAG_SET_DEFAULT(LogEventsBufferEntries, 250); 152 } 153 154 if (ShenandoahAlwaysPreTouch) { 155 if (!FLAG_IS_DEFAULT(ShenandoahUncommit)) { 156 warning("AlwaysPreTouch is enabled, disabling ShenandoahUncommit"); 157 } 158 FLAG_SET_DEFAULT(ShenandoahUncommit, false); 159 } 160 161 // If class unloading is disabled, no unloading for concurrent cycles as well. 162 // If class unloading is enabled, users should opt-in for unloading during 163 // concurrent cycles. 164 if (!ClassUnloading || !FLAG_IS_CMDLINE(ClassUnloadingWithConcurrentMark)) { 165 log_info(gc)("Consider -XX:+ClassUnloadingWithConcurrentMark if large pause times " 166 "are observed on class-unloading sensitive workloads"); 167 FLAG_SET_DEFAULT(ClassUnloadingWithConcurrentMark, false); 168 } 169 170 // AOT is not supported yet 171 if (UseAOT) { 172 if (!FLAG_IS_DEFAULT(UseAOT)) { 173 warning("Shenandoah does not support AOT at this moment, disabling UseAOT"); 174 } 175 FLAG_SET_DEFAULT(UseAOT, false); 176 } 177 178 // JNI fast get field stuff is not currently supported by Shenandoah. 179 // It would introduce another heap memory access for reading the forwarding 180 // pointer, which would have to be guarded by the signal handler machinery. 181 // See: 182 // http://mail.openjdk.java.net/pipermail/hotspot-dev/2018-June/032763.html 183 FLAG_SET_DEFAULT(UseFastJNIAccessors, false); 184 185 // TLAB sizing policy makes resizing decisions before each GC cycle. It averages 186 // historical data, assigning more recent data the weight according to TLABAllocationWeight. 187 // Current default is good for generational collectors that run frequent young GCs. 188 // With Shenandoah, GC cycles are much less frequent, so we need we need sizing policy 189 // to converge faster over smaller number of resizing decisions. 190 if (FLAG_IS_DEFAULT(TLABAllocationWeight)) { 191 FLAG_SET_DEFAULT(TLABAllocationWeight, 90); 192 } 193 194 // Shenandoah needs more C2 nodes to compile some methods with lots of barriers. 195 // NodeLimitFudgeFactor needs to stay the same relative to MaxNodeLimit. 196 #ifdef COMPILER2 197 if (FLAG_IS_DEFAULT(MaxNodeLimit)) { 198 FLAG_SET_DEFAULT(MaxNodeLimit, MaxNodeLimit * 3); 199 FLAG_SET_DEFAULT(NodeLimitFudgeFactor, NodeLimitFudgeFactor * 3); 200 } 201 #endif 202 203 // Make sure safepoint deadlocks are failing predictably. This sets up VM to report 204 // fatal error after 10 seconds of wait for safepoint syncronization (not the VM 205 // operation itself). There is no good reason why Shenandoah would spend that 206 // much time synchronizing. 207 #ifdef ASSERT 208 FLAG_SET_DEFAULT(SafepointTimeout, true); 209 FLAG_SET_DEFAULT(SafepointTimeoutDelay, 10000); 210 FLAG_SET_DEFAULT(AbortVMOnSafepointTimeout, true); 211 #endif 212 } 213 214 size_t ShenandoahArguments::conservative_max_heap_alignment() { 215 size_t align = ShenandoahMaxRegionSize; 216 if (UseLargePages) { 217 align = MAX2(align, os::large_page_size()); 218 } 219 return align; 220 } 221 222 CollectedHeap* ShenandoahArguments::create_heap() { 223 return create_heap_with_policy<ShenandoahHeap, ShenandoahCollectorPolicy>(); 224 }