src/share/vm/compiler/compileBroker.hpp

Wed, 22 Jan 2014 17:42:23 -0800

author
kvn
date
Wed, 22 Jan 2014 17:42:23 -0800
changeset 6503
a9becfeecd1b
parent 6220
7b9127b17b7a
child 6876
710a3c8b516e
child 7179
7301840ea20e
permissions
-rw-r--r--

Merge

duke@435 1 /*
sla@5237 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_COMPILER_COMPILEBROKER_HPP
stefank@2314 26 #define SHARE_VM_COMPILER_COMPILEBROKER_HPP
stefank@2314 27
stefank@2314 28 #include "ci/compilerInterface.hpp"
stefank@2314 29 #include "compiler/abstractCompiler.hpp"
stefank@2314 30 #include "runtime/perfData.hpp"
stefank@2314 31
duke@435 32 class nmethod;
duke@435 33 class nmethodLocker;
duke@435 34
duke@435 35 // CompileTask
duke@435 36 //
duke@435 37 // An entry in the compile queue. It represents a pending or current
duke@435 38 // compilation.
zgu@3900 39 class CompileTask : public CHeapObj<mtCompiler> {
never@3138 40 friend class VMStructs;
never@3138 41
duke@435 42 private:
duke@435 43 Monitor* _lock;
duke@435 44 uint _compile_id;
coleenp@4037 45 Method* _method;
coleenp@4304 46 jobject _method_holder;
duke@435 47 int _osr_bci;
duke@435 48 bool _is_complete;
duke@435 49 bool _is_success;
duke@435 50 bool _is_blocking;
duke@435 51 int _comp_level;
duke@435 52 int _num_inlined_bytecodes;
duke@435 53 nmethodLocker* _code_handle; // holder of eventual result
iveresov@2138 54 CompileTask* _next, *_prev;
duke@435 55
duke@435 56 // Fields used for logging why the compilation was initiated:
duke@435 57 jlong _time_queued; // in units of os::elapsed_counter()
coleenp@4037 58 Method* _hot_method; // which method actually triggered this task
coleenp@4304 59 jobject _hot_method_holder;
duke@435 60 int _hot_count; // information about its invocation counter
duke@435 61 const char* _comment; // more info about the task
duke@435 62
duke@435 63 public:
duke@435 64 CompileTask() {
duke@435 65 _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
duke@435 66 }
duke@435 67
duke@435 68 void initialize(int compile_id, methodHandle method, int osr_bci, int comp_level,
duke@435 69 methodHandle hot_method, int hot_count, const char* comment,
duke@435 70 bool is_blocking);
duke@435 71
duke@435 72 void free();
duke@435 73
duke@435 74 int compile_id() const { return _compile_id; }
coleenp@4037 75 Method* method() const { return _method; }
duke@435 76 int osr_bci() const { return _osr_bci; }
duke@435 77 bool is_complete() const { return _is_complete; }
duke@435 78 bool is_blocking() const { return _is_blocking; }
duke@435 79 bool is_success() const { return _is_success; }
duke@435 80
duke@435 81 nmethodLocker* code_handle() const { return _code_handle; }
duke@435 82 void set_code_handle(nmethodLocker* l) { _code_handle = l; }
duke@435 83 nmethod* code() const; // _code_handle->code()
duke@435 84 void set_code(nmethod* nm); // _code_handle->set_code(nm)
duke@435 85
duke@435 86 Monitor* lock() const { return _lock; }
duke@435 87
duke@435 88 void mark_complete() { _is_complete = true; }
duke@435 89 void mark_success() { _is_success = true; }
duke@435 90
duke@435 91 int comp_level() { return _comp_level;}
duke@435 92 void set_comp_level(int comp_level) { _comp_level = comp_level;}
duke@435 93
duke@435 94 int num_inlined_bytecodes() const { return _num_inlined_bytecodes; }
duke@435 95 void set_num_inlined_bytecodes(int n) { _num_inlined_bytecodes = n; }
duke@435 96
duke@435 97 CompileTask* next() const { return _next; }
duke@435 98 void set_next(CompileTask* next) { _next = next; }
iveresov@2138 99 CompileTask* prev() const { return _prev; }
iveresov@2138 100 void set_prev(CompileTask* prev) { _prev = prev; }
duke@435 101
twisti@2687 102 private:
coleenp@4037 103 static void print_compilation_impl(outputStream* st, Method* method, int compile_id, int comp_level,
never@3499 104 bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,
never@3499 105 const char* msg = NULL, bool short_form = false);
twisti@2687 106
twisti@2687 107 public:
twisti@4111 108 void print_compilation(outputStream* st = tty, const char* msg = NULL, bool short_form = false);
twisti@3969 109 static void print_compilation(outputStream* st, const nmethod* nm, const char* msg = NULL, bool short_form = false) {
never@3499 110 print_compilation_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
never@3499 111 nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
twisti@3969 112 msg, short_form);
twisti@2687 113 }
twisti@2687 114
twisti@2687 115 static void print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL);
twisti@2687 116 static void print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
twisti@2687 117 print_inlining(tty, method, inline_level, bci, msg);
twisti@2687 118 }
twisti@2687 119
coleenp@4037 120 // Redefine Classes support
coleenp@4037 121 void mark_on_stack();
coleenp@4037 122
twisti@2687 123 static void print_inline_indent(int inline_level, outputStream* st = tty);
twisti@2687 124
duke@435 125 void print();
duke@435 126 void print_line();
twisti@2687 127 void print_line_on_error(outputStream* st, char* buf, int buflen);
iveresov@2138 128
duke@435 129 void log_task(xmlStream* log);
duke@435 130 void log_task_queued();
duke@435 131 void log_task_start(CompileLog* log);
duke@435 132 void log_task_done(CompileLog* log);
duke@435 133 };
duke@435 134
duke@435 135 // CompilerCounters
duke@435 136 //
duke@435 137 // Per Compiler Performance Counters.
duke@435 138 //
zgu@3900 139 class CompilerCounters : public CHeapObj<mtCompiler> {
duke@435 140
duke@435 141 public:
duke@435 142 enum {
duke@435 143 cmname_buffer_length = 160
duke@435 144 };
duke@435 145
duke@435 146 private:
duke@435 147
duke@435 148 char _current_method[cmname_buffer_length];
duke@435 149 PerfStringVariable* _perf_current_method;
duke@435 150
duke@435 151 int _compile_type;
duke@435 152 PerfVariable* _perf_compile_type;
duke@435 153
duke@435 154 PerfCounter* _perf_time;
duke@435 155 PerfCounter* _perf_compiles;
duke@435 156
duke@435 157 public:
duke@435 158 CompilerCounters(const char* name, int instance, TRAPS);
duke@435 159
duke@435 160 // these methods should be called in a thread safe context
duke@435 161
duke@435 162 void set_current_method(const char* method) {
duke@435 163 strncpy(_current_method, method, (size_t)cmname_buffer_length);
duke@435 164 if (UsePerfData) _perf_current_method->set_value(method);
duke@435 165 }
duke@435 166
duke@435 167 char* current_method() { return _current_method; }
duke@435 168
duke@435 169 void set_compile_type(int compile_type) {
duke@435 170 _compile_type = compile_type;
duke@435 171 if (UsePerfData) _perf_compile_type->set_value((jlong)compile_type);
duke@435 172 }
duke@435 173
duke@435 174 int compile_type() { return _compile_type; }
duke@435 175
duke@435 176 PerfCounter* time_counter() { return _perf_time; }
duke@435 177 PerfCounter* compile_counter() { return _perf_compiles; }
duke@435 178 };
duke@435 179
duke@435 180 // CompileQueue
duke@435 181 //
duke@435 182 // A list of CompileTasks.
zgu@3900 183 class CompileQueue : public CHeapObj<mtCompiler> {
duke@435 184 private:
duke@435 185 const char* _name;
duke@435 186 Monitor* _lock;
duke@435 187
duke@435 188 CompileTask* _first;
duke@435 189 CompileTask* _last;
duke@435 190
iveresov@2138 191 int _size;
duke@435 192 public:
duke@435 193 CompileQueue(const char* name, Monitor* lock) {
duke@435 194 _name = name;
duke@435 195 _lock = lock;
duke@435 196 _first = NULL;
duke@435 197 _last = NULL;
iveresov@2138 198 _size = 0;
duke@435 199 }
duke@435 200
duke@435 201 const char* name() const { return _name; }
duke@435 202 Monitor* lock() const { return _lock; }
duke@435 203
duke@435 204 void add(CompileTask* task);
iveresov@2138 205 void remove(CompileTask* task);
iveresov@2138 206 CompileTask* first() { return _first; }
iveresov@2138 207 CompileTask* last() { return _last; }
duke@435 208
duke@435 209 CompileTask* get();
duke@435 210
duke@435 211 bool is_empty() const { return _first == NULL; }
iveresov@2138 212 int size() const { return _size; }
duke@435 213
coleenp@4037 214 // Redefine Classes support
coleenp@4037 215 void mark_on_stack();
anoll@5919 216 void delete_all();
anoll@5919 217 void print();
coleenp@4037 218
anoll@5919 219 ~CompileQueue() {
anoll@5919 220 assert (is_empty(), " Compile Queue must be empty");
anoll@5919 221 }
duke@435 222 };
duke@435 223
iveresov@2138 224 // CompileTaskWrapper
iveresov@2138 225 //
iveresov@2138 226 // Assign this task to the current thread. Deallocate the task
iveresov@2138 227 // when the compilation is complete.
iveresov@2138 228 class CompileTaskWrapper : StackObj {
iveresov@2138 229 public:
iveresov@2138 230 CompileTaskWrapper(CompileTask* task);
iveresov@2138 231 ~CompileTaskWrapper();
iveresov@2138 232 };
iveresov@2138 233
duke@435 234
duke@435 235 // Compilation
duke@435 236 //
duke@435 237 // The broker for all compilation requests.
duke@435 238 class CompileBroker: AllStatic {
duke@435 239 friend class Threads;
duke@435 240 friend class CompileTaskWrapper;
duke@435 241
duke@435 242 public:
duke@435 243 enum {
duke@435 244 name_buffer_length = 100
duke@435 245 };
duke@435 246
duke@435 247 // Compile type Information for print_last_compile() and CompilerCounters
duke@435 248 enum { no_compile, normal_compile, osr_compile, native_compile };
anoll@6220 249 static int assign_compile_id (methodHandle method, int osr_bci);
anoll@6220 250
duke@435 251
duke@435 252 private:
duke@435 253 static bool _initialized;
duke@435 254 static volatile bool _should_block;
duke@435 255
kvn@1637 256 // This flag can be used to stop compilation or turn it back on
kvn@1637 257 static volatile jint _should_compile_new_jobs;
kvn@1637 258
duke@435 259 // The installed compiler(s)
duke@435 260 static AbstractCompiler* _compilers[2];
duke@435 261
duke@435 262 // These counters are used for assigning id's to each compilation
anoll@6220 263 static volatile jint _compilation_id;
anoll@6220 264 static volatile jint _osr_compilation_id;
duke@435 265
duke@435 266 static int _last_compile_type;
duke@435 267 static int _last_compile_level;
duke@435 268 static char _last_method_compiled[name_buffer_length];
duke@435 269
iveresov@2138 270 static CompileQueue* _c2_method_queue;
iveresov@2138 271 static CompileQueue* _c1_method_queue;
duke@435 272 static CompileTask* _task_free_list;
duke@435 273
anoll@5919 274 static GrowableArray<CompilerThread*>* _compiler_threads;
duke@435 275
duke@435 276 // performance counters
duke@435 277 static PerfCounter* _perf_total_compilation;
duke@435 278 static PerfCounter* _perf_native_compilation;
duke@435 279 static PerfCounter* _perf_osr_compilation;
duke@435 280 static PerfCounter* _perf_standard_compilation;
duke@435 281
duke@435 282 static PerfCounter* _perf_total_bailout_count;
duke@435 283 static PerfCounter* _perf_total_invalidated_count;
duke@435 284 static PerfCounter* _perf_total_compile_count;
duke@435 285 static PerfCounter* _perf_total_native_compile_count;
duke@435 286 static PerfCounter* _perf_total_osr_compile_count;
duke@435 287 static PerfCounter* _perf_total_standard_compile_count;
duke@435 288
duke@435 289 static PerfCounter* _perf_sum_osr_bytes_compiled;
duke@435 290 static PerfCounter* _perf_sum_standard_bytes_compiled;
duke@435 291 static PerfCounter* _perf_sum_nmethod_size;
duke@435 292 static PerfCounter* _perf_sum_nmethod_code_size;
duke@435 293
duke@435 294 static PerfStringVariable* _perf_last_method;
duke@435 295 static PerfStringVariable* _perf_last_failed_method;
duke@435 296 static PerfStringVariable* _perf_last_invalidated_method;
duke@435 297 static PerfVariable* _perf_last_compile_type;
duke@435 298 static PerfVariable* _perf_last_compile_size;
duke@435 299 static PerfVariable* _perf_last_failed_type;
duke@435 300 static PerfVariable* _perf_last_invalidated_type;
duke@435 301
duke@435 302 // Timers and counters for generating statistics
duke@435 303 static elapsedTimer _t_total_compilation;
duke@435 304 static elapsedTimer _t_osr_compilation;
duke@435 305 static elapsedTimer _t_standard_compilation;
duke@435 306
sla@5237 307 static int _total_compile_count;
duke@435 308 static int _total_bailout_count;
duke@435 309 static int _total_invalidated_count;
duke@435 310 static int _total_native_compile_count;
duke@435 311 static int _total_osr_compile_count;
duke@435 312 static int _total_standard_compile_count;
duke@435 313 static int _sum_osr_bytes_compiled;
duke@435 314 static int _sum_standard_bytes_compiled;
duke@435 315 static int _sum_nmethod_size;
duke@435 316 static int _sum_nmethod_code_size;
sla@5237 317 static long _peak_compilation_time;
duke@435 318
anoll@6099 319 static volatile jint _print_compilation_warning;
anoll@6099 320
anoll@5919 321 static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, TRAPS);
iveresov@2138 322 static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count);
duke@435 323 static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level);
duke@435 324 static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
duke@435 325 static bool is_compile_blocking (methodHandle method, int osr_bci);
duke@435 326 static void preload_classes (methodHandle method, TRAPS);
duke@435 327
duke@435 328 static CompileTask* create_compile_task(CompileQueue* queue,
duke@435 329 int compile_id,
duke@435 330 methodHandle method,
duke@435 331 int osr_bci,
duke@435 332 int comp_level,
duke@435 333 methodHandle hot_method,
duke@435 334 int hot_count,
duke@435 335 const char* comment,
duke@435 336 bool blocking);
duke@435 337 static CompileTask* allocate_task();
duke@435 338 static void free_task(CompileTask* task);
duke@435 339 static void wait_for_completion(CompileTask* task);
duke@435 340
duke@435 341 static void invoke_compiler_on_method(CompileTask* task);
duke@435 342 static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
duke@435 343 static void push_jni_handle_block();
duke@435 344 static void pop_jni_handle_block();
duke@435 345 static bool check_break_at(methodHandle method, int compile_id, bool is_osr);
duke@435 346 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
duke@435 347
duke@435 348 static void compile_method_base(methodHandle method,
duke@435 349 int osr_bci,
duke@435 350 int comp_level,
duke@435 351 methodHandle hot_method,
duke@435 352 int hot_count,
duke@435 353 const char* comment,
iveresov@3452 354 Thread* thread);
iveresov@2138 355 static CompileQueue* compile_queue(int comp_level) {
iveresov@2138 356 if (is_c2_compile(comp_level)) return _c2_method_queue;
iveresov@2138 357 if (is_c1_compile(comp_level)) return _c1_method_queue;
iveresov@2138 358 return NULL;
iveresov@2138 359 }
anoll@5919 360 static bool init_compiler_runtime();
anoll@5919 361 static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
anoll@5919 362
duke@435 363 public:
duke@435 364 enum {
duke@435 365 // The entry bci used for non-OSR compilations.
duke@435 366 standard_entry_bci = InvocationEntryBci
duke@435 367 };
duke@435 368
iveresov@2138 369 static AbstractCompiler* compiler(int comp_level) {
iveresov@2138 370 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
iveresov@2138 371 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
iveresov@2138 372 return NULL;
duke@435 373 }
duke@435 374
iveresov@2138 375 static bool compilation_is_in_queue(methodHandle method, int osr_bci);
iveresov@2138 376 static int queue_size(int comp_level) {
iveresov@2138 377 CompileQueue *q = compile_queue(comp_level);
iveresov@2138 378 return q != NULL ? q->size() : 0;
iveresov@2138 379 }
duke@435 380 static void compilation_init();
duke@435 381 static void init_compiler_thread_log();
iveresov@2138 382 static nmethod* compile_method(methodHandle method,
iveresov@2138 383 int osr_bci,
iveresov@2138 384 int comp_level,
iveresov@2138 385 methodHandle hot_method,
iveresov@2138 386 int hot_count,
iveresov@3452 387 const char* comment, Thread* thread);
duke@435 388
duke@435 389 static void compiler_thread_loop();
kvn@1637 390 static uint get_compilation_id() { return _compilation_id; }
duke@435 391
duke@435 392 // Set _should_block.
duke@435 393 // Call this from the VM, with Threads_lock held and a safepoint requested.
duke@435 394 static void set_should_block();
duke@435 395
duke@435 396 // Call this from the compiler at convenient points, to poll for _should_block.
duke@435 397 static void maybe_block();
duke@435 398
kvn@1637 399 enum {
kvn@1637 400 // Flags for toggling compiler activity
anoll@5919 401 stop_compilation = 0,
anoll@5919 402 run_compilation = 1,
anoll@5919 403 shutdown_compilaton = 2
kvn@1637 404 };
kvn@1637 405
kvn@1637 406 static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); }
kvn@1637 407 static bool set_should_compile_new_jobs(jint new_state) {
kvn@1637 408 // Return success if the current caller set it
kvn@1637 409 jint old = Atomic::cmpxchg(new_state, &_should_compile_new_jobs, 1-new_state);
kvn@1637 410 return (old == (1-new_state));
kvn@1637 411 }
anoll@5919 412
anoll@5919 413 static void disable_compilation_forever() {
anoll@5919 414 UseCompiler = false;
anoll@5919 415 AlwaysCompileLoopMethods = false;
anoll@5919 416 Atomic::xchg(shutdown_compilaton, &_should_compile_new_jobs);
anoll@5919 417 }
anoll@5919 418
anoll@5919 419 static bool is_compilation_disabled_forever() {
anoll@5919 420 return _should_compile_new_jobs == shutdown_compilaton;
anoll@5919 421 }
kvn@1637 422 static void handle_full_code_cache();
anoll@6099 423 // Ensures that warning is only printed once.
anoll@6099 424 static bool should_print_compiler_warning() {
anoll@6099 425 jint old = Atomic::cmpxchg(1, &_print_compilation_warning, 0);
anoll@6099 426 return old == 0;
anoll@6099 427 }
duke@435 428 // Return total compilation ticks
duke@435 429 static jlong total_compilation_ticks() {
duke@435 430 return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
duke@435 431 }
duke@435 432
coleenp@4037 433 // Redefine Classes support
coleenp@4037 434 static void mark_on_stack();
coleenp@4037 435
duke@435 436 // Print a detailed accounting of compilation time
duke@435 437 static void print_times();
duke@435 438
duke@435 439 // Debugging output for failure
duke@435 440 static void print_last_compile();
duke@435 441
duke@435 442 static void print_compiler_threads_on(outputStream* st);
morris@4771 443
morris@4771 444 // compiler name for debugging
morris@4771 445 static const char* compiler_name(int comp_level);
sla@5237 446
sla@5237 447 static int get_total_compile_count() { return _total_compile_count; }
sla@5237 448 static int get_total_bailout_count() { return _total_bailout_count; }
sla@5237 449 static int get_total_invalidated_count() { return _total_invalidated_count; }
sla@5237 450 static int get_total_native_compile_count() { return _total_native_compile_count; }
sla@5237 451 static int get_total_osr_compile_count() { return _total_osr_compile_count; }
sla@5237 452 static int get_total_standard_compile_count() { return _total_standard_compile_count; }
sla@5237 453 static int get_sum_osr_bytes_compiled() { return _sum_osr_bytes_compiled; }
sla@5237 454 static int get_sum_standard_bytes_compiled() { return _sum_standard_bytes_compiled; }
sla@5237 455 static int get_sum_nmethod_size() { return _sum_nmethod_size;}
sla@5237 456 static int get_sum_nmethod_code_size() { return _sum_nmethod_code_size; }
sla@5237 457 static long get_peak_compilation_time() { return _peak_compilation_time; }
sla@5237 458 static long get_total_compilation_time() { return _t_total_compilation.milliseconds(); }
duke@435 459 };
stefank@2314 460
stefank@2314 461 #endif // SHARE_VM_COMPILER_COMPILEBROKER_HPP

mercurial