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 "runtime/arguments.hpp"
27 #include "runtime/commandLineFlagConstraintsGC.hpp"
28 #include "runtime/commandLineFlagRangeList.hpp"
29 #include "runtime/globals.hpp"
30 #include "utilities/defaultStream.hpp"
31
32 #if INCLUDE_ALL_GCS
33 #include "gc/g1/g1_globals.hpp"
34 #include "gc/g1/heapRegionBounds.inline.hpp"
35 #include "gc/parallel/parallelScavengeHeap.hpp"
36 #include "gc/shared/plab.hpp"
37 #endif // INCLUDE_ALL_GCS
38 #ifdef COMPILER1
39 #include "c1/c1_globals.hpp"
40 #endif // COMPILER1
41 #ifdef COMPILER2
42 #include "opto/c2_globals.hpp"
43 #endif // COMPILER2
44
45 static Flag::Error MinPLABSizeBounds(const char* name, size_t value, bool verbose) {
46 #if INCLUDE_ALL_GCS
47 if ((UseConcMarkSweepGC || UseG1GC) && (value < PLAB::min_size())) {
48 CommandLineError::print(verbose,
49 "%s (" SIZE_FORMAT ") must be "
50 "greater than or equal to ergonomic PLAB minimum size (" SIZE_FORMAT ")\n",
51 name, value, PLAB::min_size());
52 return Flag::VIOLATES_CONSTRAINT;
53 }
54 #endif // INCLUDE_ALL_GCS
55 return Flag::SUCCESS;
56 }
57
58 static Flag::Error MaxPLABSizeBounds(const char* name, size_t value, bool verbose) {
59 #if INCLUDE_ALL_GCS
60 if ((UseConcMarkSweepGC || UseG1GC) && (value > PLAB::max_size())) {
61 CommandLineError::print(verbose,
62 "%s (" SIZE_FORMAT ") must be "
63 "less than or equal to ergonomic PLAB maximum size (" SIZE_FORMAT ")\n",
64 name, value, PLAB::max_size());
65 return Flag::VIOLATES_CONSTRAINT;
66 }
67 #endif // INCLUDE_ALL_GCS
68 return Flag::SUCCESS;
69 }
70
71 static Flag::Error MinMaxPLABSizeBounds(const char* name, size_t value, bool verbose) {
72 if (MinPLABSizeBounds(name, value, verbose) == Flag::SUCCESS) {
73 return MaxPLABSizeBounds(name, value, verbose);
74 }
75 return Flag::VIOLATES_CONSTRAINT;
76 }
77
78 Flag::Error YoungPLABSizeConstraintFunc(size_t value, bool verbose) {
79 return MinMaxPLABSizeBounds("YoungPLABSize", value, verbose);
80 }
81
82 Flag::Error MinHeapFreeRatioConstraintFunc(uintx value, bool verbose) {
83 if (value > MaxHeapFreeRatio) {
84 CommandLineError::print(verbose,
85 "MinHeapFreeRatio (" UINTX_FORMAT ") must be "
86 "less than or equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
87 value, MaxHeapFreeRatio);
88 return Flag::VIOLATES_CONSTRAINT;
89 } else {
90 return Flag::SUCCESS;
91 }
92 }
93
94 Flag::Error MaxHeapFreeRatioConstraintFunc(uintx value, bool verbose) {
95 if (value < MinHeapFreeRatio) {
96 CommandLineError::print(verbose,
97 "MaxHeapFreeRatio (" UINTX_FORMAT ") must be "
98 "greater than or equal to MinHeapFreeRatio (" UINTX_FORMAT ")\n",
99 value, MinHeapFreeRatio);
100 return Flag::VIOLATES_CONSTRAINT;
101 } else {
102 return Flag::SUCCESS;
103 }
104 }
105
106 Flag::Error MinMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) {
107 if (value > MaxMetaspaceFreeRatio) {
108 CommandLineError::print(verbose,
109 "MinMetaspaceFreeRatio (" UINTX_FORMAT ") must be "
110 "less than or equal to MaxMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
111 value, MaxMetaspaceFreeRatio);
112 return Flag::VIOLATES_CONSTRAINT;
113 } else {
114 return Flag::SUCCESS;
115 }
116 }
117
118 Flag::Error MaxMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) {
119 if (value < MinMetaspaceFreeRatio) {
120 CommandLineError::print(verbose,
121 "MaxMetaspaceFreeRatio (" UINTX_FORMAT ") must be "
122 "greater than or equal to MinMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
123 value, MinMetaspaceFreeRatio);
124 return Flag::VIOLATES_CONSTRAINT;
125 } else {
126 return Flag::SUCCESS;
127 }
128 }
129
130 // GC workaround for "-XX:+UseConcMarkSweepGC"
131 // which sets InitialTenuringThreshold to 7 but leaves MaxTenuringThreshold remaining at 6
132 // and therefore would invalidate the constraint
133 #define UseConcMarkSweepGCWorkaroundIfNeeded(initial, max) { \
134 if ((initial == 7) && (max == 6)) { \
135 return Flag::SUCCESS; \
136 } \
137 }
138
139 Flag::Error InitialTenuringThresholdConstraintFunc(uintx value, bool verbose) {
140 UseConcMarkSweepGCWorkaroundIfNeeded(value, MaxTenuringThreshold);
141
142 if (value > MaxTenuringThreshold) {
143 CommandLineError::print(verbose,
144 "InitialTenuringThreshold (" UINTX_FORMAT ") must be "
145 "less than or equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n",
146 value, MaxTenuringThreshold);
147 return Flag::VIOLATES_CONSTRAINT;
148 } else {
149 return Flag::SUCCESS;
150 }
151 }
152
153 Flag::Error MaxTenuringThresholdConstraintFunc(uintx value, bool verbose) {
154 UseConcMarkSweepGCWorkaroundIfNeeded(InitialTenuringThreshold, value);
155
156 if (value < InitialTenuringThreshold) {
157 CommandLineError::print(verbose,
158 "MaxTenuringThreshold (" UINTX_FORMAT ") must be "
159 "greater than or equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n",
160 value, InitialTenuringThreshold);
161 return Flag::VIOLATES_CONSTRAINT;
162 } else {
163 return Flag::SUCCESS;
164 }
165 }
166
167 #if INCLUDE_ALL_GCS
168 Flag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) {
169 if (value > G1MaxNewSizePercent) {
170 CommandLineError::print(verbose,
171 "G1NewSizePercent (" UINTX_FORMAT ") must be "
172 "less than or equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n",
173 value, G1MaxNewSizePercent);
174 return Flag::VIOLATES_CONSTRAINT;
175 } else {
176 return Flag::SUCCESS;
177 }
178 }
179
180 Flag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) {
181 if (value < G1NewSizePercent) {
182 CommandLineError::print(verbose,
183 "G1MaxNewSizePercent (" UINTX_FORMAT ") must be "
184 "greater than or equal to G1NewSizePercent (" UINTX_FORMAT ")\n",
185 value, G1NewSizePercent);
186 return Flag::VIOLATES_CONSTRAINT;
187 } else {
188 return Flag::SUCCESS;
189 }
190 }
191
192 #endif // INCLUDE_ALL_GCS
193
194 Flag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) {
195 if (value > CMSOldPLABMax) {
196 CommandLineError::print(verbose,
197 "CMSOldPLABMin (" SIZE_FORMAT ") must be "
198 "less than or equal to CMSOldPLABMax (" SIZE_FORMAT ")\n",
199 value, CMSOldPLABMax);
200 return Flag::VIOLATES_CONSTRAINT;
201 } else {
202 return Flag::SUCCESS;
203 }
204 }
205
206 Flag::Error CMSPrecleanDenominatorConstraintFunc(uintx value, bool verbose) {
207 if (value <= CMSPrecleanNumerator) {
208 CommandLineError::print(verbose,
209 "CMSPrecleanDenominator (" UINTX_FORMAT ") must be "
210 "strickly greater than CMSPrecleanNumerator (" UINTX_FORMAT ")\n",
211 value, CMSPrecleanNumerator);
212 return Flag::VIOLATES_CONSTRAINT;
213 } else {
214 return Flag::SUCCESS;
215 }
216 }
217
218 Flag::Error CMSPrecleanNumeratorConstraintFunc(uintx value, bool verbose) {
219 if (value > (CMSPrecleanDenominator - 1)) {
220 CommandLineError::print(verbose,
221 "CMSPrecleanNumerator (" UINTX_FORMAT ") must be "
222 "less than or equal to CMSPrecleanDenominator - 1 (" UINTX_FORMAT ")\n",
223 value, CMSPrecleanDenominator - 1);
224 return Flag::VIOLATES_CONSTRAINT;
225 } else {
226 return Flag::SUCCESS;
227 }
228 }
229
230 Flag::Error SurvivorAlignmentInBytesConstraintFunc(intx value, bool verbose) {
231 if (value != 0) {
232 if (!is_power_of_2(value)) {
233 CommandLineError::print(verbose,
234 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be "
235 "power of 2\n",
236 value);
237 return Flag::VIOLATES_CONSTRAINT;
238 }
239 if (value < ObjectAlignmentInBytes) {
240 CommandLineError::print(verbose,
241 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be "
242 "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n",
243 value, ObjectAlignmentInBytes);
|
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/collectedHeap.hpp"
27 #include "gc/shared/collectorPolicy.hpp"
28 #include "gc/shared/threadLocalAllocBuffer.hpp"
29 #include "runtime/arguments.hpp"
30 #include "runtime/commandLineFlagConstraintsGC.hpp"
31 #include "runtime/commandLineFlagRangeList.hpp"
32 #include "runtime/globals.hpp"
33 #include "runtime/globals_extension.hpp"
34 #include "utilities/defaultStream.hpp"
35
36 #if INCLUDE_ALL_GCS
37 #include "gc/g1/g1_globals.hpp"
38 #include "gc/g1/heapRegionBounds.inline.hpp"
39 #include "gc/shared/plab.hpp"
40 #endif // INCLUDE_ALL_GCS
41 #ifdef COMPILER1
42 #include "c1/c1_globals.hpp"
43 #endif // COMPILER1
44 #ifdef COMPILER2
45 #include "opto/c2_globals.hpp"
46 #endif // COMPILER2
47
48 #if INCLUDE_ALL_GCS
49 static Flag::Error ParallelGCThreadsAndCMSWorkQueueDrainThreshold(uint threads, uintx threshold, bool verbose) {
50 // CMSWorkQueueDrainThreshold is verified to be less than max_juint
51 if (UseConcMarkSweepGC && (threads > (uint)(max_jint / (uint)threshold))) {
52 CommandLineError::print(verbose,
53 "ParallelGCThreads (" UINT32_FORMAT ") or CMSWorkQueueDrainThreshold ("
54 UINTX_FORMAT ") is too large\n",
55 threads, threshold);
56 return Flag::VIOLATES_CONSTRAINT;
57 }
58 return Flag::SUCCESS;
59 }
60 #endif
61
62 // As ParallelGCThreads differs among GC modes, we need constraint function.
63 Flag::Error ParallelGCThreadsConstraintFunc(uint value, bool verbose) {
64 Flag::Error status = Flag::SUCCESS;
65
66 #if INCLUDE_ALL_GCS
67 // Parallel GC passes ParallelGCThreads when creating GrowableArray as 'int' type parameter.
68 // So can't exceed with "max_jint"
69 if (UseParallelGC && (value > (uint)max_jint)) {
70 CommandLineError::print(verbose,
71 "ParallelGCThreads (" UINT32_FORMAT ") must be "
72 "less than or equal to " UINT32_FORMAT " for Parallel GC\n",
73 value, max_jint);
74 return Flag::VIOLATES_CONSTRAINT;
75 }
76 // To avoid overflow at ParScanClosure::do_oop_work.
77 if (UseConcMarkSweepGC && (value > (max_jint / 10))) {
78 CommandLineError::print(verbose,
79 "ParallelGCThreads (" UINT32_FORMAT ") must be "
80 "less than or equal to " UINT32_FORMAT " for CMS GC\n",
81 value, (max_jint / 10));
82 return Flag::VIOLATES_CONSTRAINT;
83 }
84 status = ParallelGCThreadsAndCMSWorkQueueDrainThreshold(value, CMSWorkQueueDrainThreshold, verbose);
85 #endif
86 return status;
87 }
88
89 // As ConcGCThreads should be smaller than ParallelGCThreads,
90 // we need constraint function.
91 Flag::Error ConcGCThreadsConstraintFunc(uint value, bool verbose) {
92 #if INCLUDE_ALL_GCS
93 // CMS and G1 GCs use ConcGCThreads.
94 if ((UseConcMarkSweepGC || UseG1GC) && (value > ParallelGCThreads)) {
95 CommandLineError::print(verbose,
96 "ConcGCThreads (" UINT32_FORMAT ") must be "
97 "less than or equal to ParallelGCThreads (" UINT32_FORMAT ")\n",
98 value, ParallelGCThreads);
99 return Flag::VIOLATES_CONSTRAINT;
100 }
101 #endif
102 return Flag::SUCCESS;
103 }
104
105 static Flag::Error MinPLABSizeBounds(const char* name, size_t value, bool verbose) {
106 #if INCLUDE_ALL_GCS
107 if ((UseConcMarkSweepGC || UseG1GC) && (value < PLAB::min_size())) {
108 CommandLineError::print(verbose,
109 "%s (" SIZE_FORMAT ") must be "
110 "greater than or equal to ergonomic PLAB minimum size (" SIZE_FORMAT ")\n",
111 name, value, PLAB::min_size());
112 return Flag::VIOLATES_CONSTRAINT;
113 }
114 #endif // INCLUDE_ALL_GCS
115 return Flag::SUCCESS;
116 }
117
118 static Flag::Error MaxPLABSizeBounds(const char* name, size_t value, bool verbose) {
119 #if INCLUDE_ALL_GCS
120 if ((UseConcMarkSweepGC || UseG1GC) && (value > PLAB::max_size())) {
121 CommandLineError::print(verbose,
122 "%s (" SIZE_FORMAT ") must be "
123 "less than or equal to ergonomic PLAB maximum size (" SIZE_FORMAT ")\n",
124 name, value, PLAB::max_size());
125 return Flag::VIOLATES_CONSTRAINT;
126 }
127 #endif // INCLUDE_ALL_GCS
128 return Flag::SUCCESS;
129 }
130
131 static Flag::Error MinMaxPLABSizeBounds(const char* name, size_t value, bool verbose) {
132 Flag::Error status = MinPLABSizeBounds(name, value, verbose);
133
134 if (status == Flag::SUCCESS) {
135 return MaxPLABSizeBounds(name, value, verbose);
136 }
137 return status;
138 }
139
140 Flag::Error YoungPLABSizeConstraintFunc(size_t value, bool verbose) {
141 return MinMaxPLABSizeBounds("YoungPLABSize", value, verbose);
142 }
143
144 Flag::Error OldPLABSizeConstraintFunc(size_t value, bool verbose) {
145 Flag::Error status = Flag::SUCCESS;
146
147 #if INCLUDE_ALL_GCS
148 if (UseConcMarkSweepGC) {
149 if (value == 0) {
150 CommandLineError::print(verbose,
151 "OldPLABSize (" SIZE_FORMAT ") must be greater than 0",
152 value);
153 return Flag::VIOLATES_CONSTRAINT;
154 }
155 // For CMS, OldPLABSize is the number of free blocks of a given size that are used when
156 // replenishing the local per-worker free list caches.
157 // For more details, please refer to Arguments::set_cms_and_parnew_gc_flags().
158 status = MaxPLABSizeBounds("OldPLABSize", value, verbose);
159 } else {
160 status = MinMaxPLABSizeBounds("OldPLABSize", value, verbose);
161 }
162 #endif
163 return status;
164 }
165
166 Flag::Error MinHeapFreeRatioConstraintFunc(uintx value, bool verbose) {
167 if (value > MaxHeapFreeRatio) {
168 CommandLineError::print(verbose,
169 "MinHeapFreeRatio (" UINTX_FORMAT ") must be "
170 "less than or equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
171 value, MaxHeapFreeRatio);
172 return Flag::VIOLATES_CONSTRAINT;
173 } else {
174 return Flag::SUCCESS;
175 }
176 }
177
178 Flag::Error MaxHeapFreeRatioConstraintFunc(uintx value, bool verbose) {
179 if (value < MinHeapFreeRatio) {
180 CommandLineError::print(verbose,
181 "MaxHeapFreeRatio (" UINTX_FORMAT ") must be "
182 "greater than or equal to MinHeapFreeRatio (" UINTX_FORMAT ")\n",
183 value, MinHeapFreeRatio);
184 return Flag::VIOLATES_CONSTRAINT;
185 } else {
186 return Flag::SUCCESS;
187 }
188 }
189
190 static Flag::Error CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(size_t maxHeap, intx softRef, bool verbose) {
191 if ((softRef > 0) && ((maxHeap / M) > (max_uintx / softRef))) {
192 CommandLineError::print(verbose,
193 "Desired lifetime of SoftReferences cannot be expressed correctly. "
194 "MaxHeapSize (" SIZE_FORMAT ") or SoftRefLRUPolicyMSPerMB "
195 "(" INTX_FORMAT ") is too large\n",
196 maxHeap, softRef);
197 return Flag::VIOLATES_CONSTRAINT;
198 } else {
199 return Flag::SUCCESS;
200 }
201 }
202
203 Flag::Error SoftRefLRUPolicyMSPerMBConstraintFunc(intx value, bool verbose) {
204 return CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(MaxHeapSize, value, verbose);
205 }
206
207 Flag::Error MinMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) {
208 if (value > MaxMetaspaceFreeRatio) {
209 CommandLineError::print(verbose,
210 "MinMetaspaceFreeRatio (" UINTX_FORMAT ") must be "
211 "less than or equal to MaxMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
212 value, MaxMetaspaceFreeRatio);
213 return Flag::VIOLATES_CONSTRAINT;
214 } else {
215 return Flag::SUCCESS;
216 }
217 }
218
219 Flag::Error MaxMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) {
220 if (value < MinMetaspaceFreeRatio) {
221 CommandLineError::print(verbose,
222 "MaxMetaspaceFreeRatio (" UINTX_FORMAT ") must be "
223 "greater than or equal to MinMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
224 value, MinMetaspaceFreeRatio);
225 return Flag::VIOLATES_CONSTRAINT;
226 } else {
227 return Flag::SUCCESS;
228 }
229 }
230
231 Flag::Error InitialTenuringThresholdConstraintFunc(uintx value, bool verbose) {
232 #if INCLUDE_ALL_GCS
233 // InitialTenuringThreshold is only used for ParallelGC.
234 if (UseParallelGC && (value > MaxTenuringThreshold)) {
235 CommandLineError::print(verbose,
236 "InitialTenuringThreshold (" UINTX_FORMAT ") must be "
237 "less than or equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n",
238 value, MaxTenuringThreshold);
239 return Flag::VIOLATES_CONSTRAINT;
240 }
241 #endif
242 return Flag::SUCCESS;
243 }
244
245 Flag::Error MaxTenuringThresholdConstraintFunc(uintx value, bool verbose) {
246 #if INCLUDE_ALL_GCS
247 // As only ParallelGC uses InitialTenuringThreshold,
248 // we don't need to compare InitialTenuringThreshold with MaxTenuringThreshold.
249 if (UseParallelGC && (value < InitialTenuringThreshold)) {
250 CommandLineError::print(verbose,
251 "MaxTenuringThreshold (" UINTX_FORMAT ") must be "
252 "greater than or equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n",
253 value, InitialTenuringThreshold);
254 return Flag::VIOLATES_CONSTRAINT;
255 }
256 #endif
257
258 // MaxTenuringThreshold=0 means NeverTenure=false && AlwaysTenure=true
259 if ((value == 0) && (NeverTenure || !AlwaysTenure)) {
260 CommandLineError::print(verbose,
261 "MaxTenuringThreshold (0) should match to NeverTenure=false "
262 "&& AlwaysTenure=true. But we have NeverTenure=%s "
263 "AlwaysTenure=%s\n",
264 NeverTenure ? "true" : "false",
265 AlwaysTenure ? "true" : "false");
266 return Flag::VIOLATES_CONSTRAINT;
267 }
268 return Flag::SUCCESS;
269 }
270
271 #if INCLUDE_ALL_GCS
272 Flag::Error G1RSetRegionEntriesConstraintFunc(intx value, bool verbose) {
273 if (!UseG1GC) return Flag::SUCCESS;
274
275 // Default value of G1RSetRegionEntries=0 means will be set ergonomically.
276 // Minimum value is 1.
277 if (FLAG_IS_CMDLINE(G1RSetRegionEntries) && (value < 1)) {
278 CommandLineError::print(verbose,
279 "G1RSetRegionEntries (" INTX_FORMAT ") must be "
280 "greater than or equal to 1\n",
281 value);
282 return Flag::VIOLATES_CONSTRAINT;
283 } else {
284 return Flag::SUCCESS;
285 }
286 }
287
288 Flag::Error G1RSetSparseRegionEntriesConstraintFunc(intx value, bool verbose) {
289 if (!UseG1GC) return Flag::SUCCESS;
290
291 // Default value of G1RSetSparseRegionEntries=0 means will be set ergonomically.
292 // Minimum value is 1.
293 if (FLAG_IS_CMDLINE(G1RSetSparseRegionEntries) && (value < 1)) {
294 CommandLineError::print(verbose,
295 "G1RSetSparseRegionEntries (" INTX_FORMAT ") must be "
296 "greater than or equal to 1\n",
297 value);
298 return Flag::VIOLATES_CONSTRAINT;
299 } else {
300 return Flag::SUCCESS;
301 }
302 }
303
304 Flag::Error G1YoungSurvRateNumRegionsSummaryConstraintFunc(intx value, bool verbose) {
305 if (!UseG1GC) return Flag::SUCCESS;
306
307 if (value > (intx)HeapRegionBounds::target_number()) {
308 CommandLineError::print(verbose,
309 "G1YoungSurvRateNumRegionsSummary (" INTX_FORMAT ") must be "
310 "less than or equal to region count (" SIZE_FORMAT ")\n",
311 value, HeapRegionBounds::target_number());
312 return Flag::VIOLATES_CONSTRAINT;
313 } else {
314 return Flag::SUCCESS;
315 }
316 }
317
318 Flag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) {
319 if (!UseG1GC) return Flag::SUCCESS;
320
321 // Default value of G1HeapRegionSize=0 means will be set ergonomically.
322 if (FLAG_IS_CMDLINE(G1HeapRegionSize) && (value < HeapRegionBounds::min_size())) {
323 CommandLineError::print(verbose,
324 "G1HeapRegionSize (" SIZE_FORMAT ") must be "
325 "greater than or equal to ergonomic heap region minimum size\n",
326 value);
327 return Flag::VIOLATES_CONSTRAINT;
328 } else {
329 return Flag::SUCCESS;
330 }
331 }
332
333 Flag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) {
334 if (!UseG1GC) return Flag::SUCCESS;
335
336 if (value > G1MaxNewSizePercent) {
337 CommandLineError::print(verbose,
338 "G1NewSizePercent (" UINTX_FORMAT ") must be "
339 "less than or equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n",
340 value, G1MaxNewSizePercent);
341 return Flag::VIOLATES_CONSTRAINT;
342 } else {
343 return Flag::SUCCESS;
344 }
345 }
346
347 Flag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) {
348 if (!UseG1GC) return Flag::SUCCESS;
349
350 if (value < G1NewSizePercent) {
351 CommandLineError::print(verbose,
352 "G1MaxNewSizePercent (" UINTX_FORMAT ") must be "
353 "greater than or equal to G1NewSizePercent (" UINTX_FORMAT ")\n",
354 value, G1NewSizePercent);
355 return Flag::VIOLATES_CONSTRAINT;
356 } else {
357 return Flag::SUCCESS;
358 }
359 }
360 #endif // INCLUDE_ALL_GCS
361
362 Flag::Error ParGCStridesPerThreadConstraintFunc(uintx value, bool verbose) {
363 #if INCLUDE_ALL_GCS
364 if (UseConcMarkSweepGC && (value > ((uintx)max_jint / (uintx)ParallelGCThreads))) {
365 CommandLineError::print(verbose,
366 "ParGCStridesPerThread (" UINTX_FORMAT ") must be "
367 "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n",
368 value, ((uintx)max_jint / (uintx)ParallelGCThreads));
369 return Flag::VIOLATES_CONSTRAINT;
370 }
371 #endif
372 return Flag::SUCCESS;
373 }
374
375 Flag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) {
376 Flag::Error status = Flag::SUCCESS;
377
378 #if INCLUDE_ALL_GCS
379 if (UseConcMarkSweepGC) {
380 if (value > CMSOldPLABMax) {
381 CommandLineError::print(verbose,
382 "CMSOldPLABMin (" SIZE_FORMAT ") must be "
383 "less than or equal to CMSOldPLABMax (" SIZE_FORMAT ")\n",
384 value, CMSOldPLABMax);
385 return Flag::VIOLATES_CONSTRAINT;
386 }
387 status = MaxPLABSizeBounds("CMSOldPLABMin", value, verbose);
388 }
389 #endif
390 return status;
391 }
392
393 Flag::Error CMSOldPLABMaxConstraintFunc(size_t value, bool verbose) {
394 Flag::Error status = Flag::SUCCESS;
395
396 #if INCLUDE_ALL_GCS
397 if (UseConcMarkSweepGC) {
398 status = MaxPLABSizeBounds("CMSOldPLABMax", value, verbose);
399 }
400 #endif
401 return status;
402 }
403
404 Flag::Error MarkStackSizeConstraintFunc(size_t value, bool verbose) {
405 if (value > MarkStackSizeMax) {
406 CommandLineError::print(verbose,
407 "MarkStackSize (" SIZE_FORMAT ") must be "
408 "less than or equal to MarkStackSizeMax (" SIZE_FORMAT ")\n",
409 value, MarkStackSizeMax);
410 return Flag::VIOLATES_CONSTRAINT;
411 } else {
412 return Flag::SUCCESS;
413 }
414 }
415
416 Flag::Error CMSPrecleanDenominatorConstraintFunc(uintx value, bool verbose) {
417 #if INCLUDE_ALL_GCS
418 if (UseConcMarkSweepGC && (value <= CMSPrecleanNumerator)) {
419 CommandLineError::print(verbose,
420 "CMSPrecleanDenominator (" UINTX_FORMAT ") must be "
421 "strickly greater than CMSPrecleanNumerator (" UINTX_FORMAT ")\n",
422 value, CMSPrecleanNumerator);
423 return Flag::VIOLATES_CONSTRAINT;
424 }
425 #endif
426 return Flag::SUCCESS;
427 }
428
429 Flag::Error CMSPrecleanNumeratorConstraintFunc(uintx value, bool verbose) {
430 #if INCLUDE_ALL_GCS
431 if (UseConcMarkSweepGC && (value >= CMSPrecleanDenominator)) {
432 CommandLineError::print(verbose,
433 "CMSPrecleanNumerator (" UINTX_FORMAT ") must be "
434 "less than CMSPrecleanDenominator (" UINTX_FORMAT ")\n",
435 value, CMSPrecleanDenominator);
436 return Flag::VIOLATES_CONSTRAINT;
437 }
438 #endif
439 return Flag::SUCCESS;
440 }
441
442 Flag::Error CMSWorkQueueDrainThresholdConstraintFunc(uintx value, bool verbose) {
443 #if INCLUDE_ALL_GCS
444 if (UseConcMarkSweepGC) {
445 return ParallelGCThreadsAndCMSWorkQueueDrainThreshold(ParallelGCThreads, value, verbose);
446 }
447 #endif
448 return Flag::SUCCESS;
449 }
450
451 Flag::Error MaxGCPauseMillisConstraintFunc(uintx value, bool verbose) {
452 #if INCLUDE_ALL_GCS
453 if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) {
454 CommandLineError::print(verbose,
455 "MaxGCPauseMillis (" UINTX_FORMAT ") must be "
456 "less than GCPauseIntervalMillis (" UINTX_FORMAT ")\n",
457 value, GCPauseIntervalMillis);
458 return Flag::VIOLATES_CONSTRAINT;
459 }
460 #endif
461
462 return Flag::SUCCESS;
463 }
464
465 Flag::Error GCPauseIntervalMillisConstraintFunc(uintx value, bool verbose) {
466 #if INCLUDE_ALL_GCS
467 if (UseG1GC) {
468 if (FLAG_IS_CMDLINE(GCPauseIntervalMillis)) {
469 if (value < 1) {
470 CommandLineError::print(verbose,
471 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
472 "greater than or equal to 1\n",
473 value);
474 return Flag::VIOLATES_CONSTRAINT;
475 }
476 if (value <= MaxGCPauseMillis) {
477 CommandLineError::print(verbose,
478 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
479 "greater than MaxGCPauseMillis (" UINTX_FORMAT ")\n",
480 value, MaxGCPauseMillis);
481 return Flag::VIOLATES_CONSTRAINT;
482 }
483 }
484 }
485 #endif
486 return Flag::SUCCESS;
487 }
488
489 Flag::Error InitialBootClassLoaderMetaspaceSizeConstraintFunc(size_t value, bool verbose) {
490 size_t aligned_max = (size_t)align_size_down(max_uintx/2, Metaspace::reserve_alignment_words());
491 if (value > aligned_max) {
492 CommandLineError::print(verbose,
493 "InitialBootClassLoaderMetaspaceSize (" SIZE_FORMAT ") must be "
494 "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n",
495 value, aligned_max);
496 return Flag::VIOLATES_CONSTRAINT;
497 }
498 return Flag::SUCCESS;
499 }
500
501 static Flag::Error MaxSizeForHeapAlignment(const char* name, size_t value, bool verbose) {
502 // For G1 GC, we don't know until G1CollectorPolicy is created.
503 size_t heap_alignment;
504
505 #if INCLUDE_ALL_GCS
506 if (UseG1GC) {
507 heap_alignment = HeapRegionBounds::max_size();
508 } else
509 #endif
510 {
511 heap_alignment = CollectorPolicy::compute_heap_alignment();
512 }
513
514 // Not to overflow 'align_size_up(value, _heap_alignment) used from CollectorPolicy::initialize_flags()'.
515 size_t aligned_max = ((max_uintx - heap_alignment) & ~(heap_alignment-1));
516 if (value > aligned_max) {
517 CommandLineError::print(verbose,
518 "%s (" SIZE_FORMAT ") must be "
519 "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n",
520 name, value, aligned_max);
521 return Flag::VIOLATES_CONSTRAINT;
522 }
523 return Flag::SUCCESS;
524 }
525
526 Flag::Error InitialHeapSizeConstraintFunc(size_t value, bool verbose) {
527 return MaxSizeForHeapAlignment("InitialHeapSize", value, verbose);
528 }
529
530 Flag::Error MaxHeapSizeConstraintFunc(size_t value, bool verbose) {
531 Flag::Error status = MaxSizeForHeapAlignment("MaxHeapSize", value, verbose);
532
533 if (status == Flag::SUCCESS) {
534 status = CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(value, SoftRefLRUPolicyMSPerMB, verbose);
535 }
536 return status;
537 }
538
539 Flag::Error NewSizeConstraintFunc(size_t value, bool verbose) {
540 #ifdef _LP64
541 #if INCLUDE_ALL_GCS
542 // Overflow would happen for uint type variable of YoungGenSizer::_min_desired_young_length
543 // when the value to be assigned exceeds uint range.
544 // i.e. result of '(uint)(NewSize / region size(1~32MB))'
545 // So maximum of NewSize should be 'max_juint * 1M'
546 if (UseG1GC && (value > (max_juint * 1 * M))) {
547 CommandLineError::print(verbose,
548 "NewSize (" SIZE_FORMAT ") must be less than ergonomic maximum value\n",
549 value);
550 return Flag::VIOLATES_CONSTRAINT;
551 }
552 #endif // INCLUDE_ALL_GCS
553 #endif // _LP64
554 return Flag::SUCCESS;
555 }
556
557 Flag::Error MinTLABSizeConstraintFunc(size_t value, bool verbose) {
558 // At least, alignment reserve area is needed.
559 if (value < ThreadLocalAllocBuffer::alignment_reserve_in_bytes()) {
560 CommandLineError::print(verbose,
561 "MinTLABSize (" SIZE_FORMAT ") must be "
562 "greater than or equal to reserved area in TLAB (" SIZE_FORMAT ")\n",
563 value, ThreadLocalAllocBuffer::alignment_reserve_in_bytes());
564 return Flag::VIOLATES_CONSTRAINT;
565 } else {
566 return Flag::SUCCESS;
567 }
568 }
569
570 Flag::Error TLABSizeConstraintFunc(size_t value, bool verbose) {
571 // Skip for default value of zero which means set ergonomically.
572 if (FLAG_IS_CMDLINE(TLABSize)) {
573 if (value < MinTLABSize) {
574 CommandLineError::print(verbose,
575 "TLABSize (" SIZE_FORMAT ") must be "
576 "greater than or equal to MinTLABSize (" SIZE_FORMAT ")\n",
577 value, MinTLABSize);
578 return Flag::VIOLATES_CONSTRAINT;
579 }
580 if (value > (ThreadLocalAllocBuffer::max_size() * HeapWordSize)) {
581 CommandLineError::print(verbose,
582 "TLABSize (" SIZE_FORMAT ") must be "
583 "less than or equal to ergonomic TLAB maximum size (" SIZE_FORMAT ")\n",
584 value, (ThreadLocalAllocBuffer::max_size() * HeapWordSize));
585 return Flag::VIOLATES_CONSTRAINT;
586 }
587 }
588 return Flag::SUCCESS;
589 }
590
591 Flag::Error SurvivorRatioConstraintFunc(uintx value, bool verbose) {
592 if (FLAG_IS_CMDLINE(SurvivorRatio) &&
593 (value > (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment()))) {
594 CommandLineError::print(verbose,
595 "SurvivorRatio (" UINTX_FORMAT ") must be "
596 "less than or equal to ergonomic SurvivorRatio maximum (" SIZE_FORMAT ")\n",
597 value,
598 (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment()));
599 return Flag::VIOLATES_CONSTRAINT;
600 } else {
601 return Flag::SUCCESS;
602 }
603 }
604
605 Flag::Error MetaspaceSizeConstraintFunc(size_t value, bool verbose) {
606 if (value > MaxMetaspaceSize) {
607 CommandLineError::print(verbose,
608 "MetaspaceSize (" SIZE_FORMAT ") must be "
609 "less than or equal to MaxMetaspaceSize (" SIZE_FORMAT ")\n",
610 value, MaxMetaspaceSize);
611 return Flag::VIOLATES_CONSTRAINT;
612 } else {
613 return Flag::SUCCESS;
614 }
615 }
616
617 Flag::Error MaxMetaspaceSizeConstraintFunc(size_t value, bool verbose) {
618 if (value < MetaspaceSize) {
619 CommandLineError::print(verbose,
620 "MaxMetaspaceSize (" SIZE_FORMAT ") must be "
621 "greater than or equal to MetaspaceSize (" SIZE_FORMAT ")\n",
622 value, MaxMetaspaceSize);
623 return Flag::VIOLATES_CONSTRAINT;
624 } else {
625 return Flag::SUCCESS;
626 }
627 }
628
629 Flag::Error SurvivorAlignmentInBytesConstraintFunc(intx value, bool verbose) {
630 if (value != 0) {
631 if (!is_power_of_2(value)) {
632 CommandLineError::print(verbose,
633 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be "
634 "power of 2\n",
635 value);
636 return Flag::VIOLATES_CONSTRAINT;
637 }
638 if (value < ObjectAlignmentInBytes) {
639 CommandLineError::print(verbose,
640 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be "
641 "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n",
642 value, ObjectAlignmentInBytes);
|