< 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 {

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 {

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

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