57 #elif defined(COMPILER1) |
59 #elif defined(COMPILER1) |
58 CompMode Compilation_mode = CompMode_client; |
60 CompMode Compilation_mode = CompMode_client; |
59 #else |
61 #else |
60 CompMode Compilation_mode = CompMode_none; |
62 CompMode Compilation_mode = CompMode_none; |
61 #endif |
63 #endif |
|
64 |
|
65 // Returns threshold scaled with CompileThresholdScaling |
|
66 intx CompilerConfig::scaled_compile_threshold(intx threshold) { |
|
67 return scaled_compile_threshold(threshold, CompileThresholdScaling); |
|
68 } |
|
69 |
|
70 // Returns freq_log scaled with CompileThresholdScaling |
|
71 intx CompilerConfig::scaled_freq_log(intx freq_log) { |
|
72 return scaled_freq_log(freq_log, CompileThresholdScaling); |
|
73 } |
|
74 |
|
75 // Returns threshold scaled with the value of scale. |
|
76 // If scale < 0.0, threshold is returned without scaling. |
|
77 intx CompilerConfig::scaled_compile_threshold(intx threshold, double scale) { |
|
78 if (scale == 1.0 || scale < 0.0) { |
|
79 return threshold; |
|
80 } else { |
|
81 return (intx)(threshold * scale); |
|
82 } |
|
83 } |
|
84 |
|
85 // Returns freq_log scaled with the value of scale. |
|
86 // Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1]. |
|
87 // If scale < 0.0, freq_log is returned without scaling. |
|
88 intx CompilerConfig::scaled_freq_log(intx freq_log, double scale) { |
|
89 // Check if scaling is necessary or if negative value was specified. |
|
90 if (scale == 1.0 || scale < 0.0) { |
|
91 return freq_log; |
|
92 } |
|
93 // Check values to avoid calculating log2 of 0. |
|
94 if (scale == 0.0 || freq_log == 0) { |
|
95 return 0; |
|
96 } |
|
97 // Determine the maximum notification frequency value currently supported. |
|
98 // The largest mask value that the interpreter/C1 can handle is |
|
99 // of length InvocationCounter::number_of_count_bits. Mask values are always |
|
100 // one bit shorter then the value of the notification frequency. Set |
|
101 // max_freq_bits accordingly. |
|
102 intx max_freq_bits = InvocationCounter::number_of_count_bits + 1; |
|
103 intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale); |
|
104 if (scaled_freq == 0) { |
|
105 // Return 0 right away to avoid calculating log2 of 0. |
|
106 return 0; |
|
107 } else if (scaled_freq > nth_bit(max_freq_bits)) { |
|
108 return max_freq_bits; |
|
109 } else { |
|
110 return log2_intptr(scaled_freq); |
|
111 } |
|
112 } |
62 |
113 |
63 #ifdef TIERED |
114 #ifdef TIERED |
64 void set_client_compilation_mode() { |
115 void set_client_compilation_mode() { |
65 Compilation_mode = CompMode_client; |
116 Compilation_mode = CompMode_client; |
66 CompLevel_highest_tier = CompLevel_simple; |
117 CompLevel_highest_tier = CompLevel_simple; |
111 } |
162 } |
112 if (FLAG_IS_DEFAULT(CICompilerCount)) { |
163 if (FLAG_IS_DEFAULT(CICompilerCount)) { |
113 FLAG_SET_ERGO(intx, CICompilerCount, 1); |
164 FLAG_SET_ERGO(intx, CICompilerCount, 1); |
114 } |
165 } |
115 } |
166 } |
|
167 |
|
168 bool compilation_mode_selected() { |
|
169 return !FLAG_IS_DEFAULT(TieredCompilation) || |
|
170 !FLAG_IS_DEFAULT(TieredStopAtLevel) || |
|
171 !FLAG_IS_DEFAULT(UseAOT) |
|
172 JVMCI_ONLY(|| !FLAG_IS_DEFAULT(EnableJVMCI) |
|
173 || !FLAG_IS_DEFAULT(UseJVMCICompiler)); |
|
174 } |
|
175 |
|
176 void select_compilation_mode_ergonomically() { |
|
177 #if defined(_WINDOWS) && !defined(_LP64) |
|
178 if (FLAG_IS_DEFAULT(NeverActAsServerClassMachine)) { |
|
179 FLAG_SET_ERGO(bool, NeverActAsServerClassMachine, true); |
|
180 } |
|
181 #endif |
|
182 if (NeverActAsServerClassMachine) { |
|
183 set_client_compilation_mode(); |
|
184 } |
|
185 } |
|
186 |
116 #endif // TIERED |
187 #endif // TIERED |
|
188 |
|
189 void CompilerConfig::set_tiered_flags() { |
|
190 // With tiered, set default policy to SimpleThresholdPolicy, which is 2. |
|
191 if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) { |
|
192 FLAG_SET_DEFAULT(CompilationPolicyChoice, 2); |
|
193 } |
|
194 if (CompilationPolicyChoice < 2) { |
|
195 vm_exit_during_initialization( |
|
196 "Incompatible compilation policy selected", NULL); |
|
197 } |
|
198 // Increase the code cache size - tiered compiles a lot more. |
|
199 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { |
|
200 FLAG_SET_ERGO(uintx, ReservedCodeCacheSize, |
|
201 MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5)); |
|
202 } |
|
203 // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M |
|
204 if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) { |
|
205 FLAG_SET_ERGO(bool, SegmentedCodeCache, true); |
|
206 } |
|
207 if (!UseInterpreter) { // -Xcomp |
|
208 Tier3InvokeNotifyFreqLog = 0; |
|
209 Tier4InvocationThreshold = 0; |
|
210 } |
|
211 |
|
212 if (CompileThresholdScaling < 0) { |
|
213 vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL); |
|
214 } |
|
215 |
|
216 // Scale tiered compilation thresholds. |
|
217 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged. |
|
218 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { |
|
219 FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog)); |
|
220 FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog)); |
|
221 |
|
222 FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold)); |
|
223 FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold)); |
|
224 FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold)); |
|
225 FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold)); |
|
226 |
|
227 // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here |
|
228 // once these thresholds become supported. |
|
229 |
|
230 FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog)); |
|
231 FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog)); |
|
232 |
|
233 FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog)); |
|
234 FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog)); |
|
235 |
|
236 FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog)); |
|
237 |
|
238 FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold)); |
|
239 FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold)); |
|
240 FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold)); |
|
241 FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold)); |
|
242 } |
|
243 } |
|
244 |
|
245 #if INCLUDE_JVMCI |
|
246 void set_jvmci_specific_flags() { |
|
247 if (UseJVMCICompiler) { |
|
248 Compilation_mode = CompMode_server; |
|
249 |
|
250 if (FLAG_IS_DEFAULT(TypeProfileWidth)) { |
|
251 FLAG_SET_DEFAULT(TypeProfileWidth, 8); |
|
252 } |
|
253 if (FLAG_IS_DEFAULT(OnStackReplacePercentage)) { |
|
254 FLAG_SET_DEFAULT(OnStackReplacePercentage, 933); |
|
255 } |
|
256 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { |
|
257 FLAG_SET_DEFAULT(ReservedCodeCacheSize, 64*M); |
|
258 } |
|
259 if (FLAG_IS_DEFAULT(InitialCodeCacheSize)) { |
|
260 FLAG_SET_DEFAULT(InitialCodeCacheSize, 16*M); |
|
261 } |
|
262 if (FLAG_IS_DEFAULT(MetaspaceSize)) { |
|
263 FLAG_SET_DEFAULT(MetaspaceSize, 12*M); |
|
264 } |
|
265 if (FLAG_IS_DEFAULT(NewSizeThreadIncrease)) { |
|
266 FLAG_SET_DEFAULT(NewSizeThreadIncrease, 4*K); |
|
267 } |
|
268 if (TieredStopAtLevel != CompLevel_full_optimization) { |
|
269 // Currently JVMCI compiler can only work at the full optimization level |
|
270 warning("forcing TieredStopAtLevel to full optimization because JVMCI is enabled"); |
|
271 FLAG_SET_ERGO(intx, TieredStopAtLevel, CompLevel_full_optimization); |
|
272 } |
|
273 if (FLAG_IS_DEFAULT(TypeProfileLevel)) { |
|
274 FLAG_SET_DEFAULT(TypeProfileLevel, 0); |
|
275 } |
|
276 } |
|
277 } |
|
278 #endif // INCLUDE_JVMCI |
|
279 |
|
280 bool CompilerConfig::check_args_consistency(bool status) { |
|
281 // Check lower bounds of the code cache |
|
282 // Template Interpreter code is approximately 3X larger in debug builds. |
|
283 uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); |
|
284 if (ReservedCodeCacheSize < InitialCodeCacheSize) { |
|
285 jio_fprintf(defaultStream::error_stream(), |
|
286 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", |
|
287 ReservedCodeCacheSize/K, InitialCodeCacheSize/K); |
|
288 status = false; |
|
289 } else if (ReservedCodeCacheSize < min_code_cache_size) { |
|
290 jio_fprintf(defaultStream::error_stream(), |
|
291 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K, |
|
292 min_code_cache_size/K); |
|
293 status = false; |
|
294 } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) { |
|
295 // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported. |
|
296 jio_fprintf(defaultStream::error_stream(), |
|
297 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M, |
|
298 CODE_CACHE_SIZE_LIMIT/M); |
|
299 status = false; |
|
300 } else if (NonNMethodCodeHeapSize < min_code_cache_size) { |
|
301 jio_fprintf(defaultStream::error_stream(), |
|
302 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K, |
|
303 min_code_cache_size/K); |
|
304 status = false; |
|
305 } |
|
306 |
|
307 #ifdef _LP64 |
|
308 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { |
|
309 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); |
|
310 } |
|
311 #endif |
|
312 |
|
313 if (BackgroundCompilation && (CompileTheWorld || ReplayCompiles)) { |
|
314 if (!FLAG_IS_DEFAULT(BackgroundCompilation)) { |
|
315 warning("BackgroundCompilation disabled due to CompileTheWorld or ReplayCompiles options."); |
|
316 } |
|
317 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); |
|
318 } |
|
319 |
|
320 #ifdef COMPILER2 |
|
321 if (PostLoopMultiversioning && !RangeCheckElimination) { |
|
322 if (!FLAG_IS_DEFAULT(PostLoopMultiversioning)) { |
|
323 warning("PostLoopMultiversioning disabled because RangeCheckElimination is disabled."); |
|
324 } |
|
325 FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false); |
|
326 } |
|
327 if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) { |
|
328 if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) { |
|
329 warning("When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1"); |
|
330 } |
|
331 LoopStripMiningIter = 1; |
|
332 } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) { |
|
333 if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) { |
|
334 warning("Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0"); |
|
335 } |
|
336 LoopStripMiningIter = 0; |
|
337 } |
|
338 #endif // COMPILER2 |
|
339 |
|
340 if (Arguments::is_interpreter_only()) { |
|
341 if (UseCompiler) { |
|
342 if (!FLAG_IS_DEFAULT(UseCompiler)) { |
|
343 warning("UseCompiler disabled due to -Xint."); |
|
344 } |
|
345 FLAG_SET_CMDLINE(bool, UseCompiler, false); |
|
346 } |
|
347 if (ProfileInterpreter) { |
|
348 if (!FLAG_IS_DEFAULT(ProfileInterpreter)) { |
|
349 warning("ProfileInterpreter disabled due to -Xint."); |
|
350 } |
|
351 FLAG_SET_CMDLINE(bool, ProfileInterpreter, false); |
|
352 } |
|
353 if (TieredCompilation) { |
|
354 if (!FLAG_IS_DEFAULT(TieredCompilation)) { |
|
355 warning("TieredCompilation disabled due to -Xint."); |
|
356 } |
|
357 FLAG_SET_CMDLINE(bool, TieredCompilation, false); |
|
358 } |
|
359 #if INCLUDE_JVMCI |
|
360 if (EnableJVMCI) { |
|
361 if (!FLAG_IS_DEFAULT(EnableJVMCI) || !FLAG_IS_DEFAULT(UseJVMCICompiler)) { |
|
362 warning("JVMCI Compiler disabled due to -Xint."); |
|
363 } |
|
364 FLAG_SET_CMDLINE(bool, EnableJVMCI, false); |
|
365 FLAG_SET_CMDLINE(bool, UseJVMCICompiler, false); |
|
366 } |
|
367 #endif |
|
368 } else { |
|
369 #if INCLUDE_JVMCI |
|
370 status = status && JVMCIGlobals::check_jvmci_flags_are_consistent(); |
|
371 #endif |
|
372 } |
|
373 return status; |
|
374 } |
|
375 |
|
376 void CompilerConfig::ergo_initialize() { |
|
377 if (Arguments::is_interpreter_only()) { |
|
378 return; // Nothing to do. |
|
379 } |
|
380 |
|
381 #ifdef TIERED |
|
382 if (!compilation_mode_selected()) { |
|
383 select_compilation_mode_ergonomically(); |
|
384 } |
|
385 #endif |
|
386 |
|
387 #if INCLUDE_JVMCI |
|
388 // Check that JVMCI compiler supports selested GC. |
|
389 // Should be done after GCConfig::initialize() was called. |
|
390 JVMCIGlobals::check_jvmci_supported_gc(); |
|
391 set_jvmci_specific_flags(); |
|
392 #endif |
|
393 |
|
394 if (TieredCompilation) { |
|
395 set_tiered_flags(); |
|
396 } else { |
|
397 int max_compilation_policy_choice = 1; |
|
398 #ifdef COMPILER2 |
|
399 if (is_server_compilation_mode_vm()) { |
|
400 max_compilation_policy_choice = 2; |
|
401 } |
|
402 #endif |
|
403 // Check if the policy is valid. |
|
404 if (CompilationPolicyChoice >= max_compilation_policy_choice) { |
|
405 vm_exit_during_initialization( |
|
406 "Incompatible compilation policy selected", NULL); |
|
407 } |
|
408 // Scale CompileThreshold |
|
409 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged. |
|
410 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { |
|
411 FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold)); |
|
412 } |
|
413 } |
|
414 |
|
415 if (UseOnStackReplacement && !UseLoopCounter) { |
|
416 warning("On-stack-replacement requires loop counters; enabling loop counters"); |
|
417 FLAG_SET_DEFAULT(UseLoopCounter, true); |
|
418 } |
|
419 |
|
420 #ifdef COMPILER2 |
|
421 if (!EliminateLocks) { |
|
422 EliminateNestedLocks = false; |
|
423 } |
|
424 if (!Inline) { |
|
425 IncrementalInline = false; |
|
426 } |
|
427 #ifndef PRODUCT |
|
428 if (!IncrementalInline) { |
|
429 AlwaysIncrementalInline = false; |
|
430 } |
|
431 if (PrintIdealGraphLevel > 0) { |
|
432 FLAG_SET_ERGO(bool, PrintIdealGraph, true); |
|
433 } |
|
434 #endif |
|
435 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { |
|
436 // nothing to use the profiling, turn if off |
|
437 FLAG_SET_DEFAULT(TypeProfileLevel, 0); |
|
438 } |
|
439 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { |
|
440 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); |
|
441 } |
|
442 if (FLAG_IS_DEFAULT(LoopStripMiningIterShortLoop)) { |
|
443 // blind guess |
|
444 LoopStripMiningIterShortLoop = LoopStripMiningIter / 10; |
|
445 } |
|
446 #endif // COMPILER2 |
|
447 } |