1 /*
   2  * Copyright (c) 2017, 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/g1/g1Arguments.hpp"
  27 #include "gc/g1/heapRegion.hpp"
  28 #include "runtime/globals.hpp"
  29 #include "runtime/globals_extension.hpp"
  30 #include "runtime/vm_version.hpp"
  31 
  32 size_t G1Arguments::conservative_max_heap_alignment() {
  33   return HeapRegion::max_region_size();
  34 }
  35 
  36 void G1Arguments::initialize_flags() {
  37   GCArguments::initialize_flags();
  38   assert(UseG1GC, "Error");
  39 #if defined(COMPILER1) || INCLUDE_JVMCI
  40   FastTLABRefill = false;
  41 #endif
  42   FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
  43   if (ParallelGCThreads == 0) {
  44     assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0.");
  45     vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL);
  46   }
  47 
  48 #if INCLUDE_ALL_GCS
  49   if (FLAG_IS_DEFAULT(G1ConcRefinementThreads)) {
  50     FLAG_SET_ERGO(uint, G1ConcRefinementThreads, ParallelGCThreads);
  51   }
  52 #endif
  53 
  54   // MarkStackSize will be set (if it hasn't been set by the user)
  55   // when concurrent marking is initialized.
  56   // Its value will be based upon the number of parallel marking threads.
  57   // But we do set the maximum mark stack size here.
  58   if (FLAG_IS_DEFAULT(MarkStackSizeMax)) {
  59     FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
  60   }
  61 
  62   if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
  63     // In G1, we want the default GC overhead goal to be higher than
  64     // it is for PS, or the heap might be expanded too aggressively.
  65     // We set it here to ~8%.
  66     FLAG_SET_DEFAULT(GCTimeRatio, 12);
  67   }
  68 
  69   // Below, we might need to calculate the pause time interval based on
  70   // the pause target. When we do so we are going to give G1 maximum
  71   // flexibility and allow it to do pauses when it needs to. So, we'll
  72   // arrange that the pause interval to be pause time target + 1 to
  73   // ensure that a) the pause time target is maximized with respect to
  74   // the pause interval and b) we maintain the invariant that pause
  75   // time target < pause interval. If the user does not want this
  76   // maximum flexibility, they will have to set the pause interval
  77   // explicitly.
  78 
  79   if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
  80     // The default pause time target in G1 is 200ms
  81     FLAG_SET_DEFAULT(MaxGCPauseMillis, 200);
  82   }
  83 
  84   // Then, if the interval parameter was not set, set it according to
  85   // the pause time target (this will also deal with the case when the
  86   // pause time target is the default value).
  87   if (FLAG_IS_DEFAULT(GCPauseIntervalMillis)) {
  88     FLAG_SET_DEFAULT(GCPauseIntervalMillis, MaxGCPauseMillis + 1);
  89   }
  90 
  91   log_trace(gc)("MarkStackSize: %uk  MarkStackSizeMax: %uk", (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K));
  92 }