< prev index next >

src/hotspot/share/compiler/compileBroker.hpp

Print this page

 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_COMPILER_COMPILEBROKER_HPP
 26 #define SHARE_COMPILER_COMPILEBROKER_HPP
 27 
 28 #include "ci/compilerInterface.hpp"
 29 #include "compiler/abstractCompiler.hpp"
 30 #include "compiler/compileTask.hpp"
 31 #include "compiler/compilerDirectives.hpp"
 32 #include "compiler/compilerThread.hpp"
 33 #include "runtime/atomic.hpp"

 34 #include "runtime/perfDataTypes.hpp"

 35 #include "utilities/stack.hpp"
 36 #if INCLUDE_JVMCI
 37 #include "jvmci/jvmciCompiler.hpp"
 38 #endif
 39 
 40 class nmethod;
 41 
 42 // CompilerCounters
 43 //
 44 // Per Compiler Performance Counters.
 45 //
 46 class CompilerCounters : public CHeapObj<mtCompiler> {
 47 
 48   public:
 49     enum {
 50       cmname_buffer_length = 160
 51     };
 52 
 53   private:
 54 

 65       _current_method[cmname_buffer_length-1] = '\0';
 66     }
 67 
 68     char* current_method()                  { return _current_method; }
 69 
 70     void set_compile_type(int compile_type) {
 71       _compile_type = compile_type;
 72     }
 73 
 74     int compile_type()                       { return _compile_type; }
 75 
 76 };
 77 
 78 // CompileQueue
 79 //
 80 // A list of CompileTasks.
 81 class CompileQueue : public CHeapObj<mtCompiler> {
 82  private:
 83   const char* _name;
 84 


 85   CompileTask* _first;
 86   CompileTask* _last;
 87 
 88   CompileTask* _first_stale;
 89 


 90   int _size;
 91   int _peak_size;
 92   uint _total_added;
 93   uint _total_removed;
 94 
 95   void purge_stale_tasks();
 96  public:
 97   CompileQueue(const char* name) {
 98     _name = name;

 99     _first = nullptr;
100     _last = nullptr;
101     _size = 0;
102     _total_added = 0;
103     _total_removed = 0;
104     _peak_size = 0;
105     _first_stale = nullptr;
106   }
107 
108   const char*  name() const                      { return _name; }
109 



110   void         add(CompileTask* task);
111   void         remove(CompileTask* task);
112   void         remove_and_mark_stale(CompileTask* task);
113   CompileTask* first()                           { return _first; }
114   CompileTask* last()                            { return _last;  }
115 
116   CompileTask* get(CompilerThread* thread);
117 
118   bool         is_empty() const                  { return _first == nullptr; }
119   int          size()     const                  { return _size;          }
120 


121   int         get_peak_size()     const          { return _peak_size; }
122   uint        get_total_added()   const          { return _total_added; }
123   uint        get_total_removed() const          { return _total_removed; }
124 
125   // Redefine Classes support
126   void mark_on_stack();
127   void free_all();
128   void print_tty();
129   void print(outputStream* st = tty);
130 
131   ~CompileQueue() {
132     assert (is_empty(), " Compile Queue must be empty");
133   }
134 };
135 
136 // CompileTaskWrapper
137 //
138 // Assign this task to the current thread.  Deallocate the task
139 // when the compilation is complete.
140 class CompileTaskWrapper : StackObj {

145 
146 // Compilation
147 //
148 // The broker for all compilation requests.
149 class CompileBroker: AllStatic {
150  friend class Threads;
151  friend class CompileTaskWrapper;
152 
153  public:
154   enum {
155     name_buffer_length = 100
156   };
157 
158   // Compile type Information for print_last_compile() and CompilerCounters
159   enum { no_compile, normal_compile, osr_compile, native_compile };
160   static int assign_compile_id (const methodHandle& method, int osr_bci);
161 
162 
163  private:
164   static bool _initialized;

165   static volatile bool _should_block;
166 
167   // This flag can be used to stop compilation or turn it back on
168   static volatile jint _should_compile_new_jobs;
169 
170   // The installed compiler(s)
171   static AbstractCompiler* _compilers[2];
172 
173   // The maximum numbers of compiler threads to be determined during startup.
174   static int _c1_count, _c2_count;
175 
176   // An array of compiler thread Java objects
177   static jobject *_compiler1_objects, *_compiler2_objects;
178 
179   // An array of compiler logs
180   static CompileLog **_compiler1_logs, **_compiler2_logs;
181 
182   // These counters are used for assigning id's to each compilation
183   static volatile jint _compilation_id;
184   static volatile jint _osr_compilation_id;
185   static volatile jint _native_compilation_id;
186 

187   static CompileQueue* _c2_compile_queue;
188   static CompileQueue* _c1_compile_queue;


189 
190   // performance counters
191   static PerfCounter* _perf_total_compilation;
192   static PerfCounter* _perf_osr_compilation;
193   static PerfCounter* _perf_standard_compilation;
194 
195   static PerfCounter* _perf_total_bailout_count;
196   static PerfCounter* _perf_total_invalidated_count;
197   static PerfCounter* _perf_total_compile_count;
198   static PerfCounter* _perf_total_osr_compile_count;
199   static PerfCounter* _perf_total_standard_compile_count;
200 
201   static PerfCounter* _perf_sum_osr_bytes_compiled;
202   static PerfCounter* _perf_sum_standard_bytes_compiled;
203   static PerfCounter* _perf_sum_nmethod_size;
204   static PerfCounter* _perf_sum_nmethod_code_size;
205 
206   static PerfStringVariable* _perf_last_method;
207   static PerfStringVariable* _perf_last_failed_method;
208   static PerfStringVariable* _perf_last_invalidated_method;
209   static PerfVariable*       _perf_last_compile_type;
210   static PerfVariable*       _perf_last_compile_size;
211   static PerfVariable*       _perf_last_failed_type;
212   static PerfVariable*       _perf_last_invalidated_type;
213 
214   // Timers and counters for generating statistics
215   static elapsedTimer _t_total_compilation;
216   static elapsedTimer _t_osr_compilation;
217   static elapsedTimer _t_standard_compilation;
218   static elapsedTimer _t_invalidated_compilation;
219   static elapsedTimer _t_bailedout_compilation;
220 
221   static uint _total_compile_count;
222   static uint _total_bailout_count;
223   static uint _total_invalidated_count;

224   static uint _total_native_compile_count;
225   static uint _total_osr_compile_count;
226   static uint _total_standard_compile_count;
227   static uint _total_compiler_stopped_count;
228   static uint _total_compiler_restarted_count;
229   static uint _sum_osr_bytes_compiled;
230   static uint _sum_standard_bytes_compiled;
231   static uint _sum_nmethod_size;
232   static uint _sum_nmethod_code_size;
233   static jlong _peak_compilation_time;
234 
235   static CompilerStatistics _stats_per_level[];


236 
237   static volatile int _print_compilation_warning;
238 
239   enum ThreadType {
240     compiler_t,
241     deoptimizer_t

242   };
243 

244   static JavaThread* make_thread(ThreadType type, jobject thread_oop, CompileQueue* queue, AbstractCompiler* comp, JavaThread* THREAD);
245   static void init_compiler_threads();

246   static void possibly_add_compiler_threads(JavaThread* THREAD);
247   static bool compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded);
248 
249   static CompileTask* create_compile_task(CompileQueue*       queue,
250                                           int                 compile_id,
251                                           const methodHandle& method,
252                                           int                 osr_bci,
253                                           int                 comp_level,
254                                           const methodHandle& hot_method,
255                                           int                 hot_count,

256                                           CompileTask::CompileReason compile_reason,

257                                           bool                blocking);
258   static void wait_for_completion(CompileTask* task);
259 #if INCLUDE_JVMCI
260   static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
261 #endif
262 
263   static void free_buffer_blob_if_allocated(CompilerThread* thread);
264 
265   static void invoke_compiler_on_method(CompileTask* task);
266   static void handle_compile_error(CompilerThread* thread, CompileTask* task, ciEnv* ci_env,
267                                    int compilable, const char* failure_reason);
268   static void update_compile_perf_data(CompilerThread *thread, const methodHandle& method, bool is_osr);
269 
270   static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
271 
272   static void compile_method_base(const methodHandle& method,
273                                   int osr_bci,
274                                   int comp_level,
275                                   const methodHandle& hot_method,
276                                   int hot_count,
277                                   CompileTask::CompileReason compile_reason,

278                                   bool blocking,
279                                   Thread* thread);
280 
281   static CompileQueue* compile_queue(int comp_level);
282   static bool init_compiler_runtime();
283   static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
284 




285 public:
286   enum {
287     // The entry bci used for non-OSR compilations.
288     standard_entry_bci = InvocationEntryBci
289   };
290 
291   static AbstractCompiler* compiler(int comp_level) {
292     if (is_c2_compile(comp_level)) return _compilers[1]; // C2
293     if (is_c1_compile(comp_level)) return _compilers[0]; // C1
294     return nullptr;
295   }
296 
297   static bool compilation_is_complete(const methodHandle& method, int osr_bci, int comp_level);



298   static bool compilation_is_in_queue(const methodHandle& method);
299   static void print_compile_queues(outputStream* st);
300   static int queue_size(int comp_level) {
301     CompileQueue *q = compile_queue(comp_level);
302     return q != nullptr ? q->size() : 0;
303   }
304   static void compilation_init(JavaThread* THREAD);
305   static void init_compiler_thread_log();
306   static nmethod* compile_method(const methodHandle& method,
307                                  int osr_bci,
308                                  int comp_level,
309                                  const methodHandle& hot_method,
310                                  int hot_count,

311                                  CompileTask::CompileReason compile_reason,
312                                  TRAPS);
313   static CompileQueue* c1_compile_queue();
314   static CompileQueue* c2_compile_queue();
315 
316 private:
317   static nmethod* compile_method(const methodHandle& method,
318                                    int osr_bci,
319                                    int comp_level,
320                                    const methodHandle& hot_method,
321                                    int hot_count,

322                                    CompileTask::CompileReason compile_reason,
323                                    DirectiveSet* directive,
324                                    TRAPS);
325 
326 public:
327   // Acquire any needed locks and assign a compile id
328   static int assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci);
329 
330   static void compiler_thread_loop();
331   static int get_compilation_id() { return _compilation_id; }
332 
333   // Set _should_block.
334   // Call this from the VM, with Threads_lock held and a safepoint requested.
335   static void set_should_block();
336 
337   // Call this from the compiler at convenient points, to poll for _should_block.
338   static void maybe_block();
339 
340   enum CompilerActivity {
341     // Flags for toggling compiler activity

386 
387   // Print a detailed accounting of compilation time
388   static void print_times(bool per_compiler = true, bool aggregate = true);
389 
390   // compiler name for debugging
391   static const char* compiler_name(int comp_level);
392 
393   // Provide access to compiler thread Java objects
394   static jobject compiler1_object(int idx) {
395     assert(_compiler1_objects != nullptr, "must be initialized");
396     assert(idx < _c1_count, "oob");
397     return _compiler1_objects[idx];
398   }
399 
400   static jobject compiler2_object(int idx) {
401     assert(_compiler2_objects != nullptr, "must be initialized");
402     assert(idx < _c2_count, "oob");
403     return _compiler2_objects[idx];
404   }
405 












406   static AbstractCompiler* compiler1() { return _compilers[0]; }
407   static AbstractCompiler* compiler2() { return _compilers[1]; }

408 
409   static bool can_remove(CompilerThread *ct, bool do_it);
410 
411   static CompileLog* get_log(CompilerThread* ct);
412 
413   static int get_c1_thread_count() {                return _compilers[0]->num_compiler_threads(); }
414   static int get_c2_thread_count() {                return _compilers[1]->num_compiler_threads(); }
415   static int get_total_compile_count() {            return _total_compile_count; }
416   static int get_total_bailout_count() {            return _total_bailout_count; }
417   static int get_total_invalidated_count() {        return _total_invalidated_count; }
418   static int get_total_native_compile_count() {     return _total_native_compile_count; }
419   static int get_total_osr_compile_count() {        return _total_osr_compile_count; }
420   static int get_total_standard_compile_count() {   return _total_standard_compile_count; }
421   static int get_total_compiler_stopped_count() {   return _total_compiler_stopped_count; }
422   static int get_total_compiler_restarted_count() { return _total_compiler_restarted_count; }
423   static int get_sum_osr_bytes_compiled() {         return _sum_osr_bytes_compiled; }
424   static int get_sum_standard_bytes_compiled() {    return _sum_standard_bytes_compiled; }
425   static int get_sum_nmethod_size() {               return _sum_nmethod_size;}
426   static int get_sum_nmethod_code_size() {          return _sum_nmethod_code_size; }
427   static jlong get_peak_compilation_time() {        return _peak_compilation_time; }
428   static jlong get_total_compilation_time() {       return _t_total_compilation.milliseconds(); }
429 


430   // Log that compilation profiling is skipped because metaspace is full.
431   static void log_metaspace_failure();
432 


433   // CodeHeap State Analytics.
434   static void print_info(outputStream *out);
435   static void print_heapinfo(outputStream *out, const char* function, size_t granularity);
436 };
437 








