commandLineFlagConstraintsCompiler.cpp revision 9314:d3870bf39fae
1/*
2 * Copyright (c) 2015, 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 "oops/metadata.hpp"
27#include "runtime/os.hpp"
28#include "code/relocInfo.hpp"
29#include "interpreter/invocationCounter.hpp"
30#include "runtime/arguments.hpp"
31#include "runtime/commandLineFlagConstraintsCompiler.hpp"
32#include "runtime/commandLineFlagRangeList.hpp"
33#include "runtime/globals.hpp"
34#include "utilities/defaultStream.hpp"
35
36Flag::Error AliasLevelConstraintFunc(intx value, bool verbose) {
37  if ((value <= 1) && (Arguments::mode() == Arguments::_comp || Arguments::mode() == Arguments::_mixed)) {
38    CommandLineError::print(verbose,
39                            "AliasLevel (" INTX_FORMAT ") is not "
40                            "compatible with -Xcomp or -Xmixed\n",
41                            value);
42    return Flag::VIOLATES_CONSTRAINT;
43  } else {
44    return Flag::SUCCESS;
45  }
46}
47
48/**
49 * Validate the minimum number of compiler threads needed to run the
50 * JVM. The following configurations are possible.
51 *
52 * 1) The JVM is build using an interpreter only. As a result, the minimum number of
53 *    compiler threads is 0.
54 * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As
55 *    a result, either C1 or C2 is used, so the minimum number of compiler threads is 1.
56 * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However,
57 *    the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only
58 *    C1 can be used, so the minimum number of compiler threads is 1.
59 * 4) The JVM is build using the compilers and tiered compilation is enabled. The option
60 *    'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result,
61 *    the minimum number of compiler threads is 2.
62 */
63Flag::Error CICompilerCountConstraintFunc(intx value, bool verbose) {
64  int min_number_of_compiler_threads = 0;
65#if !defined(COMPILER1) && !defined(COMPILER2) && !defined(SHARK) && !INCLUDE_JVMCI
66  // case 1
67#else
68  if (!TieredCompilation || (TieredStopAtLevel < CompLevel_full_optimization)) {
69    min_number_of_compiler_threads = 1; // case 2 or case 3
70  } else {
71    min_number_of_compiler_threads = 2;   // case 4 (tiered)
72  }
73#endif
74
75  // The default CICompilerCount's value is CI_COMPILER_COUNT.
76  // With a client VM, -XX:+TieredCompilation causes TieredCompilation
77  // to be true here (the option is validated later) and
78  // min_number_of_compiler_threads to exceed CI_COMPILER_COUNT.
79  min_number_of_compiler_threads = MIN2(min_number_of_compiler_threads, CI_COMPILER_COUNT);
80
81  if (value < (intx)min_number_of_compiler_threads) {
82    CommandLineError::print(verbose,
83                            "CICompilerCount (" INTX_FORMAT ") must be "
84                            "at least %d \n",
85                            value, min_number_of_compiler_threads);
86    return Flag::VIOLATES_CONSTRAINT;
87  } else {
88    return Flag::SUCCESS;
89  }
90}
91
92Flag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) {
93  if (value < 0) {
94    CommandLineError::print(verbose,
95                            "Unable to determine system-specific value for AllocatePrefetchDistance. "
96                            "Please provide appropriate value, if unsure, use 0 to disable prefetching\n");
97    return Flag::VIOLATES_CONSTRAINT;
98  }
99
100  return Flag::SUCCESS;
101}
102
103Flag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) {
104  intx max_value = max_intx;
105#if defined(SPARC)
106  max_value = 1;
107#elif defined(X86)
108  max_value = 3;
109#endif
110  if (value < 0 || value > max_value) {
111    CommandLineError::print(verbose,
112                            "AllocatePrefetchInstr (" INTX_FORMAT ") must be "
113                            "between 0 and " INTX_FORMAT "\n", value, max_value);
114    return Flag::VIOLATES_CONSTRAINT;
115  }
116
117  return Flag::SUCCESS;
118}
119
120Flag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) {
121  if (value < 1 || value > max_jint) {
122    CommandLineError::print(verbose,
123                            "AllocatePrefetchStepSize (" INTX_FORMAT ") "
124                            "must be between 1 and %d\n",
125                            AllocatePrefetchStepSize,
126                            max_jint);
127    return Flag::VIOLATES_CONSTRAINT;
128  }
129
130  if (AllocatePrefetchDistance % AllocatePrefetchStepSize != 0) {
131     CommandLineError::print(verbose,
132                             "AllocatePrefetchDistance (" INTX_FORMAT ") "
133                             "%% AllocatePrefetchStepSize (" INTX_FORMAT ") "
134                             "= " INTX_FORMAT " "
135                             "must be 0\n",
136                             AllocatePrefetchDistance, AllocatePrefetchStepSize,
137                             AllocatePrefetchDistance % AllocatePrefetchStepSize);
138     return Flag::VIOLATES_CONSTRAINT;
139   }
140
141   return Flag::SUCCESS;
142}
143
144Flag::Error CompileThresholdConstraintFunc(intx value, bool verbose) {
145  if (value < 0 || value > INT_MAX >> InvocationCounter::count_shift) {
146    CommandLineError::print(verbose,
147                            "CompileThreshold (" INTX_FORMAT ") "
148                            "must be between 0 and %d\n",
149                            value,
150                            INT_MAX >> InvocationCounter::count_shift);
151    return Flag::VIOLATES_CONSTRAINT;
152  }
153
154  return Flag::SUCCESS;
155}
156
157Flag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose) {
158  int backward_branch_limit;
159  if (ProfileInterpreter) {
160    if (OnStackReplacePercentage < InterpreterProfilePercentage) {
161      CommandLineError::print(verbose,
162                              "OnStackReplacePercentage (" INTX_FORMAT ") must be "
163                              "larger than InterpreterProfilePercentage (" INTX_FORMAT ")\n",
164                              OnStackReplacePercentage, InterpreterProfilePercentage);
165      return Flag::VIOLATES_CONSTRAINT;
166    }
167
168    backward_branch_limit = ((CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100)
169                            << InvocationCounter::count_shift;
170
171    if (backward_branch_limit < 0) {
172      CommandLineError::print(verbose,
173                              "CompileThreshold * (InterpreterProfilePercentage - OnStackReplacePercentage) / 100 = "
174                              INTX_FORMAT " "
175                              "must be between 0 and " INTX_FORMAT ", try changing "
176                              "CompileThreshold, InterpreterProfilePercentage, and/or OnStackReplacePercentage\n",
177                              (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100,
178                              INT_MAX >> InvocationCounter::count_shift);
179      return Flag::VIOLATES_CONSTRAINT;
180    }
181  } else {
182    if (OnStackReplacePercentage < 0 ) {
183      CommandLineError::print(verbose,
184                              "OnStackReplacePercentage (" INTX_FORMAT ") must be "
185                              "non-negative\n", OnStackReplacePercentage);
186      return Flag::VIOLATES_CONSTRAINT;
187    }
188
189    backward_branch_limit = ((CompileThreshold * OnStackReplacePercentage) / 100)
190                            << InvocationCounter::count_shift;
191
192    if (backward_branch_limit < 0) {
193      CommandLineError::print(verbose,
194                              "CompileThreshold * OnStackReplacePercentage / 100 = " INTX_FORMAT " "
195                              "must be between 0 and " INTX_FORMAT ", try changing "
196                              "CompileThreshold and/or OnStackReplacePercentage\n",
197                              (CompileThreshold * OnStackReplacePercentage) / 100,
198                              INT_MAX >> InvocationCounter::count_shift);
199      return Flag::VIOLATES_CONSTRAINT;
200    }
201  }
202  return Flag::SUCCESS;
203}
204
205Flag::Error CodeCacheSegmentSizeConstraintFunc(uintx value, bool verbose) {
206  if (CodeCacheSegmentSize < (uintx)CodeEntryAlignment) {
207    CommandLineError::print(verbose,
208                            "CodeCacheSegmentSize  (" UINTX_FORMAT ") must be "
209                            "larger than or equal to CodeEntryAlignment (" INTX_FORMAT ") "
210                            "to align entry points\n",
211                            CodeCacheSegmentSize, CodeEntryAlignment);
212    return Flag::VIOLATES_CONSTRAINT;
213  }
214
215  if (CodeCacheSegmentSize < sizeof(jdouble)) {
216    CommandLineError::print(verbose,
217                            "CodeCacheSegmentSize  (" UINTX_FORMAT ") must be "
218                            "at least " SIZE_FORMAT " to align constants\n",
219                            CodeCacheSegmentSize, sizeof(jdouble));
220    return Flag::VIOLATES_CONSTRAINT;
221  }
222
223#ifdef COMPILER2
224  if (CodeCacheSegmentSize < (uintx)OptoLoopAlignment) {
225    CommandLineError::print(verbose,
226                            "CodeCacheSegmentSize  (" UINTX_FORMAT ") must be "
227                            "larger than or equal to OptoLoopAlignment (" INTX_FORMAT ") "
228                            "to align inner loops\n",
229                            CodeCacheSegmentSize, OptoLoopAlignment);
230    return Flag::VIOLATES_CONSTRAINT;
231  }
232#endif
233
234  return Flag::SUCCESS;
235}
236
237Flag::Error CompilerThreadPriorityConstraintFunc(intx value, bool verbose) {
238#ifdef SOLARIS
239  if ((value < MinimumPriority || value > MaximumPriority) &&
240      (value != -1) && (value != -FXCriticalPriority)) {
241    CommandLineError::print(verbose,
242                            "CompileThreadPriority (" INTX_FORMAT ") must be "
243                            "between %d and %d inclusively or -1 (means no change) "
244                            "or %d (special value for critical thread class/priority)\n",
245                            value, MinimumPriority, MaximumPriority, -FXCriticalPriority);
246    return Flag::VIOLATES_CONSTRAINT;
247  }
248#endif
249
250  return Flag::SUCCESS;
251}
252
253Flag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) {
254#ifdef SPARC
255  if (CodeEntryAlignment % relocInfo::addr_unit() != 0) {
256    CommandLineError::print(verbose,
257                            "CodeEntryAlignment (" INTX_FORMAT ") must be "
258                            "multiple of NOP size\n", CodeEntryAlignment);
259    return Flag::VIOLATES_CONSTRAINT;
260  }
261#endif
262
263  if (!is_power_of_2(value)) {
264    CommandLineError::print(verbose,
265                            "CodeEntryAlignment (" INTX_FORMAT ") must be "
266                            "a power of two\n", CodeEntryAlignment);
267    return Flag::VIOLATES_CONSTRAINT;
268  }
269
270  if (CodeEntryAlignment < 16) {
271      CommandLineError::print(verbose,
272                              "CodeEntryAlignment (" INTX_FORMAT ") must be "
273                              "greater than or equal to %d\n",
274                              CodeEntryAlignment, 16);
275      return Flag::VIOLATES_CONSTRAINT;
276  }
277
278  return Flag::SUCCESS;
279}
280
281Flag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) {
282  if (!is_power_of_2(value)) {
283    CommandLineError::print(verbose,
284                            "OptoLoopAlignment (" INTX_FORMAT ") "
285                            "must be a power of two\n",
286                            value);
287    return Flag::VIOLATES_CONSTRAINT;
288  }
289
290#ifdef SPARC
291  if (OptoLoopAlignment % relocInfo::addr_unit() != 0) {
292    CommandLineError::print(verbose,
293                            "OptoLoopAlignment (" INTX_FORMAT ") must be "
294                            "multiple of NOP size\n");
295    return Flag::VIOLATES_CONSTRAINT;
296  }
297#endif
298
299  return Flag::SUCCESS;
300}
301
302Flag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verbose) {
303  if (value != 0) {
304    CommandLineError::print(verbose,
305                            "ArraycopyDstPrefetchDistance (" UINTX_FORMAT ") must be 0\n",
306                            value);
307    return Flag::VIOLATES_CONSTRAINT;
308  }
309
310  return Flag::SUCCESS;
311}
312
313Flag::Error ArraycopySrcPrefetchDistanceConstraintFunc(uintx value, bool verbose) {
314  if (value != 0) {
315    CommandLineError::print(verbose,
316                            "ArraycopySrcPrefetchDistance (" UINTX_FORMAT ") must be 0\n",
317                            value);
318    return Flag::VIOLATES_CONSTRAINT;
319  }
320
321  return Flag::SUCCESS;
322}
323
324Flag::Error TypeProfileLevelConstraintFunc(uintx value, bool verbose) {
325  for (int i = 0; i < 3; i++) {
326    if (value % 10 > 2) {
327      CommandLineError::print(verbose,
328                              "Invalid value (" UINTX_FORMAT ") "
329                              "in TypeProfileLevel at position %d\n", value, i);
330      return Flag::VIOLATES_CONSTRAINT;
331    }
332    value = value / 10;
333  }
334
335  return Flag::SUCCESS;
336}
337
338#ifdef COMPILER2
339Flag::Error InteriorEntryAlignmentConstraintFunc(intx value, bool verbose) {
340  if (InteriorEntryAlignment > CodeEntryAlignment) {
341    CommandLineError::print(verbose,
342                           "InteriorEntryAlignment (" INTX_FORMAT ") must be "
343                           "less than or equal to CodeEntryAlignment (" INTX_FORMAT ")\n",
344                           InteriorEntryAlignment, CodeEntryAlignment);
345    return Flag::VIOLATES_CONSTRAINT;
346  }
347
348#ifdef SPARC
349  if (InteriorEntryAlignment % relocInfo::addr_unit() != 0) {
350    CommandLineError::print(verbose,
351                            "InteriorEntryAlignment (" INTX_FORMAT ") must be "
352                            "multiple of NOP size\n");
353    return Flag::VIOLATES_CONSTRAINT;
354  }
355#endif
356
357  if (!is_power_of_2(value)) {
358     CommandLineError::print(verbose,
359                             "InteriorEntryAlignment (" INTX_FORMAT ") must be "
360                             "a power of two\n", InteriorEntryAlignment);
361     return Flag::VIOLATES_CONSTRAINT;
362   }
363
364  int minimum_alignment = 16;
365#if defined(SPARC) || (defined(X86) && !defined(AMD64))
366  minimum_alignment = 4;
367#endif
368
369  if (InteriorEntryAlignment < minimum_alignment) {
370    CommandLineError::print(verbose,
371                            "InteriorEntryAlignment (" INTX_FORMAT ") must be "
372                            "greater than or equal to %d\n",
373                            InteriorEntryAlignment, minimum_alignment);
374    return Flag::VIOLATES_CONSTRAINT;
375  }
376
377  return Flag::SUCCESS;
378}
379
380Flag::Error NodeLimitFudgeFactorConstraintFunc(intx value, bool verbose) {
381  if (value < MaxNodeLimit * 2 / 100 || value > MaxNodeLimit * 40 / 100) {
382    CommandLineError::print(verbose,
383                            "NodeLimitFudgeFactor must be between 2%% and 40%% "
384                            "of MaxNodeLimit (" INTX_FORMAT ")\n",
385                            MaxNodeLimit);
386    return Flag::VIOLATES_CONSTRAINT;
387  }
388
389  return Flag::SUCCESS;
390}
391#endif // COMPILER2
392