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