hotspot/src/share/vm/compiler/compileBroker.hpp
changeset 6453 970dc585ab63
parent 5547 f4b087cbb361
child 7397 5b173b4ca846
equal deleted inserted replaced
6452:cc624b341ab2 6453:970dc585ab63
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    39   bool         _is_success;
    39   bool         _is_success;
    40   bool         _is_blocking;
    40   bool         _is_blocking;
    41   int          _comp_level;
    41   int          _comp_level;
    42   int          _num_inlined_bytecodes;
    42   int          _num_inlined_bytecodes;
    43   nmethodLocker* _code_handle;  // holder of eventual result
    43   nmethodLocker* _code_handle;  // holder of eventual result
    44   CompileTask* _next;
    44   CompileTask* _next, *_prev;
    45 
    45 
    46   // Fields used for logging why the compilation was initiated:
    46   // Fields used for logging why the compilation was initiated:
    47   jlong        _time_queued;  // in units of os::elapsed_counter()
    47   jlong        _time_queued;  // in units of os::elapsed_counter()
    48   jobject      _hot_method;   // which method actually triggered this task
    48   jobject      _hot_method;   // which method actually triggered this task
    49   int          _hot_count;    // information about its invocation counter
    49   int          _hot_count;    // information about its invocation counter
    50   const char*  _comment;      // more info about the task
    50   const char*  _comment;      // more info about the task
    51 
    51 
       
    52   void print_compilation(outputStream *st, methodOop method, char* method_name);
    52  public:
    53  public:
    53   CompileTask() {
    54   CompileTask() {
    54     _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
    55     _lock = new Monitor(Mutex::nonleaf+2, "CompileTaskLock");
    55   }
    56   }
    56 
    57 
    83   int          num_inlined_bytecodes() const     { return _num_inlined_bytecodes; }
    84   int          num_inlined_bytecodes() const     { return _num_inlined_bytecodes; }
    84   void         set_num_inlined_bytecodes(int n)  { _num_inlined_bytecodes = n; }
    85   void         set_num_inlined_bytecodes(int n)  { _num_inlined_bytecodes = n; }
    85 
    86 
    86   CompileTask* next() const                      { return _next; }
    87   CompileTask* next() const                      { return _next; }
    87   void         set_next(CompileTask* next)       { _next = next; }
    88   void         set_next(CompileTask* next)       { _next = next; }
       
    89   CompileTask* prev() const                      { return _prev; }
       
    90   void         set_prev(CompileTask* prev)       { _prev = prev; }
    88 
    91 
    89   void         print();
    92   void         print();
    90   void         print_line();
    93   void         print_line();
       
    94 
    91   void         print_line_on_error(outputStream* st, char* buf, int buflen);
    95   void         print_line_on_error(outputStream* st, char* buf, int buflen);
    92   void         log_task(xmlStream* log);
    96   void         log_task(xmlStream* log);
    93   void         log_task_queued();
    97   void         log_task_queued();
    94   void         log_task_start(CompileLog* log);
    98   void         log_task_start(CompileLog* log);
    95   void         log_task_done(CompileLog* log);
    99   void         log_task_done(CompileLog* log);
    96 
       
    97 };
   100 };
    98 
   101 
    99 // CompilerCounters
   102 // CompilerCounters
   100 //
   103 //
   101 // Per Compiler Performance Counters.
   104 // Per Compiler Performance Counters.
   138     int compile_type()                       { return _compile_type; }
   141     int compile_type()                       { return _compile_type; }
   139 
   142 
   140     PerfCounter* time_counter()              { return _perf_time; }
   143     PerfCounter* time_counter()              { return _perf_time; }
   141     PerfCounter* compile_counter()           { return _perf_compiles; }
   144     PerfCounter* compile_counter()           { return _perf_compiles; }
   142 };
   145 };
   143 
       
   144 
   146 
   145 // CompileQueue
   147 // CompileQueue
   146 //
   148 //
   147 // A list of CompileTasks.
   149 // A list of CompileTasks.
   148 class CompileQueue : public CHeapObj {
   150 class CompileQueue : public CHeapObj {
   151   Monitor*    _lock;
   153   Monitor*    _lock;
   152 
   154 
   153   CompileTask* _first;
   155   CompileTask* _first;
   154   CompileTask* _last;
   156   CompileTask* _last;
   155 
   157 
       
   158   int _size;
   156  public:
   159  public:
   157   CompileQueue(const char* name, Monitor* lock) {
   160   CompileQueue(const char* name, Monitor* lock) {
   158     _name = name;
   161     _name = name;
   159     _lock = lock;
   162     _lock = lock;
   160     _first = NULL;
   163     _first = NULL;
   161     _last = NULL;
   164     _last = NULL;
       
   165     _size = 0;
   162   }
   166   }
   163 
   167 
   164   const char*  name() const                      { return _name; }
   168   const char*  name() const                      { return _name; }
   165   Monitor*     lock() const                      { return _lock; }
   169   Monitor*     lock() const                      { return _lock; }
   166 
   170 
   167   void         add(CompileTask* task);
   171   void         add(CompileTask* task);
       
   172   void         remove(CompileTask* task);
       
   173   CompileTask* first()                           { return _first; }
       
   174   CompileTask* last()                            { return _last;  }
   168 
   175 
   169   CompileTask* get();
   176   CompileTask* get();
   170 
   177 
   171   bool         is_empty() const                  { return _first == NULL; }
   178   bool         is_empty() const                  { return _first == NULL; }
       
   179   int          size()     const                  { return _size;          }
   172 
   180 
   173   void         print();
   181   void         print();
       
   182 };
       
   183 
       
   184 // CompileTaskWrapper
       
   185 //
       
   186 // Assign this task to the current thread.  Deallocate the task
       
   187 // when the compilation is complete.
       
   188 class CompileTaskWrapper : StackObj {
       
   189 public:
       
   190   CompileTaskWrapper(CompileTask* task);
       
   191   ~CompileTaskWrapper();
   174 };
   192 };
   175 
   193 
   176 
   194 
   177 // Compilation
   195 // Compilation
   178 //
   196 //
   206 
   224 
   207   static int  _last_compile_type;
   225   static int  _last_compile_type;
   208   static int  _last_compile_level;
   226   static int  _last_compile_level;
   209   static char _last_method_compiled[name_buffer_length];
   227   static char _last_method_compiled[name_buffer_length];
   210 
   228 
   211   static CompileQueue* _method_queue;
   229   static CompileQueue* _c2_method_queue;
       
   230   static CompileQueue* _c1_method_queue;
   212   static CompileTask* _task_free_list;
   231   static CompileTask* _task_free_list;
   213 
   232 
   214   static GrowableArray<CompilerThread*>* _method_threads;
   233   static GrowableArray<CompilerThread*>* _method_threads;
   215 
   234 
   216   // performance counters
   235   // performance counters
   254   static int _sum_osr_bytes_compiled;
   273   static int _sum_osr_bytes_compiled;
   255   static int _sum_standard_bytes_compiled;
   274   static int _sum_standard_bytes_compiled;
   256   static int _sum_nmethod_size;
   275   static int _sum_nmethod_size;
   257   static int _sum_nmethod_code_size;
   276   static int _sum_nmethod_code_size;
   258 
   277 
   259   static int compiler_count() {
       
   260     return CICompilerCountPerCPU
       
   261       // Example: if CICompilerCountPerCPU is true, then we get
       
   262       // max(log2(8)-1,1) = 2 compiler threads on an 8-way machine.
       
   263       // May help big-app startup time.
       
   264       ? (MAX2(log2_intptr(os::active_processor_count())-1,1))
       
   265       : CICompilerCount;
       
   266   }
       
   267 
       
   268   static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS);
   278   static CompilerThread* make_compiler_thread(const char* name, CompileQueue* queue, CompilerCounters* counters, TRAPS);
   269   static void init_compiler_threads(int compiler_count);
   279   static void init_compiler_threads(int c1_compiler_count, int c2_compiler_count);
   270   static bool compilation_is_complete  (methodHandle method, int osr_bci, int comp_level);
   280   static bool compilation_is_complete  (methodHandle method, int osr_bci, int comp_level);
   271   static bool compilation_is_in_queue  (methodHandle method, int osr_bci);
       
   272   static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
   281   static bool compilation_is_prohibited(methodHandle method, int osr_bci, int comp_level);
   273   static uint assign_compile_id        (methodHandle method, int osr_bci);
   282   static uint assign_compile_id        (methodHandle method, int osr_bci);
   274   static bool is_compile_blocking      (methodHandle method, int osr_bci);
   283   static bool is_compile_blocking      (methodHandle method, int osr_bci);
   275   static void preload_classes          (methodHandle method, TRAPS);
   284   static void preload_classes          (methodHandle method, TRAPS);
   276 
   285 
   299                                   int comp_level,
   308                                   int comp_level,
   300                                   methodHandle hot_method,
   309                                   methodHandle hot_method,
   301                                   int hot_count,
   310                                   int hot_count,
   302                                   const char* comment,
   311                                   const char* comment,
   303                                   TRAPS);
   312                                   TRAPS);
   304 
   313   static CompileQueue* compile_queue(int comp_level) {
       
   314     if (is_c2_compile(comp_level)) return _c2_method_queue;
       
   315     if (is_c1_compile(comp_level)) return _c1_method_queue;
       
   316     return NULL;
       
   317   }
   305  public:
   318  public:
   306   enum {
   319   enum {
   307     // The entry bci used for non-OSR compilations.
   320     // The entry bci used for non-OSR compilations.
   308     standard_entry_bci = InvocationEntryBci
   321     standard_entry_bci = InvocationEntryBci
   309   };
   322   };
   310 
   323 
   311   static AbstractCompiler* compiler(int level ) {
   324   static AbstractCompiler* compiler(int comp_level) {
   312     if (level == CompLevel_fast_compile) return _compilers[0];
   325     if (is_c2_compile(comp_level)) return _compilers[1]; // C2
   313     assert(level == CompLevel_highest_tier, "what level?");
   326     if (is_c1_compile(comp_level)) return _compilers[0]; // C1
   314     return _compilers[1];
   327     return NULL;
   315   }
   328   }
   316 
   329 
       
   330   static bool compilation_is_in_queue(methodHandle method, int osr_bci);
       
   331   static int queue_size(int comp_level) {
       
   332     CompileQueue *q = compile_queue(comp_level);
       
   333     return q != NULL ? q->size() : 0;
       
   334   }
   317   static void compilation_init();
   335   static void compilation_init();
   318   static void init_compiler_thread_log();
   336   static void init_compiler_thread_log();
   319   static nmethod* compile_method(methodHandle method, int osr_bci,
   337   static nmethod* compile_method(methodHandle method,
   320                                  methodHandle hot_method, int hot_count,
   338                                  int osr_bci,
       
   339                                  int comp_level,
       
   340                                  methodHandle hot_method,
       
   341                                  int hot_count,
   321                                  const char* comment, TRAPS);
   342                                  const char* comment, TRAPS);
   322 
   343 
   323   static void compiler_thread_loop();
   344   static void compiler_thread_loop();
   324 
   345 
   325   static uint get_compilation_id() { return _compilation_id; }
   346   static uint get_compilation_id() { return _compilation_id; }