438 #endif // SHARE_COMPILER_COMPILEBROKER_HPP

 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_COMPILER_COMPILEBROKER_HPP
 26 #define SHARE_COMPILER_COMPILEBROKER_HPP
 27 
 28 #include "ci/compilerInterface.hpp"
 29 #include "compiler/abstractCompiler.hpp"
 30 #include "compiler/compileTask.hpp"
 31 #include "compiler/compilerDirectives.hpp"
 32 #include "compiler/compilerThread.hpp"
 33 #include "runtime/atomic.hpp"
 34 #include "runtime/javaThread.hpp"
 35 #include "runtime/perfDataTypes.hpp"
 36 #include "utilities/nonblockingQueue.inline.hpp"
 37 #include "utilities/stack.hpp"
 38 #if INCLUDE_JVMCI
 39 #include "jvmci/jvmciCompiler.hpp"
 40 #endif
 41 
 42 class nmethod;
 43 
 44 // CompilerCounters
 45 //
 46 // Per Compiler Performance Counters.
 47 //
 48 class CompilerCounters : public CHeapObj<mtCompiler> {
 49 
 50   public:
 51     enum {
 52       cmname_buffer_length = 160
 53     };
 54 
 55   private:
 56 

 67       _current_method[cmname_buffer_length-1] = '\0';
 68     }
 69 
 70     char* current_method()                  { return _current_method; }
 71 
 72     void set_compile_type(int compile_type) {
 73       _compile_type = compile_type;
 74     }
 75 
 76     int compile_type()                       { return _compile_type; }
 77 
 78 };
 79 
 80 // CompileQueue
 81 //
 82 // A list of CompileTasks.
 83 class CompileQueue : public CHeapObj<mtCompiler> {
 84  private:
 85   const char* _name;
 86 
 87   NonblockingQueue<CompileTask, &CompileTask::next_ptr> _queue;
 88 
 89   CompileTask* _first;
 90   CompileTask* _last;
 91 
 92   CompileTask* _first_stale;
 93 
 94   Monitor* _lock;
 95 
 96   int _size;
 97   int _peak_size;
 98   uint _total_added;
 99   uint _total_removed;
100 
101   void purge_stale_tasks();
102  public:
103   CompileQueue(const char* name, Monitor* lock) {
104     _name = name;
105     _lock = lock;
106     _first = nullptr;
107     _last = nullptr;
108     _size = 0;
109     _total_added = 0;
110     _total_removed = 0;
111     _peak_size = 0;
112     _first_stale = nullptr;
113   }
114 
115   const char*  name() const                      { return _name; }
116 
117   void         add_pending(CompileTask* task);
118   void         transfer_pending();
119 
120   void         add(CompileTask* task);
121   void         remove(CompileTask* task);
122   void         remove_and_mark_stale(CompileTask* task);
123   CompileTask* first()                           { return _first; }
124   CompileTask* last()                            { return _last;  }
125 
126   CompileTask* get(CompilerThread* thread);
127 
128   bool         is_empty() const                  { return _first == nullptr; }
129   int          size()     const                  { return _size;          }
130 
131   Monitor* lock() const { return _lock; }
132 
133   int         get_peak_size()     const          { return _peak_size; }
134   uint        get_total_added()   const          { return _total_added; }
135   uint        get_total_removed() const          { return _total_removed; }
136 
137   // Redefine Classes support
138   void mark_on_stack();
139   void free_all();
140   void print_tty();
141   void print(outputStream* st = tty);
142 
143   ~CompileQueue() {
144     assert (is_empty(), " Compile Queue must be empty");
145   }
146 };
147 
148 // CompileTaskWrapper
149 //
150 // Assign this task to the current thread.  Deallocate the task
151 // when the compilation is complete.
152 class CompileTaskWrapper : StackObj {

157 
158 // Compilation
159 //
160 // The broker for all compilation requests.
161 class CompileBroker: AllStatic {
162  friend class Threads;
163  friend class CompileTaskWrapper;
164 
165  public:
166   enum {
167     name_buffer_length = 100
168   };
169 
170   // Compile type Information for print_last_compile() and CompilerCounters
171   enum { no_compile, normal_compile, osr_compile, native_compile };
172   static int assign_compile_id (const methodHandle& method, int osr_bci);
173 
174 
175  private:
176   static bool _initialized;
177   static bool _replay_initialized;
178   static volatile bool _should_block;
179 
180   // This flag can be used to stop compilation or turn it back on
181   static volatile jint _should_compile_new_jobs;
182 
183   // The installed compiler(s)
184   static AbstractCompiler* _compilers[3];
185 
186   // The maximum numbers of compiler threads to be determined during startup.
187   static int _c1_count, _c2_count, _c3_count, _sc_count;
188 
189   // An array of compiler thread Java objects
190   static jobject *_compiler1_objects, *_compiler2_objects, *_compiler3_objects, *_sc_objects;
191 
192   // An array of compiler logs
193   static CompileLog **_compiler1_logs, **_compiler2_logs, **_compiler3_logs, **_sc_logs;
194 
195   // These counters are used for assigning id's to each compilation
196   static volatile jint _compilation_id;
197   static volatile jint _osr_compilation_id;
198   static volatile jint _native_compilation_id;
199 
200   static CompileQueue* _c3_compile_queue;
201   static CompileQueue* _c2_compile_queue;
202   static CompileQueue* _c1_compile_queue;
203   static CompileQueue* _sc1_compile_queue;
204   static CompileQueue* _sc2_compile_queue;
205 
206   // performance counters
207   static PerfCounter* _perf_total_compilation;
208   static PerfCounter* _perf_osr_compilation;
209   static PerfCounter* _perf_standard_compilation;
210 
211   static PerfCounter* _perf_total_bailout_count;
212   static PerfCounter* _perf_total_invalidated_count;
213   static PerfCounter* _perf_total_compile_count;
214   static PerfCounter* _perf_total_osr_compile_count;
215   static PerfCounter* _perf_total_standard_compile_count;
216 
217   static PerfCounter* _perf_sum_osr_bytes_compiled;
218   static PerfCounter* _perf_sum_standard_bytes_compiled;
219   static PerfCounter* _perf_sum_nmethod_size;
220   static PerfCounter* _perf_sum_nmethod_code_size;
221 
222   static PerfStringVariable* _perf_last_method;
223   static PerfStringVariable* _perf_last_failed_method;
224   static PerfStringVariable* _perf_last_invalidated_method;
225   static PerfVariable*       _perf_last_compile_type;
226   static PerfVariable*       _perf_last_compile_size;
227   static PerfVariable*       _perf_last_failed_type;
228   static PerfVariable*       _perf_last_invalidated_type;
229 
230   // Timers and counters for generating statistics
231   static elapsedTimer _t_total_compilation;
232   static elapsedTimer _t_osr_compilation;
233   static elapsedTimer _t_standard_compilation;
234   static elapsedTimer _t_invalidated_compilation;
235   static elapsedTimer _t_bailedout_compilation;
236 
237   static uint _total_compile_count;
238   static uint _total_bailout_count;
239   static uint _total_invalidated_count;
240   static uint _total_not_entrant_count;
241   static uint _total_native_compile_count;
242   static uint _total_osr_compile_count;
243   static uint _total_standard_compile_count;
244   static uint _total_compiler_stopped_count;
245   static uint _total_compiler_restarted_count;
246   static uint _sum_osr_bytes_compiled;
247   static uint _sum_standard_bytes_compiled;
248   static uint _sum_nmethod_size;
249   static uint _sum_nmethod_code_size;
250   static jlong _peak_compilation_time;
251 
252   static CompilerStatistics _stats_per_level[];
253   static CompilerStatistics _scc_stats;
254   static CompilerStatistics _scc_stats_per_level[];
255 
256   static volatile int _print_compilation_warning;
257 
258   enum ThreadType {
259     compiler_t,
260     deoptimizer_t,
261     training_replay_t
262   };
263 
264   static Handle create_thread_oop(const char* name, TRAPS);
265   static JavaThread* make_thread(ThreadType type, jobject thread_oop, CompileQueue* queue, AbstractCompiler* comp, JavaThread* THREAD);
266   static void init_compiler_threads();
267   static void init_training_replay();
268   static void possibly_add_compiler_threads(JavaThread* THREAD);
269   static bool compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded);
270 
271   static CompileTask* create_compile_task(CompileQueue*       queue,
272                                           int                 compile_id,
273                                           const methodHandle& method,
274                                           int                 osr_bci,
275                                           int                 comp_level,
276                                           const methodHandle& hot_method,
277                                           int                 hot_count,
278                                           SCCEntry*           scc_entry,
279                                           CompileTask::CompileReason compile_reason,
280                                           bool                requires_online_compilation,
281                                           bool                blocking);
282   static void wait_for_completion(CompileTask* task);
283 #if INCLUDE_JVMCI
284   static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
285 #endif
286 
287   static void free_buffer_blob_if_allocated(CompilerThread* thread);
288 
289   static void invoke_compiler_on_method(CompileTask* task);
290   static void handle_compile_error(CompilerThread* thread, CompileTask* task, ciEnv* ci_env,
291                                    int compilable, const char* failure_reason);
292   static void update_compile_perf_data(CompilerThread *thread, const methodHandle& method, bool is_osr);
293 
294   static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
295 
296   static void compile_method_base(const methodHandle& method,
297                                   int osr_bci,
298                                   int comp_level,
299                                   const methodHandle& hot_method,
300                                   int hot_count,
301                                   CompileTask::CompileReason compile_reason,
302                                   bool requires_online_compilation,
303                                   bool blocking,
304                                   Thread* thread);
305 
306   static CompileQueue* compile_queue(int comp_level, bool is_scc);
307   static bool init_compiler_runtime();
308   static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
309 
310   static SCCEntry* find_scc_entry(const methodHandle& method, int osr_bci, int comp_level,
311                                   CompileTask::CompileReason compile_reason,
312                                   bool requires_online_compilation);
313 
314 public:
315   enum {
316     // The entry bci used for non-OSR compilations.
317     standard_entry_bci = InvocationEntryBci
318   };
319 
320   static AbstractCompiler* compiler(int comp_level) {
321     if (is_c2_compile(comp_level)) return _compilers[1]; // C2
322     if (is_c1_compile(comp_level)) return _compilers[0]; // C1
323     return nullptr;
324   }
325 
326   static bool initialized() { return _initialized; }
327   static bool replay_initialized() { return _replay_initialized; }
328   static bool compilation_is_complete(Method* method, int osr_bci, int comp_level, bool online_only,
329                                       CompileTask::CompileReason compile_reason);
330   static bool compilation_is_in_queue(const methodHandle& method);
331   static void print_compile_queues(outputStream* st);
332   static int queue_size(int comp_level, bool is_scc = false) {
333     CompileQueue *q = compile_queue(comp_level, is_scc);
334     return q != nullptr ? q->size() : 0;
335   }
336   static void compilation_init(JavaThread* THREAD);
337   static void init_compiler_thread_log();
338   static nmethod* compile_method(const methodHandle& method,
339                                  int osr_bci,
340                                  int comp_level,
341                                  const methodHandle& hot_method,
342                                  int hot_count,
343                                  bool requires_online_compilation,
344                                  CompileTask::CompileReason compile_reason,
345                                  TRAPS);
346   static CompileQueue* c1_compile_queue();
347   static CompileQueue* c2_compile_queue();
348 
349 private:
350   static nmethod* compile_method(const methodHandle& method,
351                                    int osr_bci,
352                                    int comp_level,
353                                    const methodHandle& hot_method,
354                                    int hot_count,
355                                    bool requires_online_compilation,
356                                    CompileTask::CompileReason compile_reason,
357                                    DirectiveSet* directive,
358                                    TRAPS);
359 
360 public:
361   // Acquire any needed locks and assign a compile id
362   static int assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci);
363 
364   static void compiler_thread_loop();
365   static int get_compilation_id() { return _compilation_id; }
366 
367   // Set _should_block.
368   // Call this from the VM, with Threads_lock held and a safepoint requested.
369   static void set_should_block();
370 
371   // Call this from the compiler at convenient points, to poll for _should_block.
372   static void maybe_block();
373 
374   enum CompilerActivity {
375     // Flags for toggling compiler activity

420 
421   // Print a detailed accounting of compilation time
422   static void print_times(bool per_compiler = true, bool aggregate = true);
423 
424   // compiler name for debugging
425   static const char* compiler_name(int comp_level);
426 
427   // Provide access to compiler thread Java objects
428   static jobject compiler1_object(int idx) {
429     assert(_compiler1_objects != nullptr, "must be initialized");
430     assert(idx < _c1_count, "oob");
431     return _compiler1_objects[idx];
432   }
433 
434   static jobject compiler2_object(int idx) {
435     assert(_compiler2_objects != nullptr, "must be initialized");
436     assert(idx < _c2_count, "oob");
437     return _compiler2_objects[idx];
438   }
439 
440   static jobject compiler3_object(int idx) {
441     assert(_compiler3_objects != nullptr, "must be initialized");
442     assert(idx < _c3_count, "oob");
443     return _compiler3_objects[idx];
444   }
445 
446   static jobject sc_object(int idx) {
447     assert(_sc_objects != nullptr, "must be initialized");
448     assert(idx < _sc_count, "oob");
449     return _sc_objects[idx];
450   }
451 
452   static AbstractCompiler* compiler1() { return _compilers[0]; }
453   static AbstractCompiler* compiler2() { return _compilers[1]; }
454   static AbstractCompiler* compiler3() { return _compilers[2]; }
455 
456   static bool can_remove(CompilerThread *ct, bool do_it);
457 
458   static CompileLog* get_log(CompilerThread* ct);
459 
460   static int get_c1_thread_count() {                return _compilers[0]->num_compiler_threads(); }
461   static int get_c2_thread_count() {                return _compilers[1]->num_compiler_threads(); }
462   static int get_total_compile_count() {            return _total_compile_count; }
463   static int get_total_bailout_count() {            return _total_bailout_count; }
464   static int get_total_invalidated_count() {        return _total_invalidated_count; }
465   static int get_total_native_compile_count() {     return _total_native_compile_count; }
466   static int get_total_osr_compile_count() {        return _total_osr_compile_count; }
467   static int get_total_standard_compile_count() {   return _total_standard_compile_count; }
468   static int get_total_compiler_stopped_count() {   return _total_compiler_stopped_count; }
469   static int get_total_compiler_restarted_count() { return _total_compiler_restarted_count; }
470   static int get_sum_osr_bytes_compiled() {         return _sum_osr_bytes_compiled; }
471   static int get_sum_standard_bytes_compiled() {    return _sum_standard_bytes_compiled; }
472   static int get_sum_nmethod_size() {               return _sum_nmethod_size;}
473   static int get_sum_nmethod_code_size() {          return _sum_nmethod_code_size; }
474   static jlong get_peak_compilation_time() {        return _peak_compilation_time; }
475   static jlong get_total_compilation_time() {       return _t_total_compilation.milliseconds(); }
476 
477   static void log_not_entrant(nmethod* nm);
478 
479   // Log that compilation profiling is skipped because metaspace is full.
480   static void log_metaspace_failure();
481 
482   static void print_statistics_on(outputStream* st);
483 
484   // CodeHeap State Analytics.
485   static void print_info(outputStream *out);
486   static void print_heapinfo(outputStream *out, const char* function, size_t granularity);
487 };
488 
489 class TrainingReplayThread : public JavaThread {
490   static void training_replay_thread_entry(JavaThread* thread, TRAPS);
491 public:
492   TrainingReplayThread() : JavaThread(&training_replay_thread_entry) { }
493 
494   bool is_hidden_from_external_view() const      { return true; }
495 };
496 
497 #endif // SHARE_COMPILER_COMPILEBROKER_HPP
< prev index next >