src/share/vm/compiler/compileBroker.hpp

Mon, 04 Apr 2011 03:02:00 -0700

author
twisti
date
Mon, 04 Apr 2011 03:02:00 -0700
changeset 2729
e863062e521d
parent 2687
3d58a4983660
child 3138
f6f3bb0ee072
permissions
-rw-r--r--

7032458: Zero and Shark fixes
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

duke@435 1 /*
twisti@2687 2 * Copyright (c) 1999, 2011, 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.
duke@435 39 class CompileTask : public CHeapObj {
duke@435 40 private:
duke@435 41 Monitor* _lock;
duke@435 42 uint _compile_id;
duke@435 43 jobject _method;
duke@435 44 int _osr_bci;
duke@435 45 bool _is_complete;
duke@435 46 bool _is_success;
duke@435 47 bool _is_blocking;
duke@435 48 int _comp_level;
duke@435 49 int _num_inlined_bytecodes;
duke@435 50 nmethodLocker* _code_handle; // holder of eventual result
iveresov@2138 51 CompileTask* _next, *_prev;
duke@435 52
duke@435 53 // Fields used for logging why the compilation was initiated:
duke@435 54 jlong _time_queued; // in units of os::elapsed_counter()
duke@435 55 jobject _hot_method; // which method actually triggered this task
duke@435 56 int _hot_count; // information about its invocation counter
duke@435 57 const char* _comment; // more info about the task
duke@435 58
duke@435 59 public:
duke@435 60 CompileTask() {
duke@435 61 _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
duke@435 62 }
duke@435 63
duke@435 64 void initialize(int compile_id, methodHandle method, int osr_bci, int comp_level,
duke@435 65 methodHandle hot_method, int hot_count, const char* comment,
duke@435 66 bool is_blocking);
duke@435 67
duke@435 68 void free();
duke@435 69
duke@435 70 int compile_id() const { return _compile_id; }
duke@435 71 jobject method_handle() const { return _method; }
duke@435 72 int osr_bci() const { return _osr_bci; }
duke@435 73 bool is_complete() const { return _is_complete; }
duke@435 74 bool is_blocking() const { return _is_blocking; }
duke@435 75 bool is_success() const { return _is_success; }
duke@435 76
duke@435 77 nmethodLocker* code_handle() const { return _code_handle; }
duke@435 78 void set_code_handle(nmethodLocker* l) { _code_handle = l; }
duke@435 79 nmethod* code() const; // _code_handle->code()
duke@435 80 void set_code(nmethod* nm); // _code_handle->set_code(nm)
duke@435 81
duke@435 82 Monitor* lock() const { return _lock; }
duke@435 83
duke@435 84 void mark_complete() { _is_complete = true; }
duke@435 85 void mark_success() { _is_success = true; }
duke@435 86
duke@435 87 int comp_level() { return _comp_level;}
duke@435 88 void set_comp_level(int comp_level) { _comp_level = comp_level;}
duke@435 89
duke@435 90 int num_inlined_bytecodes() const { return _num_inlined_bytecodes; }
duke@435 91 void set_num_inlined_bytecodes(int n) { _num_inlined_bytecodes = n; }
duke@435 92
duke@435 93 CompileTask* next() const { return _next; }
duke@435 94 void set_next(CompileTask* next) { _next = next; }
iveresov@2138 95 CompileTask* prev() const { return _prev; }
iveresov@2138 96 void set_prev(CompileTask* prev) { _prev = prev; }
duke@435 97
twisti@2687 98 private:
twisti@2687 99 static void print_compilation_impl(outputStream* st, methodOop method, int compile_id, int comp_level, bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false, const char* msg = NULL);
twisti@2687 100
twisti@2687 101 public:
twisti@2687 102 void print_compilation(outputStream* st = tty);
twisti@2687 103 static void print_compilation(outputStream* st, const nmethod* nm, const char* msg = NULL) {
twisti@2687 104 print_compilation_impl(st, nm->method(), nm->compile_id(), nm->comp_level(), nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false, msg);
twisti@2687 105 }
twisti@2687 106
twisti@2687 107 static void print_inlining(outputStream* st, ciMethod* method, int inline_level, int bci, const char* msg = NULL);
twisti@2687 108 static void print_inlining(ciMethod* method, int inline_level, int bci, const char* msg = NULL) {
twisti@2687 109 print_inlining(tty, method, inline_level, bci, msg);
twisti@2687 110 }
twisti@2687 111
twisti@2687 112 static void print_inline_indent(int inline_level, outputStream* st = tty);
twisti@2687 113
duke@435 114 void print();
duke@435 115 void print_line();
twisti@2687 116 void print_line_on_error(outputStream* st, char* buf, int buflen);
iveresov@2138 117
duke@435 118 void log_task(xmlStream* log);
duke@435 119 void log_task_queued();
duke@435 120 void log_task_start(CompileLog* log);
duke@435 121 void log_task_done(CompileLog* log);
duke@435 122 };
duke@435 123
duke@435 124 // CompilerCounters
duke@435 125 //
duke@435 126 // Per Compiler Performance Counters.
duke@435 127 //
duke@435 128 class CompilerCounters : public CHeapObj {
duke@435 129
duke@435 130 public:
duke@435 131 enum {
duke@435 132 cmname_buffer_length = 160
duke@435 133 };
duke@435 134
duke@435 135 private:
duke@435 136
duke@435 137 char _current_method[cmname_buffer_length];
duke@435 138 PerfStringVariable* _perf_current_method;
duke@435 139
duke@435 140 int _compile_type;
duke@435 141 PerfVariable* _perf_compile_type;
duke@435 142
duke@435 143 PerfCounter* _perf_time;
duke@435 144 PerfCounter* _perf_compiles;
duke@435 145
duke@435 146 public:
duke@435 147 CompilerCounters(const char* name, int instance, TRAPS);
duke@435 148
duke@435 149 // these methods should be called in a thread safe context
duke@435 150
duke@435 151 void set_current_method(const char* method) {
duke@435 152 strncpy(_current_method, method, (size_t)cmname_buffer_length);
duke@435 153 if (UsePerfData) _perf_current_method->set_value(method);
duke@435 154 }
duke@435 155
duke@435 156 char* current_method() { return _current_method; }
duke@435 157
duke@435 158 void set_compile_type(int compile_type) {
duke@435 159 _compile_type = compile_type;
duke@435 160 if (UsePerfData) _perf_compile_type->set_value((jlong)compile_type);
duke@435 161 }
duke@435 162
duke@435 163 int compile_type() { return _compile_type; }
duke@435 164
duke@435 165 PerfCounter* time_counter() { return _perf_time; }
duke@435 166 PerfCounter* compile_counter() { return _perf_compiles; }
duke@435 167 };
duke@435 168
duke@435 169 // CompileQueue
duke@435 170 //
duke@435 171 // A list of CompileTasks.
duke@435 172 class CompileQueue : public CHeapObj {
duke@435 173 private:
duke@435 174 const char* _name;
duke@435 175 Monitor* _lock;
duke@435 176
duke@435 177 CompileTask* _first;
duke@435 178 CompileTask* _last;
duke@435 179
iveresov@2138 180 int _size;
duke@435 181 public:
duke@435 182 CompileQueue(const char* name, Monitor* lock) {
duke@435 183 _name = name;
duke@435 184 _lock = lock;
duke@435 185 _first = NULL;
duke@435 186 _last = NULL;
iveresov@2138 187 _size = 0;
duke@435 188 }
duke@435 189
duke@435 190 const char* name() const { return _name; }
duke@435 191 Monitor* lock() const { return _lock; }
duke@435 192
duke@435 193 void add(CompileTask* task);
iveresov@2138 194 void remove(CompileTask* task);
iveresov@2138 195 CompileTask* first() { return _first; }
iveresov@2138 196 CompileTask* last() { return _last; }
duke@435 197
duke@435 198 CompileTask* get();
duke@435 199
duke@435 200 bool is_empty() const { return _first == NULL; }
iveresov@2138 201 int size() const { return _size; }
duke@435 202
duke@435 203 void print();
duke@435 204 };
duke@435 205
iveresov@2138 206 // CompileTaskWrapper
iveresov@2138 207 //
iveresov@2138 208 // Assign this task to the current thread. Deallocate the task
iveresov@2138 209 // when the compilation is complete.
iveresov@2138 210 class CompileTaskWrapper : StackObj {
iveresov@2138 211 public:
iveresov@2138 212 CompileTaskWrapper(CompileTask* task);
iveresov@2138 213 ~CompileTaskWrapper();
iveresov@2138 214 };
iveresov@2138 215
duke@435 216
duke@435 217 // Compilation
duke@435 218 //
duke@435 219 // The broker for all compilation requests.
duke@435 220 class CompileBroker: AllStatic {
duke@435 221 friend class Threads;
duke@435 222 friend class CompileTaskWrapper;
duke@435 223
duke@435 224 public:
duke@435 225 enum {
duke@435 226 name_buffer_length = 100
duke@435 227 };
duke@435 228
duke@435 229 // Compile type Information for print_last_compile() and CompilerCounters
duke@435 230 enum { no_compile, normal_compile, osr_compile, native_compile };
duke@435 231
duke@435 232 private:
duke@435 233 static bool _initialized;
duke@435 234 static volatile bool _should_block;
duke@435 235
kvn@1637 236 // This flag can be used to stop compilation or turn it back on
kvn@1637 237 static volatile jint _should_compile_new_jobs;
kvn@1637 238
duke@435 239 // The installed compiler(s)
duke@435 240 static AbstractCompiler* _compilers[2];
duke@435 241
duke@435 242 // These counters are used for assigning id's to each compilation
duke@435 243 static uint _compilation_id;
duke@435 244 static uint _osr_compilation_id;
duke@435 245 static uint _native_compilation_id;
duke@435 246
duke@435 247 static int _last_compile_type;
duke@435 248 static int _last_compile_level;
duke@435 249 static char _last_method_compiled[name_buffer_length];
duke@435 250
iveresov@2138 251 static CompileQueue* _c2_method_queue;
iveresov@2138 252 static CompileQueue* _c1_method_queue;
duke@435 253 static CompileTask* _task_free_list;
duke@435 254
duke@435 255 static GrowableArray<CompilerThread*>* _method_threads;
duke@435 256
duke@435 257 // performance counters
duke@435 258 static PerfCounter* _perf_total_compilation;
duke@435 259 static PerfCounter* _perf_native_compilation;
duke@435 260 static PerfCounter* _perf_osr_compilation;
duke@435 261 static PerfCounter* _perf_standard_compilation;
duke@435 262
duke@435 263 static PerfCounter* _perf_total_bailout_count;
duke@435 264 static PerfCounter* _perf_total_invalidated_count;
duke@435 265 static PerfCounter* _perf_total_compile_count;
duke@435 266 static PerfCounter* _perf_total_native_compile_count;
duke@435 267 static PerfCounter* _perf_total_osr_compile_count;
duke@435 268 static PerfCounter* _perf_total_standard_compile_count;
duke@435 269
duke@435 270 static PerfCounter* _perf_sum_osr_bytes_compiled;
duke@435 271 static PerfCounter* _perf_sum_standard_bytes_compiled;
duke@435 272 static PerfCounter* _perf_sum_nmethod_size;
duke@435 273 static PerfCounter* _perf_sum_nmethod_code_size;
duke@435 274
duke@435 275 static PerfStringVariable* _perf_last_method;
duke@435 276 static PerfStringVariable* _perf_last_failed_method;
duke@435 277 static PerfStringVariable* _perf_last_invalidated_method;
duke@435 278 static PerfVariable* _perf_last_compile_type;
duke@435 279 static PerfVariable* _perf_last_compile_size;
duke@435 280 static PerfVariable* _perf_last_failed_type;
duke@435 281 static PerfVariable* _perf_last_invalidated_type;
duke@435 282
duke@435 283 // Timers and counters for generating statistics
duke@435 284 static elapsedTimer _t_total_compilation;
duke@435 285 static elapsedTimer _t_osr_compilation;
duke@435 286 static elapsedTimer _t_standard_compilation;
duke@435 287
duke@435 288 static int _total_bailout_count;
duke@435 289 static int _total_invalidated_count;
duke@435 290 static int _total_compile_count;
duke@435 291 static int _total_native_compile_count;
duke@435 292 static int _total_osr_compile_count;
duke@435 293 static int _total_standard_compile_count;
duke@435 294
duke@435 295 static int _sum_osr_bytes_compiled;
duke@435 296 static int _sum_standard_bytes_compiled;
duke@435 297 static int _sum_nmethod_size;
duke@435 298 static int _sum_nmethod_code_size;
duke@435 299
duke@435 300 static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS);
iveresov@2138 301 static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count);
duke@435 302 static bool compilation_is_complete (methodHandle method, int osr_bci, int comp_level);
duke@435 303 static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
duke@435 304 static uint assign_compile_id (methodHandle method, int osr_bci);
duke@435 305 static bool is_compile_blocking (methodHandle method, int osr_bci);
duke@435 306 static void preload_classes (methodHandle method, TRAPS);
duke@435 307
duke@435 308 static CompileTask* create_compile_task(CompileQueue* queue,
duke@435 309 int compile_id,
duke@435 310 methodHandle method,
duke@435 311 int osr_bci,
duke@435 312 int comp_level,
duke@435 313 methodHandle hot_method,
duke@435 314 int hot_count,
duke@435 315 const char* comment,
duke@435 316 bool blocking);
duke@435 317 static CompileTask* allocate_task();
duke@435 318 static void free_task(CompileTask* task);
duke@435 319 static void wait_for_completion(CompileTask* task);
duke@435 320
duke@435 321 static void invoke_compiler_on_method(CompileTask* task);
duke@435 322 static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
duke@435 323 static void push_jni_handle_block();
duke@435 324 static void pop_jni_handle_block();
duke@435 325 static bool check_break_at(methodHandle method, int compile_id, bool is_osr);
duke@435 326 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
duke@435 327
duke@435 328 static void compile_method_base(methodHandle method,
duke@435 329 int osr_bci,
duke@435 330 int comp_level,
duke@435 331 methodHandle hot_method,
duke@435 332 int hot_count,
duke@435 333 const char* comment,
duke@435 334 TRAPS);
iveresov@2138 335 static CompileQueue* compile_queue(int comp_level) {
iveresov@2138 336 if (is_c2_compile(comp_level)) return _c2_method_queue;
iveresov@2138 337 if (is_c1_compile(comp_level)) return _c1_method_queue;
iveresov@2138 338 return NULL;
iveresov@2138 339 }
duke@435 340 public:
duke@435 341 enum {
duke@435 342 // The entry bci used for non-OSR compilations.
duke@435 343 standard_entry_bci = InvocationEntryBci
duke@435 344 };
duke@435 345
iveresov@2138 346 static AbstractCompiler* compiler(int comp_level) {
iveresov@2138 347 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
iveresov@2138 348 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
iveresov@2138 349 return NULL;
duke@435 350 }
duke@435 351
iveresov@2138 352 static bool compilation_is_in_queue(methodHandle method, int osr_bci);
iveresov@2138 353 static int queue_size(int comp_level) {
iveresov@2138 354 CompileQueue *q = compile_queue(comp_level);
iveresov@2138 355 return q != NULL ? q->size() : 0;
iveresov@2138 356 }
duke@435 357 static void compilation_init();
duke@435 358 static void init_compiler_thread_log();
iveresov@2138 359 static nmethod* compile_method(methodHandle method,
iveresov@2138 360 int osr_bci,
iveresov@2138 361 int comp_level,
iveresov@2138 362 methodHandle hot_method,
iveresov@2138 363 int hot_count,
duke@435 364 const char* comment, TRAPS);
duke@435 365
duke@435 366 static void compiler_thread_loop();
duke@435 367
kvn@1637 368 static uint get_compilation_id() { return _compilation_id; }
duke@435 369 static bool is_idle();
duke@435 370
duke@435 371 // Set _should_block.
duke@435 372 // Call this from the VM, with Threads_lock held and a safepoint requested.
duke@435 373 static void set_should_block();
duke@435 374
duke@435 375 // Call this from the compiler at convenient points, to poll for _should_block.
duke@435 376 static void maybe_block();
duke@435 377
kvn@1637 378 enum {
kvn@1637 379 // Flags for toggling compiler activity
kvn@1637 380 stop_compilation = 0,
kvn@1637 381 run_compilation = 1
kvn@1637 382 };
kvn@1637 383
kvn@1637 384 static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); }
kvn@1637 385 static bool set_should_compile_new_jobs(jint new_state) {
kvn@1637 386 // Return success if the current caller set it
kvn@1637 387 jint old = Atomic::cmpxchg(new_state, &_should_compile_new_jobs, 1-new_state);
kvn@1637 388 return (old == (1-new_state));
kvn@1637 389 }
kvn@1637 390 static void handle_full_code_cache();
kvn@1637 391
duke@435 392 // Return total compilation ticks
duke@435 393 static jlong total_compilation_ticks() {
duke@435 394 return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
duke@435 395 }
duke@435 396
duke@435 397 // Print a detailed accounting of compilation time
duke@435 398 static void print_times();
duke@435 399
duke@435 400 // Debugging output for failure
duke@435 401 static void print_last_compile();
duke@435 402
duke@435 403 static void print_compiler_threads_on(outputStream* st);
duke@435 404 };
stefank@2314 405
stefank@2314 406 #endif // SHARE_VM_COMPILER_COMPILEBROKER_HPP

mercurial