Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/compiler/compileBroker.cpp
40930 views
1
/*
2
* Copyright (c) 1999, 2021, 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 "jvm.h"
27
#include "classfile/javaClasses.hpp"
28
#include "classfile/symbolTable.hpp"
29
#include "classfile/vmClasses.hpp"
30
#include "classfile/vmSymbols.hpp"
31
#include "code/codeCache.hpp"
32
#include "code/codeHeapState.hpp"
33
#include "code/dependencyContext.hpp"
34
#include "compiler/compilationPolicy.hpp"
35
#include "compiler/compileBroker.hpp"
36
#include "compiler/compileLog.hpp"
37
#include "compiler/compilerEvent.hpp"
38
#include "compiler/compilerOracle.hpp"
39
#include "compiler/directivesParser.hpp"
40
#include "interpreter/linkResolver.hpp"
41
#include "jfr/jfrEvents.hpp"
42
#include "logging/log.hpp"
43
#include "logging/logStream.hpp"
44
#include "memory/allocation.inline.hpp"
45
#include "memory/resourceArea.hpp"
46
#include "memory/universe.hpp"
47
#include "oops/methodData.hpp"
48
#include "oops/method.inline.hpp"
49
#include "oops/oop.inline.hpp"
50
#include "prims/jvmtiExport.hpp"
51
#include "prims/nativeLookup.hpp"
52
#include "prims/whitebox.hpp"
53
#include "runtime/atomic.hpp"
54
#include "runtime/escapeBarrier.hpp"
55
#include "runtime/globals_extension.hpp"
56
#include "runtime/handles.inline.hpp"
57
#include "runtime/init.hpp"
58
#include "runtime/interfaceSupport.inline.hpp"
59
#include "runtime/java.hpp"
60
#include "runtime/javaCalls.hpp"
61
#include "runtime/jniHandles.inline.hpp"
62
#include "runtime/os.hpp"
63
#include "runtime/perfData.hpp"
64
#include "runtime/safepointVerifiers.hpp"
65
#include "runtime/sharedRuntime.hpp"
66
#include "runtime/sweeper.hpp"
67
#include "runtime/threadSMR.hpp"
68
#include "runtime/timerTrace.hpp"
69
#include "runtime/vframe.inline.hpp"
70
#include "utilities/debug.hpp"
71
#include "utilities/dtrace.hpp"
72
#include "utilities/events.hpp"
73
#include "utilities/formatBuffer.hpp"
74
#include "utilities/macros.hpp"
75
#ifdef COMPILER1
76
#include "c1/c1_Compiler.hpp"
77
#endif
78
#if INCLUDE_JVMCI
79
#include "jvmci/jvmciEnv.hpp"
80
#include "jvmci/jvmciRuntime.hpp"
81
#endif
82
#ifdef COMPILER2
83
#include "opto/c2compiler.hpp"
84
#endif
85
86
#ifdef DTRACE_ENABLED
87
88
// Only bother with this argument setup if dtrace is available
89
90
#define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name) \
91
{ \
92
Symbol* klass_name = (method)->klass_name(); \
93
Symbol* name = (method)->name(); \
94
Symbol* signature = (method)->signature(); \
95
HOTSPOT_METHOD_COMPILE_BEGIN( \
96
(char *) comp_name, strlen(comp_name), \
97
(char *) klass_name->bytes(), klass_name->utf8_length(), \
98
(char *) name->bytes(), name->utf8_length(), \
99
(char *) signature->bytes(), signature->utf8_length()); \
100
}
101
102
#define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success) \
103
{ \
104
Symbol* klass_name = (method)->klass_name(); \
105
Symbol* name = (method)->name(); \
106
Symbol* signature = (method)->signature(); \
107
HOTSPOT_METHOD_COMPILE_END( \
108
(char *) comp_name, strlen(comp_name), \
109
(char *) klass_name->bytes(), klass_name->utf8_length(), \
110
(char *) name->bytes(), name->utf8_length(), \
111
(char *) signature->bytes(), signature->utf8_length(), (success)); \
112
}
113
114
#else // ndef DTRACE_ENABLED
115
116
#define DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, comp_name)
117
#define DTRACE_METHOD_COMPILE_END_PROBE(method, comp_name, success)
118
119
#endif // ndef DTRACE_ENABLED
120
121
bool CompileBroker::_initialized = false;
122
volatile bool CompileBroker::_should_block = false;
123
volatile int CompileBroker::_print_compilation_warning = 0;
124
volatile jint CompileBroker::_should_compile_new_jobs = run_compilation;
125
126
// The installed compiler(s)
127
AbstractCompiler* CompileBroker::_compilers[2];
128
129
// The maximum numbers of compiler threads to be determined during startup.
130
int CompileBroker::_c1_count = 0;
131
int CompileBroker::_c2_count = 0;
132
133
// An array of compiler names as Java String objects
134
jobject* CompileBroker::_compiler1_objects = NULL;
135
jobject* CompileBroker::_compiler2_objects = NULL;
136
137
CompileLog** CompileBroker::_compiler1_logs = NULL;
138
CompileLog** CompileBroker::_compiler2_logs = NULL;
139
140
// These counters are used to assign an unique ID to each compilation.
141
volatile jint CompileBroker::_compilation_id = 0;
142
volatile jint CompileBroker::_osr_compilation_id = 0;
143
144
// Performance counters
145
PerfCounter* CompileBroker::_perf_total_compilation = NULL;
146
PerfCounter* CompileBroker::_perf_osr_compilation = NULL;
147
PerfCounter* CompileBroker::_perf_standard_compilation = NULL;
148
149
PerfCounter* CompileBroker::_perf_total_bailout_count = NULL;
150
PerfCounter* CompileBroker::_perf_total_invalidated_count = NULL;
151
PerfCounter* CompileBroker::_perf_total_compile_count = NULL;
152
PerfCounter* CompileBroker::_perf_total_osr_compile_count = NULL;
153
PerfCounter* CompileBroker::_perf_total_standard_compile_count = NULL;
154
155
PerfCounter* CompileBroker::_perf_sum_osr_bytes_compiled = NULL;
156
PerfCounter* CompileBroker::_perf_sum_standard_bytes_compiled = NULL;
157
PerfCounter* CompileBroker::_perf_sum_nmethod_size = NULL;
158
PerfCounter* CompileBroker::_perf_sum_nmethod_code_size = NULL;
159
160
PerfStringVariable* CompileBroker::_perf_last_method = NULL;
161
PerfStringVariable* CompileBroker::_perf_last_failed_method = NULL;
162
PerfStringVariable* CompileBroker::_perf_last_invalidated_method = NULL;
163
PerfVariable* CompileBroker::_perf_last_compile_type = NULL;
164
PerfVariable* CompileBroker::_perf_last_compile_size = NULL;
165
PerfVariable* CompileBroker::_perf_last_failed_type = NULL;
166
PerfVariable* CompileBroker::_perf_last_invalidated_type = NULL;
167
168
// Timers and counters for generating statistics
169
elapsedTimer CompileBroker::_t_total_compilation;
170
elapsedTimer CompileBroker::_t_osr_compilation;
171
elapsedTimer CompileBroker::_t_standard_compilation;
172
elapsedTimer CompileBroker::_t_invalidated_compilation;
173
elapsedTimer CompileBroker::_t_bailedout_compilation;
174
175
int CompileBroker::_total_bailout_count = 0;
176
int CompileBroker::_total_invalidated_count = 0;
177
int CompileBroker::_total_compile_count = 0;
178
int CompileBroker::_total_osr_compile_count = 0;
179
int CompileBroker::_total_standard_compile_count = 0;
180
int CompileBroker::_total_compiler_stopped_count = 0;
181
int CompileBroker::_total_compiler_restarted_count = 0;
182
183
int CompileBroker::_sum_osr_bytes_compiled = 0;
184
int CompileBroker::_sum_standard_bytes_compiled = 0;
185
int CompileBroker::_sum_nmethod_size = 0;
186
int CompileBroker::_sum_nmethod_code_size = 0;
187
188
long CompileBroker::_peak_compilation_time = 0;
189
190
CompilerStatistics CompileBroker::_stats_per_level[CompLevel_full_optimization];
191
192
CompileQueue* CompileBroker::_c2_compile_queue = NULL;
193
CompileQueue* CompileBroker::_c1_compile_queue = NULL;
194
195
196
197
class CompilationLog : public StringEventLog {
198
public:
199
CompilationLog() : StringEventLog("Compilation events", "jit") {
200
}
201
202
void log_compile(JavaThread* thread, CompileTask* task) {
203
StringLogMessage lm;
204
stringStream sstr(lm.buffer(), lm.size());
205
// msg.time_stamp().update_to(tty->time_stamp().ticks());
206
task->print(&sstr, NULL, true, false);
207
log(thread, "%s", (const char*)lm);
208
}
209
210
void log_nmethod(JavaThread* thread, nmethod* nm) {
211
log(thread, "nmethod %d%s " INTPTR_FORMAT " code [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",
212
nm->compile_id(), nm->is_osr_method() ? "%" : "",
213
p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
214
}
215
216
void log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
217
StringLogMessage lm;
218
lm.print("%4d COMPILE SKIPPED: %s", task->compile_id(), reason);
219
if (retry_message != NULL) {
220
lm.append(" (%s)", retry_message);
221
}
222
lm.print("\n");
223
log(thread, "%s", (const char*)lm);
224
}
225
226
void log_metaspace_failure(const char* reason) {
227
ResourceMark rm;
228
StringLogMessage lm;
229
lm.print("%4d COMPILE PROFILING SKIPPED: %s", -1, reason);
230
lm.print("\n");
231
log(JavaThread::current(), "%s", (const char*)lm);
232
}
233
};
234
235
static CompilationLog* _compilation_log = NULL;
236
237
bool compileBroker_init() {
238
if (LogEvents) {
239
_compilation_log = new CompilationLog();
240
}
241
242
// init directives stack, adding default directive
243
DirectivesStack::init();
244
245
if (DirectivesParser::has_file()) {
246
return DirectivesParser::parse_from_flag();
247
} else if (CompilerDirectivesPrint) {
248
// Print default directive even when no other was added
249
DirectivesStack::print(tty);
250
}
251
252
return true;
253
}
254
255
CompileTaskWrapper::CompileTaskWrapper(CompileTask* task) {
256
CompilerThread* thread = CompilerThread::current();
257
thread->set_task(task);
258
CompileLog* log = thread->log();
259
if (log != NULL && !task->is_unloaded()) task->log_task_start(log);
260
}
261
262
CompileTaskWrapper::~CompileTaskWrapper() {
263
CompilerThread* thread = CompilerThread::current();
264
CompileTask* task = thread->task();
265
CompileLog* log = thread->log();
266
if (log != NULL && !task->is_unloaded()) task->log_task_done(log);
267
thread->set_task(NULL);
268
task->set_code_handle(NULL);
269
thread->set_env(NULL);
270
if (task->is_blocking()) {
271
bool free_task = false;
272
{
273
MutexLocker notifier(thread, task->lock());
274
task->mark_complete();
275
#if INCLUDE_JVMCI
276
if (CompileBroker::compiler(task->comp_level())->is_jvmci()) {
277
if (!task->has_waiter()) {
278
// The waiting thread timed out and thus did not free the task.
279
free_task = true;
280
}
281
task->set_blocking_jvmci_compile_state(NULL);
282
}
283
#endif
284
if (!free_task) {
285
// Notify the waiting thread that the compilation has completed
286
// so that it can free the task.
287
task->lock()->notify_all();
288
}
289
}
290
if (free_task) {
291
// The task can only be freed once the task lock is released.
292
CompileTask::free(task);
293
}
294
} else {
295
task->mark_complete();
296
297
// By convention, the compiling thread is responsible for
298
// recycling a non-blocking CompileTask.
299
CompileTask::free(task);
300
}
301
}
302
303
/**
304
* Check if a CompilerThread can be removed and update count if requested.
305
*/
306
bool CompileBroker::can_remove(CompilerThread *ct, bool do_it) {
307
assert(UseDynamicNumberOfCompilerThreads, "or shouldn't be here");
308
if (!ReduceNumberOfCompilerThreads) return false;
309
310
AbstractCompiler *compiler = ct->compiler();
311
int compiler_count = compiler->num_compiler_threads();
312
bool c1 = compiler->is_c1();
313
314
// Keep at least 1 compiler thread of each type.
315
if (compiler_count < 2) return false;
316
317
// Keep thread alive for at least some time.
318
if (ct->idle_time_millis() < (c1 ? 500 : 100)) return false;
319
320
#if INCLUDE_JVMCI
321
if (compiler->is_jvmci()) {
322
// Handles for JVMCI thread objects may get released concurrently.
323
if (do_it) {
324
assert(CompileThread_lock->owner() == ct, "must be holding lock");
325
} else {
326
// Skip check if it's the last thread and let caller check again.
327
return true;
328
}
329
}
330
#endif
331
332
// We only allow the last compiler thread of each type to get removed.
333
jobject last_compiler = c1 ? compiler1_object(compiler_count - 1)
334
: compiler2_object(compiler_count - 1);
335
if (ct->threadObj() == JNIHandles::resolve_non_null(last_compiler)) {
336
if (do_it) {
337
assert_locked_or_safepoint(CompileThread_lock); // Update must be consistent.
338
compiler->set_num_compiler_threads(compiler_count - 1);
339
#if INCLUDE_JVMCI
340
if (compiler->is_jvmci()) {
341
// Old j.l.Thread object can die when no longer referenced elsewhere.
342
JNIHandles::destroy_global(compiler2_object(compiler_count - 1));
343
_compiler2_objects[compiler_count - 1] = NULL;
344
}
345
#endif
346
}
347
return true;
348
}
349
return false;
350
}
351
352
/**
353
* Add a CompileTask to a CompileQueue.
354
*/
355
void CompileQueue::add(CompileTask* task) {
356
assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
357
358
task->set_next(NULL);
359
task->set_prev(NULL);
360
361
if (_last == NULL) {
362
// The compile queue is empty.
363
assert(_first == NULL, "queue is empty");
364
_first = task;
365
_last = task;
366
} else {
367
// Append the task to the queue.
368
assert(_last->next() == NULL, "not last");
369
_last->set_next(task);
370
task->set_prev(_last);
371
_last = task;
372
}
373
++_size;
374
375
// Mark the method as being in the compile queue.
376
task->method()->set_queued_for_compilation();
377
378
if (CIPrintCompileQueue) {
379
print_tty();
380
}
381
382
if (LogCompilation && xtty != NULL) {
383
task->log_task_queued();
384
}
385
386
// Notify CompilerThreads that a task is available.
387
MethodCompileQueue_lock->notify_all();
388
}
389
390
/**
391
* Empties compilation queue by putting all compilation tasks onto
392
* a freelist. Furthermore, the method wakes up all threads that are
393
* waiting on a compilation task to finish. This can happen if background
394
* compilation is disabled.
395
*/
396
void CompileQueue::free_all() {
397
MutexLocker mu(MethodCompileQueue_lock);
398
CompileTask* next = _first;
399
400
// Iterate over all tasks in the compile queue
401
while (next != NULL) {
402
CompileTask* current = next;
403
next = current->next();
404
{
405
// Wake up thread that blocks on the compile task.
406
MutexLocker ct_lock(current->lock());
407
current->lock()->notify();
408
}
409
// Put the task back on the freelist.
410
CompileTask::free(current);
411
}
412
_first = NULL;
413
414
// Wake up all threads that block on the queue.
415
MethodCompileQueue_lock->notify_all();
416
}
417
418
/**
419
* Get the next CompileTask from a CompileQueue
420
*/
421
CompileTask* CompileQueue::get() {
422
// save methods from RedefineClasses across safepoint
423
// across MethodCompileQueue_lock below.
424
methodHandle save_method;
425
methodHandle save_hot_method;
426
427
MonitorLocker locker(MethodCompileQueue_lock);
428
// If _first is NULL we have no more compile jobs. There are two reasons for
429
// having no compile jobs: First, we compiled everything we wanted. Second,
430
// we ran out of code cache so compilation has been disabled. In the latter
431
// case we perform code cache sweeps to free memory such that we can re-enable
432
// compilation.
433
while (_first == NULL) {
434
// Exit loop if compilation is disabled forever
435
if (CompileBroker::is_compilation_disabled_forever()) {
436
return NULL;
437
}
438
439
// If there are no compilation tasks and we can compile new jobs
440
// (i.e., there is enough free space in the code cache) there is
441
// no need to invoke the sweeper. As a result, the hotness of methods
442
// remains unchanged. This behavior is desired, since we want to keep
443
// the stable state, i.e., we do not want to evict methods from the
444
// code cache if it is unnecessary.
445
// We need a timed wait here, since compiler threads can exit if compilation
446
// is disabled forever. We use 5 seconds wait time; the exiting of compiler threads
447
// is not critical and we do not want idle compiler threads to wake up too often.
448
locker.wait(5*1000);
449
450
if (UseDynamicNumberOfCompilerThreads && _first == NULL) {
451
// Still nothing to compile. Give caller a chance to stop this thread.
452
if (CompileBroker::can_remove(CompilerThread::current(), false)) return NULL;
453
}
454
}
455
456
if (CompileBroker::is_compilation_disabled_forever()) {
457
return NULL;
458
}
459
460
CompileTask* task;
461
{
462
NoSafepointVerifier nsv;
463
task = CompilationPolicy::select_task(this);
464
if (task != NULL) {
465
task = task->select_for_compilation();
466
}
467
}
468
469
if (task != NULL) {
470
// Save method pointers across unlock safepoint. The task is removed from
471
// the compilation queue, which is walked during RedefineClasses.
472
Thread* thread = Thread::current();
473
save_method = methodHandle(thread, task->method());
474
save_hot_method = methodHandle(thread, task->hot_method());
475
476
remove(task);
477
}
478
purge_stale_tasks(); // may temporarily release MCQ lock
479
return task;
480
}
481
482
// Clean & deallocate stale compile tasks.
483
// Temporarily releases MethodCompileQueue lock.
484
void CompileQueue::purge_stale_tasks() {
485
assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
486
if (_first_stale != NULL) {
487
// Stale tasks are purged when MCQ lock is released,
488
// but _first_stale updates are protected by MCQ lock.
489
// Once task processing starts and MCQ lock is released,
490
// other compiler threads can reuse _first_stale.
491
CompileTask* head = _first_stale;
492
_first_stale = NULL;
493
{
494
MutexUnlocker ul(MethodCompileQueue_lock);
495
for (CompileTask* task = head; task != NULL; ) {
496
CompileTask* next_task = task->next();
497
CompileTaskWrapper ctw(task); // Frees the task
498
task->set_failure_reason("stale task");
499
task = next_task;
500
}
501
}
502
}
503
}
504
505
void CompileQueue::remove(CompileTask* task) {
506
assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
507
if (task->prev() != NULL) {
508
task->prev()->set_next(task->next());
509
} else {
510
// max is the first element
511
assert(task == _first, "Sanity");
512
_first = task->next();
513
}
514
515
if (task->next() != NULL) {
516
task->next()->set_prev(task->prev());
517
} else {
518
// max is the last element
519
assert(task == _last, "Sanity");
520
_last = task->prev();
521
}
522
--_size;
523
}
524
525
void CompileQueue::remove_and_mark_stale(CompileTask* task) {
526
assert(MethodCompileQueue_lock->owned_by_self(), "must own lock");
527
remove(task);
528
529
// Enqueue the task for reclamation (should be done outside MCQ lock)
530
task->set_next(_first_stale);
531
task->set_prev(NULL);
532
_first_stale = task;
533
}
534
535
// methods in the compile queue need to be marked as used on the stack
536
// so that they don't get reclaimed by Redefine Classes
537
void CompileQueue::mark_on_stack() {
538
CompileTask* task = _first;
539
while (task != NULL) {
540
task->mark_on_stack();
541
task = task->next();
542
}
543
}
544
545
546
CompileQueue* CompileBroker::compile_queue(int comp_level) {
547
if (is_c2_compile(comp_level)) return _c2_compile_queue;
548
if (is_c1_compile(comp_level)) return _c1_compile_queue;
549
return NULL;
550
}
551
552
void CompileBroker::print_compile_queues(outputStream* st) {
553
st->print_cr("Current compiles: ");
554
555
char buf[2000];
556
int buflen = sizeof(buf);
557
Threads::print_threads_compiling(st, buf, buflen, /* short_form = */ true);
558
559
st->cr();
560
if (_c1_compile_queue != NULL) {
561
_c1_compile_queue->print(st);
562
}
563
if (_c2_compile_queue != NULL) {
564
_c2_compile_queue->print(st);
565
}
566
}
567
568
void CompileQueue::print(outputStream* st) {
569
assert_locked_or_safepoint(MethodCompileQueue_lock);
570
st->print_cr("%s:", name());
571
CompileTask* task = _first;
572
if (task == NULL) {
573
st->print_cr("Empty");
574
} else {
575
while (task != NULL) {
576
task->print(st, NULL, true, true);
577
task = task->next();
578
}
579
}
580
st->cr();
581
}
582
583
void CompileQueue::print_tty() {
584
ResourceMark rm;
585
stringStream ss;
586
// Dump the compile queue into a buffer before locking the tty
587
print(&ss);
588
{
589
ttyLocker ttyl;
590
tty->print("%s", ss.as_string());
591
}
592
}
593
594
CompilerCounters::CompilerCounters() {
595
_current_method[0] = '\0';
596
_compile_type = CompileBroker::no_compile;
597
}
598
599
#if INCLUDE_JFR && COMPILER2_OR_JVMCI
600
// It appends new compiler phase names to growable array phase_names(a new CompilerPhaseType mapping
601
// in compiler/compilerEvent.cpp) and registers it with its serializer.
602
//
603
// c2 uses explicit CompilerPhaseType idToPhase mapping in opto/phasetype.hpp,
604
// so if c2 is used, it should be always registered first.
605
// This function is called during vm initialization.
606
void register_jfr_phasetype_serializer(CompilerType compiler_type) {
607
ResourceMark rm;
608
static bool first_registration = true;
609
if (compiler_type == compiler_jvmci) {
610
CompilerEvent::PhaseEvent::get_phase_id("NOT_A_PHASE_NAME", false, false, false);
611
first_registration = false;
612
#ifdef COMPILER2
613
} else if (compiler_type == compiler_c2) {
614
assert(first_registration, "invariant"); // c2 must be registered first.
615
GrowableArray<const char*>* c2_phase_names = new GrowableArray<const char*>(PHASE_NUM_TYPES);
616
for (int i = 0; i < PHASE_NUM_TYPES; i++) {
617
const char* phase_name = CompilerPhaseTypeHelper::to_string((CompilerPhaseType) i);
618
CompilerEvent::PhaseEvent::get_phase_id(phase_name, false, false, false);
619
}
620
first_registration = false;
621
#endif // COMPILER2
622
}
623
}
624
#endif // INCLUDE_JFR && COMPILER2_OR_JVMCI
625
626
// ------------------------------------------------------------------
627
// CompileBroker::compilation_init
628
//
629
// Initialize the Compilation object
630
void CompileBroker::compilation_init_phase1(JavaThread* THREAD) {
631
// No need to initialize compilation system if we do not use it.
632
if (!UseCompiler) {
633
return;
634
}
635
// Set the interface to the current compiler(s).
636
_c1_count = CompilationPolicy::c1_count();
637
_c2_count = CompilationPolicy::c2_count();
638
639
#if INCLUDE_JVMCI
640
if (EnableJVMCI) {
641
// This is creating a JVMCICompiler singleton.
642
JVMCICompiler* jvmci = new JVMCICompiler();
643
644
if (UseJVMCICompiler) {
645
_compilers[1] = jvmci;
646
if (FLAG_IS_DEFAULT(JVMCIThreads)) {
647
if (BootstrapJVMCI) {
648
// JVMCI will bootstrap so give it more threads
649
_c2_count = MIN2(32, os::active_processor_count());
650
}
651
} else {
652
_c2_count = JVMCIThreads;
653
}
654
if (FLAG_IS_DEFAULT(JVMCIHostThreads)) {
655
} else {
656
#ifdef COMPILER1
657
_c1_count = JVMCIHostThreads;
658
#endif // COMPILER1
659
}
660
}
661
}
662
#endif // INCLUDE_JVMCI
663
664
#ifdef COMPILER1
665
if (_c1_count > 0) {
666
_compilers[0] = new Compiler();
667
}
668
#endif // COMPILER1
669
670
#ifdef COMPILER2
671
if (true JVMCI_ONLY( && !UseJVMCICompiler)) {
672
if (_c2_count > 0) {
673
_compilers[1] = new C2Compiler();
674
// Register c2 first as c2 CompilerPhaseType idToPhase mapping is explicit.
675
// idToPhase mapping for c2 is in opto/phasetype.hpp
676
JFR_ONLY(register_jfr_phasetype_serializer(compiler_c2);)
677
}
678
}
679
#endif // COMPILER2
680
681
#if INCLUDE_JVMCI
682
// Register after c2 registration.
683
// JVMCI CompilerPhaseType idToPhase mapping is dynamic.
684
if (EnableJVMCI) {
685
JFR_ONLY(register_jfr_phasetype_serializer(compiler_jvmci);)
686
}
687
#endif // INCLUDE_JVMCI
688
689
// Start the compiler thread(s) and the sweeper thread
690
init_compiler_sweeper_threads();
691
// totalTime performance counter is always created as it is required
692
// by the implementation of java.lang.management.CompilationMXBean.
693
{
694
// Ensure OOM leads to vm_exit_during_initialization.
695
EXCEPTION_MARK;
696
_perf_total_compilation =
697
PerfDataManager::create_counter(JAVA_CI, "totalTime",
698
PerfData::U_Ticks, CHECK);
699
}
700
701
if (UsePerfData) {
702
703
EXCEPTION_MARK;
704
705
// create the jvmstat performance counters
706
_perf_osr_compilation =
707
PerfDataManager::create_counter(SUN_CI, "osrTime",
708
PerfData::U_Ticks, CHECK);
709
710
_perf_standard_compilation =
711
PerfDataManager::create_counter(SUN_CI, "standardTime",
712
PerfData::U_Ticks, CHECK);
713
714
_perf_total_bailout_count =
715
PerfDataManager::create_counter(SUN_CI, "totalBailouts",
716
PerfData::U_Events, CHECK);
717
718
_perf_total_invalidated_count =
719
PerfDataManager::create_counter(SUN_CI, "totalInvalidates",
720
PerfData::U_Events, CHECK);
721
722
_perf_total_compile_count =
723
PerfDataManager::create_counter(SUN_CI, "totalCompiles",
724
PerfData::U_Events, CHECK);
725
_perf_total_osr_compile_count =
726
PerfDataManager::create_counter(SUN_CI, "osrCompiles",
727
PerfData::U_Events, CHECK);
728
729
_perf_total_standard_compile_count =
730
PerfDataManager::create_counter(SUN_CI, "standardCompiles",
731
PerfData::U_Events, CHECK);
732
733
_perf_sum_osr_bytes_compiled =
734
PerfDataManager::create_counter(SUN_CI, "osrBytes",
735
PerfData::U_Bytes, CHECK);
736
737
_perf_sum_standard_bytes_compiled =
738
PerfDataManager::create_counter(SUN_CI, "standardBytes",
739
PerfData::U_Bytes, CHECK);
740
741
_perf_sum_nmethod_size =
742
PerfDataManager::create_counter(SUN_CI, "nmethodSize",
743
PerfData::U_Bytes, CHECK);
744
745
_perf_sum_nmethod_code_size =
746
PerfDataManager::create_counter(SUN_CI, "nmethodCodeSize",
747
PerfData::U_Bytes, CHECK);
748
749
_perf_last_method =
750
PerfDataManager::create_string_variable(SUN_CI, "lastMethod",
751
CompilerCounters::cmname_buffer_length,
752
"", CHECK);
753
754
_perf_last_failed_method =
755
PerfDataManager::create_string_variable(SUN_CI, "lastFailedMethod",
756
CompilerCounters::cmname_buffer_length,
757
"", CHECK);
758
759
_perf_last_invalidated_method =
760
PerfDataManager::create_string_variable(SUN_CI, "lastInvalidatedMethod",
761
CompilerCounters::cmname_buffer_length,
762
"", CHECK);
763
764
_perf_last_compile_type =
765
PerfDataManager::create_variable(SUN_CI, "lastType",
766
PerfData::U_None,
767
(jlong)CompileBroker::no_compile,
768
CHECK);
769
770
_perf_last_compile_size =
771
PerfDataManager::create_variable(SUN_CI, "lastSize",
772
PerfData::U_Bytes,
773
(jlong)CompileBroker::no_compile,
774
CHECK);
775
776
777
_perf_last_failed_type =
778
PerfDataManager::create_variable(SUN_CI, "lastFailedType",
779
PerfData::U_None,
780
(jlong)CompileBroker::no_compile,
781
CHECK);
782
783
_perf_last_invalidated_type =
784
PerfDataManager::create_variable(SUN_CI, "lastInvalidatedType",
785
PerfData::U_None,
786
(jlong)CompileBroker::no_compile,
787
CHECK);
788
}
789
}
790
791
// Completes compiler initialization. Compilation requests submitted
792
// prior to this will be silently ignored.
793
void CompileBroker::compilation_init_phase2() {
794
_initialized = true;
795
}
796
797
Handle CompileBroker::create_thread_oop(const char* name, TRAPS) {
798
Handle string = java_lang_String::create_from_str(name, CHECK_NH);
799
Handle thread_group(THREAD, Universe::system_thread_group());
800
return JavaCalls::construct_new_instance(
801
vmClasses::Thread_klass(),
802
vmSymbols::threadgroup_string_void_signature(),
803
thread_group,
804
string,
805
CHECK_NH);
806
}
807
808
#if defined(ASSERT) && COMPILER2_OR_JVMCI
809
// Stress testing. Dedicated threads revert optimizations based on escape analysis concurrently to
810
// the running java application. Configured with vm options DeoptimizeObjectsALot*.
811
class DeoptimizeObjectsALotThread : public JavaThread {
812
813
static void deopt_objs_alot_thread_entry(JavaThread* thread, TRAPS);
814
void deoptimize_objects_alot_loop_single();
815
void deoptimize_objects_alot_loop_all();
816
817
public:
818
DeoptimizeObjectsALotThread() : JavaThread(&deopt_objs_alot_thread_entry) { }
819
820
bool is_hidden_from_external_view() const { return true; }
821
};
822
823
// Entry for DeoptimizeObjectsALotThread. The threads are started in
824
// CompileBroker::init_compiler_sweeper_threads() iff DeoptimizeObjectsALot is enabled
825
void DeoptimizeObjectsALotThread::deopt_objs_alot_thread_entry(JavaThread* thread, TRAPS) {
826
DeoptimizeObjectsALotThread* dt = ((DeoptimizeObjectsALotThread*) thread);
827
bool enter_single_loop;
828
{
829
MonitorLocker ml(dt, EscapeBarrier_lock, Mutex::_no_safepoint_check_flag);
830
static int single_thread_count = 0;
831
enter_single_loop = single_thread_count++ < DeoptimizeObjectsALotThreadCountSingle;
832
}
833
if (enter_single_loop) {
834
dt->deoptimize_objects_alot_loop_single();
835
} else {
836
dt->deoptimize_objects_alot_loop_all();
837
}
838
}
839
840
// Execute EscapeBarriers in an endless loop to revert optimizations based on escape analysis. Each
841
// barrier targets a single thread which is selected round robin.
842
void DeoptimizeObjectsALotThread::deoptimize_objects_alot_loop_single() {
843
HandleMark hm(this);
844
while (true) {
845
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *deoptee_thread = jtiwh.next(); ) {
846
{ // Begin new scope for escape barrier
847
HandleMarkCleaner hmc(this);
848
ResourceMark rm(this);
849
EscapeBarrier eb(true, this, deoptee_thread);
850
eb.deoptimize_objects(100);
851
}
852
// Now sleep after the escape barriers destructor resumed deoptee_thread.
853
sleep(DeoptimizeObjectsALotInterval);
854
}
855
}
856
}
857
858
// Execute EscapeBarriers in an endless loop to revert optimizations based on escape analysis. Each
859
// barrier targets all java threads in the vm at once.
860
void DeoptimizeObjectsALotThread::deoptimize_objects_alot_loop_all() {
861
HandleMark hm(this);
862
while (true) {
863
{ // Begin new scope for escape barrier
864
HandleMarkCleaner hmc(this);
865
ResourceMark rm(this);
866
EscapeBarrier eb(true, this);
867
eb.deoptimize_objects_all_threads();
868
}
869
// Now sleep after the escape barriers destructor resumed the java threads.
870
sleep(DeoptimizeObjectsALotInterval);
871
}
872
}
873
#endif // defined(ASSERT) && COMPILER2_OR_JVMCI
874
875
876
JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, JavaThread* THREAD) {
877
JavaThread* new_thread = NULL;
878
{
879
MutexLocker mu(THREAD, Threads_lock);
880
switch (type) {
881
case compiler_t:
882
assert(comp != NULL, "Compiler instance missing.");
883
if (!InjectCompilerCreationFailure || comp->num_compiler_threads() == 0) {
884
CompilerCounters* counters = new CompilerCounters();
885
new_thread = new CompilerThread(queue, counters);
886
}
887
break;
888
case sweeper_t:
889
new_thread = new CodeCacheSweeperThread();
890
break;
891
#if defined(ASSERT) && COMPILER2_OR_JVMCI
892
case deoptimizer_t:
893
new_thread = new DeoptimizeObjectsALotThread();
894
break;
895
#endif // ASSERT
896
default:
897
ShouldNotReachHere();
898
}
899
900
// At this point the new CompilerThread data-races with this startup
901
// thread (which I believe is the primoridal thread and NOT the VM
902
// thread). This means Java bytecodes being executed at startup can
903
// queue compile jobs which will run at whatever default priority the
904
// newly created CompilerThread runs at.
905
906
907
// At this point it may be possible that no osthread was created for the
908
// JavaThread due to lack of memory. We would have to throw an exception
909
// in that case. However, since this must work and we do not allow
910
// exceptions anyway, check and abort if this fails. But first release the
911
// lock.
912
913
if (new_thread != NULL && new_thread->osthread() != NULL) {
914
915
java_lang_Thread::set_thread(JNIHandles::resolve_non_null(thread_handle), new_thread);
916
917
// Note that this only sets the JavaThread _priority field, which by
918
// definition is limited to Java priorities and not OS priorities.
919
// The os-priority is set in the CompilerThread startup code itself
920
921
java_lang_Thread::set_priority(JNIHandles::resolve_non_null(thread_handle), NearMaxPriority);
922
923
// Note that we cannot call os::set_priority because it expects Java
924
// priorities and we are *explicitly* using OS priorities so that it's
925
// possible to set the compiler thread priority higher than any Java
926
// thread.
927
928
int native_prio = CompilerThreadPriority;
929
if (native_prio == -1) {
930
if (UseCriticalCompilerThreadPriority) {
931
native_prio = os::java_to_os_priority[CriticalPriority];
932
} else {
933
native_prio = os::java_to_os_priority[NearMaxPriority];
934
}
935
}
936
os::set_native_priority(new_thread, native_prio);
937
938
java_lang_Thread::set_daemon(JNIHandles::resolve_non_null(thread_handle));
939
940
new_thread->set_threadObj(JNIHandles::resolve_non_null(thread_handle));
941
if (type == compiler_t) {
942
CompilerThread::cast(new_thread)->set_compiler(comp);
943
}
944
Threads::add(new_thread);
945
Thread::start(new_thread);
946
}
947
}
948
949
// First release lock before aborting VM.
950
if (new_thread == NULL || new_thread->osthread() == NULL) {
951
if (UseDynamicNumberOfCompilerThreads && type == compiler_t && comp->num_compiler_threads() > 0) {
952
if (new_thread != NULL) {
953
new_thread->smr_delete();
954
}
955
return NULL;
956
}
957
vm_exit_during_initialization("java.lang.OutOfMemoryError",
958
os::native_thread_creation_failed_msg());
959
}
960
961
// Let go of Threads_lock before yielding
962
os::naked_yield(); // make sure that the compiler thread is started early (especially helpful on SOLARIS)
963
964
return new_thread;
965
}
966
967
968
void CompileBroker::init_compiler_sweeper_threads() {
969
NMethodSweeper::set_sweep_threshold_bytes(static_cast<size_t>(SweeperThreshold * ReservedCodeCacheSize / 100.0));
970
log_info(codecache, sweep)("Sweeper threshold: " SIZE_FORMAT " bytes", NMethodSweeper::sweep_threshold_bytes());
971
972
// Ensure any exceptions lead to vm_exit_during_initialization.
973
EXCEPTION_MARK;
974
#if !defined(ZERO)
975
assert(_c2_count > 0 || _c1_count > 0, "No compilers?");
976
#endif // !ZERO
977
// Initialize the compilation queue
978
if (_c2_count > 0) {
979
const char* name = JVMCI_ONLY(UseJVMCICompiler ? "JVMCI compile queue" :) "C2 compile queue";
980
_c2_compile_queue = new CompileQueue(name);
981
_compiler2_objects = NEW_C_HEAP_ARRAY(jobject, _c2_count, mtCompiler);
982
_compiler2_logs = NEW_C_HEAP_ARRAY(CompileLog*, _c2_count, mtCompiler);
983
}
984
if (_c1_count > 0) {
985
_c1_compile_queue = new CompileQueue("C1 compile queue");
986
_compiler1_objects = NEW_C_HEAP_ARRAY(jobject, _c1_count, mtCompiler);
987
_compiler1_logs = NEW_C_HEAP_ARRAY(CompileLog*, _c1_count, mtCompiler);
988
}
989
990
char name_buffer[256];
991
992
for (int i = 0; i < _c2_count; i++) {
993
jobject thread_handle = NULL;
994
// Create all j.l.Thread objects for C1 and C2 threads here, but only one
995
// for JVMCI compiler which can create further ones on demand.
996
JVMCI_ONLY(if (!UseJVMCICompiler || !UseDynamicNumberOfCompilerThreads || i == 0) {)
997
// Create a name for our thread.
998
sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
999
Handle thread_oop = create_thread_oop(name_buffer, CHECK);
1000
thread_handle = JNIHandles::make_global(thread_oop);
1001
JVMCI_ONLY(})
1002
_compiler2_objects[i] = thread_handle;
1003
_compiler2_logs[i] = NULL;
1004
1005
if (!UseDynamicNumberOfCompilerThreads || i == 0) {
1006
JavaThread *ct = make_thread(compiler_t, thread_handle, _c2_compile_queue, _compilers[1], THREAD);
1007
assert(ct != NULL, "should have been handled for initial thread");
1008
_compilers[1]->set_num_compiler_threads(i + 1);
1009
if (TraceCompilerThreads) {
1010
ResourceMark rm;
1011
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1012
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1013
tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
1014
}
1015
}
1016
}
1017
1018
for (int i = 0; i < _c1_count; i++) {
1019
// Create a name for our thread.
1020
sprintf(name_buffer, "C1 CompilerThread%d", i);
1021
Handle thread_oop = create_thread_oop(name_buffer, CHECK);
1022
jobject thread_handle = JNIHandles::make_global(thread_oop);
1023
_compiler1_objects[i] = thread_handle;
1024
_compiler1_logs[i] = NULL;
1025
1026
if (!UseDynamicNumberOfCompilerThreads || i == 0) {
1027
JavaThread *ct = make_thread(compiler_t, thread_handle, _c1_compile_queue, _compilers[0], THREAD);
1028
assert(ct != NULL, "should have been handled for initial thread");
1029
_compilers[0]->set_num_compiler_threads(i + 1);
1030
if (TraceCompilerThreads) {
1031
ResourceMark rm;
1032
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1033
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1034
tty->print_cr("Added initial compiler thread %s", ct->get_thread_name());
1035
}
1036
}
1037
}
1038
1039
if (UsePerfData) {
1040
PerfDataManager::create_constant(SUN_CI, "threads", PerfData::U_Bytes, _c1_count + _c2_count, CHECK);
1041
}
1042
1043
if (MethodFlushing) {
1044
// Initialize the sweeper thread
1045
Handle thread_oop = create_thread_oop("Sweeper thread", CHECK);
1046
jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop());
1047
make_thread(sweeper_t, thread_handle, NULL, NULL, THREAD);
1048
}
1049
1050
#if defined(ASSERT) && COMPILER2_OR_JVMCI
1051
if (DeoptimizeObjectsALot) {
1052
// Initialize and start the object deoptimizer threads
1053
const int total_count = DeoptimizeObjectsALotThreadCountSingle + DeoptimizeObjectsALotThreadCountAll;
1054
for (int count = 0; count < total_count; count++) {
1055
Handle thread_oop = create_thread_oop("Deoptimize objects a lot single mode", CHECK);
1056
jobject thread_handle = JNIHandles::make_local(THREAD, thread_oop());
1057
make_thread(deoptimizer_t, thread_handle, NULL, NULL, THREAD);
1058
}
1059
}
1060
#endif // defined(ASSERT) && COMPILER2_OR_JVMCI
1061
}
1062
1063
void CompileBroker::possibly_add_compiler_threads(JavaThread* THREAD) {
1064
1065
julong available_memory = os::available_memory();
1066
// If SegmentedCodeCache is off, both values refer to the single heap (with type CodeBlobType::All).
1067
size_t available_cc_np = CodeCache::unallocated_capacity(CodeBlobType::MethodNonProfiled),
1068
available_cc_p = CodeCache::unallocated_capacity(CodeBlobType::MethodProfiled);
1069
1070
// Only do attempt to start additional threads if the lock is free.
1071
if (!CompileThread_lock->try_lock()) return;
1072
1073
if (_c2_compile_queue != NULL) {
1074
int old_c2_count = _compilers[1]->num_compiler_threads();
1075
int new_c2_count = MIN4(_c2_count,
1076
_c2_compile_queue->size() / 2,
1077
(int)(available_memory / (200*M)),
1078
(int)(available_cc_np / (128*K)));
1079
1080
for (int i = old_c2_count; i < new_c2_count; i++) {
1081
#if INCLUDE_JVMCI
1082
if (UseJVMCICompiler) {
1083
// Native compiler threads as used in C1/C2 can reuse the j.l.Thread
1084
// objects as their existence is completely hidden from the rest of
1085
// the VM (and those compiler threads can't call Java code to do the
1086
// creation anyway). For JVMCI we have to create new j.l.Thread objects
1087
// as they are visible and we can see unexpected thread lifecycle
1088
// transitions if we bind them to new JavaThreads.
1089
if (!THREAD->can_call_java()) break;
1090
char name_buffer[256];
1091
sprintf(name_buffer, "%s CompilerThread%d", _compilers[1]->name(), i);
1092
Handle thread_oop;
1093
{
1094
// We have to give up the lock temporarily for the Java calls.
1095
MutexUnlocker mu(CompileThread_lock);
1096
thread_oop = create_thread_oop(name_buffer, THREAD);
1097
}
1098
if (HAS_PENDING_EXCEPTION) {
1099
if (TraceCompilerThreads) {
1100
ResourceMark rm;
1101
tty->print_cr("JVMCI compiler thread creation failed:");
1102
PENDING_EXCEPTION->print();
1103
}
1104
CLEAR_PENDING_EXCEPTION;
1105
break;
1106
}
1107
// Check if another thread has beaten us during the Java calls.
1108
if (_compilers[1]->num_compiler_threads() != i) break;
1109
jobject thread_handle = JNIHandles::make_global(thread_oop);
1110
assert(compiler2_object(i) == NULL, "Old one must be released!");
1111
_compiler2_objects[i] = thread_handle;
1112
}
1113
#endif
1114
JavaThread *ct = make_thread(compiler_t, compiler2_object(i), _c2_compile_queue, _compilers[1], THREAD);
1115
if (ct == NULL) break;
1116
_compilers[1]->set_num_compiler_threads(i + 1);
1117
if (TraceCompilerThreads) {
1118
ResourceMark rm;
1119
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1120
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1121
tty->print_cr("Added compiler thread %s (available memory: %dMB, available non-profiled code cache: %dMB)",
1122
ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_np/M));
1123
}
1124
}
1125
}
1126
1127
if (_c1_compile_queue != NULL) {
1128
int old_c1_count = _compilers[0]->num_compiler_threads();
1129
int new_c1_count = MIN4(_c1_count,
1130
_c1_compile_queue->size() / 4,
1131
(int)(available_memory / (100*M)),
1132
(int)(available_cc_p / (128*K)));
1133
1134
for (int i = old_c1_count; i < new_c1_count; i++) {
1135
JavaThread *ct = make_thread(compiler_t, compiler1_object(i), _c1_compile_queue, _compilers[0], THREAD);
1136
if (ct == NULL) break;
1137
_compilers[0]->set_num_compiler_threads(i + 1);
1138
if (TraceCompilerThreads) {
1139
ResourceMark rm;
1140
ThreadsListHandle tlh; // get_thread_name() depends on the TLH.
1141
assert(tlh.includes(ct), "ct=" INTPTR_FORMAT " exited unexpectedly.", p2i(ct));
1142
tty->print_cr("Added compiler thread %s (available memory: %dMB, available profiled code cache: %dMB)",
1143
ct->get_thread_name(), (int)(available_memory/M), (int)(available_cc_p/M));
1144
}
1145
}
1146
}
1147
1148
CompileThread_lock->unlock();
1149
}
1150
1151
1152
/**
1153
* Set the methods on the stack as on_stack so that redefine classes doesn't
1154
* reclaim them. This method is executed at a safepoint.
1155
*/
1156
void CompileBroker::mark_on_stack() {
1157
assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
1158
// Since we are at a safepoint, we do not need a lock to access
1159
// the compile queues.
1160
if (_c2_compile_queue != NULL) {
1161
_c2_compile_queue->mark_on_stack();
1162
}
1163
if (_c1_compile_queue != NULL) {
1164
_c1_compile_queue->mark_on_stack();
1165
}
1166
}
1167
1168
// ------------------------------------------------------------------
1169
// CompileBroker::compile_method
1170
//
1171
// Request compilation of a method.
1172
void CompileBroker::compile_method_base(const methodHandle& method,
1173
int osr_bci,
1174
int comp_level,
1175
const methodHandle& hot_method,
1176
int hot_count,
1177
CompileTask::CompileReason compile_reason,
1178
bool blocking,
1179
Thread* thread) {
1180
guarantee(!method->is_abstract(), "cannot compile abstract methods");
1181
assert(method->method_holder()->is_instance_klass(),
1182
"sanity check");
1183
assert(!method->method_holder()->is_not_initialized(),
1184
"method holder must be initialized");
1185
assert(!method->is_method_handle_intrinsic(), "do not enqueue these guys");
1186
1187
if (CIPrintRequests) {
1188
tty->print("request: ");
1189
method->print_short_name(tty);
1190
if (osr_bci != InvocationEntryBci) {
1191
tty->print(" osr_bci: %d", osr_bci);
1192
}
1193
tty->print(" level: %d comment: %s count: %d", comp_level, CompileTask::reason_name(compile_reason), hot_count);
1194
if (!hot_method.is_null()) {
1195
tty->print(" hot: ");
1196
if (hot_method() != method()) {
1197
hot_method->print_short_name(tty);
1198
} else {
1199
tty->print("yes");
1200
}
1201
}
1202
tty->cr();
1203
}
1204
1205
// A request has been made for compilation. Before we do any
1206
// real work, check to see if the method has been compiled
1207
// in the meantime with a definitive result.
1208
if (compilation_is_complete(method, osr_bci, comp_level)) {
1209
return;
1210
}
1211
1212
#ifndef PRODUCT
1213
if (osr_bci != -1 && !FLAG_IS_DEFAULT(OSROnlyBCI)) {
1214
if ((OSROnlyBCI > 0) ? (OSROnlyBCI != osr_bci) : (-OSROnlyBCI == osr_bci)) {
1215
// Positive OSROnlyBCI means only compile that bci. Negative means don't compile that BCI.
1216
return;
1217
}
1218
}
1219
#endif
1220
1221
// If this method is already in the compile queue, then
1222
// we do not block the current thread.
1223
if (compilation_is_in_queue(method)) {
1224
// We may want to decay our counter a bit here to prevent
1225
// multiple denied requests for compilation. This is an
1226
// open compilation policy issue. Note: The other possibility,
1227
// in the case that this is a blocking compile request, is to have
1228
// all subsequent blocking requesters wait for completion of
1229
// ongoing compiles. Note that in this case we'll need a protocol
1230
// for freeing the associated compile tasks. [Or we could have
1231
// a single static monitor on which all these waiters sleep.]
1232
return;
1233
}
1234
1235
// Tiered policy requires MethodCounters to exist before adding a method to
1236
// the queue. Create if we don't have them yet.
1237
method->get_method_counters(thread);
1238
1239
// Outputs from the following MutexLocker block:
1240
CompileTask* task = NULL;
1241
CompileQueue* queue = compile_queue(comp_level);
1242
1243
// Acquire our lock.
1244
{
1245
MutexLocker locker(thread, MethodCompileQueue_lock);
1246
1247
// Make sure the method has not slipped into the queues since
1248
// last we checked; note that those checks were "fast bail-outs".
1249
// Here we need to be more careful, see 14012000 below.
1250
if (compilation_is_in_queue(method)) {
1251
return;
1252
}
1253
1254
// We need to check again to see if the compilation has
1255
// completed. A previous compilation may have registered
1256
// some result.
1257
if (compilation_is_complete(method, osr_bci, comp_level)) {
1258
return;
1259
}
1260
1261
// We now know that this compilation is not pending, complete,
1262
// or prohibited. Assign a compile_id to this compilation
1263
// and check to see if it is in our [Start..Stop) range.
1264
int compile_id = assign_compile_id(method, osr_bci);
1265
if (compile_id == 0) {
1266
// The compilation falls outside the allowed range.
1267
return;
1268
}
1269
1270
#if INCLUDE_JVMCI
1271
if (UseJVMCICompiler && blocking) {
1272
// Don't allow blocking compiles for requests triggered by JVMCI.
1273
if (thread->is_Compiler_thread()) {
1274
blocking = false;
1275
}
1276
1277
if (!UseJVMCINativeLibrary) {
1278
// Don't allow blocking compiles if inside a class initializer or while performing class loading
1279
vframeStream vfst(thread->as_Java_thread());
1280
for (; !vfst.at_end(); vfst.next()) {
1281
if (vfst.method()->is_static_initializer() ||
1282
(vfst.method()->method_holder()->is_subclass_of(vmClasses::ClassLoader_klass()) &&
1283
vfst.method()->name() == vmSymbols::loadClass_name())) {
1284
blocking = false;
1285
break;
1286
}
1287
}
1288
}
1289
1290
// Don't allow blocking compilation requests to JVMCI
1291
// if JVMCI itself is not yet initialized
1292
if (!JVMCI::is_compiler_initialized() && compiler(comp_level)->is_jvmci()) {
1293
blocking = false;
1294
}
1295
1296
// Don't allow blocking compilation requests if we are in JVMCIRuntime::shutdown
1297
// to avoid deadlock between compiler thread(s) and threads run at shutdown
1298
// such as the DestroyJavaVM thread.
1299
if (JVMCI::in_shutdown()) {
1300
blocking = false;
1301
}
1302
}
1303
#endif // INCLUDE_JVMCI
1304
1305
// We will enter the compilation in the queue.
1306
// 14012000: Note that this sets the queued_for_compile bits in
1307
// the target method. We can now reason that a method cannot be
1308
// queued for compilation more than once, as follows:
1309
// Before a thread queues a task for compilation, it first acquires
1310
// the compile queue lock, then checks if the method's queued bits
1311
// are set or it has already been compiled. Thus there can not be two
1312
// instances of a compilation task for the same method on the
1313
// compilation queue. Consider now the case where the compilation
1314
// thread has already removed a task for that method from the queue
1315
// and is in the midst of compiling it. In this case, the
1316
// queued_for_compile bits must be set in the method (and these
1317
// will be visible to the current thread, since the bits were set
1318
// under protection of the compile queue lock, which we hold now.
1319
// When the compilation completes, the compiler thread first sets
1320
// the compilation result and then clears the queued_for_compile
1321
// bits. Neither of these actions are protected by a barrier (or done
1322
// under the protection of a lock), so the only guarantee we have
1323
// (on machines with TSO (Total Store Order)) is that these values
1324
// will update in that order. As a result, the only combinations of
1325
// these bits that the current thread will see are, in temporal order:
1326
// <RESULT, QUEUE> :
1327
// <0, 1> : in compile queue, but not yet compiled
1328
// <1, 1> : compiled but queue bit not cleared
1329
// <1, 0> : compiled and queue bit cleared
1330
// Because we first check the queue bits then check the result bits,
1331
// we are assured that we cannot introduce a duplicate task.
1332
// Note that if we did the tests in the reverse order (i.e. check
1333
// result then check queued bit), we could get the result bit before
1334
// the compilation completed, and the queue bit after the compilation
1335
// completed, and end up introducing a "duplicate" (redundant) task.
1336
// In that case, the compiler thread should first check if a method
1337
// has already been compiled before trying to compile it.
1338
// NOTE: in the event that there are multiple compiler threads and
1339
// there is de-optimization/recompilation, things will get hairy,
1340
// and in that case it's best to protect both the testing (here) of
1341
// these bits, and their updating (here and elsewhere) under a
1342
// common lock.
1343
task = create_compile_task(queue,
1344
compile_id, method,
1345
osr_bci, comp_level,
1346
hot_method, hot_count, compile_reason,
1347
blocking);
1348
}
1349
1350
if (blocking) {
1351
wait_for_completion(task);
1352
}
1353
}
1354
1355
nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
1356
int comp_level,
1357
const methodHandle& hot_method, int hot_count,
1358
CompileTask::CompileReason compile_reason,
1359
TRAPS) {
1360
// Do nothing if compilebroker is not initalized or compiles are submitted on level none
1361
if (!_initialized || comp_level == CompLevel_none) {
1362
return NULL;
1363
}
1364
1365
AbstractCompiler *comp = CompileBroker::compiler(comp_level);
1366
assert(comp != NULL, "Ensure we have a compiler");
1367
1368
DirectiveSet* directive = DirectivesStack::getMatchingDirective(method, comp);
1369
// CompileBroker::compile_method can trap and can have pending aysnc exception.
1370
nmethod* nm = CompileBroker::compile_method(method, osr_bci, comp_level, hot_method, hot_count, compile_reason, directive, THREAD);
1371
DirectivesStack::release(directive);
1372
return nm;
1373
}
1374
1375
nmethod* CompileBroker::compile_method(const methodHandle& method, int osr_bci,
1376
int comp_level,
1377
const methodHandle& hot_method, int hot_count,
1378
CompileTask::CompileReason compile_reason,
1379
DirectiveSet* directive,
1380
TRAPS) {
1381
1382
// make sure arguments make sense
1383
assert(method->method_holder()->is_instance_klass(), "not an instance method");
1384
assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range");
1385
assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods");
1386
assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized");
1387
// return quickly if possible
1388
1389
// lock, make sure that the compilation
1390
// isn't prohibited in a straightforward way.
1391
AbstractCompiler* comp = CompileBroker::compiler(comp_level);
1392
if (comp == NULL || compilation_is_prohibited(method, osr_bci, comp_level, directive->ExcludeOption)) {
1393
return NULL;
1394
}
1395
1396
#if INCLUDE_JVMCI
1397
if (comp->is_jvmci() && !JVMCI::can_initialize_JVMCI()) {
1398
return NULL;
1399
}
1400
#endif
1401
1402
if (osr_bci == InvocationEntryBci) {
1403
// standard compilation
1404
CompiledMethod* method_code = method->code();
1405
if (method_code != NULL && method_code->is_nmethod()) {
1406
if (compilation_is_complete(method, osr_bci, comp_level)) {
1407
return (nmethod*) method_code;
1408
}
1409
}
1410
if (method->is_not_compilable(comp_level)) {
1411
return NULL;
1412
}
1413
} else {
1414
// osr compilation
1415
// We accept a higher level osr method
1416
nmethod* nm = method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1417
if (nm != NULL) return nm;
1418
if (method->is_not_osr_compilable(comp_level)) return NULL;
1419
}
1420
1421
assert(!HAS_PENDING_EXCEPTION, "No exception should be present");
1422
// some prerequisites that are compiler specific
1423
if (comp->is_c2()) {
1424
method->constants()->resolve_string_constants(CHECK_AND_CLEAR_NONASYNC_NULL);
1425
// Resolve all classes seen in the signature of the method
1426
// we are compiling.
1427
Method::load_signature_classes(method, CHECK_AND_CLEAR_NONASYNC_NULL);
1428
}
1429
1430
// If the method is native, do the lookup in the thread requesting
1431
// the compilation. Native lookups can load code, which is not
1432
// permitted during compilation.
1433
//
1434
// Note: A native method implies non-osr compilation which is
1435
// checked with an assertion at the entry of this method.
1436
if (method->is_native() && !method->is_method_handle_intrinsic()) {
1437
address adr = NativeLookup::lookup(method, THREAD);
1438
if (HAS_PENDING_EXCEPTION) {
1439
// In case of an exception looking up the method, we just forget
1440
// about it. The interpreter will kick-in and throw the exception.
1441
method->set_not_compilable("NativeLookup::lookup failed"); // implies is_not_osr_compilable()
1442
CLEAR_PENDING_EXCEPTION;
1443
return NULL;
1444
}
1445
assert(method->has_native_function(), "must have native code by now");
1446
}
1447
1448
// RedefineClasses() has replaced this method; just return
1449
if (method->is_old()) {
1450
return NULL;
1451
}
1452
1453
// JVMTI -- post_compile_event requires jmethod_id() that may require
1454
// a lock the compiling thread can not acquire. Prefetch it here.
1455
if (JvmtiExport::should_post_compiled_method_load()) {
1456
method->jmethod_id();
1457
}
1458
1459
// do the compilation
1460
if (method->is_native()) {
1461
if (!PreferInterpreterNativeStubs || method->is_method_handle_intrinsic()) {
1462
#if defined(X86) && !defined(ZERO)
1463
// The following native methods:
1464
//
1465
// java.lang.Float.intBitsToFloat
1466
// java.lang.Float.floatToRawIntBits
1467
// java.lang.Double.longBitsToDouble
1468
// java.lang.Double.doubleToRawLongBits
1469
//
1470
// are called through the interpreter even if interpreter native stubs
1471
// are not preferred (i.e., calling through adapter handlers is preferred).
1472
// The reason is that on x86_32 signaling NaNs (sNaNs) are not preserved
1473
// if the version of the methods from the native libraries is called.
1474
// As the interpreter and the C2-intrinsified version of the methods preserves
1475
// sNaNs, that would result in an inconsistent way of handling of sNaNs.
1476
if ((UseSSE >= 1 &&
1477
(method->intrinsic_id() == vmIntrinsics::_intBitsToFloat ||
1478
method->intrinsic_id() == vmIntrinsics::_floatToRawIntBits)) ||
1479
(UseSSE >= 2 &&
1480
(method->intrinsic_id() == vmIntrinsics::_longBitsToDouble ||
1481
method->intrinsic_id() == vmIntrinsics::_doubleToRawLongBits))) {
1482
return NULL;
1483
}
1484
#endif // X86 && !ZERO
1485
1486
// To properly handle the appendix argument for out-of-line calls we are using a small trampoline that
1487
// pops off the appendix argument and jumps to the target (see gen_special_dispatch in SharedRuntime).
1488
//
1489
// Since normal compiled-to-compiled calls are not able to handle such a thing we MUST generate an adapter
1490
// in this case. If we can't generate one and use it we can not execute the out-of-line method handle calls.
1491
AdapterHandlerLibrary::create_native_wrapper(method);
1492
} else {
1493
return NULL;
1494
}
1495
} else {
1496
// If the compiler is shut off due to code cache getting full
1497
// fail out now so blocking compiles dont hang the java thread
1498
if (!should_compile_new_jobs()) {
1499
return NULL;
1500
}
1501
bool is_blocking = !directive->BackgroundCompilationOption || ReplayCompiles;
1502
compile_method_base(method, osr_bci, comp_level, hot_method, hot_count, compile_reason, is_blocking, THREAD);
1503
}
1504
1505
// return requested nmethod
1506
// We accept a higher level osr method
1507
if (osr_bci == InvocationEntryBci) {
1508
CompiledMethod* code = method->code();
1509
if (code == NULL) {
1510
return (nmethod*) code;
1511
} else {
1512
return code->as_nmethod_or_null();
1513
}
1514
}
1515
return method->lookup_osr_nmethod_for(osr_bci, comp_level, false);
1516
}
1517
1518
1519
// ------------------------------------------------------------------
1520
// CompileBroker::compilation_is_complete
1521
//
1522
// See if compilation of this method is already complete.
1523
bool CompileBroker::compilation_is_complete(const methodHandle& method,
1524
int osr_bci,
1525
int comp_level) {
1526
bool is_osr = (osr_bci != standard_entry_bci);
1527
if (is_osr) {
1528
if (method->is_not_osr_compilable(comp_level)) {
1529
return true;
1530
} else {
1531
nmethod* result = method->lookup_osr_nmethod_for(osr_bci, comp_level, true);
1532
return (result != NULL);
1533
}
1534
} else {
1535
if (method->is_not_compilable(comp_level)) {
1536
return true;
1537
} else {
1538
CompiledMethod* result = method->code();
1539
if (result == NULL) return false;
1540
return comp_level == result->comp_level();
1541
}
1542
}
1543
}
1544
1545
1546
/**
1547
* See if this compilation is already requested.
1548
*
1549
* Implementation note: there is only a single "is in queue" bit
1550
* for each method. This means that the check below is overly
1551
* conservative in the sense that an osr compilation in the queue
1552
* will block a normal compilation from entering the queue (and vice
1553
* versa). This can be remedied by a full queue search to disambiguate
1554
* cases. If it is deemed profitable, this may be done.
1555
*/
1556
bool CompileBroker::compilation_is_in_queue(const methodHandle& method) {
1557
return method->queued_for_compilation();
1558
}
1559
1560
// ------------------------------------------------------------------
1561
// CompileBroker::compilation_is_prohibited
1562
//
1563
// See if this compilation is not allowed.
1564
bool CompileBroker::compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded) {
1565
bool is_native = method->is_native();
1566
// Some compilers may not support the compilation of natives.
1567
AbstractCompiler *comp = compiler(comp_level);
1568
if (is_native && (!CICompileNatives || comp == NULL)) {
1569
method->set_not_compilable_quietly("native methods not supported", comp_level);
1570
return true;
1571
}
1572
1573
bool is_osr = (osr_bci != standard_entry_bci);
1574
// Some compilers may not support on stack replacement.
1575
if (is_osr && (!CICompileOSR || comp == NULL)) {
1576
method->set_not_osr_compilable("OSR not supported", comp_level);
1577
return true;
1578
}
1579
1580
// The method may be explicitly excluded by the user.
1581
double scale;
1582
if (excluded || (CompilerOracle::has_option_value(method, CompileCommand::CompileThresholdScaling, scale) && scale == 0)) {
1583
bool quietly = CompilerOracle::be_quiet();
1584
if (PrintCompilation && !quietly) {
1585
// This does not happen quietly...
1586
ResourceMark rm;
1587
tty->print("### Excluding %s:%s",
1588
method->is_native() ? "generation of native wrapper" : "compile",
1589
(method->is_static() ? " static" : ""));
1590
method->print_short_name(tty);
1591
tty->cr();
1592
}
1593
method->set_not_compilable("excluded by CompileCommand", comp_level, !quietly);
1594
}
1595
1596
return false;
1597
}
1598
1599
/**
1600
* Generate serialized IDs for compilation requests. If certain debugging flags are used
1601
* and the ID is not within the specified range, the method is not compiled and 0 is returned.
1602
* The function also allows to generate separate compilation IDs for OSR compilations.
1603
*/
1604
int CompileBroker::assign_compile_id(const methodHandle& method, int osr_bci) {
1605
#ifdef ASSERT
1606
bool is_osr = (osr_bci != standard_entry_bci);
1607
int id;
1608
if (method->is_native()) {
1609
assert(!is_osr, "can't be osr");
1610
// Adapters, native wrappers and method handle intrinsics
1611
// should be generated always.
1612
return Atomic::add(&_compilation_id, 1);
1613
} else if (CICountOSR && is_osr) {
1614
id = Atomic::add(&_osr_compilation_id, 1);
1615
if (CIStartOSR <= id && id < CIStopOSR) {
1616
return id;
1617
}
1618
} else {
1619
id = Atomic::add(&_compilation_id, 1);
1620
if (CIStart <= id && id < CIStop) {
1621
return id;
1622
}
1623
}
1624
1625
// Method was not in the appropriate compilation range.
1626
method->set_not_compilable_quietly("Not in requested compile id range");
1627
return 0;
1628
#else
1629
// CICountOSR is a develop flag and set to 'false' by default. In a product built,
1630
// only _compilation_id is incremented.
1631
return Atomic::add(&_compilation_id, 1);
1632
#endif
1633
}
1634
1635
// ------------------------------------------------------------------
1636
// CompileBroker::assign_compile_id_unlocked
1637
//
1638
// Public wrapper for assign_compile_id that acquires the needed locks
1639
uint CompileBroker::assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci) {
1640
MutexLocker locker(thread, MethodCompileQueue_lock);
1641
return assign_compile_id(method, osr_bci);
1642
}
1643
1644
// ------------------------------------------------------------------
1645
// CompileBroker::create_compile_task
1646
//
1647
// Create a CompileTask object representing the current request for
1648
// compilation. Add this task to the queue.
1649
CompileTask* CompileBroker::create_compile_task(CompileQueue* queue,
1650
int compile_id,
1651
const methodHandle& method,
1652
int osr_bci,
1653
int comp_level,
1654
const methodHandle& hot_method,
1655
int hot_count,
1656
CompileTask::CompileReason compile_reason,
1657
bool blocking) {
1658
CompileTask* new_task = CompileTask::allocate();
1659
new_task->initialize(compile_id, method, osr_bci, comp_level,
1660
hot_method, hot_count, compile_reason,
1661
blocking);
1662
queue->add(new_task);
1663
return new_task;
1664
}
1665
1666
#if INCLUDE_JVMCI
1667
// The number of milliseconds to wait before checking if
1668
// JVMCI compilation has made progress.
1669
static const long JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE = 1000;
1670
1671
// The number of JVMCI compilation progress checks that must fail
1672
// before unblocking a thread waiting for a blocking compilation.
1673
static const int JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS = 10;
1674
1675
/**
1676
* Waits for a JVMCI compiler to complete a given task. This thread
1677
* waits until either the task completes or it sees no JVMCI compilation
1678
* progress for N consecutive milliseconds where N is
1679
* JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE *
1680
* JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS.
1681
*
1682
* @return true if this thread needs to free/recycle the task
1683
*/
1684
bool CompileBroker::wait_for_jvmci_completion(JVMCICompiler* jvmci, CompileTask* task, JavaThread* thread) {
1685
assert(UseJVMCICompiler, "sanity");
1686
MonitorLocker ml(thread, task->lock());
1687
int progress_wait_attempts = 0;
1688
jint thread_jvmci_compilation_ticks = 0;
1689
jint global_jvmci_compilation_ticks = jvmci->global_compilation_ticks();
1690
while (!task->is_complete() && !is_compilation_disabled_forever() &&
1691
ml.wait(JVMCI_COMPILATION_PROGRESS_WAIT_TIMESLICE)) {
1692
JVMCICompileState* jvmci_compile_state = task->blocking_jvmci_compile_state();
1693
1694
bool progress;
1695
if (jvmci_compile_state != NULL) {
1696
jint ticks = jvmci_compile_state->compilation_ticks();
1697
progress = (ticks - thread_jvmci_compilation_ticks) != 0;
1698
JVMCI_event_1("waiting on compilation %d [ticks=%d]", task->compile_id(), ticks);
1699
thread_jvmci_compilation_ticks = ticks;
1700
} else {
1701
// Still waiting on JVMCI compiler queue. This thread may be holding a lock
1702
// that all JVMCI compiler threads are blocked on. We use the global JVMCI
1703
// compilation ticks to determine whether JVMCI compilation
1704
// is still making progress through the JVMCI compiler queue.
1705
jint ticks = jvmci->global_compilation_ticks();
1706
progress = (ticks - global_jvmci_compilation_ticks) != 0;
1707
JVMCI_event_1("waiting on compilation %d to be queued [ticks=%d]", task->compile_id(), ticks);
1708
global_jvmci_compilation_ticks = ticks;
1709
}
1710
1711
if (!progress) {
1712
if (++progress_wait_attempts == JVMCI_COMPILATION_PROGRESS_WAIT_ATTEMPTS) {
1713
if (PrintCompilation) {
1714
task->print(tty, "wait for blocking compilation timed out");
1715
}
1716
JVMCI_event_1("waiting on compilation %d timed out", task->compile_id());
1717
break;
1718
}
1719
} else {
1720
progress_wait_attempts = 0;
1721
}
1722
}
1723
task->clear_waiter();
1724
return task->is_complete();
1725
}
1726
#endif
1727
1728
/**
1729
* Wait for the compilation task to complete.
1730
*/
1731
void CompileBroker::wait_for_completion(CompileTask* task) {
1732
if (CIPrintCompileQueue) {
1733
ttyLocker ttyl;
1734
tty->print_cr("BLOCKING FOR COMPILE");
1735
}
1736
1737
assert(task->is_blocking(), "can only wait on blocking task");
1738
1739
JavaThread* thread = JavaThread::current();
1740
1741
methodHandle method(thread, task->method());
1742
bool free_task;
1743
#if INCLUDE_JVMCI
1744
AbstractCompiler* comp = compiler(task->comp_level());
1745
if (comp->is_jvmci() && !task->should_wait_for_compilation()) {
1746
// It may return before compilation is completed.
1747
free_task = wait_for_jvmci_completion((JVMCICompiler*) comp, task, thread);
1748
} else
1749
#endif
1750
{
1751
MonitorLocker ml(thread, task->lock());
1752
free_task = true;
1753
while (!task->is_complete() && !is_compilation_disabled_forever()) {
1754
ml.wait();
1755
}
1756
}
1757
1758
if (free_task) {
1759
if (is_compilation_disabled_forever()) {
1760
CompileTask::free(task);
1761
return;
1762
}
1763
1764
// It is harmless to check this status without the lock, because
1765
// completion is a stable property (until the task object is recycled).
1766
assert(task->is_complete(), "Compilation should have completed");
1767
assert(task->code_handle() == NULL, "must be reset");
1768
1769
// By convention, the waiter is responsible for recycling a
1770
// blocking CompileTask. Since there is only one waiter ever
1771
// waiting on a CompileTask, we know that no one else will
1772
// be using this CompileTask; we can free it.
1773
CompileTask::free(task);
1774
}
1775
}
1776
1777
/**
1778
* Initialize compiler thread(s) + compiler object(s). The postcondition
1779
* of this function is that the compiler runtimes are initialized and that
1780
* compiler threads can start compiling.
1781
*/
1782
bool CompileBroker::init_compiler_runtime() {
1783
CompilerThread* thread = CompilerThread::current();
1784
AbstractCompiler* comp = thread->compiler();
1785
// Final sanity check - the compiler object must exist
1786
guarantee(comp != NULL, "Compiler object must exist");
1787
1788
{
1789
// Must switch to native to allocate ci_env
1790
ThreadToNativeFromVM ttn(thread);
1791
ciEnv ci_env((CompileTask*)NULL);
1792
// Cache Jvmti state
1793
ci_env.cache_jvmti_state();
1794
// Cache DTrace flags
1795
ci_env.cache_dtrace_flags();
1796
1797
// Switch back to VM state to do compiler initialization
1798
ThreadInVMfromNative tv(thread);
1799
1800
// Perform per-thread and global initializations
1801
comp->initialize();
1802
}
1803
1804
if (comp->is_failed()) {
1805
disable_compilation_forever();
1806
// If compiler initialization failed, no compiler thread that is specific to a
1807
// particular compiler runtime will ever start to compile methods.
1808
shutdown_compiler_runtime(comp, thread);
1809
return false;
1810
}
1811
1812
// C1 specific check
1813
if (comp->is_c1() && (thread->get_buffer_blob() == NULL)) {
1814
warning("Initialization of %s thread failed (no space to run compilers)", thread->name());
1815
return false;
1816
}
1817
1818
return true;
1819
}
1820
1821
/**
1822
* If C1 and/or C2 initialization failed, we shut down all compilation.
1823
* We do this to keep things simple. This can be changed if it ever turns
1824
* out to be a problem.
1825
*/
1826
void CompileBroker::shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread) {
1827
// Free buffer blob, if allocated
1828
if (thread->get_buffer_blob() != NULL) {
1829
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1830
CodeCache::free(thread->get_buffer_blob());
1831
}
1832
1833
if (comp->should_perform_shutdown()) {
1834
// There are two reasons for shutting down the compiler
1835
// 1) compiler runtime initialization failed
1836
// 2) The code cache is full and the following flag is set: -XX:-UseCodeCacheFlushing
1837
warning("%s initialization failed. Shutting down all compilers", comp->name());
1838
1839
// Only one thread per compiler runtime object enters here
1840
// Set state to shut down
1841
comp->set_shut_down();
1842
1843
// Delete all queued compilation tasks to make compiler threads exit faster.
1844
if (_c1_compile_queue != NULL) {
1845
_c1_compile_queue->free_all();
1846
}
1847
1848
if (_c2_compile_queue != NULL) {
1849
_c2_compile_queue->free_all();
1850
}
1851
1852
// Set flags so that we continue execution with using interpreter only.
1853
UseCompiler = false;
1854
UseInterpreter = true;
1855
1856
// We could delete compiler runtimes also. However, there are references to
1857
// the compiler runtime(s) (e.g., nmethod::is_compiled_by_c1()) which then
1858
// fail. This can be done later if necessary.
1859
}
1860
}
1861
1862
/**
1863
* Helper function to create new or reuse old CompileLog.
1864
*/
1865
CompileLog* CompileBroker::get_log(CompilerThread* ct) {
1866
if (!LogCompilation) return NULL;
1867
1868
AbstractCompiler *compiler = ct->compiler();
1869
bool c1 = compiler->is_c1();
1870
jobject* compiler_objects = c1 ? _compiler1_objects : _compiler2_objects;
1871
assert(compiler_objects != NULL, "must be initialized at this point");
1872
CompileLog** logs = c1 ? _compiler1_logs : _compiler2_logs;
1873
assert(logs != NULL, "must be initialized at this point");
1874
int count = c1 ? _c1_count : _c2_count;
1875
1876
// Find Compiler number by its threadObj.
1877
oop compiler_obj = ct->threadObj();
1878
int compiler_number = 0;
1879
bool found = false;
1880
for (; compiler_number < count; compiler_number++) {
1881
if (JNIHandles::resolve_non_null(compiler_objects[compiler_number]) == compiler_obj) {
1882
found = true;
1883
break;
1884
}
1885
}
1886
assert(found, "Compiler must exist at this point");
1887
1888
// Determine pointer for this thread's log.
1889
CompileLog** log_ptr = &logs[compiler_number];
1890
1891
// Return old one if it exists.
1892
CompileLog* log = *log_ptr;
1893
if (log != NULL) {
1894
ct->init_log(log);
1895
return log;
1896
}
1897
1898
// Create a new one and remember it.
1899
init_compiler_thread_log();
1900
log = ct->log();
1901
*log_ptr = log;
1902
return log;
1903
}
1904
1905
// ------------------------------------------------------------------
1906
// CompileBroker::compiler_thread_loop
1907
//
1908
// The main loop run by a CompilerThread.
1909
void CompileBroker::compiler_thread_loop() {
1910
CompilerThread* thread = CompilerThread::current();
1911
CompileQueue* queue = thread->queue();
1912
// For the thread that initializes the ciObjectFactory
1913
// this resource mark holds all the shared objects
1914
ResourceMark rm;
1915
1916
// First thread to get here will initialize the compiler interface
1917
1918
{
1919
ASSERT_IN_VM;
1920
MutexLocker only_one (thread, CompileThread_lock);
1921
if (!ciObjectFactory::is_initialized()) {
1922
ciObjectFactory::initialize();
1923
}
1924
}
1925
1926
// Open a log.
1927
CompileLog* log = get_log(thread);
1928
if (log != NULL) {
1929
log->begin_elem("start_compile_thread name='%s' thread='" UINTX_FORMAT "' process='%d'",
1930
thread->name(),
1931
os::current_thread_id(),
1932
os::current_process_id());
1933
log->stamp();
1934
log->end_elem();
1935
}
1936
1937
// If compiler thread/runtime initialization fails, exit the compiler thread
1938
if (!init_compiler_runtime()) {
1939
return;
1940
}
1941
1942
thread->start_idle_timer();
1943
1944
// Poll for new compilation tasks as long as the JVM runs. Compilation
1945
// should only be disabled if something went wrong while initializing the
1946
// compiler runtimes. This, in turn, should not happen. The only known case
1947
// when compiler runtime initialization fails is if there is not enough free
1948
// space in the code cache to generate the necessary stubs, etc.
1949
while (!is_compilation_disabled_forever()) {
1950
// We need this HandleMark to avoid leaking VM handles.
1951
HandleMark hm(thread);
1952
1953
CompileTask* task = queue->get();
1954
if (task == NULL) {
1955
if (UseDynamicNumberOfCompilerThreads) {
1956
// Access compiler_count under lock to enforce consistency.
1957
MutexLocker only_one(CompileThread_lock);
1958
if (can_remove(thread, true)) {
1959
if (TraceCompilerThreads) {
1960
tty->print_cr("Removing compiler thread %s after " JLONG_FORMAT " ms idle time",
1961
thread->name(), thread->idle_time_millis());
1962
}
1963
// Free buffer blob, if allocated
1964
if (thread->get_buffer_blob() != NULL) {
1965
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1966
CodeCache::free(thread->get_buffer_blob());
1967
}
1968
return; // Stop this thread.
1969
}
1970
}
1971
} else {
1972
// Assign the task to the current thread. Mark this compilation
1973
// thread as active for the profiler.
1974
// CompileTaskWrapper also keeps the Method* from being deallocated if redefinition
1975
// occurs after fetching the compile task off the queue.
1976
CompileTaskWrapper ctw(task);
1977
nmethodLocker result_handle; // (handle for the nmethod produced by this task)
1978
task->set_code_handle(&result_handle);
1979
methodHandle method(thread, task->method());
1980
1981
// Never compile a method if breakpoints are present in it
1982
if (method()->number_of_breakpoints() == 0) {
1983
// Compile the method.
1984
if ((UseCompiler || AlwaysCompileLoopMethods) && CompileBroker::should_compile_new_jobs()) {
1985
invoke_compiler_on_method(task);
1986
thread->start_idle_timer();
1987
} else {
1988
// After compilation is disabled, remove remaining methods from queue
1989
method->clear_queued_for_compilation();
1990
task->set_failure_reason("compilation is disabled");
1991
}
1992
}
1993
1994
if (UseDynamicNumberOfCompilerThreads) {
1995
possibly_add_compiler_threads(thread);
1996
assert(!thread->has_pending_exception(), "should have been handled");
1997
}
1998
}
1999
}
2000
2001
// Shut down compiler runtime
2002
shutdown_compiler_runtime(thread->compiler(), thread);
2003
}
2004
2005
// ------------------------------------------------------------------
2006
// CompileBroker::init_compiler_thread_log
2007
//
2008
// Set up state required by +LogCompilation.
2009
void CompileBroker::init_compiler_thread_log() {
2010
CompilerThread* thread = CompilerThread::current();
2011
char file_name[4*K];
2012
FILE* fp = NULL;
2013
intx thread_id = os::current_thread_id();
2014
for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) {
2015
const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL);
2016
if (dir == NULL) {
2017
jio_snprintf(file_name, sizeof(file_name), "hs_c" UINTX_FORMAT "_pid%u.log",
2018
thread_id, os::current_process_id());
2019
} else {
2020
jio_snprintf(file_name, sizeof(file_name),
2021
"%s%shs_c" UINTX_FORMAT "_pid%u.log", dir,
2022
os::file_separator(), thread_id, os::current_process_id());
2023
}
2024
2025
fp = fopen(file_name, "wt");
2026
if (fp != NULL) {
2027
if (LogCompilation && Verbose) {
2028
tty->print_cr("Opening compilation log %s", file_name);
2029
}
2030
CompileLog* log = new(ResourceObj::C_HEAP, mtCompiler) CompileLog(file_name, fp, thread_id);
2031
if (log == NULL) {
2032
fclose(fp);
2033
return;
2034
}
2035
thread->init_log(log);
2036
2037
if (xtty != NULL) {
2038
ttyLocker ttyl;
2039
// Record any per thread log files
2040
xtty->elem("thread_logfile thread='" INTX_FORMAT "' filename='%s'", thread_id, file_name);
2041
}
2042
return;
2043
}
2044
}
2045
warning("Cannot open log file: %s", file_name);
2046
}
2047
2048
void CompileBroker::log_metaspace_failure() {
2049
const char* message = "some methods may not be compiled because metaspace "
2050
"is out of memory";
2051
if (_compilation_log != NULL) {
2052
_compilation_log->log_metaspace_failure(message);
2053
}
2054
if (PrintCompilation) {
2055
tty->print_cr("COMPILE PROFILING SKIPPED: %s", message);
2056
}
2057
}
2058
2059
2060
// ------------------------------------------------------------------
2061
// CompileBroker::set_should_block
2062
//
2063
// Set _should_block.
2064
// Call this from the VM, with Threads_lock held and a safepoint requested.
2065
void CompileBroker::set_should_block() {
2066
assert(Threads_lock->owner() == Thread::current(), "must have threads lock");
2067
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint already");
2068
#ifndef PRODUCT
2069
if (PrintCompilation && (Verbose || WizardMode))
2070
tty->print_cr("notifying compiler thread pool to block");
2071
#endif
2072
_should_block = true;
2073
}
2074
2075
// ------------------------------------------------------------------
2076
// CompileBroker::maybe_block
2077
//
2078
// Call this from the compiler at convenient points, to poll for _should_block.
2079
void CompileBroker::maybe_block() {
2080
if (_should_block) {
2081
#ifndef PRODUCT
2082
if (PrintCompilation && (Verbose || WizardMode))
2083
tty->print_cr("compiler thread " INTPTR_FORMAT " poll detects block request", p2i(Thread::current()));
2084
#endif
2085
ThreadInVMfromNative tivfn(JavaThread::current());
2086
}
2087
}
2088
2089
// wrapper for CodeCache::print_summary()
2090
static void codecache_print(bool detailed)
2091
{
2092
ResourceMark rm;
2093
stringStream s;
2094
// Dump code cache into a buffer before locking the tty,
2095
{
2096
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
2097
CodeCache::print_summary(&s, detailed);
2098
}
2099
ttyLocker ttyl;
2100
tty->print("%s", s.as_string());
2101
}
2102
2103
// wrapper for CodeCache::print_summary() using outputStream
2104
static void codecache_print(outputStream* out, bool detailed) {
2105
ResourceMark rm;
2106
stringStream s;
2107
2108
// Dump code cache into a buffer
2109
{
2110
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
2111
CodeCache::print_summary(&s, detailed);
2112
}
2113
2114
char* remaining_log = s.as_string();
2115
while (*remaining_log != '\0') {
2116
char* eol = strchr(remaining_log, '\n');
2117
if (eol == NULL) {
2118
out->print_cr("%s", remaining_log);
2119
remaining_log = remaining_log + strlen(remaining_log);
2120
} else {
2121
*eol = '\0';
2122
out->print_cr("%s", remaining_log);
2123
remaining_log = eol + 1;
2124
}
2125
}
2126
}
2127
2128
void CompileBroker::post_compile(CompilerThread* thread, CompileTask* task, bool success, ciEnv* ci_env,
2129
int compilable, const char* failure_reason) {
2130
if (success) {
2131
task->mark_success();
2132
if (ci_env != NULL) {
2133
task->set_num_inlined_bytecodes(ci_env->num_inlined_bytecodes());
2134
}
2135
if (_compilation_log != NULL) {
2136
nmethod* code = task->code();
2137
if (code != NULL) {
2138
_compilation_log->log_nmethod(thread, code);
2139
}
2140
}
2141
} else if (AbortVMOnCompilationFailure) {
2142
if (compilable == ciEnv::MethodCompilable_not_at_tier) {
2143
fatal("Not compilable at tier %d: %s", task->comp_level(), failure_reason);
2144
}
2145
if (compilable == ciEnv::MethodCompilable_never) {
2146
fatal("Never compilable: %s", failure_reason);
2147
}
2148
}
2149
// simulate crash during compilation
2150
assert(task->compile_id() != CICrashAt, "just as planned");
2151
}
2152
2153
static void post_compilation_event(EventCompilation& event, CompileTask* task) {
2154
assert(task != NULL, "invariant");
2155
CompilerEvent::CompilationEvent::post(event,
2156
task->compile_id(),
2157
task->compiler()->type(),
2158
task->method(),
2159
task->comp_level(),
2160
task->is_success(),
2161
task->osr_bci() != CompileBroker::standard_entry_bci,
2162
(task->code() == NULL) ? 0 : task->code()->total_size(),
2163
task->num_inlined_bytecodes());
2164
}
2165
2166
int DirectivesStack::_depth = 0;
2167
CompilerDirectives* DirectivesStack::_top = NULL;
2168
CompilerDirectives* DirectivesStack::_bottom = NULL;
2169
2170
// ------------------------------------------------------------------
2171
// CompileBroker::invoke_compiler_on_method
2172
//
2173
// Compile a method.
2174
//
2175
void CompileBroker::invoke_compiler_on_method(CompileTask* task) {
2176
task->print_ul();
2177
if (PrintCompilation) {
2178
ResourceMark rm;
2179
task->print_tty();
2180
}
2181
elapsedTimer time;
2182
2183
CompilerThread* thread = CompilerThread::current();
2184
ResourceMark rm(thread);
2185
2186
if (LogEvents) {
2187
_compilation_log->log_compile(thread, task);
2188
}
2189
2190
// Common flags.
2191
uint compile_id = task->compile_id();
2192
int osr_bci = task->osr_bci();
2193
bool is_osr = (osr_bci != standard_entry_bci);
2194
bool should_log = (thread->log() != NULL);
2195
bool should_break = false;
2196
const int task_level = task->comp_level();
2197
AbstractCompiler* comp = task->compiler();
2198
2199
DirectiveSet* directive;
2200
{
2201
// create the handle inside it's own block so it can't
2202
// accidentally be referenced once the thread transitions to
2203
// native. The NoHandleMark before the transition should catch
2204
// any cases where this occurs in the future.
2205
methodHandle method(thread, task->method());
2206
assert(!method->is_native(), "no longer compile natives");
2207
2208
// Look up matching directives
2209
directive = DirectivesStack::getMatchingDirective(method, comp);
2210
2211
// Update compile information when using perfdata.
2212
if (UsePerfData) {
2213
update_compile_perf_data(thread, method, is_osr);
2214
}
2215
2216
DTRACE_METHOD_COMPILE_BEGIN_PROBE(method, compiler_name(task_level));
2217
}
2218
2219
should_break = directive->BreakAtCompileOption || task->check_break_at_flags();
2220
if (should_log && !directive->LogOption) {
2221
should_log = false;
2222
}
2223
2224
// Allocate a new set of JNI handles.
2225
push_jni_handle_block();
2226
Method* target_handle = task->method();
2227
int compilable = ciEnv::MethodCompilable;
2228
const char* failure_reason = NULL;
2229
bool failure_reason_on_C_heap = false;
2230
const char* retry_message = NULL;
2231
2232
#if INCLUDE_JVMCI
2233
if (UseJVMCICompiler && comp != NULL && comp->is_jvmci()) {
2234
JVMCICompiler* jvmci = (JVMCICompiler*) comp;
2235
2236
TraceTime t1("compilation", &time);
2237
EventCompilation event;
2238
JVMCICompileState compile_state(task, jvmci);
2239
JVMCIRuntime *runtime = NULL;
2240
2241
if (JVMCI::in_shutdown()) {
2242
failure_reason = "in JVMCI shutdown";
2243
retry_message = "not retryable";
2244
compilable = ciEnv::MethodCompilable_never;
2245
} else if (compile_state.target_method_is_old()) {
2246
// Skip redefined methods
2247
failure_reason = "redefined method";
2248
retry_message = "not retryable";
2249
compilable = ciEnv::MethodCompilable_never;
2250
} else {
2251
JVMCIEnv env(thread, &compile_state, __FILE__, __LINE__);
2252
methodHandle method(thread, target_handle);
2253
runtime = env.runtime();
2254
runtime->compile_method(&env, jvmci, method, osr_bci);
2255
2256
failure_reason = compile_state.failure_reason();
2257
failure_reason_on_C_heap = compile_state.failure_reason_on_C_heap();
2258
if (!compile_state.retryable()) {
2259
retry_message = "not retryable";
2260
compilable = ciEnv::MethodCompilable_not_at_tier;
2261
}
2262
if (task->code() == NULL) {
2263
assert(failure_reason != NULL, "must specify failure_reason");
2264
}
2265
}
2266
post_compile(thread, task, task->code() != NULL, NULL, compilable, failure_reason);
2267
if (event.should_commit()) {
2268
post_compilation_event(event, task);
2269
}
2270
2271
} else
2272
#endif // INCLUDE_JVMCI
2273
{
2274
NoHandleMark nhm;
2275
ThreadToNativeFromVM ttn(thread);
2276
2277
ciEnv ci_env(task);
2278
if (should_break) {
2279
ci_env.set_break_at_compile(true);
2280
}
2281
if (should_log) {
2282
ci_env.set_log(thread->log());
2283
}
2284
assert(thread->env() == &ci_env, "set by ci_env");
2285
// The thread-env() field is cleared in ~CompileTaskWrapper.
2286
2287
// Cache Jvmti state
2288
bool method_is_old = ci_env.cache_jvmti_state();
2289
2290
// Skip redefined methods
2291
if (method_is_old) {
2292
ci_env.record_method_not_compilable("redefined method", true);
2293
}
2294
2295
// Cache DTrace flags
2296
ci_env.cache_dtrace_flags();
2297
2298
ciMethod* target = ci_env.get_method_from_handle(target_handle);
2299
2300
TraceTime t1("compilation", &time);
2301
EventCompilation event;
2302
2303
if (comp == NULL) {
2304
ci_env.record_method_not_compilable("no compiler");
2305
} else if (!ci_env.failing()) {
2306
if (WhiteBoxAPI && WhiteBox::compilation_locked) {
2307
MonitorLocker locker(Compilation_lock, Mutex::_no_safepoint_check_flag);
2308
while (WhiteBox::compilation_locked) {
2309
locker.wait();
2310
}
2311
}
2312
comp->compile_method(&ci_env, target, osr_bci, true, directive);
2313
2314
/* Repeat compilation without installing code for profiling purposes */
2315
int repeat_compilation_count = directive->RepeatCompilationOption;
2316
while (repeat_compilation_count > 0) {
2317
task->print_ul("NO CODE INSTALLED");
2318
comp->compile_method(&ci_env, target, osr_bci, false , directive);
2319
repeat_compilation_count--;
2320
}
2321
}
2322
2323
if (!ci_env.failing() && task->code() == NULL) {
2324
//assert(false, "compiler should always document failure");
2325
// The compiler elected, without comment, not to register a result.
2326
// Do not attempt further compilations of this method.
2327
ci_env.record_method_not_compilable("compile failed");
2328
}
2329
2330
// Copy this bit to the enclosing block:
2331
compilable = ci_env.compilable();
2332
2333
if (ci_env.failing()) {
2334
failure_reason = ci_env.failure_reason();
2335
retry_message = ci_env.retry_message();
2336
ci_env.report_failure(failure_reason);
2337
}
2338
2339
post_compile(thread, task, !ci_env.failing(), &ci_env, compilable, failure_reason);
2340
if (event.should_commit()) {
2341
post_compilation_event(event, task);
2342
}
2343
}
2344
// Remove the JNI handle block after the ciEnv destructor has run in
2345
// the previous block.
2346
pop_jni_handle_block();
2347
2348
if (failure_reason != NULL) {
2349
task->set_failure_reason(failure_reason, failure_reason_on_C_heap);
2350
if (_compilation_log != NULL) {
2351
_compilation_log->log_failure(thread, task, failure_reason, retry_message);
2352
}
2353
if (PrintCompilation) {
2354
FormatBufferResource msg = retry_message != NULL ?
2355
FormatBufferResource("COMPILE SKIPPED: %s (%s)", failure_reason, retry_message) :
2356
FormatBufferResource("COMPILE SKIPPED: %s", failure_reason);
2357
task->print(tty, msg);
2358
}
2359
}
2360
2361
methodHandle method(thread, task->method());
2362
2363
DTRACE_METHOD_COMPILE_END_PROBE(method, compiler_name(task_level), task->is_success());
2364
2365
collect_statistics(thread, time, task);
2366
2367
nmethod* nm = task->code();
2368
if (nm != NULL) {
2369
nm->maybe_print_nmethod(directive);
2370
}
2371
DirectivesStack::release(directive);
2372
2373
if (PrintCompilation && PrintCompilation2) {
2374
tty->print("%7d ", (int) tty->time_stamp().milliseconds()); // print timestamp
2375
tty->print("%4d ", compile_id); // print compilation number
2376
tty->print("%s ", (is_osr ? "%" : " "));
2377
if (task->code() != NULL) {
2378
tty->print("size: %d(%d) ", task->code()->total_size(), task->code()->insts_size());
2379
}
2380
tty->print_cr("time: %d inlined: %d bytes", (int)time.milliseconds(), task->num_inlined_bytecodes());
2381
}
2382
2383
Log(compilation, codecache) log;
2384
if (log.is_debug()) {
2385
LogStream ls(log.debug());
2386
codecache_print(&ls, /* detailed= */ false);
2387
}
2388
if (PrintCodeCacheOnCompilation) {
2389
codecache_print(/* detailed= */ false);
2390
}
2391
// Disable compilation, if required.
2392
switch (compilable) {
2393
case ciEnv::MethodCompilable_never:
2394
if (is_osr)
2395
method->set_not_osr_compilable_quietly("MethodCompilable_never");
2396
else
2397
method->set_not_compilable_quietly("MethodCompilable_never");
2398
break;
2399
case ciEnv::MethodCompilable_not_at_tier:
2400
if (is_osr)
2401
method->set_not_osr_compilable_quietly("MethodCompilable_not_at_tier", task_level);
2402
else
2403
method->set_not_compilable_quietly("MethodCompilable_not_at_tier", task_level);
2404
break;
2405
}
2406
2407
// Note that the queued_for_compilation bits are cleared without
2408
// protection of a mutex. [They were set by the requester thread,
2409
// when adding the task to the compile queue -- at which time the
2410
// compile queue lock was held. Subsequently, we acquired the compile
2411
// queue lock to get this task off the compile queue; thus (to belabour
2412
// the point somewhat) our clearing of the bits must be occurring
2413
// only after the setting of the bits. See also 14012000 above.
2414
method->clear_queued_for_compilation();
2415
}
2416
2417
/**
2418
* The CodeCache is full. Print warning and disable compilation.
2419
* Schedule code cache cleaning so compilation can continue later.
2420
* This function needs to be called only from CodeCache::allocate(),
2421
* since we currently handle a full code cache uniformly.
2422
*/
2423
void CompileBroker::handle_full_code_cache(int code_blob_type) {
2424
UseInterpreter = true;
2425
if (UseCompiler || AlwaysCompileLoopMethods ) {
2426
if (xtty != NULL) {
2427
ResourceMark rm;
2428
stringStream s;
2429
// Dump code cache state into a buffer before locking the tty,
2430
// because log_state() will use locks causing lock conflicts.
2431
CodeCache::log_state(&s);
2432
// Lock to prevent tearing
2433
ttyLocker ttyl;
2434
xtty->begin_elem("code_cache_full");
2435
xtty->print("%s", s.as_string());
2436
xtty->stamp();
2437
xtty->end_elem();
2438
}
2439
2440
#ifndef PRODUCT
2441
if (ExitOnFullCodeCache) {
2442
codecache_print(/* detailed= */ true);
2443
before_exit(JavaThread::current());
2444
exit_globals(); // will delete tty
2445
vm_direct_exit(1);
2446
}
2447
#endif
2448
if (UseCodeCacheFlushing) {
2449
// Since code cache is full, immediately stop new compiles
2450
if (CompileBroker::set_should_compile_new_jobs(CompileBroker::stop_compilation)) {
2451
NMethodSweeper::log_sweep("disable_compiler");
2452
}
2453
} else {
2454
disable_compilation_forever();
2455
}
2456
2457
CodeCache::report_codemem_full(code_blob_type, should_print_compiler_warning());
2458
}
2459
}
2460
2461
// ------------------------------------------------------------------
2462
// CompileBroker::update_compile_perf_data
2463
//
2464
// Record this compilation for debugging purposes.
2465
void CompileBroker::update_compile_perf_data(CompilerThread* thread, const methodHandle& method, bool is_osr) {
2466
ResourceMark rm;
2467
char* method_name = method->name()->as_C_string();
2468
char current_method[CompilerCounters::cmname_buffer_length];
2469
size_t maxLen = CompilerCounters::cmname_buffer_length;
2470
2471
const char* class_name = method->method_holder()->name()->as_C_string();
2472
2473
size_t s1len = strlen(class_name);
2474
size_t s2len = strlen(method_name);
2475
2476
// check if we need to truncate the string
2477
if (s1len + s2len + 2 > maxLen) {
2478
2479
// the strategy is to lop off the leading characters of the
2480
// class name and the trailing characters of the method name.
2481
2482
if (s2len + 2 > maxLen) {
2483
// lop of the entire class name string, let snprintf handle
2484
// truncation of the method name.
2485
class_name += s1len; // null string
2486
}
2487
else {
2488
// lop off the extra characters from the front of the class name
2489
class_name += ((s1len + s2len + 2) - maxLen);
2490
}
2491
}
2492
2493
jio_snprintf(current_method, maxLen, "%s %s", class_name, method_name);
2494
2495
int last_compile_type = normal_compile;
2496
if (CICountOSR && is_osr) {
2497
last_compile_type = osr_compile;
2498
}
2499
2500
CompilerCounters* counters = thread->counters();
2501
counters->set_current_method(current_method);
2502
counters->set_compile_type((jlong) last_compile_type);
2503
}
2504
2505
// ------------------------------------------------------------------
2506
// CompileBroker::push_jni_handle_block
2507
//
2508
// Push on a new block of JNI handles.
2509
void CompileBroker::push_jni_handle_block() {
2510
JavaThread* thread = JavaThread::current();
2511
2512
// Allocate a new block for JNI handles.
2513
// Inlined code from jni_PushLocalFrame()
2514
JNIHandleBlock* java_handles = thread->active_handles();
2515
JNIHandleBlock* compile_handles = JNIHandleBlock::allocate_block(thread);
2516
assert(compile_handles != NULL && java_handles != NULL, "should not be NULL");
2517
compile_handles->set_pop_frame_link(java_handles); // make sure java handles get gc'd.
2518
thread->set_active_handles(compile_handles);
2519
}
2520
2521
2522
// ------------------------------------------------------------------
2523
// CompileBroker::pop_jni_handle_block
2524
//
2525
// Pop off the current block of JNI handles.
2526
void CompileBroker::pop_jni_handle_block() {
2527
JavaThread* thread = JavaThread::current();
2528
2529
// Release our JNI handle block
2530
JNIHandleBlock* compile_handles = thread->active_handles();
2531
JNIHandleBlock* java_handles = compile_handles->pop_frame_link();
2532
thread->set_active_handles(java_handles);
2533
compile_handles->set_pop_frame_link(NULL);
2534
JNIHandleBlock::release_block(compile_handles, thread); // may block
2535
}
2536
2537
// ------------------------------------------------------------------
2538
// CompileBroker::collect_statistics
2539
//
2540
// Collect statistics about the compilation.
2541
2542
void CompileBroker::collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task) {
2543
bool success = task->is_success();
2544
methodHandle method (thread, task->method());
2545
uint compile_id = task->compile_id();
2546
bool is_osr = (task->osr_bci() != standard_entry_bci);
2547
const int comp_level = task->comp_level();
2548
nmethod* code = task->code();
2549
CompilerCounters* counters = thread->counters();
2550
2551
assert(code == NULL || code->is_locked_by_vm(), "will survive the MutexLocker");
2552
MutexLocker locker(CompileStatistics_lock);
2553
2554
// _perf variables are production performance counters which are
2555
// updated regardless of the setting of the CITime and CITimeEach flags
2556
//
2557
2558
// account all time, including bailouts and failures in this counter;
2559
// C1 and C2 counters are counting both successful and unsuccessful compiles
2560
_t_total_compilation.add(time);
2561
2562
if (!success) {
2563
_total_bailout_count++;
2564
if (UsePerfData) {
2565
_perf_last_failed_method->set_value(counters->current_method());
2566
_perf_last_failed_type->set_value(counters->compile_type());
2567
_perf_total_bailout_count->inc();
2568
}
2569
_t_bailedout_compilation.add(time);
2570
} else if (code == NULL) {
2571
if (UsePerfData) {
2572
_perf_last_invalidated_method->set_value(counters->current_method());
2573
_perf_last_invalidated_type->set_value(counters->compile_type());
2574
_perf_total_invalidated_count->inc();
2575
}
2576
_total_invalidated_count++;
2577
_t_invalidated_compilation.add(time);
2578
} else {
2579
// Compilation succeeded
2580
2581
// update compilation ticks - used by the implementation of
2582
// java.lang.management.CompilationMXBean
2583
_perf_total_compilation->inc(time.ticks());
2584
_peak_compilation_time = time.milliseconds() > _peak_compilation_time ? time.milliseconds() : _peak_compilation_time;
2585
2586
if (CITime) {
2587
int bytes_compiled = method->code_size() + task->num_inlined_bytecodes();
2588
if (is_osr) {
2589
_t_osr_compilation.add(time);
2590
_sum_osr_bytes_compiled += bytes_compiled;
2591
} else {
2592
_t_standard_compilation.add(time);
2593
_sum_standard_bytes_compiled += method->code_size() + task->num_inlined_bytecodes();
2594
}
2595
2596
// Collect statistic per compilation level
2597
if (comp_level > CompLevel_none && comp_level <= CompLevel_full_optimization) {
2598
CompilerStatistics* stats = &_stats_per_level[comp_level-1];
2599
if (is_osr) {
2600
stats->_osr.update(time, bytes_compiled);
2601
} else {
2602
stats->_standard.update(time, bytes_compiled);
2603
}
2604
stats->_nmethods_size += code->total_size();
2605
stats->_nmethods_code_size += code->insts_size();
2606
} else {
2607
assert(false, "CompilerStatistics object does not exist for compilation level %d", comp_level);
2608
}
2609
2610
// Collect statistic per compiler
2611
AbstractCompiler* comp = compiler(comp_level);
2612
if (comp) {
2613
CompilerStatistics* stats = comp->stats();
2614
if (is_osr) {
2615
stats->_osr.update(time, bytes_compiled);
2616
} else {
2617
stats->_standard.update(time, bytes_compiled);
2618
}
2619
stats->_nmethods_size += code->total_size();
2620
stats->_nmethods_code_size += code->insts_size();
2621
} else { // if (!comp)
2622
assert(false, "Compiler object must exist");
2623
}
2624
}
2625
2626
if (UsePerfData) {
2627
// save the name of the last method compiled
2628
_perf_last_method->set_value(counters->current_method());
2629
_perf_last_compile_type->set_value(counters->compile_type());
2630
_perf_last_compile_size->set_value(method->code_size() +
2631
task->num_inlined_bytecodes());
2632
if (is_osr) {
2633
_perf_osr_compilation->inc(time.ticks());
2634
_perf_sum_osr_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes());
2635
} else {
2636
_perf_standard_compilation->inc(time.ticks());
2637
_perf_sum_standard_bytes_compiled->inc(method->code_size() + task->num_inlined_bytecodes());
2638
}
2639
}
2640
2641
if (CITimeEach) {
2642
double compile_time = time.seconds();
2643
double bytes_per_sec = compile_time == 0.0 ? 0.0 : (double)(method->code_size() + task->num_inlined_bytecodes()) / compile_time;
2644
tty->print_cr("%3d seconds: %6.3f bytes/sec : %f (bytes %d + %d inlined)",
2645
compile_id, compile_time, bytes_per_sec, method->code_size(), task->num_inlined_bytecodes());
2646
}
2647
2648
// Collect counts of successful compilations
2649
_sum_nmethod_size += code->total_size();
2650
_sum_nmethod_code_size += code->insts_size();
2651
_total_compile_count++;
2652
2653
if (UsePerfData) {
2654
_perf_sum_nmethod_size->inc( code->total_size());
2655
_perf_sum_nmethod_code_size->inc(code->insts_size());
2656
_perf_total_compile_count->inc();
2657
}
2658
2659
if (is_osr) {
2660
if (UsePerfData) _perf_total_osr_compile_count->inc();
2661
_total_osr_compile_count++;
2662
} else {
2663
if (UsePerfData) _perf_total_standard_compile_count->inc();
2664
_total_standard_compile_count++;
2665
}
2666
}
2667
// set the current method for the thread to null
2668
if (UsePerfData) counters->set_current_method("");
2669
}
2670
2671
const char* CompileBroker::compiler_name(int comp_level) {
2672
AbstractCompiler *comp = CompileBroker::compiler(comp_level);
2673
if (comp == NULL) {
2674
return "no compiler";
2675
} else {
2676
return (comp->name());
2677
}
2678
}
2679
2680
jlong CompileBroker::total_compilation_ticks() {
2681
return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
2682
}
2683
2684
void CompileBroker::print_times(const char* name, CompilerStatistics* stats) {
2685
tty->print_cr(" %s {speed: %6.3f bytes/s; standard: %6.3f s, %d bytes, %d methods; osr: %6.3f s, %d bytes, %d methods; nmethods_size: %d bytes; nmethods_code_size: %d bytes}",
2686
name, stats->bytes_per_second(),
2687
stats->_standard._time.seconds(), stats->_standard._bytes, stats->_standard._count,
2688
stats->_osr._time.seconds(), stats->_osr._bytes, stats->_osr._count,
2689
stats->_nmethods_size, stats->_nmethods_code_size);
2690
}
2691
2692
void CompileBroker::print_times(bool per_compiler, bool aggregate) {
2693
if (per_compiler) {
2694
if (aggregate) {
2695
tty->cr();
2696
tty->print_cr("Individual compiler times (for compiled methods only)");
2697
tty->print_cr("------------------------------------------------");
2698
tty->cr();
2699
}
2700
for (unsigned int i = 0; i < sizeof(_compilers) / sizeof(AbstractCompiler*); i++) {
2701
AbstractCompiler* comp = _compilers[i];
2702
if (comp != NULL) {
2703
print_times(comp->name(), comp->stats());
2704
}
2705
}
2706
if (aggregate) {
2707
tty->cr();
2708
tty->print_cr("Individual compilation Tier times (for compiled methods only)");
2709
tty->print_cr("------------------------------------------------");
2710
tty->cr();
2711
}
2712
char tier_name[256];
2713
for (int tier = CompLevel_simple; tier <= CompilationPolicy::highest_compile_level(); tier++) {
2714
CompilerStatistics* stats = &_stats_per_level[tier-1];
2715
sprintf(tier_name, "Tier%d", tier);
2716
print_times(tier_name, stats);
2717
}
2718
}
2719
2720
if (!aggregate) {
2721
return;
2722
}
2723
2724
elapsedTimer standard_compilation = CompileBroker::_t_standard_compilation;
2725
elapsedTimer osr_compilation = CompileBroker::_t_osr_compilation;
2726
elapsedTimer total_compilation = CompileBroker::_t_total_compilation;
2727
2728
int standard_bytes_compiled = CompileBroker::_sum_standard_bytes_compiled;
2729
int osr_bytes_compiled = CompileBroker::_sum_osr_bytes_compiled;
2730
2731
int standard_compile_count = CompileBroker::_total_standard_compile_count;
2732
int osr_compile_count = CompileBroker::_total_osr_compile_count;
2733
int total_compile_count = CompileBroker::_total_compile_count;
2734
int total_bailout_count = CompileBroker::_total_bailout_count;
2735
int total_invalidated_count = CompileBroker::_total_invalidated_count;
2736
2737
int nmethods_size = CompileBroker::_sum_nmethod_code_size;
2738
int nmethods_code_size = CompileBroker::_sum_nmethod_size;
2739
2740
tty->cr();
2741
tty->print_cr("Accumulated compiler times");
2742
tty->print_cr("----------------------------------------------------------");
2743
//0000000000111111111122222222223333333333444444444455555555556666666666
2744
//0123456789012345678901234567890123456789012345678901234567890123456789
2745
tty->print_cr(" Total compilation time : %7.3f s", total_compilation.seconds());
2746
tty->print_cr(" Standard compilation : %7.3f s, Average : %2.3f s",
2747
standard_compilation.seconds(),
2748
standard_compile_count == 0 ? 0.0 : standard_compilation.seconds() / standard_compile_count);
2749
tty->print_cr(" Bailed out compilation : %7.3f s, Average : %2.3f s",
2750
CompileBroker::_t_bailedout_compilation.seconds(),
2751
total_bailout_count == 0 ? 0.0 : CompileBroker::_t_bailedout_compilation.seconds() / total_bailout_count);
2752
tty->print_cr(" On stack replacement : %7.3f s, Average : %2.3f s",
2753
osr_compilation.seconds(),
2754
osr_compile_count == 0 ? 0.0 : osr_compilation.seconds() / osr_compile_count);
2755
tty->print_cr(" Invalidated : %7.3f s, Average : %2.3f s",
2756
CompileBroker::_t_invalidated_compilation.seconds(),
2757
total_invalidated_count == 0 ? 0.0 : CompileBroker::_t_invalidated_compilation.seconds() / total_invalidated_count);
2758
2759
AbstractCompiler *comp = compiler(CompLevel_simple);
2760
if (comp != NULL) {
2761
tty->cr();
2762
comp->print_timers();
2763
}
2764
comp = compiler(CompLevel_full_optimization);
2765
if (comp != NULL) {
2766
tty->cr();
2767
comp->print_timers();
2768
}
2769
#if INCLUDE_JVMCI
2770
if (EnableJVMCI) {
2771
tty->cr();
2772
JVMCICompiler::print_hosted_timers();
2773
}
2774
#endif
2775
2776
tty->cr();
2777
tty->print_cr(" Total compiled methods : %8d methods", total_compile_count);
2778
tty->print_cr(" Standard compilation : %8d methods", standard_compile_count);
2779
tty->print_cr(" On stack replacement : %8d methods", osr_compile_count);
2780
int tcb = osr_bytes_compiled + standard_bytes_compiled;
2781
tty->print_cr(" Total compiled bytecodes : %8d bytes", tcb);
2782
tty->print_cr(" Standard compilation : %8d bytes", standard_bytes_compiled);
2783
tty->print_cr(" On stack replacement : %8d bytes", osr_bytes_compiled);
2784
double tcs = total_compilation.seconds();
2785
int bps = tcs == 0.0 ? 0 : (int)(tcb / tcs);
2786
tty->print_cr(" Average compilation speed : %8d bytes/s", bps);
2787
tty->cr();
2788
tty->print_cr(" nmethod code size : %8d bytes", nmethods_code_size);
2789
tty->print_cr(" nmethod total size : %8d bytes", nmethods_size);
2790
}
2791
2792
// Print general/accumulated JIT information.
2793
void CompileBroker::print_info(outputStream *out) {
2794
if (out == NULL) out = tty;
2795
out->cr();
2796
out->print_cr("======================");
2797
out->print_cr(" General JIT info ");
2798
out->print_cr("======================");
2799
out->cr();
2800
out->print_cr(" JIT is : %7s", should_compile_new_jobs() ? "on" : "off");
2801
out->print_cr(" Compiler threads : %7d", (int)CICompilerCount);
2802
out->cr();
2803
out->print_cr("CodeCache overview");
2804
out->print_cr("--------------------------------------------------------");
2805
out->cr();
2806
out->print_cr(" Reserved size : " SIZE_FORMAT_W(7) " KB", CodeCache::max_capacity() / K);
2807
out->print_cr(" Committed size : " SIZE_FORMAT_W(7) " KB", CodeCache::capacity() / K);
2808
out->print_cr(" Unallocated capacity : " SIZE_FORMAT_W(7) " KB", CodeCache::unallocated_capacity() / K);
2809
out->cr();
2810
2811
out->cr();
2812
out->print_cr("CodeCache cleaning overview");
2813
out->print_cr("--------------------------------------------------------");
2814
out->cr();
2815
NMethodSweeper::print(out);
2816
out->print_cr("--------------------------------------------------------");
2817
out->cr();
2818
}
2819
2820
// Note: tty_lock must not be held upon entry to this function.
2821
// Print functions called from herein do "micro-locking" on tty_lock.
2822
// That's a tradeoff which keeps together important blocks of output.
2823
// At the same time, continuous tty_lock hold time is kept in check,
2824
// preventing concurrently printing threads from stalling a long time.
2825
void CompileBroker::print_heapinfo(outputStream* out, const char* function, size_t granularity) {
2826
TimeStamp ts_total;
2827
TimeStamp ts_global;
2828
TimeStamp ts;
2829
2830
bool allFun = !strcmp(function, "all");
2831
bool aggregate = !strcmp(function, "aggregate") || !strcmp(function, "analyze") || allFun;
2832
bool usedSpace = !strcmp(function, "UsedSpace") || allFun;
2833
bool freeSpace = !strcmp(function, "FreeSpace") || allFun;
2834
bool methodCount = !strcmp(function, "MethodCount") || allFun;
2835
bool methodSpace = !strcmp(function, "MethodSpace") || allFun;
2836
bool methodAge = !strcmp(function, "MethodAge") || allFun;
2837
bool methodNames = !strcmp(function, "MethodNames") || allFun;
2838
bool discard = !strcmp(function, "discard") || allFun;
2839
2840
if (out == NULL) {
2841
out = tty;
2842
}
2843
2844
if (!(aggregate || usedSpace || freeSpace || methodCount || methodSpace || methodAge || methodNames || discard)) {
2845
out->print_cr("\n__ CodeHeapStateAnalytics: Function %s is not supported", function);
2846
out->cr();
2847
return;
2848
}
2849
2850
ts_total.update(); // record starting point
2851
2852
if (aggregate) {
2853
print_info(out);
2854
}
2855
2856
// We hold the CodeHeapStateAnalytics_lock all the time, from here until we leave this function.
2857
// That prevents other threads from destroying (making inconsistent) our view on the CodeHeap.
2858
// When we request individual parts of the analysis via the jcmd interface, it is possible
2859
// that in between another thread (another jcmd user or the vm running into CodeCache OOM)
2860
// updated the aggregated data. We will then see a modified, but again consistent, view
2861
// on the CodeHeap. That's a tolerable tradeoff we have to accept because we can't hold
2862
// a lock across user interaction.
2863
2864
// We should definitely acquire this lock before acquiring Compile_lock and CodeCache_lock.
2865
// CodeHeapStateAnalytics_lock may be held by a concurrent thread for a long time,
2866
// leading to an unnecessarily long hold time of the other locks we acquired before.
2867
ts.update(); // record starting point
2868
MutexLocker mu0(CodeHeapStateAnalytics_lock, Mutex::_safepoint_check_flag);
2869
out->print_cr("\n__ CodeHeapStateAnalytics lock wait took %10.3f seconds _________\n", ts.seconds());
2870
2871
// Holding the CodeCache_lock protects from concurrent alterations of the CodeCache.
2872
// Unfortunately, such protection is not sufficient:
2873
// When a new nmethod is created via ciEnv::register_method(), the
2874
// Compile_lock is taken first. After some initializations,
2875
// nmethod::new_nmethod() takes over, grabbing the CodeCache_lock
2876
// immediately (after finalizing the oop references). To lock out concurrent
2877
// modifiers, we have to grab both locks as well in the described sequence.
2878
//
2879
// If we serve an "allFun" call, it is beneficial to hold CodeCache_lock and Compile_lock
2880
// for the entire duration of aggregation and printing. That makes sure we see
2881
// a consistent picture and do not run into issues caused by concurrent alterations.
2882
bool should_take_Compile_lock = !SafepointSynchronize::is_at_safepoint() &&
2883
!Compile_lock->owned_by_self();
2884
bool should_take_CodeCache_lock = !SafepointSynchronize::is_at_safepoint() &&
2885
!CodeCache_lock->owned_by_self();
2886
Mutex* global_lock_1 = allFun ? (should_take_Compile_lock ? Compile_lock : NULL) : NULL;
2887
Monitor* global_lock_2 = allFun ? (should_take_CodeCache_lock ? CodeCache_lock : NULL) : NULL;
2888
Mutex* function_lock_1 = allFun ? NULL : (should_take_Compile_lock ? Compile_lock : NULL);
2889
Monitor* function_lock_2 = allFun ? NULL : (should_take_CodeCache_lock ? CodeCache_lock : NULL);
2890
ts_global.update(); // record starting point
2891
MutexLocker mu1(global_lock_1, Mutex::_safepoint_check_flag);
2892
MutexLocker mu2(global_lock_2, Mutex::_no_safepoint_check_flag);
2893
if ((global_lock_1 != NULL) || (global_lock_2 != NULL)) {
2894
out->print_cr("\n__ Compile & CodeCache (global) lock wait took %10.3f seconds _________\n", ts_global.seconds());
2895
ts_global.update(); // record starting point
2896
}
2897
2898
if (aggregate) {
2899
ts.update(); // record starting point
2900
MutexLocker mu11(function_lock_1, Mutex::_safepoint_check_flag);
2901
MutexLocker mu22(function_lock_2, Mutex::_no_safepoint_check_flag);
2902
if ((function_lock_1 != NULL) || (function_lock_1 != NULL)) {
2903
out->print_cr("\n__ Compile & CodeCache (function) lock wait took %10.3f seconds _________\n", ts.seconds());
2904
}
2905
2906
ts.update(); // record starting point
2907
CodeCache::aggregate(out, granularity);
2908
if ((function_lock_1 != NULL) || (function_lock_1 != NULL)) {
2909
out->print_cr("\n__ Compile & CodeCache (function) lock hold took %10.3f seconds _________\n", ts.seconds());
2910
}
2911
}
2912
2913
if (usedSpace) CodeCache::print_usedSpace(out);
2914
if (freeSpace) CodeCache::print_freeSpace(out);
2915
if (methodCount) CodeCache::print_count(out);
2916
if (methodSpace) CodeCache::print_space(out);
2917
if (methodAge) CodeCache::print_age(out);
2918
if (methodNames) {
2919
if (allFun) {
2920
// print_names() can only be used safely if the locks have been continuously held
2921
// since aggregation begin. That is true only for function "all".
2922
CodeCache::print_names(out);
2923
} else {
2924
out->print_cr("\nCodeHeapStateAnalytics: Function 'MethodNames' is only available as part of function 'all'");
2925
}
2926
}
2927
if (discard) CodeCache::discard(out);
2928
2929
if ((global_lock_1 != NULL) || (global_lock_2 != NULL)) {
2930
out->print_cr("\n__ Compile & CodeCache (global) lock hold took %10.3f seconds _________\n", ts_global.seconds());
2931
}
2932
out->print_cr("\n__ CodeHeapStateAnalytics total duration %10.3f seconds _________\n", ts_total.seconds());
2933
}
2934
2935