| File: | jdk/src/hotspot/share/gc/shared/genArguments.cpp |
| Warning: | line 240, column 10 Value stored to 'initial_young_size' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright (c) 2018, 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 "precompiled.hpp" |
| 26 | #include "gc/shared/cardTable.hpp" |
| 27 | #include "gc/shared/genArguments.hpp" |
| 28 | #include "gc/shared/generation.hpp" |
| 29 | #include "logging/log.hpp" |
| 30 | #include "runtime/globals_extension.hpp" |
| 31 | #include "runtime/java.hpp" |
| 32 | #include "utilities/align.hpp" |
| 33 | #include "utilities/globalDefinitions.hpp" |
| 34 | |
| 35 | size_t MinNewSize = 0; |
| 36 | |
| 37 | size_t MinOldSize = 0; |
| 38 | size_t MaxOldSize = 0; |
| 39 | |
| 40 | size_t GenAlignment = 0; |
| 41 | |
| 42 | size_t GenArguments::conservative_max_heap_alignment() { return (size_t)Generation::GenGrain; } |
| 43 | |
| 44 | static size_t young_gen_size_lower_bound() { |
| 45 | // The young generation must be aligned and have room for eden + two survivors |
| 46 | return align_up(3 * SpaceAlignment, GenAlignment); |
| 47 | } |
| 48 | |
| 49 | static size_t old_gen_size_lower_bound() { |
| 50 | return align_up(SpaceAlignment, GenAlignment); |
| 51 | } |
| 52 | |
| 53 | size_t GenArguments::scale_by_NewRatio_aligned(size_t base_size, size_t alignment) { |
| 54 | return align_down_bounded(base_size / (NewRatio + 1), alignment); |
| 55 | } |
| 56 | |
| 57 | static size_t bound_minus_alignment(size_t desired_size, |
| 58 | size_t maximum_size, |
| 59 | size_t alignment) { |
| 60 | size_t max_minus = maximum_size - alignment; |
| 61 | return desired_size < max_minus ? desired_size : max_minus; |
| 62 | } |
| 63 | |
| 64 | void GenArguments::initialize_alignments() { |
| 65 | // Initialize card size before initializing alignments |
| 66 | CardTable::initialize_card_size(); |
| 67 | SpaceAlignment = GenAlignment = (size_t)Generation::GenGrain; |
| 68 | HeapAlignment = compute_heap_alignment(); |
| 69 | } |
| 70 | |
| 71 | void GenArguments::initialize_heap_flags_and_sizes() { |
| 72 | GCArguments::initialize_heap_flags_and_sizes(); |
| 73 | |
| 74 | assert(GenAlignment != 0, "Generation alignment not set up properly")do { if (!(GenAlignment != 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 74, "assert(" "GenAlignment != 0" ") failed", "Generation alignment not set up properly" ); ::breakpoint(); } } while (0); |
| 75 | assert(HeapAlignment >= GenAlignment,do { if (!(HeapAlignment >= GenAlignment)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 77, "assert(" "HeapAlignment >= GenAlignment" ") failed" , "HeapAlignment: " "%" "l" "u" " less than GenAlignment: " "%" "l" "u", HeapAlignment, GenAlignment); ::breakpoint(); } } while (0) |
| 76 | "HeapAlignment: " SIZE_FORMAT " less than GenAlignment: " SIZE_FORMAT,do { if (!(HeapAlignment >= GenAlignment)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 77, "assert(" "HeapAlignment >= GenAlignment" ") failed" , "HeapAlignment: " "%" "l" "u" " less than GenAlignment: " "%" "l" "u", HeapAlignment, GenAlignment); ::breakpoint(); } } while (0) |
| 77 | HeapAlignment, GenAlignment)do { if (!(HeapAlignment >= GenAlignment)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 77, "assert(" "HeapAlignment >= GenAlignment" ") failed" , "HeapAlignment: " "%" "l" "u" " less than GenAlignment: " "%" "l" "u", HeapAlignment, GenAlignment); ::breakpoint(); } } while (0); |
| 78 | assert(GenAlignment % SpaceAlignment == 0,do { if (!(GenAlignment % SpaceAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 80, "assert(" "GenAlignment % SpaceAlignment == 0" ") failed" , "GenAlignment: " "%" "l" "u" " not aligned by SpaceAlignment: " "%" "l" "u", GenAlignment, SpaceAlignment); ::breakpoint(); } } while (0) |
| 79 | "GenAlignment: " SIZE_FORMAT " not aligned by SpaceAlignment: " SIZE_FORMAT,do { if (!(GenAlignment % SpaceAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 80, "assert(" "GenAlignment % SpaceAlignment == 0" ") failed" , "GenAlignment: " "%" "l" "u" " not aligned by SpaceAlignment: " "%" "l" "u", GenAlignment, SpaceAlignment); ::breakpoint(); } } while (0) |
| 80 | GenAlignment, SpaceAlignment)do { if (!(GenAlignment % SpaceAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 80, "assert(" "GenAlignment % SpaceAlignment == 0" ") failed" , "GenAlignment: " "%" "l" "u" " not aligned by SpaceAlignment: " "%" "l" "u", GenAlignment, SpaceAlignment); ::breakpoint(); } } while (0); |
| 81 | assert(HeapAlignment % GenAlignment == 0,do { if (!(HeapAlignment % GenAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 83, "assert(" "HeapAlignment % GenAlignment == 0" ") failed" , "HeapAlignment: " "%" "l" "u" " not aligned by GenAlignment: " "%" "l" "u", HeapAlignment, GenAlignment); ::breakpoint(); } } while (0) |
| 82 | "HeapAlignment: " SIZE_FORMAT " not aligned by GenAlignment: " SIZE_FORMAT,do { if (!(HeapAlignment % GenAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 83, "assert(" "HeapAlignment % GenAlignment == 0" ") failed" , "HeapAlignment: " "%" "l" "u" " not aligned by GenAlignment: " "%" "l" "u", HeapAlignment, GenAlignment); ::breakpoint(); } } while (0) |
| 83 | HeapAlignment, GenAlignment)do { if (!(HeapAlignment % GenAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 83, "assert(" "HeapAlignment % GenAlignment == 0" ") failed" , "HeapAlignment: " "%" "l" "u" " not aligned by GenAlignment: " "%" "l" "u", HeapAlignment, GenAlignment); ::breakpoint(); } } while (0); |
| 84 | |
| 85 | // All generational heaps have a young gen; handle those flags here |
| 86 | |
| 87 | // Make sure the heap is large enough for two generations |
| 88 | size_t smallest_new_size = young_gen_size_lower_bound(); |
| 89 | size_t smallest_heap_size = align_up(smallest_new_size + old_gen_size_lower_bound(), |
| 90 | HeapAlignment); |
| 91 | if (MaxHeapSize < smallest_heap_size) { |
| 92 | FLAG_SET_ERGO(MaxHeapSize, smallest_heap_size)(Flag_MaxHeapSize_set((smallest_heap_size), JVMFlagOrigin::ERGONOMIC )); |
| 93 | } |
| 94 | // If needed, synchronize MinHeapSize size and InitialHeapSize |
| 95 | if (MinHeapSize < smallest_heap_size) { |
| 96 | FLAG_SET_ERGO(MinHeapSize, smallest_heap_size)(Flag_MinHeapSize_set((smallest_heap_size), JVMFlagOrigin::ERGONOMIC )); |
| 97 | if (InitialHeapSize < MinHeapSize) { |
| 98 | FLAG_SET_ERGO(InitialHeapSize, smallest_heap_size)(Flag_InitialHeapSize_set((smallest_heap_size), JVMFlagOrigin ::ERGONOMIC)); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Make sure NewSize allows an old generation to fit even if set on the command line |
| 103 | if (FLAG_IS_CMDLINE(NewSize)(JVMFlag::is_cmdline(Flag_NewSize_enum)) && NewSize >= InitialHeapSize) { |
| 104 | log_warning(gc, ergo)(!(LogImpl<(LogTag::_gc), (LogTag::_ergo), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Warning))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_ergo), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Warning>("NewSize was set larger than initial heap size, will use initial heap size."); |
| 105 | FLAG_SET_ERGO(NewSize, bound_minus_alignment(NewSize, InitialHeapSize, GenAlignment))(Flag_NewSize_set((bound_minus_alignment(NewSize, InitialHeapSize , GenAlignment)), JVMFlagOrigin::ERGONOMIC)); |
| 106 | } |
| 107 | |
| 108 | // Now take the actual NewSize into account. We will silently increase NewSize |
| 109 | // if the user specified a smaller or unaligned value. |
| 110 | size_t bounded_new_size = bound_minus_alignment(NewSize, MaxHeapSize, GenAlignment); |
| 111 | bounded_new_size = MAX2(smallest_new_size, align_down(bounded_new_size, GenAlignment)); |
| 112 | if (bounded_new_size != NewSize) { |
| 113 | FLAG_SET_ERGO(NewSize, bounded_new_size)(Flag_NewSize_set((bounded_new_size), JVMFlagOrigin::ERGONOMIC )); |
| 114 | } |
| 115 | MinNewSize = smallest_new_size; |
| 116 | |
| 117 | if (!FLAG_IS_DEFAULT(MaxNewSize)(JVMFlag::is_default(Flag_MaxNewSize_enum))) { |
| 118 | if (MaxNewSize >= MaxHeapSize) { |
| 119 | // Make sure there is room for an old generation |
| 120 | size_t smaller_max_new_size = MaxHeapSize - GenAlignment; |
| 121 | if (FLAG_IS_CMDLINE(MaxNewSize)(JVMFlag::is_cmdline(Flag_MaxNewSize_enum))) { |
| 122 | log_warning(gc, ergo)(!(LogImpl<(LogTag::_gc), (LogTag::_ergo), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Warning))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_ergo), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Warning>("MaxNewSize (" SIZE_FORMAT"%" "l" "u" "k) is equal to or greater than the entire " |
| 123 | "heap (" SIZE_FORMAT"%" "l" "u" "k). A new max generation size of " SIZE_FORMAT"%" "l" "u" "k will be used.", |
| 124 | MaxNewSize/K, MaxHeapSize/K, smaller_max_new_size/K); |
| 125 | } |
| 126 | FLAG_SET_ERGO(MaxNewSize, smaller_max_new_size)(Flag_MaxNewSize_set((smaller_max_new_size), JVMFlagOrigin::ERGONOMIC )); |
| 127 | if (NewSize > MaxNewSize) { |
| 128 | FLAG_SET_ERGO(NewSize, MaxNewSize)(Flag_NewSize_set((MaxNewSize), JVMFlagOrigin::ERGONOMIC)); |
| 129 | } |
| 130 | } else if (MaxNewSize < NewSize) { |
| 131 | FLAG_SET_ERGO(MaxNewSize, NewSize)(Flag_MaxNewSize_set((NewSize), JVMFlagOrigin::ERGONOMIC)); |
| 132 | } else if (!is_aligned(MaxNewSize, GenAlignment)) { |
| 133 | FLAG_SET_ERGO(MaxNewSize, align_down(MaxNewSize, GenAlignment))(Flag_MaxNewSize_set((align_down(MaxNewSize, GenAlignment)), JVMFlagOrigin ::ERGONOMIC)); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (NewSize > MaxNewSize) { |
| 138 | // At this point this should only happen if the user specifies a large NewSize and/or |
| 139 | // a small (but not too small) MaxNewSize. |
| 140 | if (FLAG_IS_CMDLINE(MaxNewSize)(JVMFlag::is_cmdline(Flag_MaxNewSize_enum))) { |
| 141 | log_warning(gc, ergo)(!(LogImpl<(LogTag::_gc), (LogTag::_ergo), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Warning))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_ergo), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Warning>("NewSize (" SIZE_FORMAT"%" "l" "u" "k) is greater than the MaxNewSize (" SIZE_FORMAT"%" "l" "u" "k). " |
| 142 | "A new max generation size of " SIZE_FORMAT"%" "l" "u" "k will be used.", |
| 143 | NewSize/K, MaxNewSize/K, NewSize/K); |
| 144 | } |
| 145 | FLAG_SET_ERGO(MaxNewSize, NewSize)(Flag_MaxNewSize_set((NewSize), JVMFlagOrigin::ERGONOMIC)); |
| 146 | } |
| 147 | |
| 148 | if (SurvivorRatio < 1 || NewRatio < 1) { |
| 149 | vm_exit_during_initialization("Invalid young gen ratio specified"); |
| 150 | } |
| 151 | |
| 152 | if (OldSize < old_gen_size_lower_bound()) { |
| 153 | FLAG_SET_ERGO(OldSize, old_gen_size_lower_bound())(Flag_OldSize_set((old_gen_size_lower_bound()), JVMFlagOrigin ::ERGONOMIC)); |
| 154 | } |
| 155 | if (!is_aligned(OldSize, GenAlignment)) { |
| 156 | FLAG_SET_ERGO(OldSize, align_down(OldSize, GenAlignment))(Flag_OldSize_set((align_down(OldSize, GenAlignment)), JVMFlagOrigin ::ERGONOMIC)); |
| 157 | } |
| 158 | |
| 159 | if (FLAG_IS_CMDLINE(OldSize)(JVMFlag::is_cmdline(Flag_OldSize_enum)) && FLAG_IS_DEFAULT(MaxHeapSize)(JVMFlag::is_default(Flag_MaxHeapSize_enum))) { |
| 160 | // NewRatio will be used later to set the young generation size so we use |
| 161 | // it to calculate how big the heap should be based on the requested OldSize |
| 162 | // and NewRatio. |
| 163 | assert(NewRatio > 0, "NewRatio should have been set up earlier")do { if (!(NewRatio > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 163, "assert(" "NewRatio > 0" ") failed", "NewRatio should have been set up earlier" ); ::breakpoint(); } } while (0); |
| 164 | size_t calculated_heapsize = (OldSize / NewRatio) * (NewRatio + 1); |
| 165 | |
| 166 | calculated_heapsize = align_up(calculated_heapsize, HeapAlignment); |
| 167 | FLAG_SET_ERGO(MaxHeapSize, calculated_heapsize)(Flag_MaxHeapSize_set((calculated_heapsize), JVMFlagOrigin::ERGONOMIC )); |
| 168 | FLAG_SET_ERGO(InitialHeapSize, calculated_heapsize)(Flag_InitialHeapSize_set((calculated_heapsize), JVMFlagOrigin ::ERGONOMIC)); |
| 169 | } |
| 170 | |
| 171 | // Adjust NewSize and OldSize or MaxHeapSize to match each other |
| 172 | if (NewSize + OldSize > MaxHeapSize) { |
| 173 | if (FLAG_IS_CMDLINE(MaxHeapSize)(JVMFlag::is_cmdline(Flag_MaxHeapSize_enum))) { |
| 174 | // Somebody has set a maximum heap size with the intention that we should not |
| 175 | // exceed it. Adjust New/OldSize as necessary. |
| 176 | size_t calculated_size = NewSize + OldSize; |
| 177 | double shrink_factor = (double) MaxHeapSize / calculated_size; |
| 178 | size_t smaller_new_size = align_down((size_t)(NewSize * shrink_factor), GenAlignment); |
| 179 | FLAG_SET_ERGO(NewSize, MAX2(young_gen_size_lower_bound(), smaller_new_size))(Flag_NewSize_set((MAX2(young_gen_size_lower_bound(), smaller_new_size )), JVMFlagOrigin::ERGONOMIC)); |
| 180 | |
| 181 | // OldSize is already aligned because above we aligned MaxHeapSize to |
| 182 | // HeapAlignment, and we just made sure that NewSize is aligned to |
| 183 | // GenAlignment. In initialize_flags() we verified that HeapAlignment |
| 184 | // is a multiple of GenAlignment. |
| 185 | FLAG_SET_ERGO(OldSize, MaxHeapSize - NewSize)(Flag_OldSize_set((MaxHeapSize - NewSize), JVMFlagOrigin::ERGONOMIC )); |
| 186 | } else { |
| 187 | FLAG_SET_ERGO(MaxHeapSize, align_up(NewSize + OldSize, HeapAlignment))(Flag_MaxHeapSize_set((align_up(NewSize + OldSize, HeapAlignment )), JVMFlagOrigin::ERGONOMIC)); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // Update NewSize, if possible, to avoid sizing the young gen too small when only |
| 192 | // OldSize is set on the command line. |
| 193 | if (FLAG_IS_CMDLINE(OldSize)(JVMFlag::is_cmdline(Flag_OldSize_enum)) && !FLAG_IS_CMDLINE(NewSize)(JVMFlag::is_cmdline(Flag_NewSize_enum))) { |
| 194 | if (OldSize < InitialHeapSize) { |
| 195 | size_t new_size = InitialHeapSize - OldSize; |
| 196 | if (new_size >= MinNewSize && new_size <= MaxNewSize) { |
| 197 | FLAG_SET_ERGO(NewSize, new_size)(Flag_NewSize_set((new_size), JVMFlagOrigin::ERGONOMIC)); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | DEBUG_ONLY(assert_flags();)assert_flags(); |
| 203 | } |
| 204 | |
| 205 | // Values set on the command line win over any ergonomically |
| 206 | // set command line parameters. |
| 207 | // Ergonomic choice of parameters are done before this |
| 208 | // method is called. Values for command line parameters such as NewSize |
| 209 | // and MaxNewSize feed those ergonomic choices into this method. |
| 210 | // This method makes the final generation sizings consistent with |
| 211 | // themselves and with overall heap sizings. |
| 212 | // In the absence of explicitly set command line flags, policies |
| 213 | // such as the use of NewRatio are used to size the generation. |
| 214 | |
| 215 | // Minimum sizes of the generations may be different than |
| 216 | // the initial sizes. An inconsistency is permitted here |
| 217 | // in the total size that can be specified explicitly by |
| 218 | // command line specification of OldSize and NewSize and |
| 219 | // also a command line specification of -Xms. Issue a warning |
| 220 | // but allow the values to pass. |
| 221 | void GenArguments::initialize_size_info() { |
| 222 | GCArguments::initialize_size_info(); |
| 223 | |
| 224 | size_t max_young_size = MaxNewSize; |
| 225 | |
| 226 | // Determine maximum size of the young generation. |
| 227 | |
| 228 | if (FLAG_IS_DEFAULT(MaxNewSize)(JVMFlag::is_default(Flag_MaxNewSize_enum))) { |
| 229 | max_young_size = scale_by_NewRatio_aligned(MaxHeapSize, GenAlignment); |
| 230 | // Bound the maximum size by NewSize below (since it historically |
| 231 | // would have been NewSize and because the NewRatio calculation could |
| 232 | // yield a size that is too small) and bound it by MaxNewSize above. |
| 233 | // Ergonomics plays here by previously calculating the desired |
| 234 | // NewSize and MaxNewSize. |
| 235 | max_young_size = clamp(max_young_size, NewSize, MaxNewSize); |
| 236 | } |
| 237 | |
| 238 | // Given the maximum young size, determine the initial and |
| 239 | // minimum young sizes. |
| 240 | size_t initial_young_size = NewSize; |
Value stored to 'initial_young_size' during its initialization is never read | |
| 241 | |
| 242 | if (MaxHeapSize == InitialHeapSize) { |
| 243 | // The maximum and initial heap sizes are the same so the generation's |
| 244 | // initial size must be the same as it maximum size. Use NewSize as the |
| 245 | // size if set on command line. |
| 246 | max_young_size = FLAG_IS_CMDLINE(NewSize)(JVMFlag::is_cmdline(Flag_NewSize_enum)) ? NewSize : max_young_size; |
| 247 | initial_young_size = max_young_size; |
| 248 | |
| 249 | // Also update the minimum size if min == initial == max. |
| 250 | if (MaxHeapSize == MinHeapSize) { |
| 251 | MinNewSize = max_young_size; |
| 252 | } |
| 253 | } else { |
| 254 | if (FLAG_IS_CMDLINE(NewSize)(JVMFlag::is_cmdline(Flag_NewSize_enum))) { |
| 255 | // If NewSize is set on the command line, we should use it as |
| 256 | // the initial size, but make sure it is within the heap bounds. |
| 257 | initial_young_size = |
| 258 | MIN2(max_young_size, bound_minus_alignment(NewSize, InitialHeapSize, GenAlignment)); |
| 259 | MinNewSize = bound_minus_alignment(initial_young_size, MinHeapSize, GenAlignment); |
| 260 | } else { |
| 261 | // For the case where NewSize is not set on the command line, use |
| 262 | // NewRatio to size the initial generation size. Use the current |
| 263 | // NewSize as the floor, because if NewRatio is overly large, the resulting |
| 264 | // size can be too small. |
| 265 | initial_young_size = |
| 266 | clamp(scale_by_NewRatio_aligned(InitialHeapSize, GenAlignment), NewSize, max_young_size); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | log_trace(gc, heap)(!(LogImpl<(LogTag::_gc), (LogTag::_heap), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_heap), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("1: Minimum young " SIZE_FORMAT"%" "l" "u" " Initial young " SIZE_FORMAT"%" "l" "u" " Maximum young " SIZE_FORMAT"%" "l" "u", |
| 271 | MinNewSize, initial_young_size, max_young_size); |
| 272 | |
| 273 | // At this point the minimum, initial and maximum sizes |
| 274 | // of the overall heap and of the young generation have been determined. |
| 275 | // The maximum old size can be determined from the maximum young |
| 276 | // and maximum heap size since no explicit flags exist |
| 277 | // for setting the old generation maximum. |
| 278 | MaxOldSize = MAX2(MaxHeapSize - max_young_size, GenAlignment); |
| 279 | |
| 280 | size_t initial_old_size = OldSize; |
| 281 | |
| 282 | // If no explicit command line flag has been set for the |
| 283 | // old generation size, use what is left. |
| 284 | if (!FLAG_IS_CMDLINE(OldSize)(JVMFlag::is_cmdline(Flag_OldSize_enum))) { |
| 285 | // The user has not specified any value but the ergonomics |
| 286 | // may have chosen a value (which may or may not be consistent |
| 287 | // with the overall heap size). In either case make |
| 288 | // the minimum, maximum and initial sizes consistent |
| 289 | // with the young sizes and the overall heap sizes. |
| 290 | MinOldSize = GenAlignment; |
| 291 | initial_old_size = clamp(InitialHeapSize - initial_young_size, MinOldSize, MaxOldSize); |
| 292 | // MaxOldSize has already been made consistent above. |
| 293 | } else { |
| 294 | // OldSize has been explicitly set on the command line. Use it |
| 295 | // for the initial size but make sure the minimum allow a young |
| 296 | // generation to fit as well. |
| 297 | // If the user has explicitly set an OldSize that is inconsistent |
| 298 | // with other command line flags, issue a warning. |
| 299 | // The generation minimums and the overall heap minimum should |
| 300 | // be within one generation alignment. |
| 301 | if (initial_old_size > MaxOldSize) { |
| 302 | log_warning(gc, ergo)(!(LogImpl<(LogTag::_gc), (LogTag::_ergo), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Warning))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_ergo), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Warning>("Inconsistency between maximum heap size and maximum " |
| 303 | "generation sizes: using maximum heap = " SIZE_FORMAT"%" "l" "u" |
| 304 | ", -XX:OldSize flag is being ignored", |
| 305 | MaxHeapSize); |
| 306 | initial_old_size = MaxOldSize; |
| 307 | } |
| 308 | |
| 309 | MinOldSize = MIN2(initial_old_size, MinHeapSize - MinNewSize); |
| 310 | } |
| 311 | |
| 312 | // The initial generation sizes should match the initial heap size, |
| 313 | // if not issue a warning and resize the generations. This behavior |
| 314 | // differs from JDK8 where the generation sizes have higher priority |
| 315 | // than the initial heap size. |
| 316 | if ((initial_old_size + initial_young_size) != InitialHeapSize) { |
| 317 | log_warning(gc, ergo)(!(LogImpl<(LogTag::_gc), (LogTag::_ergo), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Warning))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_ergo), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Warning>("Inconsistency between generation sizes and heap size, resizing " |
| 318 | "the generations to fit the heap."); |
| 319 | |
| 320 | size_t desired_young_size = InitialHeapSize - initial_old_size; |
| 321 | if (InitialHeapSize < initial_old_size) { |
| 322 | // Old want all memory, use minimum for young and rest for old |
| 323 | initial_young_size = MinNewSize; |
| 324 | initial_old_size = InitialHeapSize - MinNewSize; |
| 325 | } else if (desired_young_size > max_young_size) { |
| 326 | // Need to increase both young and old generation |
| 327 | initial_young_size = max_young_size; |
| 328 | initial_old_size = InitialHeapSize - max_young_size; |
| 329 | } else if (desired_young_size < MinNewSize) { |
| 330 | // Need to decrease both young and old generation |
| 331 | initial_young_size = MinNewSize; |
| 332 | initial_old_size = InitialHeapSize - MinNewSize; |
| 333 | } else { |
| 334 | // The young generation boundaries allow us to only update the |
| 335 | // young generation. |
| 336 | initial_young_size = desired_young_size; |
| 337 | } |
| 338 | |
| 339 | log_trace(gc, heap)(!(LogImpl<(LogTag::_gc), (LogTag::_heap), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_heap), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("2: Minimum young " SIZE_FORMAT"%" "l" "u" " Initial young " SIZE_FORMAT"%" "l" "u" " Maximum young " SIZE_FORMAT"%" "l" "u", |
| 340 | MinNewSize, initial_young_size, max_young_size); |
| 341 | } |
| 342 | |
| 343 | // Write back to flags if necessary. |
| 344 | if (NewSize != initial_young_size) { |
| 345 | FLAG_SET_ERGO(NewSize, initial_young_size)(Flag_NewSize_set((initial_young_size), JVMFlagOrigin::ERGONOMIC )); |
| 346 | } |
| 347 | |
| 348 | if (MaxNewSize != max_young_size) { |
| 349 | FLAG_SET_ERGO(MaxNewSize, max_young_size)(Flag_MaxNewSize_set((max_young_size), JVMFlagOrigin::ERGONOMIC )); |
| 350 | } |
| 351 | |
| 352 | if (OldSize != initial_old_size) { |
| 353 | FLAG_SET_ERGO(OldSize, initial_old_size)(Flag_OldSize_set((initial_old_size), JVMFlagOrigin::ERGONOMIC )); |
| 354 | } |
| 355 | |
| 356 | log_trace(gc, heap)(!(LogImpl<(LogTag::_gc), (LogTag::_heap), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_gc), (LogTag::_heap), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Minimum old " SIZE_FORMAT"%" "l" "u" " Initial old " SIZE_FORMAT"%" "l" "u" " Maximum old " SIZE_FORMAT"%" "l" "u", |
| 357 | MinOldSize, OldSize, MaxOldSize); |
| 358 | |
| 359 | DEBUG_ONLY(assert_size_info();)assert_size_info(); |
| 360 | } |
| 361 | |
| 362 | #ifdef ASSERT1 |
| 363 | void GenArguments::assert_flags() { |
| 364 | GCArguments::assert_flags(); |
| 365 | assert(NewSize >= MinNewSize, "Ergonomics decided on a too small young gen size")do { if (!(NewSize >= MinNewSize)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 365, "assert(" "NewSize >= MinNewSize" ") failed", "Ergonomics decided on a too small young gen size" ); ::breakpoint(); } } while (0); |
| 366 | assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes")do { if (!(NewSize <= MaxNewSize)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 366, "assert(" "NewSize <= MaxNewSize" ") failed", "Ergonomics decided on incompatible initial and maximum young gen sizes" ); ::breakpoint(); } } while (0); |
| 367 | assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young gen and heap sizes")do { if (!((JVMFlag::is_default(Flag_MaxNewSize_enum)) || MaxNewSize < MaxHeapSize)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 367, "assert(" "(JVMFlag::is_default(Flag_MaxNewSize_enum)) || MaxNewSize < MaxHeapSize" ") failed", "Ergonomics decided on incompatible maximum young gen and heap sizes" ); ::breakpoint(); } } while (0); |
| 368 | assert(NewSize % GenAlignment == 0, "NewSize alignment")do { if (!(NewSize % GenAlignment == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 368, "assert(" "NewSize % GenAlignment == 0" ") failed", "NewSize alignment" ); ::breakpoint(); } } while (0); |
| 369 | assert(FLAG_IS_DEFAULT(MaxNewSize) || MaxNewSize % GenAlignment == 0, "MaxNewSize alignment")do { if (!((JVMFlag::is_default(Flag_MaxNewSize_enum)) || MaxNewSize % GenAlignment == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 369, "assert(" "(JVMFlag::is_default(Flag_MaxNewSize_enum)) || MaxNewSize % GenAlignment == 0" ") failed", "MaxNewSize alignment"); ::breakpoint(); } } while (0); |
| 370 | assert(OldSize + NewSize <= MaxHeapSize, "Ergonomics decided on incompatible generation and heap sizes")do { if (!(OldSize + NewSize <= MaxHeapSize)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 370, "assert(" "OldSize + NewSize <= MaxHeapSize" ") failed" , "Ergonomics decided on incompatible generation and heap sizes" ); ::breakpoint(); } } while (0); |
| 371 | assert(OldSize % GenAlignment == 0, "OldSize alignment")do { if (!(OldSize % GenAlignment == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 371, "assert(" "OldSize % GenAlignment == 0" ") failed", "OldSize alignment" ); ::breakpoint(); } } while (0); |
| 372 | } |
| 373 | |
| 374 | void GenArguments::assert_size_info() { |
| 375 | GCArguments::assert_size_info(); |
| 376 | // GenArguments::initialize_size_info may update the MaxNewSize |
| 377 | assert(MaxNewSize < MaxHeapSize, "Ergonomics decided on incompatible maximum young and heap sizes")do { if (!(MaxNewSize < MaxHeapSize)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 377, "assert(" "MaxNewSize < MaxHeapSize" ") failed", "Ergonomics decided on incompatible maximum young and heap sizes" ); ::breakpoint(); } } while (0); |
| 378 | assert(MinNewSize <= NewSize, "Ergonomics decided on incompatible minimum and initial young gen sizes")do { if (!(MinNewSize <= NewSize)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 378, "assert(" "MinNewSize <= NewSize" ") failed", "Ergonomics decided on incompatible minimum and initial young gen sizes" ); ::breakpoint(); } } while (0); |
| 379 | assert(NewSize <= MaxNewSize, "Ergonomics decided on incompatible initial and maximum young gen sizes")do { if (!(NewSize <= MaxNewSize)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 379, "assert(" "NewSize <= MaxNewSize" ") failed", "Ergonomics decided on incompatible initial and maximum young gen sizes" ); ::breakpoint(); } } while (0); |
| 380 | assert(MinNewSize % GenAlignment == 0, "_min_young_size alignment")do { if (!(MinNewSize % GenAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 380, "assert(" "MinNewSize % GenAlignment == 0" ") failed", "_min_young_size alignment"); ::breakpoint(); } } while (0); |
| 381 | assert(NewSize % GenAlignment == 0, "_initial_young_size alignment")do { if (!(NewSize % GenAlignment == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 381, "assert(" "NewSize % GenAlignment == 0" ") failed", "_initial_young_size alignment" ); ::breakpoint(); } } while (0); |
| 382 | assert(MaxNewSize % GenAlignment == 0, "MaxNewSize alignment")do { if (!(MaxNewSize % GenAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 382, "assert(" "MaxNewSize % GenAlignment == 0" ") failed", "MaxNewSize alignment"); ::breakpoint(); } } while (0); |
| 383 | assert(MinNewSize <= bound_minus_alignment(MinNewSize, MinHeapSize, GenAlignment),do { if (!(MinNewSize <= bound_minus_alignment(MinNewSize, MinHeapSize, GenAlignment))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 384, "assert(" "MinNewSize <= bound_minus_alignment(MinNewSize, MinHeapSize, GenAlignment)" ") failed", "Ergonomics made minimum young generation larger than minimum heap" ); ::breakpoint(); } } while (0) |
| 384 | "Ergonomics made minimum young generation larger than minimum heap")do { if (!(MinNewSize <= bound_minus_alignment(MinNewSize, MinHeapSize, GenAlignment))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 384, "assert(" "MinNewSize <= bound_minus_alignment(MinNewSize, MinHeapSize, GenAlignment)" ") failed", "Ergonomics made minimum young generation larger than minimum heap" ); ::breakpoint(); } } while (0); |
| 385 | assert(NewSize <= bound_minus_alignment(NewSize, InitialHeapSize, GenAlignment),do { if (!(NewSize <= bound_minus_alignment(NewSize, InitialHeapSize , GenAlignment))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 386, "assert(" "NewSize <= bound_minus_alignment(NewSize, InitialHeapSize, GenAlignment)" ") failed", "Ergonomics made initial young generation larger than initial heap" ); ::breakpoint(); } } while (0) |
| 386 | "Ergonomics made initial young generation larger than initial heap")do { if (!(NewSize <= bound_minus_alignment(NewSize, InitialHeapSize , GenAlignment))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 386, "assert(" "NewSize <= bound_minus_alignment(NewSize, InitialHeapSize, GenAlignment)" ") failed", "Ergonomics made initial young generation larger than initial heap" ); ::breakpoint(); } } while (0); |
| 387 | assert(MaxNewSize <= bound_minus_alignment(MaxNewSize, MaxHeapSize, GenAlignment),do { if (!(MaxNewSize <= bound_minus_alignment(MaxNewSize, MaxHeapSize, GenAlignment))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 388, "assert(" "MaxNewSize <= bound_minus_alignment(MaxNewSize, MaxHeapSize, GenAlignment)" ") failed", "Ergonomics made maximum young generation lager than maximum heap" ); ::breakpoint(); } } while (0) |
| 388 | "Ergonomics made maximum young generation lager than maximum heap")do { if (!(MaxNewSize <= bound_minus_alignment(MaxNewSize, MaxHeapSize, GenAlignment))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 388, "assert(" "MaxNewSize <= bound_minus_alignment(MaxNewSize, MaxHeapSize, GenAlignment)" ") failed", "Ergonomics made maximum young generation lager than maximum heap" ); ::breakpoint(); } } while (0); |
| 389 | assert(MinOldSize <= OldSize, "Ergonomics decided on incompatible minimum and initial old gen sizes")do { if (!(MinOldSize <= OldSize)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 389, "assert(" "MinOldSize <= OldSize" ") failed", "Ergonomics decided on incompatible minimum and initial old gen sizes" ); ::breakpoint(); } } while (0); |
| 390 | assert(OldSize <= MaxOldSize, "Ergonomics decided on incompatible initial and maximum old gen sizes")do { if (!(OldSize <= MaxOldSize)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 390, "assert(" "OldSize <= MaxOldSize" ") failed", "Ergonomics decided on incompatible initial and maximum old gen sizes" ); ::breakpoint(); } } while (0); |
| 391 | assert(MaxOldSize % GenAlignment == 0, "MaxOldSize alignment")do { if (!(MaxOldSize % GenAlignment == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 391, "assert(" "MaxOldSize % GenAlignment == 0" ") failed", "MaxOldSize alignment"); ::breakpoint(); } } while (0); |
| 392 | assert(OldSize % GenAlignment == 0, "OldSize alignment")do { if (!(OldSize % GenAlignment == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 392, "assert(" "OldSize % GenAlignment == 0" ") failed", "OldSize alignment" ); ::breakpoint(); } } while (0); |
| 393 | assert(MaxHeapSize <= (MaxNewSize + MaxOldSize), "Total maximum heap sizes must be sum of generation maximum sizes")do { if (!(MaxHeapSize <= (MaxNewSize + MaxOldSize))) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 393, "assert(" "MaxHeapSize <= (MaxNewSize + MaxOldSize)" ") failed", "Total maximum heap sizes must be sum of generation maximum sizes" ); ::breakpoint(); } } while (0); |
| 394 | assert(MinNewSize + MinOldSize <= MinHeapSize, "Minimum generation sizes exceed minimum heap size")do { if (!(MinNewSize + MinOldSize <= MinHeapSize)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 394, "assert(" "MinNewSize + MinOldSize <= MinHeapSize" ") failed" , "Minimum generation sizes exceed minimum heap size"); ::breakpoint (); } } while (0); |
| 395 | assert(NewSize + OldSize == InitialHeapSize, "Initial generation sizes should match initial heap size")do { if (!(NewSize + OldSize == InitialHeapSize)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 395, "assert(" "NewSize + OldSize == InitialHeapSize" ") failed" , "Initial generation sizes should match initial heap size"); ::breakpoint(); } } while (0); |
| 396 | assert(MaxNewSize + MaxOldSize == MaxHeapSize, "Maximum generation sizes should match maximum heap size")do { if (!(MaxNewSize + MaxOldSize == MaxHeapSize)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/gc/shared/genArguments.cpp" , 396, "assert(" "MaxNewSize + MaxOldSize == MaxHeapSize" ") failed" , "Maximum generation sizes should match maximum heap size"); ::breakpoint(); } } while (0); |
| 397 | } |
| 398 | #endif // ASSERT |