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