annotate src/hotspot/share/compiler/compileBroker.hpp @ 54482:c914170817d4

8221853: Data race in compile broker (set_last_compile) Summary: Remove the debug code provoking it Reviewed-by: kvn, thartmann
author jcbeyler
date Tue, 09 Apr 2019 19:34:05 -0700
parents 9807daeb47c4
children 1dc9bf9d016b
rev   line source
duke@1 1 /*
coleenp@53244 2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
coleenp@53244 25 #ifndef SHARE_COMPILER_COMPILEBROKER_HPP
coleenp@53244 26 #define SHARE_COMPILER_COMPILEBROKER_HPP
stefank@7397 27
stefank@7397 28 #include "ci/compilerInterface.hpp"
stefank@7397 29 #include "compiler/abstractCompiler.hpp"
neliasso@32582 30 #include "compiler/compileTask.hpp"
neliasso@33451 31 #include "compiler/compilerDirectives.hpp"
stefank@7397 32 #include "runtime/perfData.hpp"
neliasso@33451 33 #include "utilities/stack.hpp"
dnsimon@35845 34 #if INCLUDE_JVMCI
dnsimon@35845 35 #include "jvmci/jvmciCompiler.hpp"
dnsimon@35845 36 #endif
stefank@7397 37
duke@1 38 class nmethod;
duke@1 39 class nmethodLocker;
duke@1 40
duke@1 41 // CompilerCounters
duke@1 42 //
duke@1 43 // Per Compiler Performance Counters.
duke@1 44 //
zgu@13195 45 class CompilerCounters : public CHeapObj<mtCompiler> {
duke@1 46
duke@1 47 public:
duke@1 48 enum {
duke@1 49 cmname_buffer_length = 160
duke@1 50 };
duke@1 51
duke@1 52 private:
duke@1 53
duke@1 54 char _current_method[cmname_buffer_length];
duke@1 55 int _compile_type;
duke@1 56
duke@1 57 public:
redestad@33168 58 CompilerCounters();
duke@1 59
duke@1 60 // these methods should be called in a thread safe context
duke@1 61
duke@1 62 void set_current_method(const char* method) {
stuefe@30281 63 strncpy(_current_method, method, (size_t)cmname_buffer_length-1);
stuefe@30281 64 _current_method[cmname_buffer_length-1] = '\0';
duke@1 65 }
duke@1 66
duke@1 67 char* current_method() { return _current_method; }
duke@1 68
duke@1 69 void set_compile_type(int compile_type) {
duke@1 70 _compile_type = compile_type;
duke@1 71 }
duke@1 72
duke@1 73 int compile_type() { return _compile_type; }
duke@1 74
duke@1 75 };
duke@1 76
duke@1 77 // CompileQueue
duke@1 78 //
duke@1 79 // A list of CompileTasks.
zgu@13195 80 class CompileQueue : public CHeapObj<mtCompiler> {
duke@1 81 private:
duke@1 82 const char* _name;
duke@1 83
duke@1 84 CompileTask* _first;
duke@1 85 CompileTask* _last;
duke@1 86
vlivanov@24443 87 CompileTask* _first_stale;
vlivanov@24443 88
iveresov@6453 89 int _size;
vlivanov@24443 90
vlivanov@24443 91 void purge_stale_tasks();
duke@1 92 public:
neliasso@27696 93 CompileQueue(const char* name) {
duke@1 94 _name = name;
duke@1 95 _first = NULL;
duke@1 96 _last = NULL;
iveresov@6453 97 _size = 0;
vlivanov@24443 98 _first_stale = NULL;
duke@1 99 }
duke@1 100
duke@1 101 const char* name() const { return _name; }
duke@1 102
duke@1 103 void add(CompileTask* task);
iveresov@6453 104 void remove(CompileTask* task);
vlivanov@24443 105 void remove_and_mark_stale(CompileTask* task);
iveresov@6453 106 CompileTask* first() { return _first; }
iveresov@6453 107 CompileTask* last() { return _last; }
duke@1 108
duke@1 109 CompileTask* get();
duke@1 110
duke@1 111 bool is_empty() const { return _first == NULL; }
iveresov@6453 112 int size() const { return _size; }
duke@1 113
vlivanov@24443 114
coleenp@13728 115 // Redefine Classes support
coleenp@13728 116 void mark_on_stack();
anoll@24321 117 void free_all();
neliasso@26587 118 void print_tty();
neliasso@26587 119 void print(outputStream* st = tty);
coleenp@13728 120
anoll@20707 121 ~CompileQueue() {
anoll@20707 122 assert (is_empty(), " Compile Queue must be empty");
anoll@20707 123 }
duke@1 124 };
duke@1 125
iveresov@6453 126 // CompileTaskWrapper
iveresov@6453 127 //
iveresov@6453 128 // Assign this task to the current thread. Deallocate the task
iveresov@6453 129 // when the compilation is complete.
iveresov@6453 130 class CompileTaskWrapper : StackObj {
iveresov@6453 131 public:
iveresov@6453 132 CompileTaskWrapper(CompileTask* task);
iveresov@6453 133 ~CompileTaskWrapper();
iveresov@6453 134 };
iveresov@6453 135
duke@1 136 // Compilation
duke@1 137 //
duke@1 138 // The broker for all compilation requests.
duke@1 139 class CompileBroker: AllStatic {
duke@1 140 friend class Threads;
neliasso@33451 141 friend class CompileTaskWrapper;
duke@1 142
duke@1 143 public:
duke@1 144 enum {
duke@1 145 name_buffer_length = 100
duke@1 146 };
duke@1 147
duke@1 148 // Compile type Information for print_last_compile() and CompilerCounters
duke@1 149 enum { no_compile, normal_compile, osr_compile, native_compile };
coleenp@33593 150 static int assign_compile_id (const methodHandle& method, int osr_bci);
anoll@22247 151
duke@1 152
duke@1 153 private:
duke@1 154 static bool _initialized;
duke@1 155 static volatile bool _should_block;
duke@1 156
kvn@4750 157 // This flag can be used to stop compilation or turn it back on
kvn@4750 158 static volatile jint _should_compile_new_jobs;
kvn@4750 159
duke@1 160 // The installed compiler(s)
duke@1 161 static AbstractCompiler* _compilers[2];
duke@1 162
mdoerr@49848 163 // The maximum numbers of compiler threads to be determined during startup.
mdoerr@49848 164 static int _c1_count, _c2_count;
mdoerr@49848 165
mdoerr@49848 166 // An array of compiler thread Java objects
mdoerr@49848 167 static jobject *_compiler1_objects, *_compiler2_objects;
mdoerr@49848 168
mdoerr@49848 169 // An array of compiler logs
mdoerr@49848 170 static CompileLog **_compiler1_logs, **_compiler2_logs;
mdoerr@49848 171
duke@1 172 // These counters are used for assigning id's to each compilation
anoll@22247 173 static volatile jint _compilation_id;
anoll@22247 174 static volatile jint _osr_compilation_id;
duke@1 175
anoll@24321 176 static CompileQueue* _c2_compile_queue;
anoll@24321 177 static CompileQueue* _c1_compile_queue;
duke@1 178
duke@1 179 // performance counters
duke@1 180 static PerfCounter* _perf_total_compilation;
duke@1 181 static PerfCounter* _perf_native_compilation;
duke@1 182 static PerfCounter* _perf_osr_compilation;
duke@1 183 static PerfCounter* _perf_standard_compilation;
duke@1 184
duke@1 185 static PerfCounter* _perf_total_bailout_count;
duke@1 186 static PerfCounter* _perf_total_invalidated_count;
duke@1 187 static PerfCounter* _perf_total_compile_count;
duke@1 188 static PerfCounter* _perf_total_native_compile_count;
duke@1 189 static PerfCounter* _perf_total_osr_compile_count;
duke@1 190 static PerfCounter* _perf_total_standard_compile_count;
duke@1 191
duke@1 192 static PerfCounter* _perf_sum_osr_bytes_compiled;
duke@1 193 static PerfCounter* _perf_sum_standard_bytes_compiled;
duke@1 194 static PerfCounter* _perf_sum_nmethod_size;
duke@1 195 static PerfCounter* _perf_sum_nmethod_code_size;
duke@1 196
duke@1 197 static PerfStringVariable* _perf_last_method;
duke@1 198 static PerfStringVariable* _perf_last_failed_method;
duke@1 199 static PerfStringVariable* _perf_last_invalidated_method;
duke@1 200 static PerfVariable* _perf_last_compile_type;
duke@1 201 static PerfVariable* _perf_last_compile_size;
duke@1 202 static PerfVariable* _perf_last_failed_type;
duke@1 203 static PerfVariable* _perf_last_invalidated_type;
duke@1 204
duke@1 205 // Timers and counters for generating statistics
duke@1 206 static elapsedTimer _t_total_compilation;
duke@1 207 static elapsedTimer _t_osr_compilation;
duke@1 208 static elapsedTimer _t_standard_compilation;
shade@26913 209 static elapsedTimer _t_invalidated_compilation;
shade@26913 210 static elapsedTimer _t_bailedout_compilation;
duke@1 211
sla@18025 212 static int _total_compile_count;
duke@1 213 static int _total_bailout_count;
duke@1 214 static int _total_invalidated_count;
duke@1 215 static int _total_native_compile_count;
duke@1 216 static int _total_osr_compile_count;
duke@1 217 static int _total_standard_compile_count;
goetz@50515 218 static int _total_compiler_stopped_count;
goetz@50515 219 static int _total_compiler_restarted_count;
duke@1 220 static int _sum_osr_bytes_compiled;
duke@1 221 static int _sum_standard_bytes_compiled;
duke@1 222 static int _sum_nmethod_size;
duke@1 223 static int _sum_nmethod_code_size;
sla@18025 224 static long _peak_compilation_time;
duke@1 225
coleenp@47765 226 static volatile int _print_compilation_warning;
anoll@21575 227
mdoerr@49848 228 static Handle create_thread_oop(const char* name, TRAPS);
thartmann@52369 229 static JavaThread* make_thread(jobject thread_oop, CompileQueue* queue, AbstractCompiler* comp, TRAPS);
mdoerr@49848 230 static void init_compiler_sweeper_threads();
mdoerr@49848 231 static void possibly_add_compiler_threads();
coleenp@33593 232 static bool compilation_is_complete (const methodHandle& method, int osr_bci, int comp_level);
simonis@36597 233 static bool compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded);
coleenp@33593 234 static void preload_classes (const methodHandle& method, TRAPS);
duke@1 235
jwilhelm@33626 236 static CompileTask* create_compile_task(CompileQueue* queue,
jwilhelm@33626 237 int compile_id,
jwilhelm@33626 238 const methodHandle& method,
jwilhelm@33626 239 int osr_bci,
jwilhelm@33626 240 int comp_level,
jwilhelm@33626 241 const methodHandle& hot_method,
jwilhelm@33626 242 int hot_count,
neliasso@38218 243 CompileTask::CompileReason compile_reason,
jwilhelm@33626 244 bool blocking);
duke@1 245 static void wait_for_completion(CompileTask* task);
dnsimon@35547 246 #if INCLUDE_JVMCI
dnsimon@35845 247 static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
dnsimon@35547 248 #endif
duke@1 249
duke@1 250 static void invoke_compiler_on_method(CompileTask* task);
shade@52605 251 static void post_compile(CompilerThread* thread, CompileTask* task, bool success, ciEnv* ci_env,
shade@52605 252 int compilable, const char* failure_reason);
jcbeyler@54482 253 static void update_compile_perf_data(CompilerThread *thread, const methodHandle& method, bool is_osr);
jcbeyler@54482 254
duke@1 255 static void push_jni_handle_block();
duke@1 256 static void pop_jni_handle_block();
duke@1 257 static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
duke@1 258
coleenp@33593 259 static void compile_method_base(const methodHandle& method,
duke@1 260 int osr_bci,
duke@1 261 int comp_level,
coleenp@33593 262 const methodHandle& hot_method,
duke@1 263 int hot_count,
neliasso@38218 264 CompileTask::CompileReason compile_reason,
simonis@36597 265 bool blocking,
iveresov@11572 266 Thread* thread);
neliasso@26587 267
neliasso@26587 268 static CompileQueue* compile_queue(int comp_level);
anoll@20707 269 static bool init_compiler_runtime();
anoll@20707 270 static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
anoll@20707 271
neliasso@33451 272 public:
neliasso@33451 273
neliasso@33451 274 static DirectivesStack* dirstack();
neliasso@33451 275 static void set_dirstack(DirectivesStack* stack);
neliasso@33451 276
duke@1 277 enum {
duke@1 278 // The entry bci used for non-OSR compilations.
duke@1 279 standard_entry_bci = InvocationEntryBci
duke@1 280 };
duke@1 281
iveresov@6453 282 static AbstractCompiler* compiler(int comp_level) {
iveresov@6453 283 if (is_c2_compile(comp_level)) return _compilers[1]; // C2
iveresov@6453 284 if (is_c1_compile(comp_level)) return _compilers[0]; // C1
iveresov@6453 285 return NULL;
duke@1 286 }
duke@1 287
coleenp@33593 288 static bool compilation_is_in_queue(const methodHandle& method);
neliasso@26587 289 static void print_compile_queues(outputStream* st);
neliasso@33451 290 static void print_directives(outputStream* st);
iveresov@6453 291 static int queue_size(int comp_level) {
iveresov@6453 292 CompileQueue *q = compile_queue(comp_level);
iveresov@6453 293 return q != NULL ? q->size() : 0;
iveresov@6453 294 }
thartmann@49618 295 static void compilation_init_phase1(TRAPS);
thartmann@49618 296 static void compilation_init_phase2();
duke@1 297 static void init_compiler_thread_log();
coleenp@33593 298 static nmethod* compile_method(const methodHandle& method,
iveresov@6453 299 int osr_bci,
iveresov@6453 300 int comp_level,
coleenp@33593 301 const methodHandle& hot_method,
iveresov@6453 302 int hot_count,
neliasso@38218 303 CompileTask::CompileReason compile_reason,
neliasso@38218 304 Thread* thread);
duke@1 305
simonis@36597 306 static nmethod* compile_method(const methodHandle& method,
simonis@36597 307 int osr_bci,
simonis@36597 308 int comp_level,
simonis@36597 309 const methodHandle& hot_method,
simonis@36597 310 int hot_count,
neliasso@38218 311 CompileTask::CompileReason compile_reason,
simonis@36597 312 DirectiveSet* directive,
simonis@36597 313 Thread* thread);
simonis@36597 314
twisti@33160 315 // Acquire any needed locks and assign a compile id
coleenp@33593 316 static uint assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci);
twisti@33160 317
duke@1 318 static void compiler_thread_loop();
kvn@4750 319 static uint get_compilation_id() { return _compilation_id; }
duke@1 320
duke@1 321 // Set _should_block.
duke@1 322 // Call this from the VM, with Threads_lock held and a safepoint requested.
duke@1 323 static void set_should_block();
duke@1 324
duke@1 325 // Call this from the compiler at convenient points, to poll for _should_block.
duke@1 326 static void maybe_block();
duke@1 327
eosterlund@46650 328 enum CompilerActivity {
kvn@4750 329 // Flags for toggling compiler activity
eosterlund@46650 330 stop_compilation = 0,
eosterlund@46650 331 run_compilation = 1,
eosterlund@46650 332 shutdown_compilation = 2
kvn@4750 333 };
kvn@4750 334
iignatyev@27701 335 static jint get_compilation_activity_mode() { return _should_compile_new_jobs; }
kvn@4750 336 static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); }
kvn@4750 337 static bool set_should_compile_new_jobs(jint new_state) {
kvn@4750 338 // Return success if the current caller set it
kvn@4750 339 jint old = Atomic::cmpxchg(new_state, &_should_compile_new_jobs, 1-new_state);
goetz@50515 340 bool success = (old == (1-new_state));
goetz@50515 341 if (success) {
goetz@50515 342 if (new_state == run_compilation) {
goetz@50515 343 _total_compiler_restarted_count++;
goetz@50515 344 } else {
goetz@50515 345 _total_compiler_stopped_count++;
goetz@50515 346 }
goetz@50515 347 }
goetz@50515 348 return success;
kvn@4750 349 }
anoll@20707 350
anoll@20707 351 static void disable_compilation_forever() {
anoll@20707 352 UseCompiler = false;
anoll@20707 353 AlwaysCompileLoopMethods = false;
eosterlund@47578 354 Atomic::xchg(jint(shutdown_compilation), &_should_compile_new_jobs);
anoll@20707 355 }
anoll@20707 356
anoll@20707 357 static bool is_compilation_disabled_forever() {
eosterlund@46650 358 return _should_compile_new_jobs == shutdown_compilation;
anoll@20707 359 }
thartmann@26796 360 static void handle_full_code_cache(int code_blob_type);
anoll@21575 361 // Ensures that warning is only printed once.
anoll@21575 362 static bool should_print_compiler_warning() {
anoll@21575 363 jint old = Atomic::cmpxchg(1, &_print_compilation_warning, 0);
anoll@21575 364 return old == 0;
anoll@21575 365 }
duke@1 366 // Return total compilation ticks
duke@1 367 static jlong total_compilation_ticks() {
duke@1 368 return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
duke@1 369 }
duke@1 370
coleenp@13728 371 // Redefine Classes support
coleenp@13728 372 static void mark_on_stack();
coleenp@13728 373
twisti@33160 374 #if INCLUDE_JVMCI
twisti@33160 375 // Print curent compilation time stats for a given compiler
twisti@33160 376 static void print_times(AbstractCompiler* comp);
twisti@33160 377 #endif
twisti@33160 378
duke@1 379 // Print a detailed accounting of compilation time
twisti@33160 380 static void print_times(bool per_compiler = true, bool aggregate = true);
duke@1 381
morris@16372 382 // compiler name for debugging
morris@16372 383 static const char* compiler_name(int comp_level);
sla@18025 384
mdoerr@49848 385 // Provide access to compiler thread Java objects
mdoerr@49848 386 static jobject compiler1_object(int idx) {
mdoerr@49848 387 assert(_compiler1_objects != NULL, "must be initialized");
mdoerr@49848 388 assert(idx < _c1_count, "oob");
mdoerr@49848 389 return _compiler1_objects[idx];
mdoerr@49848 390 }
mdoerr@49848 391
mdoerr@49848 392 static jobject compiler2_object(int idx) {
mdoerr@49848 393 assert(_compiler2_objects != NULL, "must be initialized");
mdoerr@49848 394 assert(idx < _c2_count, "oob");
mdoerr@49848 395 return _compiler2_objects[idx];
mdoerr@49848 396 }
mdoerr@49848 397
mdoerr@49848 398 static CompileLog* get_log(CompilerThread* ct);
mdoerr@49848 399
goetz@50515 400 static int get_total_compile_count() { return _total_compile_count; }
goetz@50515 401 static int get_total_bailout_count() { return _total_bailout_count; }
goetz@50515 402 static int get_total_invalidated_count() { return _total_invalidated_count; }
goetz@50515 403 static int get_total_native_compile_count() { return _total_native_compile_count; }
goetz@50515 404 static int get_total_osr_compile_count() { return _total_osr_compile_count; }
goetz@50515 405 static int get_total_standard_compile_count() { return _total_standard_compile_count; }
goetz@50515 406 static int get_total_compiler_stopped_count() { return _total_compiler_stopped_count; }
goetz@50515 407 static int get_total_compiler_restarted_count() { return _total_compiler_restarted_count; }
goetz@50515 408 static int get_sum_osr_bytes_compiled() { return _sum_osr_bytes_compiled; }
goetz@50515 409 static int get_sum_standard_bytes_compiled() { return _sum_standard_bytes_compiled; }
goetz@50515 410 static int get_sum_nmethod_size() { return _sum_nmethod_size;}
goetz@50515 411 static int get_sum_nmethod_code_size() { return _sum_nmethod_code_size; }
goetz@50515 412 static long get_peak_compilation_time() { return _peak_compilation_time; }
goetz@50515 413 static long get_total_compilation_time() { return _t_total_compilation.milliseconds(); }
coleenp@27461 414
coleenp@27461 415 // Log that compilation profiling is skipped because metaspace is full.
coleenp@27461 416 static void log_metaspace_failure();
lucy@49611 417
lucy@49611 418 // CodeHeap State Analytics.
lucy@49611 419 static void print_info(outputStream *out);
lucy@49611 420 static void print_heapinfo(outputStream *out, const char* function, const char* granularity );
duke@1 421 };
stefank@7397 422
coleenp@53244 423 #endif // SHARE_COMPILER_COMPILEBROKER_HPP