< prev index next >

src/share/vm/compiler/compileBroker.hpp

Print this page




  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 #ifndef SHARE_VM_COMPILER_COMPILEBROKER_HPP
  26 #define SHARE_VM_COMPILER_COMPILEBROKER_HPP
  27 
  28 #include "ci/compilerInterface.hpp"
  29 #include "compiler/abstractCompiler.hpp"
  30 #include "compiler/compileTask.hpp"
  31 #include "runtime/perfData.hpp"

  32 
  33 class nmethod;
  34 class nmethodLocker;
  35 
  36 // CompilerCounters
  37 //
  38 // Per Compiler Performance Counters.
  39 //
  40 class CompilerCounters : public CHeapObj<mtCompiler> {
  41 
  42   public:
  43     enum {
  44       cmname_buffer_length = 160
  45     };
  46 
  47   private:
  48 
  49     char _current_method[cmname_buffer_length];
  50     PerfStringVariable* _perf_current_method;
  51 


 226 
 227   static JavaThread* make_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, bool compiler_thread, TRAPS);
 228   static void init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count);
 229   static bool compilation_is_complete  (methodHandle method, int osr_bci, int comp_level);
 230   static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
 231   static bool is_compile_blocking();
 232   static void preload_classes          (methodHandle method, TRAPS);
 233 
 234   static CompileTask* create_compile_task(CompileQueue* queue,
 235                                           int           compile_id,
 236                                           methodHandle  method,
 237                                           int           osr_bci,
 238                                           int           comp_level,
 239                                           methodHandle  hot_method,
 240                                           int           hot_count,
 241                                           const char*   comment,
 242                                           bool          blocking);
 243   static void wait_for_completion(CompileTask* task);
 244 
 245   static void invoke_compiler_on_method(CompileTask* task);

 246   static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
 247   static void push_jni_handle_block();
 248   static void pop_jni_handle_block();
 249   static bool check_break_at(methodHandle method, int compile_id, bool is_osr);
 250   static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
 251 
 252   static void compile_method_base(methodHandle method,
 253                                   int osr_bci,
 254                                   int comp_level,
 255                                   methodHandle hot_method,
 256                                   int hot_count,
 257                                   const char* comment,
 258                                   Thread* thread);
 259 
 260   static CompileQueue* compile_queue(int comp_level);
 261   static bool init_compiler_runtime();
 262   static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
 263 
 264  public:
 265   enum {


 271     if (is_c2_compile(comp_level)) return _compilers[1]; // C2
 272     if (is_c1_compile(comp_level)) return _compilers[0]; // C1
 273     return NULL;
 274   }
 275 
 276   static bool compilation_is_in_queue(methodHandle method);
 277   static void print_compile_queues(outputStream* st);
 278   static int queue_size(int comp_level) {
 279     CompileQueue *q = compile_queue(comp_level);
 280     return q != NULL ? q->size() : 0;
 281   }
 282   static void compilation_init();
 283   static void init_compiler_thread_log();
 284   static nmethod* compile_method(methodHandle method,
 285                                  int osr_bci,
 286                                  int comp_level,
 287                                  methodHandle hot_method,
 288                                  int hot_count,
 289                                  const char* comment, Thread* thread);
 290 



 291   static void compiler_thread_loop();
 292   static uint get_compilation_id() { return _compilation_id; }
 293 
 294   // Set _should_block.
 295   // Call this from the VM, with Threads_lock held and a safepoint requested.
 296   static void set_should_block();
 297 
 298   // Call this from the compiler at convenient points, to poll for _should_block.
 299   static void maybe_block();
 300 
 301   enum {
 302     // Flags for toggling compiler activity
 303     stop_compilation    = 0,
 304     run_compilation     = 1,
 305     shutdown_compilaton = 2
 306   };
 307 
 308   static jint get_compilation_activity_mode() { return _should_compile_new_jobs; }
 309   static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); }
 310   static bool set_should_compile_new_jobs(jint new_state) {


 319     Atomic::xchg(shutdown_compilaton, &_should_compile_new_jobs);
 320   }
 321 
 322   static bool is_compilation_disabled_forever() {
 323     return _should_compile_new_jobs == shutdown_compilaton;
 324   }
 325   static void handle_full_code_cache(int code_blob_type);
 326   // Ensures that warning is only printed once.
 327   static bool should_print_compiler_warning() {
 328     jint old = Atomic::cmpxchg(1, &_print_compilation_warning, 0);
 329     return old == 0;
 330   }
 331   // Return total compilation ticks
 332   static jlong total_compilation_ticks() {
 333     return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
 334   }
 335 
 336   // Redefine Classes support
 337   static void mark_on_stack();
 338 





 339   // Print a detailed accounting of compilation time
 340   static void print_times();
 341 
 342   // Debugging output for failure
 343   static void print_last_compile();
 344 
 345   static void print_compiler_threads_on(outputStream* st);
 346 
 347   // compiler name for debugging
 348   static const char* compiler_name(int comp_level);
 349 
 350   static int get_total_compile_count() {          return _total_compile_count; }
 351   static int get_total_bailout_count() {          return _total_bailout_count; }
 352   static int get_total_invalidated_count() {      return _total_invalidated_count; }
 353   static int get_total_native_compile_count() {   return _total_native_compile_count; }
 354   static int get_total_osr_compile_count() {      return _total_osr_compile_count; }
 355   static int get_total_standard_compile_count() { return _total_standard_compile_count; }
 356   static int get_sum_osr_bytes_compiled() {       return _sum_osr_bytes_compiled; }
 357   static int get_sum_standard_bytes_compiled() {  return _sum_standard_bytes_compiled; }
 358   static int get_sum_nmethod_size() {             return _sum_nmethod_size;}
 359   static int get_sum_nmethod_code_size() {        return _sum_nmethod_code_size; }
 360   static long get_peak_compilation_time() {       return _peak_compilation_time; }


  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 #ifndef SHARE_VM_COMPILER_COMPILEBROKER_HPP
  26 #define SHARE_VM_COMPILER_COMPILEBROKER_HPP
  27 
  28 #include "ci/compilerInterface.hpp"
  29 #include "compiler/abstractCompiler.hpp"
  30 #include "compiler/compileTask.hpp"
  31 #include "runtime/perfData.hpp"
  32 #include "trace/tracing.hpp"
  33 
  34 class nmethod;
  35 class nmethodLocker;
  36 
  37 // CompilerCounters
  38 //
  39 // Per Compiler Performance Counters.
  40 //
  41 class CompilerCounters : public CHeapObj<mtCompiler> {
  42 
  43   public:
  44     enum {
  45       cmname_buffer_length = 160
  46     };
  47 
  48   private:
  49 
  50     char _current_method[cmname_buffer_length];
  51     PerfStringVariable* _perf_current_method;
  52 


 227 
 228   static JavaThread* make_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, AbstractCompiler* comp, bool compiler_thread, TRAPS);
 229   static void init_compiler_sweeper_threads(int c1_compiler_count, int c2_compiler_count);
 230   static bool compilation_is_complete  (methodHandle method, int osr_bci, int comp_level);
 231   static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
 232   static bool is_compile_blocking();
 233   static void preload_classes          (methodHandle method, TRAPS);
 234 
 235   static CompileTask* create_compile_task(CompileQueue* queue,
 236                                           int           compile_id,
 237                                           methodHandle  method,
 238                                           int           osr_bci,
 239                                           int           comp_level,
 240                                           methodHandle  hot_method,
 241                                           int           hot_count,
 242                                           const char*   comment,
 243                                           bool          blocking);
 244   static void wait_for_completion(CompileTask* task);
 245 
 246   static void invoke_compiler_on_method(CompileTask* task);
 247   static void post_compile(CompilerThread* thread, CompileTask* task, EventCompilation& event, bool success, ciEnv* ci_env);
 248   static void set_last_compile(CompilerThread *thread, methodHandle method, bool is_osr, int comp_level);
 249   static void push_jni_handle_block();
 250   static void pop_jni_handle_block();
 251   static bool check_break_at(methodHandle method, int compile_id, bool is_osr);
 252   static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
 253 
 254   static void compile_method_base(methodHandle method,
 255                                   int osr_bci,
 256                                   int comp_level,
 257                                   methodHandle hot_method,
 258                                   int hot_count,
 259                                   const char* comment,
 260                                   Thread* thread);
 261 
 262   static CompileQueue* compile_queue(int comp_level);
 263   static bool init_compiler_runtime();
 264   static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
 265 
 266  public:
 267   enum {


 273     if (is_c2_compile(comp_level)) return _compilers[1]; // C2
 274     if (is_c1_compile(comp_level)) return _compilers[0]; // C1
 275     return NULL;
 276   }
 277 
 278   static bool compilation_is_in_queue(methodHandle method);
 279   static void print_compile_queues(outputStream* st);
 280   static int queue_size(int comp_level) {
 281     CompileQueue *q = compile_queue(comp_level);
 282     return q != NULL ? q->size() : 0;
 283   }
 284   static void compilation_init();
 285   static void init_compiler_thread_log();
 286   static nmethod* compile_method(methodHandle method,
 287                                  int osr_bci,
 288                                  int comp_level,
 289                                  methodHandle hot_method,
 290                                  int hot_count,
 291                                  const char* comment, Thread* thread);
 292 
 293   // Acquire any needed locks and assign a compile id
 294   static uint assign_compile_id_unlocked(Thread* thread, methodHandle method, int osr_bci);
 295 
 296   static void compiler_thread_loop();
 297   static uint get_compilation_id() { return _compilation_id; }
 298 
 299   // Set _should_block.
 300   // Call this from the VM, with Threads_lock held and a safepoint requested.
 301   static void set_should_block();
 302 
 303   // Call this from the compiler at convenient points, to poll for _should_block.
 304   static void maybe_block();
 305 
 306   enum {
 307     // Flags for toggling compiler activity
 308     stop_compilation    = 0,
 309     run_compilation     = 1,
 310     shutdown_compilaton = 2
 311   };
 312 
 313   static jint get_compilation_activity_mode() { return _should_compile_new_jobs; }
 314   static bool should_compile_new_jobs() { return UseCompiler && (_should_compile_new_jobs == run_compilation); }
 315   static bool set_should_compile_new_jobs(jint new_state) {


 324     Atomic::xchg(shutdown_compilaton, &_should_compile_new_jobs);
 325   }
 326 
 327   static bool is_compilation_disabled_forever() {
 328     return _should_compile_new_jobs == shutdown_compilaton;
 329   }
 330   static void handle_full_code_cache(int code_blob_type);
 331   // Ensures that warning is only printed once.
 332   static bool should_print_compiler_warning() {
 333     jint old = Atomic::cmpxchg(1, &_print_compilation_warning, 0);
 334     return old == 0;
 335   }
 336   // Return total compilation ticks
 337   static jlong total_compilation_ticks() {
 338     return _perf_total_compilation != NULL ? _perf_total_compilation->get_value() : 0;
 339   }
 340 
 341   // Redefine Classes support
 342   static void mark_on_stack();
 343 
 344 #if INCLUDE_JVMCI
 345   // Print curent compilation time stats for a given compiler
 346   static void print_times(AbstractCompiler* comp);
 347 #endif
 348 
 349   // Print a detailed accounting of compilation time
 350   static void print_times(bool per_compiler = true, bool aggregate = true);
 351 
 352   // Debugging output for failure
 353   static void print_last_compile();
 354 
 355   static void print_compiler_threads_on(outputStream* st);
 356 
 357   // compiler name for debugging
 358   static const char* compiler_name(int comp_level);
 359 
 360   static int get_total_compile_count() {          return _total_compile_count; }
 361   static int get_total_bailout_count() {          return _total_bailout_count; }
 362   static int get_total_invalidated_count() {      return _total_invalidated_count; }
 363   static int get_total_native_compile_count() {   return _total_native_compile_count; }
 364   static int get_total_osr_compile_count() {      return _total_osr_compile_count; }
 365   static int get_total_standard_compile_count() { return _total_standard_compile_count; }
 366   static int get_sum_osr_bytes_compiled() {       return _sum_osr_bytes_compiled; }
 367   static int get_sum_standard_bytes_compiled() {  return _sum_standard_bytes_compiled; }
 368   static int get_sum_nmethod_size() {             return _sum_nmethod_size;}
 369   static int get_sum_nmethod_code_size() {        return _sum_nmethod_code_size; }
 370   static long get_peak_compilation_time() {       return _peak_compilation_time; }
< prev index next >