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(ShenandoahKeepAliveBarrier)       ||
 102            !FLAG_IS_DEFAULT(ShenandoahWriteBarrier)           ||
 103            !FLAG_IS_DEFAULT(ShenandoahReadBarrier)            ||
 104            !FLAG_IS_DEFAULT(ShenandoahStoreValEnqueueBarrier) ||
 105            !FLAG_IS_DEFAULT(ShenandoahStoreValReadBarrier)    ||
 106            !FLAG_IS_DEFAULT(ShenandoahCASBarrier)             ||
 107            !FLAG_IS_DEFAULT(ShenandoahAcmpBarrier)            ||
 108            !FLAG_IS_DEFAULT(ShenandoahCloneBarrier)
 109           )) {
 110     warning("Unusual barrier configuration, disabling C2 barrier verification");
 111     FLAG_SET_DEFAULT(ShenandoahVerifyOptoBarriers, false);
 112   }
 113 #else
 114   guarantee(!ShenandoahVerifyOptoBarriers, "Should be disabled");
 115 #endif // ASSERT
 116 #endif // COMPILER2
 117 
 118   if (AlwaysPreTouch) {
 119     // Shenandoah handles pre-touch on its own. It does not let the
 120     // generic storage code to do the pre-touch before Shenandoah has
 121     // a chance to do it on its own.
 122     FLAG_SET_DEFAULT(AlwaysPreTouch, false);
 123     FLAG_SET_DEFAULT(ShenandoahAlwaysPreTouch, true);
 124   }
 125 
 126   // Shenandoah C2 optimizations apparently dislike the shape of thread-local handshakes.
 127   // Disable it by default, unless we enable it specifically for debugging.
 128   if (FLAG_IS_DEFAULT(ThreadLocalHandshakes)) {
 129     if (ThreadLocalHandshakes) {
 130       FLAG_SET_DEFAULT(ThreadLocalHandshakes, false);
 131     }
 132   } else {
 133     if (ThreadLocalHandshakes) {
 134       warning("Thread-local handshakes are not working correctly with Shenandoah at the moment. Enable at your own risk.");
 135     }
 136   }
 137 
 138   // Record more information about previous cycles for improved debugging pleasure
 139   if (FLAG_IS_DEFAULT(LogEventsBufferEntries)) {
 140     FLAG_SET_DEFAULT(LogEventsBufferEntries, 250);
 141   }
 142 
 143   if (ShenandoahConcurrentEvacCodeRoots) {
 144     if (!ShenandoahBarriersForConst) {
 145       if (FLAG_IS_DEFAULT(ShenandoahBarriersForConst)) {
 146         warning("Concurrent code cache evacuation is enabled, enabling barriers for constants.");
 147         FLAG_SET_DEFAULT(ShenandoahBarriersForConst, true);
 148       } else {
 149         warning("Concurrent code cache evacuation is enabled, but barriers for constants are disabled. "
 150                 "This may lead to surprising crashes.");
 151       }
 152     }
 153   } else {
 154     if (ShenandoahBarriersForConst) {
 155       if (FLAG_IS_DEFAULT(ShenandoahBarriersForConst)) {
 156         warning("Concurrent code cache evacuation is disabled, disabling barriers for constants.");
 157         FLAG_SET_DEFAULT(ShenandoahBarriersForConst, false);
 158       }
 159     }
 160   }
 161 
 162   if (ShenandoahAlwaysPreTouch) {
 163     if (!FLAG_IS_DEFAULT(ShenandoahUncommit)) {
 164       warning("AlwaysPreTouch is enabled, disabling ShenandoahUncommit");
 165     }
 166     FLAG_SET_DEFAULT(ShenandoahUncommit, false);
 167   }
 168 }
 169 
 170 size_t ShenandoahArguments::conservative_max_heap_alignment() {
 171   return ShenandoahMaxRegionSize;
 172 }
 173 
 174 CollectedHeap* ShenandoahArguments::create_heap() {
 175   return create_heap_with_policy<ShenandoahHeap, ShenandoahCollectorPolicy>();
 176 }