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/parallel/parallelArguments.hpp"
  27 #include "gc/shared/collectorPolicy.hpp"
  28 #include "runtime/globals.hpp"
  29 #include "runtime/globals_extension.hpp"
  30 #include "runtime/java.hpp"
  31 #include "runtime/vm_version.hpp"
  32 #include "utilities/defaultStream.hpp"
  33 
  34 size_t ParallelArguments::conservative_max_heap_alignment() {
  35   return CollectorPolicy::compute_heap_alignment();
  36 }
  37 
  38 void ParallelArguments::initialize_flags() {
  39   GCArguments::initialize_flags();
  40   assert(UseParallelGC || UseParallelOldGC, "Error");
  41   // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file).
  42   if (FLAG_IS_DEFAULT(UseParallelOldGC)) {
  43     FLAG_SET_DEFAULT(UseParallelOldGC, true);
  44   }
  45   FLAG_SET_DEFAULT(UseParallelGC, true);
  46 
  47   // If no heap maximum was requested explicitly, use some reasonable fraction
  48   // of the physical memory, up to a maximum of 1GB.
  49   FLAG_SET_DEFAULT(ParallelGCThreads,
  50                    Abstract_VM_Version::parallel_worker_threads());
  51   if (ParallelGCThreads == 0) {
  52     jio_fprintf(defaultStream::error_stream(),
  53         "The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n");
  54     vm_exit(1);
  55   }
  56 
  57   if (UseAdaptiveSizePolicy) {
  58     // We don't want to limit adaptive heap sizing's freedom to adjust the heap
  59     // unless the user actually sets these flags.
  60     if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) {
  61       FLAG_SET_DEFAULT(MinHeapFreeRatio, 0);
  62     }
  63     if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) {
  64       FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100);
  65     }
  66   }
  67 
  68   // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
  69   // SurvivorRatio has been set, reset their default values to SurvivorRatio +
  70   // 2.  By doing this we make SurvivorRatio also work for Parallel Scavenger.
  71   // See CR 6362902 for details.
  72   if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
  73     if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
  74        FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
  75     }
  76     if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
  77       FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
  78     }
  79   }
  80 
  81   if (UseParallelOldGC) {
  82     // Par compact uses lower default values since they are treated as
  83     // minimums.  These are different defaults because of the different
  84     // interpretation and are not ergonomically set.
  85     if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
  86       FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
  87     }
  88   }
  89 }