< prev index next >

src/hotspot/share/gc/shared/gcArguments.cpp

Print this page


   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "gc/shared/cardTableRS.hpp"
  28 #include "gc/shared/gcArguments.hpp"
  29 #include "logging/log.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/globals.hpp"
  32 #include "runtime/globals_extension.hpp"
  33 #include "utilities/defaultStream.hpp"
  34 #include "utilities/macros.hpp"
  35 


  36 size_t HeapAlignment = 0;
  37 size_t SpaceAlignment = 0;
  38 
  39 void GCArguments::initialize() {
  40   if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
  41     MarkSweepAlwaysCompactCount = 1;  // Move objects every gc.
  42   }
  43 
  44   if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) {
  45     FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false);
  46   }
  47 
  48   if (GCTimeLimit == 100) {
  49     // Turn off gc-overhead-limit-exceeded checks
  50     FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
  51   }
  52 
  53   if (MinHeapFreeRatio == 100) {
  54     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
  55     FLAG_SET_ERGO(MinHeapFreeRatio, 99);


 103   }
 104   if (!FLAG_IS_DEFAULT(AllocateOldGenAt) && (UseSerialGC || UseConcMarkSweepGC || UseEpsilonGC || UseZGC)) {
 105     jio_fprintf(defaultStream::error_stream(),
 106       "AllocateOldGenAt is not supported for selected GC.\n");
 107     status = false;
 108   }
 109   return status;
 110 }
 111 
 112 #ifdef ASSERT
 113 void GCArguments::assert_flags() {
 114   assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
 115   assert(InitialHeapSize % HeapAlignment == 0, "InitialHeapSize alignment");
 116   assert(MaxHeapSize % HeapAlignment == 0, "MaxHeapSize alignment");
 117 }
 118 
 119 void GCArguments::assert_size_info() {
 120   assert(MaxHeapSize >= MinHeapSize, "Ergonomics decided on incompatible minimum and maximum heap sizes");
 121   assert(InitialHeapSize >= MinHeapSize, "Ergonomics decided on incompatible initial and minimum heap sizes");
 122   assert(MaxHeapSize >= InitialHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
 123   assert(MinHeapSize % HeapAlignment == 0, "MinHeapSize alignment");
 124   assert(InitialHeapSize % HeapAlignment == 0, "InitialHeapSize alignment");
 125   assert(MaxHeapSize % HeapAlignment == 0, "MaxHeapSize alignment");
 126 }
 127 #endif // ASSERT
 128 
 129 void GCArguments::initialize_size_info() {
 130   log_debug(gc, heap)("Minimum heap " SIZE_FORMAT "  Initial heap " SIZE_FORMAT "  Maximum heap " SIZE_FORMAT,
 131                       MinHeapSize, InitialHeapSize, MaxHeapSize);
 132 
 133   DEBUG_ONLY(assert_size_info();)
 134 }
 135 
 136 void GCArguments::initialize_heap_flags_and_sizes() {
 137   assert(SpaceAlignment != 0, "Space alignment not set up properly");
 138   assert(HeapAlignment != 0, "Heap alignment not set up properly");
 139   assert(HeapAlignment >= SpaceAlignment,
 140          "HeapAlignment: " SIZE_FORMAT " less than SpaceAlignment: " SIZE_FORMAT,
 141          HeapAlignment, SpaceAlignment);
 142   assert(HeapAlignment % SpaceAlignment == 0,
 143          "HeapAlignment: " SIZE_FORMAT " not aligned by SpaceAlignment: " SIZE_FORMAT,
 144          HeapAlignment, SpaceAlignment);
 145 
 146   if (FLAG_IS_CMDLINE(MaxHeapSize)) {
 147     if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
 148       vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size");
 149     }
 150     if (FLAG_IS_CMDLINE(MinHeapSize) && MaxHeapSize < MinHeapSize) {
 151       vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
 152     }
 153   }
 154 
 155   // Check heap parameter properties
 156   if (MaxHeapSize < 2 * M) {
 157     vm_exit_during_initialization("Too small maximum heap");
 158   }
 159   if (InitialHeapSize < M) {
 160     vm_exit_during_initialization("Too small initial heap");
 161   }
 162   if (MinHeapSize < M) {
 163     vm_exit_during_initialization("Too small minimum heap");
 164   }
 165 
 166   // User inputs from -Xmx and -Xms must be aligned




 167   // Write back to flags if the values changed
 168   if (!is_aligned(MinHeapSize, HeapAlignment)) {
 169     FLAG_SET_ERGO(MinHeapSize, align_up(MinHeapSize, HeapAlignment));
 170   }
 171   if (!is_aligned(InitialHeapSize, HeapAlignment)) {
 172     FLAG_SET_ERGO(InitialHeapSize, align_up(InitialHeapSize, HeapAlignment));
 173   }
 174   if (!is_aligned(MaxHeapSize, HeapAlignment)) {
 175     FLAG_SET_ERGO(MaxHeapSize, align_up(MaxHeapSize, HeapAlignment));
 176   }
 177 
 178   if (FLAG_IS_CMDLINE(InitialHeapSize) && FLAG_IS_CMDLINE(MinHeapSize) &&
 179       InitialHeapSize < MinHeapSize) {
 180     vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");
 181   }
 182 
 183   if (!FLAG_IS_DEFAULT(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
 184     FLAG_SET_ERGO(MaxHeapSize, InitialHeapSize);
 185   } else if (!FLAG_IS_DEFAULT(MaxHeapSize) && InitialHeapSize > MaxHeapSize) {
 186     FLAG_SET_ERGO(InitialHeapSize, MaxHeapSize);
 187     if (InitialHeapSize < MinHeapSize) {
 188       FLAG_SET_ERGO(MinHeapSize, InitialHeapSize);
 189     }
 190   }
 191 
 192   if (FLAG_IS_DEFAULT(SoftMaxHeapSize)) {
 193     FLAG_SET_ERGO(SoftMaxHeapSize, MaxHeapSize);
 194   }
 195 
 196   FLAG_SET_ERGO(MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, SpaceAlignment));
 197 
 198   DEBUG_ONLY(assert_flags();)
 199 }
   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "gc/shared/cardTableRS.hpp"
  28 #include "gc/shared/gcArguments.hpp"
  29 #include "logging/log.hpp"
  30 #include "runtime/arguments.hpp"
  31 #include "runtime/globals.hpp"
  32 #include "runtime/globals_extension.hpp"
  33 #include "utilities/defaultStream.hpp"
  34 #include "utilities/macros.hpp"
  35 
  36 size_t MinHeapSize = 0;
  37 
  38 size_t HeapAlignment = 0;
  39 size_t SpaceAlignment = 0;
  40 
  41 void GCArguments::initialize() {
  42   if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
  43     MarkSweepAlwaysCompactCount = 1;  // Move objects every gc.
  44   }
  45 
  46   if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) {
  47     FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false);
  48   }
  49 
  50   if (GCTimeLimit == 100) {
  51     // Turn off gc-overhead-limit-exceeded checks
  52     FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
  53   }
  54 
  55   if (MinHeapFreeRatio == 100) {
  56     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
  57     FLAG_SET_ERGO(MinHeapFreeRatio, 99);


 105   }
 106   if (!FLAG_IS_DEFAULT(AllocateOldGenAt) && (UseSerialGC || UseConcMarkSweepGC || UseEpsilonGC || UseZGC)) {
 107     jio_fprintf(defaultStream::error_stream(),
 108       "AllocateOldGenAt is not supported for selected GC.\n");
 109     status = false;
 110   }
 111   return status;
 112 }
 113 
 114 #ifdef ASSERT
 115 void GCArguments::assert_flags() {
 116   assert(InitialHeapSize <= MaxHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
 117   assert(InitialHeapSize % HeapAlignment == 0, "InitialHeapSize alignment");
 118   assert(MaxHeapSize % HeapAlignment == 0, "MaxHeapSize alignment");
 119 }
 120 
 121 void GCArguments::assert_size_info() {
 122   assert(MaxHeapSize >= MinHeapSize, "Ergonomics decided on incompatible minimum and maximum heap sizes");
 123   assert(InitialHeapSize >= MinHeapSize, "Ergonomics decided on incompatible initial and minimum heap sizes");
 124   assert(MaxHeapSize >= InitialHeapSize, "Ergonomics decided on incompatible initial and maximum heap sizes");
 125   assert(MaxHeapSize % HeapAlignment == 0, "MinHeapSize alignment");
 126   assert(InitialHeapSize % HeapAlignment == 0, "InitialHeapSize alignment");
 127   assert(MaxHeapSize % HeapAlignment == 0, "MaxHeapSize alignment");
 128 }
 129 #endif // ASSERT
 130 
 131 void GCArguments::initialize_size_info() {
 132   log_debug(gc, heap)("Minimum heap " SIZE_FORMAT "  Initial heap " SIZE_FORMAT "  Maximum heap " SIZE_FORMAT,
 133                       MinHeapSize, InitialHeapSize, MaxHeapSize);
 134 
 135   DEBUG_ONLY(assert_size_info();)
 136 }
 137 
 138 void GCArguments::initialize_heap_flags_and_sizes() {
 139   assert(SpaceAlignment != 0, "Space alignment not set up properly");
 140   assert(HeapAlignment != 0, "Heap alignment not set up properly");
 141   assert(HeapAlignment >= SpaceAlignment,
 142          "HeapAlignment: " SIZE_FORMAT " less than SpaceAlignment: " SIZE_FORMAT,
 143          HeapAlignment, SpaceAlignment);
 144   assert(HeapAlignment % SpaceAlignment == 0,
 145          "HeapAlignment: " SIZE_FORMAT " not aligned by SpaceAlignment: " SIZE_FORMAT,
 146          HeapAlignment, SpaceAlignment);
 147 
 148   if (FLAG_IS_CMDLINE(MaxHeapSize)) {
 149     if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
 150       vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size");
 151     }
 152     if (MinHeapSize != 0 && MaxHeapSize < MinHeapSize) {
 153       vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified");
 154     }
 155   }
 156 
 157   // Check heap parameter properties
 158   if (MaxHeapSize < 2 * M) {
 159     vm_exit_during_initialization("Too small maximum heap");
 160   }
 161   if (InitialHeapSize < M) {
 162     vm_exit_during_initialization("Too small initial heap");
 163   }
 164   if (MinHeapSize < M) {
 165     vm_exit_during_initialization("Too small minimum heap");
 166   }
 167 
 168   // User inputs from -Xmx and -Xms must be aligned
 169   MinHeapSize = align_up(MinHeapSize, HeapAlignment);
 170   size_t aligned_initial_heap_size = align_up(InitialHeapSize, HeapAlignment);
 171   size_t aligned_max_heap_size = align_up(MaxHeapSize, HeapAlignment);
 172 
 173   // Write back to flags if the values changed
 174   if (aligned_initial_heap_size != InitialHeapSize) {
 175     FLAG_SET_ERGO(InitialHeapSize, aligned_initial_heap_size);



 176   }
 177   if (aligned_max_heap_size != MaxHeapSize) {
 178     FLAG_SET_ERGO(MaxHeapSize, aligned_max_heap_size);
 179   }
 180 
 181   if (FLAG_IS_CMDLINE(InitialHeapSize) && MinHeapSize != 0 &&
 182       InitialHeapSize < MinHeapSize) {
 183     vm_exit_during_initialization("Incompatible minimum and initial heap sizes specified");
 184   }

 185   if (!FLAG_IS_DEFAULT(InitialHeapSize) && InitialHeapSize > MaxHeapSize) {
 186     FLAG_SET_ERGO(MaxHeapSize, InitialHeapSize);
 187   } else if (!FLAG_IS_DEFAULT(MaxHeapSize) && InitialHeapSize > MaxHeapSize) {
 188     FLAG_SET_ERGO(InitialHeapSize, MaxHeapSize);
 189     if (InitialHeapSize < MinHeapSize) {
 190       MinHeapSize = InitialHeapSize;
 191     }




 192   }
 193 
 194   FLAG_SET_ERGO(MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, SpaceAlignment));
 195 
 196   DEBUG_ONLY(assert_flags();)
 197 }
< prev index next >