Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/compiler/compilationPolicy.cpp
64440 views
1
/*
2
* Copyright (c) 2010, 2022, 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 "code/scopeDesc.hpp"
27
#include "compiler/compilationPolicy.hpp"
28
#include "compiler/compileBroker.hpp"
29
#include "compiler/compilerOracle.hpp"
30
#include "memory/resourceArea.hpp"
31
#include "oops/methodData.hpp"
32
#include "oops/method.inline.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "prims/jvmtiExport.hpp"
35
#include "runtime/arguments.hpp"
36
#include "runtime/deoptimization.hpp"
37
#include "runtime/frame.hpp"
38
#include "runtime/frame.inline.hpp"
39
#include "runtime/globals_extension.hpp"
40
#include "runtime/handles.inline.hpp"
41
#include "runtime/safepoint.hpp"
42
#include "runtime/safepointVerifiers.hpp"
43
44
#if INCLUDE_JVMCI
45
#include "jvmci/jvmci.hpp"
46
#endif
47
48
#ifdef COMPILER1
49
#include "c1/c1_Compiler.hpp"
50
#endif
51
52
#ifdef COMPILER2
53
#include "opto/c2compiler.hpp"
54
#endif
55
56
jlong CompilationPolicy::_start_time = 0;
57
int CompilationPolicy::_c1_count = 0;
58
int CompilationPolicy::_c2_count = 0;
59
double CompilationPolicy::_increase_threshold_at_ratio = 0;
60
61
void compilationPolicy_init() {
62
CompilationPolicy::initialize();
63
}
64
65
int CompilationPolicy::compiler_count(CompLevel comp_level) {
66
if (is_c1_compile(comp_level)) {
67
return c1_count();
68
} else if (is_c2_compile(comp_level)) {
69
return c2_count();
70
}
71
return 0;
72
}
73
74
// Returns true if m must be compiled before executing it
75
// This is intended to force compiles for methods (usually for
76
// debugging) that would otherwise be interpreted for some reason.
77
bool CompilationPolicy::must_be_compiled(const methodHandle& m, int comp_level) {
78
// Don't allow Xcomp to cause compiles in replay mode
79
if (ReplayCompiles) return false;
80
81
if (m->has_compiled_code()) return false; // already compiled
82
if (!can_be_compiled(m, comp_level)) return false;
83
84
return !UseInterpreter || // must compile all methods
85
(UseCompiler && AlwaysCompileLoopMethods && m->has_loops() && CompileBroker::should_compile_new_jobs()); // eagerly compile loop methods
86
}
87
88
void CompilationPolicy::compile_if_required(const methodHandle& m, TRAPS) {
89
if (must_be_compiled(m)) {
90
// This path is unusual, mostly used by the '-Xcomp' stress test mode.
91
92
if (!THREAD->can_call_java() || THREAD->is_Compiler_thread()) {
93
// don't force compilation, resolve was on behalf of compiler
94
return;
95
}
96
if (m->method_holder()->is_not_initialized()) {
97
// 'is_not_initialized' means not only '!is_initialized', but also that
98
// initialization has not been started yet ('!being_initialized')
99
// Do not force compilation of methods in uninitialized classes.
100
// Note that doing this would throw an assert later,
101
// in CompileBroker::compile_method.
102
// We sometimes use the link resolver to do reflective lookups
103
// even before classes are initialized.
104
return;
105
}
106
CompLevel level = initial_compile_level(m);
107
if (PrintTieredEvents) {
108
print_event(COMPILE, m(), m(), InvocationEntryBci, level);
109
}
110
CompileBroker::compile_method(m, InvocationEntryBci, level, methodHandle(), 0, CompileTask::Reason_MustBeCompiled, THREAD);
111
}
112
}
113
114
static inline CompLevel adjust_level_for_compilability_query(CompLevel comp_level) {
115
if (comp_level == CompLevel_any) {
116
if (CompilerConfig::is_c1_only()) {
117
comp_level = CompLevel_simple;
118
} else if (CompilerConfig::is_c2_or_jvmci_compiler_only()) {
119
comp_level = CompLevel_full_optimization;
120
}
121
}
122
return comp_level;
123
}
124
125
// Returns true if m is allowed to be compiled
126
bool CompilationPolicy::can_be_compiled(const methodHandle& m, int comp_level) {
127
// allow any levels for WhiteBox
128
assert(WhiteBoxAPI || comp_level == CompLevel_any || is_compile(comp_level), "illegal compilation level");
129
130
if (m->is_abstract()) return false;
131
if (DontCompileHugeMethods && m->code_size() > HugeMethodLimit) return false;
132
133
// Math intrinsics should never be compiled as this can lead to
134
// monotonicity problems because the interpreter will prefer the
135
// compiled code to the intrinsic version. This can't happen in
136
// production because the invocation counter can't be incremented
137
// but we shouldn't expose the system to this problem in testing
138
// modes.
139
if (!AbstractInterpreter::can_be_compiled(m)) {
140
return false;
141
}
142
comp_level = adjust_level_for_compilability_query((CompLevel) comp_level);
143
if (comp_level == CompLevel_any || is_compile(comp_level)) {
144
return !m->is_not_compilable(comp_level);
145
}
146
return false;
147
}
148
149
// Returns true if m is allowed to be osr compiled
150
bool CompilationPolicy::can_be_osr_compiled(const methodHandle& m, int comp_level) {
151
bool result = false;
152
comp_level = adjust_level_for_compilability_query((CompLevel) comp_level);
153
if (comp_level == CompLevel_any || is_compile(comp_level)) {
154
result = !m->is_not_osr_compilable(comp_level);
155
}
156
return (result && can_be_compiled(m, comp_level));
157
}
158
159
bool CompilationPolicy::is_compilation_enabled() {
160
// NOTE: CompileBroker::should_compile_new_jobs() checks for UseCompiler
161
return CompileBroker::should_compile_new_jobs();
162
}
163
164
CompileTask* CompilationPolicy::select_task_helper(CompileQueue* compile_queue) {
165
// Remove unloaded methods from the queue
166
for (CompileTask* task = compile_queue->first(); task != NULL; ) {
167
CompileTask* next = task->next();
168
if (task->is_unloaded()) {
169
compile_queue->remove_and_mark_stale(task);
170
}
171
task = next;
172
}
173
#if INCLUDE_JVMCI
174
if (UseJVMCICompiler && !BackgroundCompilation) {
175
/*
176
* In blocking compilation mode, the CompileBroker will make
177
* compilations submitted by a JVMCI compiler thread non-blocking. These
178
* compilations should be scheduled after all blocking compilations
179
* to service non-compiler related compilations sooner and reduce the
180
* chance of such compilations timing out.
181
*/
182
for (CompileTask* task = compile_queue->first(); task != NULL; task = task->next()) {
183
if (task->is_blocking()) {
184
return task;
185
}
186
}
187
}
188
#endif
189
return compile_queue->first();
190
}
191
192
// Simple methods are as good being compiled with C1 as C2.
193
// Determine if a given method is such a case.
194
bool CompilationPolicy::is_trivial(const methodHandle& method) {
195
if (method->is_accessor() ||
196
method->is_constant_getter()) {
197
return true;
198
}
199
return false;
200
}
201
202
bool CompilationPolicy::force_comp_at_level_simple(const methodHandle& method) {
203
if (CompilationModeFlag::quick_internal()) {
204
#if INCLUDE_JVMCI
205
if (UseJVMCICompiler) {
206
AbstractCompiler* comp = CompileBroker::compiler(CompLevel_full_optimization);
207
if (comp != NULL && comp->is_jvmci() && ((JVMCICompiler*) comp)->force_comp_at_level_simple(method)) {
208
return true;
209
}
210
}
211
#endif
212
}
213
return false;
214
}
215
216
CompLevel CompilationPolicy::comp_level(Method* method) {
217
CompiledMethod *nm = method->code();
218
if (nm != NULL && nm->is_in_use()) {
219
return (CompLevel)nm->comp_level();
220
}
221
return CompLevel_none;
222
}
223
224
// Call and loop predicates determine whether a transition to a higher
225
// compilation level should be performed (pointers to predicate functions
226
// are passed to common()).
227
// Tier?LoadFeedback is basically a coefficient that determines of
228
// how many methods per compiler thread can be in the queue before
229
// the threshold values double.
230
class LoopPredicate : AllStatic {
231
public:
232
static bool apply_scaled(const methodHandle& method, CompLevel cur_level, int i, int b, double scale) {
233
double threshold_scaling;
234
if (CompilerOracle::has_option_value(method, CompileCommand::CompileThresholdScaling, threshold_scaling)) {
235
scale *= threshold_scaling;
236
}
237
switch(cur_level) {
238
case CompLevel_none:
239
case CompLevel_limited_profile:
240
return b >= Tier3BackEdgeThreshold * scale;
241
case CompLevel_full_profile:
242
return b >= Tier4BackEdgeThreshold * scale;
243
default:
244
return true;
245
}
246
}
247
248
static bool apply(const methodHandle& method, CompLevel cur_level, int i, int b) {
249
double k = 1;
250
switch(cur_level) {
251
case CompLevel_none:
252
// Fall through
253
case CompLevel_limited_profile: {
254
k = CompilationPolicy::threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
255
break;
256
}
257
case CompLevel_full_profile: {
258
k = CompilationPolicy::threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
259
break;
260
}
261
default:
262
return true;
263
}
264
return apply_scaled(method, cur_level, i, b, k);
265
}
266
};
267
268
class CallPredicate : AllStatic {
269
public:
270
static bool apply_scaled(const methodHandle& method, CompLevel cur_level, int i, int b, double scale) {
271
double threshold_scaling;
272
if (CompilerOracle::has_option_value(method, CompileCommand::CompileThresholdScaling, threshold_scaling)) {
273
scale *= threshold_scaling;
274
}
275
switch(cur_level) {
276
case CompLevel_none:
277
case CompLevel_limited_profile:
278
return (i >= Tier3InvocationThreshold * scale) ||
279
(i >= Tier3MinInvocationThreshold * scale && i + b >= Tier3CompileThreshold * scale);
280
case CompLevel_full_profile:
281
return (i >= Tier4InvocationThreshold * scale) ||
282
(i >= Tier4MinInvocationThreshold * scale && i + b >= Tier4CompileThreshold * scale);
283
default:
284
return true;
285
}
286
}
287
288
static bool apply(const methodHandle& method, CompLevel cur_level, int i, int b) {
289
double k = 1;
290
switch(cur_level) {
291
case CompLevel_none:
292
case CompLevel_limited_profile: {
293
k = CompilationPolicy::threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
294
break;
295
}
296
case CompLevel_full_profile: {
297
k = CompilationPolicy::threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
298
break;
299
}
300
default:
301
return true;
302
}
303
return apply_scaled(method, cur_level, i, b, k);
304
}
305
};
306
307
double CompilationPolicy::threshold_scale(CompLevel level, int feedback_k) {
308
int comp_count = compiler_count(level);
309
if (comp_count > 0) {
310
double queue_size = CompileBroker::queue_size(level);
311
double k = queue_size / (feedback_k * comp_count) + 1;
312
313
// Increase C1 compile threshold when the code cache is filled more
314
// than specified by IncreaseFirstTierCompileThresholdAt percentage.
315
// The main intention is to keep enough free space for C2 compiled code
316
// to achieve peak performance if the code cache is under stress.
317
if (CompilerConfig::is_tiered() && !CompilationModeFlag::disable_intermediate() && is_c1_compile(level)) {
318
double current_reverse_free_ratio = CodeCache::reverse_free_ratio();
319
if (current_reverse_free_ratio > _increase_threshold_at_ratio) {
320
k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio);
321
}
322
}
323
return k;
324
}
325
return 1;
326
}
327
328
void CompilationPolicy::print_counters(const char* prefix, const Method* m) {
329
int invocation_count = m->invocation_count();
330
int backedge_count = m->backedge_count();
331
MethodData* mdh = m->method_data();
332
int mdo_invocations = 0, mdo_backedges = 0;
333
int mdo_invocations_start = 0, mdo_backedges_start = 0;
334
if (mdh != NULL) {
335
mdo_invocations = mdh->invocation_count();
336
mdo_backedges = mdh->backedge_count();
337
mdo_invocations_start = mdh->invocation_count_start();
338
mdo_backedges_start = mdh->backedge_count_start();
339
}
340
tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix,
341
invocation_count, backedge_count, prefix,
342
mdo_invocations, mdo_invocations_start,
343
mdo_backedges, mdo_backedges_start);
344
tty->print(" %smax levels=%d,%d", prefix,
345
m->highest_comp_level(), m->highest_osr_comp_level());
346
}
347
348
// Print an event.
349
void CompilationPolicy::print_event(EventType type, const Method* m, const Method* im, int bci, CompLevel level) {
350
bool inlinee_event = m != im;
351
352
ttyLocker tty_lock;
353
tty->print("%lf: [", os::elapsedTime());
354
355
switch(type) {
356
case CALL:
357
tty->print("call");
358
break;
359
case LOOP:
360
tty->print("loop");
361
break;
362
case COMPILE:
363
tty->print("compile");
364
break;
365
case REMOVE_FROM_QUEUE:
366
tty->print("remove-from-queue");
367
break;
368
case UPDATE_IN_QUEUE:
369
tty->print("update-in-queue");
370
break;
371
case REPROFILE:
372
tty->print("reprofile");
373
break;
374
case MAKE_NOT_ENTRANT:
375
tty->print("make-not-entrant");
376
break;
377
default:
378
tty->print("unknown");
379
}
380
381
tty->print(" level=%d ", level);
382
383
ResourceMark rm;
384
char *method_name = m->name_and_sig_as_C_string();
385
tty->print("[%s", method_name);
386
if (inlinee_event) {
387
char *inlinee_name = im->name_and_sig_as_C_string();
388
tty->print(" [%s]] ", inlinee_name);
389
}
390
else tty->print("] ");
391
tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile),
392
CompileBroker::queue_size(CompLevel_full_optimization));
393
394
tty->print(" rate=");
395
if (m->prev_time() == 0) tty->print("n/a");
396
else tty->print("%f", m->rate());
397
398
tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
399
threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
400
401
if (type != COMPILE) {
402
print_counters("", m);
403
if (inlinee_event) {
404
print_counters("inlinee ", im);
405
}
406
tty->print(" compilable=");
407
bool need_comma = false;
408
if (!m->is_not_compilable(CompLevel_full_profile)) {
409
tty->print("c1");
410
need_comma = true;
411
}
412
if (!m->is_not_osr_compilable(CompLevel_full_profile)) {
413
if (need_comma) tty->print(",");
414
tty->print("c1-osr");
415
need_comma = true;
416
}
417
if (!m->is_not_compilable(CompLevel_full_optimization)) {
418
if (need_comma) tty->print(",");
419
tty->print("c2");
420
need_comma = true;
421
}
422
if (!m->is_not_osr_compilable(CompLevel_full_optimization)) {
423
if (need_comma) tty->print(",");
424
tty->print("c2-osr");
425
}
426
tty->print(" status=");
427
if (m->queued_for_compilation()) {
428
tty->print("in-queue");
429
} else tty->print("idle");
430
}
431
tty->print_cr("]");
432
}
433
434
void CompilationPolicy::initialize() {
435
if (!CompilerConfig::is_interpreter_only()) {
436
int count = CICompilerCount;
437
bool c1_only = CompilerConfig::is_c1_only();
438
bool c2_only = CompilerConfig::is_c2_or_jvmci_compiler_only();
439
440
#ifdef _LP64
441
// Turn on ergonomic compiler count selection
442
if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
443
FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);
444
}
445
if (CICompilerCountPerCPU) {
446
// Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n
447
int log_cpu = log2i(os::active_processor_count());
448
int loglog_cpu = log2i(MAX2(log_cpu, 1));
449
count = MAX2(log_cpu * loglog_cpu * 3 / 2, 2);
450
// Make sure there is enough space in the code cache to hold all the compiler buffers
451
size_t c1_size = 0;
452
#ifdef COMPILER1
453
c1_size = Compiler::code_buffer_size();
454
#endif
455
size_t c2_size = 0;
456
#ifdef COMPILER2
457
c2_size = C2Compiler::initial_code_buffer_size();
458
#endif
459
size_t buffer_size = c1_only ? c1_size : (c1_size/3 + 2*c2_size/3);
460
int max_count = (ReservedCodeCacheSize - (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3))) / (int)buffer_size;
461
if (count > max_count) {
462
// Lower the compiler count such that all buffers fit into the code cache
463
count = MAX2(max_count, c1_only ? 1 : 2);
464
}
465
FLAG_SET_ERGO(CICompilerCount, count);
466
}
467
#else
468
// On 32-bit systems, the number of compiler threads is limited to 3.
469
// On these systems, the virtual address space available to the JVM
470
// is usually limited to 2-4 GB (the exact value depends on the platform).
471
// As the compilers (especially C2) can consume a large amount of
472
// memory, scaling the number of compiler threads with the number of
473
// available cores can result in the exhaustion of the address space
474
/// available to the VM and thus cause the VM to crash.
475
if (FLAG_IS_DEFAULT(CICompilerCount)) {
476
count = 3;
477
FLAG_SET_ERGO(CICompilerCount, count);
478
}
479
#endif
480
481
if (c1_only) {
482
// No C2 compiler thread required
483
set_c1_count(count);
484
} else if (c2_only) {
485
set_c2_count(count);
486
} else {
487
set_c1_count(MAX2(count / 3, 1));
488
set_c2_count(MAX2(count - c1_count(), 1));
489
}
490
assert(count == c1_count() + c2_count(), "inconsistent compiler thread count");
491
set_increase_threshold_at_ratio();
492
}
493
set_start_time(nanos_to_millis(os::javaTimeNanos()));
494
}
495
496
497
#ifdef ASSERT
498
bool CompilationPolicy::verify_level(CompLevel level) {
499
if (TieredCompilation && level > TieredStopAtLevel) {
500
return false;
501
}
502
// Check if there is a compiler to process the requested level
503
if (!CompilerConfig::is_c1_enabled() && is_c1_compile(level)) {
504
return false;
505
}
506
if (!CompilerConfig::is_c2_or_jvmci_compiler_enabled() && is_c2_compile(level)) {
507
return false;
508
}
509
510
// Interpreter level is always valid.
511
if (level == CompLevel_none) {
512
return true;
513
}
514
if (CompilationModeFlag::normal()) {
515
return true;
516
} else if (CompilationModeFlag::quick_only()) {
517
return level == CompLevel_simple;
518
} else if (CompilationModeFlag::high_only()) {
519
return level == CompLevel_full_optimization;
520
} else if (CompilationModeFlag::high_only_quick_internal()) {
521
return level == CompLevel_full_optimization || level == CompLevel_simple;
522
}
523
return false;
524
}
525
#endif
526
527
528
CompLevel CompilationPolicy::highest_compile_level() {
529
CompLevel level = CompLevel_none;
530
// Setup the maximum level availible for the current compiler configuration.
531
if (!CompilerConfig::is_interpreter_only()) {
532
if (CompilerConfig::is_c2_or_jvmci_compiler_enabled()) {
533
level = CompLevel_full_optimization;
534
} else if (CompilerConfig::is_c1_enabled()) {
535
if (CompilerConfig::is_c1_simple_only()) {
536
level = CompLevel_simple;
537
} else {
538
level = CompLevel_full_profile;
539
}
540
}
541
}
542
// Clamp the maximum level with TieredStopAtLevel.
543
if (TieredCompilation) {
544
level = MIN2(level, (CompLevel) TieredStopAtLevel);
545
}
546
547
// Fix it up if after the clamping it has become invalid.
548
// Bring it monotonically down depending on the next available level for
549
// the compilation mode.
550
if (!CompilationModeFlag::normal()) {
551
// a) quick_only - levels 2,3,4 are invalid; levels -1,0,1 are valid;
552
// b) high_only - levels 1,2,3 are invalid; levels -1,0,4 are valid;
553
// c) high_only_quick_internal - levels 2,3 are invalid; levels -1,0,1,4 are valid.
554
if (CompilationModeFlag::quick_only()) {
555
if (level == CompLevel_limited_profile || level == CompLevel_full_profile || level == CompLevel_full_optimization) {
556
level = CompLevel_simple;
557
}
558
} else if (CompilationModeFlag::high_only()) {
559
if (level == CompLevel_simple || level == CompLevel_limited_profile || level == CompLevel_full_profile) {
560
level = CompLevel_none;
561
}
562
} else if (CompilationModeFlag::high_only_quick_internal()) {
563
if (level == CompLevel_limited_profile || level == CompLevel_full_profile) {
564
level = CompLevel_simple;
565
}
566
}
567
}
568
569
assert(verify_level(level), "Invalid highest compilation level: %d", level);
570
return level;
571
}
572
573
CompLevel CompilationPolicy::limit_level(CompLevel level) {
574
level = MIN2(level, highest_compile_level());
575
assert(verify_level(level), "Invalid compilation level: %d", level);
576
return level;
577
}
578
579
CompLevel CompilationPolicy::initial_compile_level(const methodHandle& method) {
580
CompLevel level = CompLevel_any;
581
if (CompilationModeFlag::normal()) {
582
level = CompLevel_full_profile;
583
} else if (CompilationModeFlag::quick_only()) {
584
level = CompLevel_simple;
585
} else if (CompilationModeFlag::high_only()) {
586
level = CompLevel_full_optimization;
587
} else if (CompilationModeFlag::high_only_quick_internal()) {
588
if (force_comp_at_level_simple(method)) {
589
level = CompLevel_simple;
590
} else {
591
level = CompLevel_full_optimization;
592
}
593
}
594
assert(level != CompLevel_any, "Unhandled compilation mode");
595
return limit_level(level);
596
}
597
598
// Set carry flags on the counters if necessary
599
void CompilationPolicy::handle_counter_overflow(const methodHandle& method) {
600
MethodCounters *mcs = method->method_counters();
601
if (mcs != NULL) {
602
mcs->invocation_counter()->set_carry_on_overflow();
603
mcs->backedge_counter()->set_carry_on_overflow();
604
}
605
MethodData* mdo = method->method_data();
606
if (mdo != NULL) {
607
mdo->invocation_counter()->set_carry_on_overflow();
608
mdo->backedge_counter()->set_carry_on_overflow();
609
}
610
}
611
612
// Called with the queue locked and with at least one element
613
CompileTask* CompilationPolicy::select_task(CompileQueue* compile_queue) {
614
CompileTask *max_blocking_task = NULL;
615
CompileTask *max_task = NULL;
616
Method* max_method = NULL;
617
618
jlong t = nanos_to_millis(os::javaTimeNanos());
619
// Iterate through the queue and find a method with a maximum rate.
620
for (CompileTask* task = compile_queue->first(); task != NULL;) {
621
CompileTask* next_task = task->next();
622
// If a method was unloaded or has been stale for some time, remove it from the queue.
623
// Blocking tasks and tasks submitted from whitebox API don't become stale
624
if (task->is_unloaded()) {
625
compile_queue->remove_and_mark_stale(task);
626
task = next_task;
627
continue;
628
}
629
Method* method = task->method();
630
methodHandle mh(Thread::current(), method);
631
if (task->can_become_stale() && is_stale(t, TieredCompileTaskTimeout, mh) && !is_old(mh)) {
632
if (PrintTieredEvents) {
633
print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel) task->comp_level());
634
}
635
method->clear_queued_for_compilation();
636
compile_queue->remove_and_mark_stale(task);
637
task = next_task;
638
continue;
639
}
640
update_rate(t, mh);
641
if (max_task == NULL || compare_methods(method, max_method)) {
642
// Select a method with the highest rate
643
max_task = task;
644
max_method = method;
645
}
646
647
if (task->is_blocking()) {
648
if (max_blocking_task == NULL || compare_methods(method, max_blocking_task->method())) {
649
max_blocking_task = task;
650
}
651
}
652
653
task = next_task;
654
}
655
656
if (max_blocking_task != NULL) {
657
// In blocking compilation mode, the CompileBroker will make
658
// compilations submitted by a JVMCI compiler thread non-blocking. These
659
// compilations should be scheduled after all blocking compilations
660
// to service non-compiler related compilations sooner and reduce the
661
// chance of such compilations timing out.
662
max_task = max_blocking_task;
663
max_method = max_task->method();
664
}
665
666
methodHandle max_method_h(Thread::current(), max_method);
667
668
if (max_task != NULL && max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile &&
669
max_method != NULL && is_method_profiled(max_method_h) && !Arguments::is_compiler_only()) {
670
max_task->set_comp_level(CompLevel_limited_profile);
671
672
if (CompileBroker::compilation_is_complete(max_method_h, max_task->osr_bci(), CompLevel_limited_profile)) {
673
if (PrintTieredEvents) {
674
print_event(REMOVE_FROM_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
675
}
676
compile_queue->remove_and_mark_stale(max_task);
677
max_method->clear_queued_for_compilation();
678
return NULL;
679
}
680
681
if (PrintTieredEvents) {
682
print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
683
}
684
}
685
686
return max_task;
687
}
688
689
void CompilationPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
690
for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) {
691
if (PrintTieredEvents) {
692
print_event(REPROFILE, sd->method(), sd->method(), InvocationEntryBci, CompLevel_none);
693
}
694
MethodData* mdo = sd->method()->method_data();
695
if (mdo != NULL) {
696
mdo->reset_start_counters();
697
}
698
if (sd->is_top()) break;
699
}
700
}
701
702
nmethod* CompilationPolicy::event(const methodHandle& method, const methodHandle& inlinee,
703
int branch_bci, int bci, CompLevel comp_level, CompiledMethod* nm, TRAPS) {
704
if (PrintTieredEvents) {
705
print_event(bci == InvocationEntryBci ? CALL : LOOP, method(), inlinee(), bci, comp_level);
706
}
707
708
if (comp_level == CompLevel_none &&
709
JvmtiExport::can_post_interpreter_events() &&
710
THREAD->is_interp_only_mode()) {
711
return NULL;
712
}
713
if (ReplayCompiles) {
714
// Don't trigger other compiles in testing mode
715
return NULL;
716
}
717
718
handle_counter_overflow(method);
719
if (method() != inlinee()) {
720
handle_counter_overflow(inlinee);
721
}
722
723
if (bci == InvocationEntryBci) {
724
method_invocation_event(method, inlinee, comp_level, nm, THREAD);
725
} else {
726
// method == inlinee if the event originated in the main method
727
method_back_branch_event(method, inlinee, bci, comp_level, nm, THREAD);
728
// Check if event led to a higher level OSR compilation
729
CompLevel expected_comp_level = MIN2(CompLevel_full_optimization, static_cast<CompLevel>(comp_level + 1));
730
if (!CompilationModeFlag::disable_intermediate() && inlinee->is_not_osr_compilable(expected_comp_level)) {
731
// It's not possble to reach the expected level so fall back to simple.
732
expected_comp_level = CompLevel_simple;
733
}
734
CompLevel max_osr_level = static_cast<CompLevel>(inlinee->highest_osr_comp_level());
735
if (max_osr_level >= expected_comp_level) { // fast check to avoid locking in a typical scenario
736
nmethod* osr_nm = inlinee->lookup_osr_nmethod_for(bci, expected_comp_level, false);
737
assert(osr_nm == NULL || osr_nm->comp_level() >= expected_comp_level, "lookup_osr_nmethod_for is broken");
738
if (osr_nm != NULL && osr_nm->comp_level() != comp_level) {
739
// Perform OSR with new nmethod
740
return osr_nm;
741
}
742
}
743
}
744
return NULL;
745
}
746
747
// Check if the method can be compiled, change level if necessary
748
void CompilationPolicy::compile(const methodHandle& mh, int bci, CompLevel level, TRAPS) {
749
assert(verify_level(level), "Invalid compilation level requested: %d", level);
750
751
if (level == CompLevel_none) {
752
if (mh->has_compiled_code()) {
753
// Happens when we switch to interpreter to profile.
754
MutexLocker ml(Compile_lock);
755
NoSafepointVerifier nsv;
756
if (mh->has_compiled_code()) {
757
mh->code()->make_not_used();
758
}
759
// Deoptimize immediately (we don't have to wait for a compile).
760
JavaThread* jt = THREAD;
761
RegisterMap map(jt, false);
762
frame fr = jt->last_frame().sender(&map);
763
Deoptimization::deoptimize_frame(jt, fr.id());
764
}
765
return;
766
}
767
768
if (!CompilationModeFlag::disable_intermediate()) {
769
// Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
770
// in the interpreter and then compile with C2 (the transition function will request that,
771
// see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
772
// pure C1.
773
if ((bci == InvocationEntryBci && !can_be_compiled(mh, level))) {
774
if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
775
compile(mh, bci, CompLevel_simple, THREAD);
776
}
777
return;
778
}
779
if ((bci != InvocationEntryBci && !can_be_osr_compiled(mh, level))) {
780
if (level == CompLevel_full_optimization && can_be_osr_compiled(mh, CompLevel_simple)) {
781
nmethod* osr_nm = mh->lookup_osr_nmethod_for(bci, CompLevel_simple, false);
782
if (osr_nm != NULL && osr_nm->comp_level() > CompLevel_simple) {
783
// Invalidate the existing OSR nmethod so that a compile at CompLevel_simple is permitted.
784
osr_nm->make_not_entrant();
785
}
786
compile(mh, bci, CompLevel_simple, THREAD);
787
}
788
return;
789
}
790
}
791
if (bci != InvocationEntryBci && mh->is_not_osr_compilable(level)) {
792
return;
793
}
794
if (!CompileBroker::compilation_is_in_queue(mh)) {
795
if (PrintTieredEvents) {
796
print_event(COMPILE, mh(), mh(), bci, level);
797
}
798
int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
799
update_rate(nanos_to_millis(os::javaTimeNanos()), mh);
800
CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, THREAD);
801
}
802
}
803
804
// update_rate() is called from select_task() while holding a compile queue lock.
805
void CompilationPolicy::update_rate(jlong t, const methodHandle& method) {
806
// Skip update if counters are absent.
807
// Can't allocate them since we are holding compile queue lock.
808
if (method->method_counters() == NULL) return;
809
810
if (is_old(method)) {
811
// We don't remove old methods from the queue,
812
// so we can just zero the rate.
813
method->set_rate(0);
814
return;
815
}
816
817
// We don't update the rate if we've just came out of a safepoint.
818
// delta_s is the time since last safepoint in milliseconds.
819
jlong delta_s = t - SafepointTracing::end_of_last_safepoint_ms();
820
jlong delta_t = t - (method->prev_time() != 0 ? method->prev_time() : start_time()); // milliseconds since the last measurement
821
// How many events were there since the last time?
822
int event_count = method->invocation_count() + method->backedge_count();
823
int delta_e = event_count - method->prev_event_count();
824
825
// We should be running for at least 1ms.
826
if (delta_s >= TieredRateUpdateMinTime) {
827
// And we must've taken the previous point at least 1ms before.
828
if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) {
829
method->set_prev_time(t);
830
method->set_prev_event_count(event_count);
831
method->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond
832
} else {
833
if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) {
834
// If nothing happened for 25ms, zero the rate. Don't modify prev values.
835
method->set_rate(0);
836
}
837
}
838
}
839
}
840
841
// Check if this method has been stale for a given number of milliseconds.
842
// See select_task().
843
bool CompilationPolicy::is_stale(jlong t, jlong timeout, const methodHandle& method) {
844
jlong delta_s = t - SafepointTracing::end_of_last_safepoint_ms();
845
jlong delta_t = t - method->prev_time();
846
if (delta_t > timeout && delta_s > timeout) {
847
int event_count = method->invocation_count() + method->backedge_count();
848
int delta_e = event_count - method->prev_event_count();
849
// Return true if there were no events.
850
return delta_e == 0;
851
}
852
return false;
853
}
854
855
// We don't remove old methods from the compile queue even if they have
856
// very low activity. See select_task().
857
bool CompilationPolicy::is_old(const methodHandle& method) {
858
int i = method->invocation_count();
859
int b = method->backedge_count();
860
double k = TieredOldPercentage / 100.0;
861
862
return CallPredicate::apply_scaled(method, CompLevel_none, i, b, k) || LoopPredicate::apply_scaled(method, CompLevel_none, i, b, k);
863
}
864
865
double CompilationPolicy::weight(Method* method) {
866
return (double)(method->rate() + 1) * (method->invocation_count() + 1) * (method->backedge_count() + 1);
867
}
868
869
// Apply heuristics and return true if x should be compiled before y
870
bool CompilationPolicy::compare_methods(Method* x, Method* y) {
871
if (x->highest_comp_level() > y->highest_comp_level()) {
872
// recompilation after deopt
873
return true;
874
} else
875
if (x->highest_comp_level() == y->highest_comp_level()) {
876
if (weight(x) > weight(y)) {
877
return true;
878
}
879
}
880
return false;
881
}
882
883
// Is method profiled enough?
884
bool CompilationPolicy::is_method_profiled(const methodHandle& method) {
885
MethodData* mdo = method->method_data();
886
if (mdo != NULL) {
887
int i = mdo->invocation_count_delta();
888
int b = mdo->backedge_count_delta();
889
return CallPredicate::apply_scaled(method, CompLevel_full_profile, i, b, 1);
890
}
891
return false;
892
}
893
894
895
// Determine is a method is mature.
896
bool CompilationPolicy::is_mature(Method* method) {
897
methodHandle mh(Thread::current(), method);
898
MethodData* mdo = method->method_data();
899
if (mdo != NULL) {
900
int i = mdo->invocation_count();
901
int b = mdo->backedge_count();
902
double k = ProfileMaturityPercentage / 100.0;
903
return CallPredicate::apply_scaled(mh, CompLevel_full_profile, i, b, k) || LoopPredicate::apply_scaled(mh, CompLevel_full_profile, i, b, k);
904
}
905
return false;
906
}
907
908
// If a method is old enough and is still in the interpreter we would want to
909
// start profiling without waiting for the compiled method to arrive.
910
// We also take the load on compilers into the account.
911
bool CompilationPolicy::should_create_mdo(const methodHandle& method, CompLevel cur_level) {
912
if (cur_level != CompLevel_none || force_comp_at_level_simple(method) || CompilationModeFlag::quick_only() || !ProfileInterpreter) {
913
return false;
914
}
915
if (is_old(method)) {
916
return true;
917
}
918
int i = method->invocation_count();
919
int b = method->backedge_count();
920
double k = Tier0ProfilingStartPercentage / 100.0;
921
922
// If the top level compiler is not keeping up, delay profiling.
923
if (CompileBroker::queue_size(CompLevel_full_optimization) <= Tier0Delay * compiler_count(CompLevel_full_optimization)) {
924
return CallPredicate::apply_scaled(method, CompLevel_none, i, b, k) || LoopPredicate::apply_scaled(method, CompLevel_none, i, b, k);
925
}
926
return false;
927
}
928
929
// Inlining control: if we're compiling a profiled method with C1 and the callee
930
// is known to have OSRed in a C2 version, don't inline it.
931
bool CompilationPolicy::should_not_inline(ciEnv* env, ciMethod* callee) {
932
CompLevel comp_level = (CompLevel)env->comp_level();
933
if (comp_level == CompLevel_full_profile ||
934
comp_level == CompLevel_limited_profile) {
935
return callee->highest_osr_comp_level() == CompLevel_full_optimization;
936
}
937
return false;
938
}
939
940
// Create MDO if necessary.
941
void CompilationPolicy::create_mdo(const methodHandle& mh, JavaThread* THREAD) {
942
if (mh->is_native() ||
943
mh->is_abstract() ||
944
mh->is_accessor() ||
945
mh->is_constant_getter()) {
946
return;
947
}
948
if (mh->method_data() == NULL) {
949
Method::build_interpreter_method_data(mh, CHECK_AND_CLEAR);
950
}
951
if (ProfileInterpreter) {
952
MethodData* mdo = mh->method_data();
953
if (mdo != NULL) {
954
frame last_frame = THREAD->last_frame();
955
if (last_frame.is_interpreted_frame() && mh == last_frame.interpreter_frame_method()) {
956
int bci = last_frame.interpreter_frame_bci();
957
address dp = mdo->bci_to_dp(bci);
958
last_frame.interpreter_frame_set_mdp(dp);
959
}
960
}
961
}
962
}
963
964
965
966
/*
967
* Method states:
968
* 0 - interpreter (CompLevel_none)
969
* 1 - pure C1 (CompLevel_simple)
970
* 2 - C1 with invocation and backedge counting (CompLevel_limited_profile)
971
* 3 - C1 with full profiling (CompLevel_full_profile)
972
* 4 - C2 or Graal (CompLevel_full_optimization)
973
*
974
* Common state transition patterns:
975
* a. 0 -> 3 -> 4.
976
* The most common path. But note that even in this straightforward case
977
* profiling can start at level 0 and finish at level 3.
978
*
979
* b. 0 -> 2 -> 3 -> 4.
980
* This case occurs when the load on C2 is deemed too high. So, instead of transitioning
981
* into state 3 directly and over-profiling while a method is in the C2 queue we transition to
982
* level 2 and wait until the load on C2 decreases. This path is disabled for OSRs.
983
*
984
* c. 0 -> (3->2) -> 4.
985
* In this case we enqueue a method for compilation at level 3, but the C1 queue is long enough
986
* to enable the profiling to fully occur at level 0. In this case we change the compilation level
987
* of the method to 2 while the request is still in-queue, because it'll allow it to run much faster
988
* without full profiling while c2 is compiling.
989
*
990
* d. 0 -> 3 -> 1 or 0 -> 2 -> 1.
991
* After a method was once compiled with C1 it can be identified as trivial and be compiled to
992
* level 1. These transition can also occur if a method can't be compiled with C2 but can with C1.
993
*
994
* e. 0 -> 4.
995
* This can happen if a method fails C1 compilation (it will still be profiled in the interpreter)
996
* or because of a deopt that didn't require reprofiling (compilation won't happen in this case because
997
* the compiled version already exists).
998
*
999
* Note that since state 0 can be reached from any other state via deoptimization different loops
1000
* are possible.
1001
*
1002
*/
1003
1004
// Common transition function. Given a predicate determines if a method should transition to another level.
1005
template<typename Predicate>
1006
CompLevel CompilationPolicy::common(const methodHandle& method, CompLevel cur_level, bool disable_feedback) {
1007
CompLevel next_level = cur_level;
1008
int i = method->invocation_count();
1009
int b = method->backedge_count();
1010
1011
if (force_comp_at_level_simple(method)) {
1012
next_level = CompLevel_simple;
1013
} else {
1014
if (is_trivial(method)) {
1015
next_level = CompilationModeFlag::disable_intermediate() ? CompLevel_full_optimization : CompLevel_simple;
1016
} else {
1017
switch(cur_level) {
1018
default: break;
1019
case CompLevel_none:
1020
// If we were at full profile level, would we switch to full opt?
1021
if (common<Predicate>(method, CompLevel_full_profile, disable_feedback) == CompLevel_full_optimization) {
1022
next_level = CompLevel_full_optimization;
1023
} else if (!CompilationModeFlag::disable_intermediate() && Predicate::apply(method, cur_level, i, b)) {
1024
// C1-generated fully profiled code is about 30% slower than the limited profile
1025
// code that has only invocation and backedge counters. The observation is that
1026
// if C2 queue is large enough we can spend too much time in the fully profiled code
1027
// while waiting for C2 to pick the method from the queue. To alleviate this problem
1028
// we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
1029
// we choose to compile a limited profiled version and then recompile with full profiling
1030
// when the load on C2 goes down.
1031
if (!disable_feedback && CompileBroker::queue_size(CompLevel_full_optimization) >
1032
Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
1033
next_level = CompLevel_limited_profile;
1034
} else {
1035
next_level = CompLevel_full_profile;
1036
}
1037
}
1038
break;
1039
case CompLevel_limited_profile:
1040
if (is_method_profiled(method)) {
1041
// Special case: we got here because this method was fully profiled in the interpreter.
1042
next_level = CompLevel_full_optimization;
1043
} else {
1044
MethodData* mdo = method->method_data();
1045
if (mdo != NULL) {
1046
if (mdo->would_profile()) {
1047
if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
1048
Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
1049
Predicate::apply(method, cur_level, i, b))) {
1050
next_level = CompLevel_full_profile;
1051
}
1052
} else {
1053
next_level = CompLevel_full_optimization;
1054
}
1055
} else {
1056
// If there is no MDO we need to profile
1057
if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <=
1058
Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
1059
Predicate::apply(method, cur_level, i, b))) {
1060
next_level = CompLevel_full_profile;
1061
}
1062
}
1063
}
1064
break;
1065
case CompLevel_full_profile:
1066
{
1067
MethodData* mdo = method->method_data();
1068
if (mdo != NULL) {
1069
if (mdo->would_profile() || CompilationModeFlag::disable_intermediate()) {
1070
int mdo_i = mdo->invocation_count_delta();
1071
int mdo_b = mdo->backedge_count_delta();
1072
if (Predicate::apply(method, cur_level, mdo_i, mdo_b)) {
1073
next_level = CompLevel_full_optimization;
1074
}
1075
} else {
1076
next_level = CompLevel_full_optimization;
1077
}
1078
}
1079
}
1080
break;
1081
}
1082
}
1083
}
1084
return (next_level != cur_level) ? limit_level(next_level) : next_level;
1085
}
1086
1087
1088
1089
// Determine if a method should be compiled with a normal entry point at a different level.
1090
CompLevel CompilationPolicy::call_event(const methodHandle& method, CompLevel cur_level, Thread* thread) {
1091
CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(), common<LoopPredicate>(method, cur_level, true));
1092
CompLevel next_level = common<CallPredicate>(method, cur_level, is_old(method));
1093
1094
// If OSR method level is greater than the regular method level, the levels should be
1095
// equalized by raising the regular method level in order to avoid OSRs during each
1096
// invocation of the method.
1097
if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
1098
MethodData* mdo = method->method_data();
1099
guarantee(mdo != NULL, "MDO should not be NULL");
1100
if (mdo->invocation_count() >= 1) {
1101
next_level = CompLevel_full_optimization;
1102
}
1103
} else {
1104
next_level = MAX2(osr_level, next_level);
1105
}
1106
return next_level;
1107
}
1108
1109
// Determine if we should do an OSR compilation of a given method.
1110
CompLevel CompilationPolicy::loop_event(const methodHandle& method, CompLevel cur_level, Thread* thread) {
1111
CompLevel next_level = common<LoopPredicate>(method, cur_level, true);
1112
if (cur_level == CompLevel_none) {
1113
// If there is a live OSR method that means that we deopted to the interpreter
1114
// for the transition.
1115
CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
1116
if (osr_level > CompLevel_none) {
1117
return osr_level;
1118
}
1119
}
1120
return next_level;
1121
}
1122
1123
// Handle the invocation event.
1124
void CompilationPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
1125
CompLevel level, CompiledMethod* nm, TRAPS) {
1126
if (should_create_mdo(mh, level)) {
1127
create_mdo(mh, THREAD);
1128
}
1129
CompLevel next_level = call_event(mh, level, THREAD);
1130
if (next_level != level) {
1131
if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
1132
compile(mh, InvocationEntryBci, next_level, THREAD);
1133
}
1134
}
1135
}
1136
1137
// Handle the back branch event. Notice that we can compile the method
1138
// with a regular entry from here.
1139
void CompilationPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
1140
int bci, CompLevel level, CompiledMethod* nm, TRAPS) {
1141
if (should_create_mdo(mh, level)) {
1142
create_mdo(mh, THREAD);
1143
}
1144
// Check if MDO should be created for the inlined method
1145
if (should_create_mdo(imh, level)) {
1146
create_mdo(imh, THREAD);
1147
}
1148
1149
if (is_compilation_enabled()) {
1150
CompLevel next_osr_level = loop_event(imh, level, THREAD);
1151
CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level();
1152
// At the very least compile the OSR version
1153
if (!CompileBroker::compilation_is_in_queue(imh) && (next_osr_level != level)) {
1154
compile(imh, bci, next_osr_level, CHECK);
1155
}
1156
1157
// Use loop event as an opportunity to also check if there's been
1158
// enough calls.
1159
CompLevel cur_level, next_level;
1160
if (mh() != imh()) { // If there is an enclosing method
1161
{
1162
guarantee(nm != NULL, "Should have nmethod here");
1163
cur_level = comp_level(mh());
1164
next_level = call_event(mh, cur_level, THREAD);
1165
1166
if (max_osr_level == CompLevel_full_optimization) {
1167
// The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts
1168
bool make_not_entrant = false;
1169
if (nm->is_osr_method()) {
1170
// This is an osr method, just make it not entrant and recompile later if needed
1171
make_not_entrant = true;
1172
} else {
1173
if (next_level != CompLevel_full_optimization) {
1174
// next_level is not full opt, so we need to recompile the
1175
// enclosing method without the inlinee
1176
cur_level = CompLevel_none;
1177
make_not_entrant = true;
1178
}
1179
}
1180
if (make_not_entrant) {
1181
if (PrintTieredEvents) {
1182
int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci;
1183
print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level);
1184
}
1185
nm->make_not_entrant();
1186
}
1187
}
1188
// Fix up next_level if necessary to avoid deopts
1189
if (next_level == CompLevel_limited_profile && max_osr_level == CompLevel_full_profile) {
1190
next_level = CompLevel_full_profile;
1191
}
1192
if (cur_level != next_level) {
1193
if (!CompileBroker::compilation_is_in_queue(mh)) {
1194
compile(mh, InvocationEntryBci, next_level, THREAD);
1195
}
1196
}
1197
}
1198
} else {
1199
cur_level = comp_level(mh());
1200
next_level = call_event(mh, cur_level, THREAD);
1201
if (next_level != cur_level) {
1202
if (!CompileBroker::compilation_is_in_queue(mh)) {
1203
compile(mh, InvocationEntryBci, next_level, THREAD);
1204
}
1205
}
1206
}
1207
}
1208
}
1209
1210
1211