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