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/shared/taskqueue.hpp" 28 #include "gc/shenandoah/shenandoahArguments.hpp" 29 #include "gc/shenandoah/shenandoahCollectorPolicy.hpp" 30 #include "gc/shenandoah/shenandoahHeap.hpp" 31 #include "utilities/defaultStream.hpp" 32 33 void ShenandoahArguments::initialize() { 34 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(ShenandoahConditionalSATBBarrier, 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(ShenandoahStoreValWriteBarrier, false); 53 FLAG_SET_DEFAULT(ShenandoahStoreValReadBarrier, false); 54 FLAG_SET_DEFAULT(ShenandoahCASBarrier, false); 55 FLAG_SET_DEFAULT(ShenandoahAcmpBarrier, false); 56 FLAG_SET_DEFAULT(ShenandoahCloneBarrier, false); 57 FLAG_SET_DEFAULT(UseShenandoahMatrix, false); 58 #endif 59 60 #ifdef _LP64 61 // The optimized ObjArrayChunkedTask takes some bits away from the full 64 addressable 62 // bits, fail if we ever attempt to address more than we can. Only valid on 64bit. 63 if (MaxHeapSize >= ObjArrayChunkedTask::max_addressable()) { 64 jio_fprintf(defaultStream::error_stream(), 65 "Shenandoah GC cannot address more than " SIZE_FORMAT " bytes, and " SIZE_FORMAT " bytes heap requested.", 66 ObjArrayChunkedTask::max_addressable(), MaxHeapSize); 67 vm_exit(1); 68 } 69 #endif 70 71 FLAG_SET_DEFAULT(ParallelGCThreads, 72 Abstract_VM_Version::parallel_worker_threads()); 73 74 if (FLAG_IS_DEFAULT(ConcGCThreads)) { 75 uint conc_threads = MAX2((uint) 1, ParallelGCThreads); 76 FLAG_SET_DEFAULT(ConcGCThreads, conc_threads); 77 } 78 79 if (FLAG_IS_DEFAULT(ParallelRefProcEnabled)) { 80 FLAG_SET_DEFAULT(ParallelRefProcEnabled, true); 81 } 82 83 if (ShenandoahRegionSampling && FLAG_IS_DEFAULT(PerfDataMemorySize)) { 84 // When sampling is enabled, max out the PerfData memory to get more 85 // Shenandoah data in, including Matrix. 86 FLAG_SET_DEFAULT(PerfDataMemorySize, 2048*K); 87 } 88 89 #ifdef COMPILER2 90 // Shenandoah cares more about pause times, rather than raw throughput. 91 if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) { 92 FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true); 93 if (FLAG_IS_DEFAULT(LoopStripMiningIter)) { 94 FLAG_SET_DEFAULT(LoopStripMiningIter, 1000); 95 } 96 } 97 #ifdef ASSERT 98 // C2 barrier verification is only reliable when all default barriers are enabled 99 if (ShenandoahVerifyOptoBarriers && 100 (!FLAG_IS_DEFAULT(ShenandoahSATBBarrier) || 101 !FLAG_IS_DEFAULT(ShenandoahConditionalSATBBarrier) || 102 !FLAG_IS_DEFAULT(ShenandoahKeepAliveBarrier) || 103 !FLAG_IS_DEFAULT(ShenandoahWriteBarrier) || 104 !FLAG_IS_DEFAULT(ShenandoahReadBarrier) || 105 !FLAG_IS_DEFAULT(ShenandoahStoreValEnqueueBarrier) || 106 !FLAG_IS_DEFAULT(ShenandoahStoreValWriteBarrier) || 107 !FLAG_IS_DEFAULT(ShenandoahStoreValReadBarrier) || 108 !FLAG_IS_DEFAULT(ShenandoahCASBarrier) || 109 !FLAG_IS_DEFAULT(ShenandoahAcmpBarrier) || 110 !FLAG_IS_DEFAULT(ShenandoahCloneBarrier) 111 )) { 112 warning("Unusual barrier configuration, disabling C2 barrier verification"); 113 FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false); 114 } 115 #else 116 guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled"); 117 #endif // ASSERT 118 #endif // COMPILER2 119 120 if (AlwaysPreTouch) { 121 // Shenandoah handles pre-touch on its own. It does not let the 122 // generic storage code to do the pre-touch before Shenandoah has 123 // a chance to do it on its own. 124 FLAG_SET_DEFAULT(AlwaysPreTouch, false); 125 FLAG_SET_DEFAULT(ShenandoahAlwaysPreTouch, true); 126 } 127 128 // Shenandoah C2 optimizations apparently dislike the shape of thread-local handshakes. 129 // Disable it by default, unless we enable it specifically for debugging. 130 if (FLAG_IS_DEFAULT(ThreadLocalHandshakes)) { 131 if (ThreadLocalHandshakes) { 132 FLAG_SET_DEFAULT(ThreadLocalHandshakes, false); 133 } 134 } else { 135 if (ThreadLocalHandshakes) { 136 warning("Thread-local handshakes are not working correctly with Shenandoah at the moment. Enable at your own risk."); 137 } 138 } 139 140 // Record more information about previous cycles for improved debugging pleasure 141 if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) { 142 FLAG_SET_DEFAULT(LogEventsBufferEntries, 250); 143 } 144 145 if (ShenandoahConcurrentEvacCodeRoots) { 146 if (!ShenandoahBarriersForConst) { 147 if (FLAG_IS_DEFAULT(ShenandoahBarriersForConst)) { 148 warning("Concurrent code cache evacuation is enabled, enabling barriers for constants."); 149 FLAG_SET_DEFAULT(ShenandoahBarriersForConst, true); 150 } else { 151 warning("Concurrent code cache evacuation is enabled, but barriers for constants are disabled. " 152 "This may lead to surprising crashes."); 153 } 154 } 155 } else { 156 if (ShenandoahBarriersForConst) { 157 if (FLAG_IS_DEFAULT(ShenandoahBarriersForConst)) { 158 warning("Concurrent code cache evacuation is disabled, disabling barriers for constants."); 159 FLAG_SET_DEFAULT(ShenandoahBarriersForConst, false); 160 } 161 } 162 } 163 164 if (ShenandoahAlwaysPreTouch) { 165 if (!FLAG_IS_DEFAULT(ShenandoahUncommit)) { 166 warning("AlwaysPreTouch is enabled, disabling ShenandoahUncommit"); 167 } 168 FLAG_SET_DEFAULT(ShenandoahUncommit, false); 169 } 170 } 171 172 size_t ShenandoahArguments::conservative_max_heap_alignment() { 173 return ShenandoahMaxRegionSize; 174 } 175 176 CollectedHeap* ShenandoahArguments::create_heap() { 177 return create_heap_with_policy<ShenandoahHeap, ShenandoahCollectorPolicy>(); 178 }