< 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/compilerDirectives.hpp"
 31 #include "compiler/compilerThread.hpp"
 32 #include "compiler/compileTask.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 #if defined(ASSERT) && COMPILER2_OR_JVMCI
 43 // Stress testing. Dedicated threads revert optimizations based on escape analysis concurrently to
 44 // the running java application.  Configured with vm options DeoptimizeObjectsALot*.
 45 class DeoptimizeObjectsALotThread : public JavaThread {
 46 
 47   static void deopt_objs_alot_thread_entry(JavaThread* thread, TRAPS);
 48   void deoptimize_objects_alot_loop_single();
 49   void deoptimize_objects_alot_loop_all();
 50 
 51 public:
 52   DeoptimizeObjectsALotThread() : JavaThread(&deopt_objs_alot_thread_entry) { }
 53 
 54   bool is_hidden_from_external_view() const      { return true; }

 81       _current_method[cmname_buffer_length-1] = '\0';
 82     }
 83 
 84     char* current_method()                  { return _current_method; }
 85 
 86     void set_compile_type(int compile_type) {
 87       _compile_type = compile_type;
 88     }
 89 
 90     int compile_type()                       { return _compile_type; }
 91 
 92 };
 93 
 94 // CompileQueue
 95 //
 96 // A list of CompileTasks.
 97 class CompileQueue : public CHeapObj<mtCompiler> {
 98  private:
 99   const char* _name;
100 


101   CompileTask* _first;
102   CompileTask* _last;
103 
104   CompileTask* _first_stale;
105 


106   volatile int _size;
107   int _peak_size;
108   uint _total_added;
109   uint _total_removed;
110 
111   void purge_stale_tasks();
112  public:
113   CompileQueue(const char* name) {
114     _name = name;

115     _first = nullptr;
116     _last = nullptr;
117     _size = 0;
118     _total_added = 0;
119     _total_removed = 0;
120     _peak_size = 0;
121     _first_stale = nullptr;
122   }
123 
124   const char*  name() const                      { return _name; }
125 



126   void         add(CompileTask* task);
127   void         remove(CompileTask* task);
128   void         remove_and_mark_stale(CompileTask* task);
129   CompileTask* first()                           { return _first; }
130   CompileTask* last()                            { return _last;  }
131 
132   CompileTask* get(CompilerThread* thread);
133 
134   bool         is_empty() const                  { return _first == nullptr; }
135   int          size()     const                  { return _size;          }
136 


137   int         get_peak_size()     const          { return _peak_size; }
138   uint        get_total_added()   const          { return _total_added; }
139   uint        get_total_removed() const          { return _total_removed; }
140 
141   // Redefine Classes support
142   void mark_on_stack();
143   void free_all();
144   void print_tty();
145   void print(outputStream* st = tty);
146 
147   ~CompileQueue() {
148     assert (is_empty(), " Compile Queue must be empty");
149   }
150 };
151 
152 // CompileTaskWrapper
153 //
154 // Assign this task to the current thread.  Deallocate the task
155 // when the compilation is complete.
156 class CompileTaskWrapper : StackObj {

167  friend class CompileTaskWrapper;
168 
169  public:
170   enum {
171     name_buffer_length = 100
172   };
173 
174   // Compile type Information for print_last_compile() and CompilerCounters
175   enum { no_compile, normal_compile, osr_compile, native_compile };
176   static int assign_compile_id (const methodHandle& method, int osr_bci);
177 
178 
179  private:
180   static bool _initialized;
181   static volatile bool _should_block;
182 
183   // This flag can be used to stop compilation or turn it back on
184   static volatile jint _should_compile_new_jobs;
185 
186   // The installed compiler(s)
187   static AbstractCompiler* _compilers[2];
188 
189   // The maximum numbers of compiler threads to be determined during startup.
190   static int _c1_count, _c2_count;
191 
192   // An array of compiler thread Java objects
193   static jobject *_compiler1_objects, *_compiler2_objects;
194 
195   // An array of compiler logs
196   static CompileLog **_compiler1_logs, **_compiler2_logs;
197 
198   // These counters are used for assigning id's to each compilation
199   static volatile jint _compilation_id;
200   static volatile jint _osr_compilation_id;
201   static volatile jint _native_compilation_id;
202 

203   static CompileQueue* _c2_compile_queue;
204   static CompileQueue* _c1_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_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 
253   static volatile int _print_compilation_warning;
254 
255   enum ThreadType {
256     compiler_t,
257     deoptimizer_t,
258     training_replay_t
259   };
260 

261   static JavaThread* make_thread(ThreadType type, jobject thread_oop, CompileQueue* queue, AbstractCompiler* comp, JavaThread* THREAD);
262   static void init_compiler_threads();
263   static void init_training_replay();
264   static void possibly_add_compiler_threads(JavaThread* THREAD);
265   static bool compilation_is_prohibited(const methodHandle& method, int osr_bci, int comp_level, bool excluded);
266 
267   static CompileTask* create_compile_task(CompileQueue*       queue,
268                                           int                 compile_id,
269                                           const methodHandle& method,
270                                           int                 osr_bci,
271                                           int                 comp_level,
272                                           int                 hot_count,

273                                           CompileTask::CompileReason compile_reason,

274                                           bool                blocking);
275   static void wait_for_completion(CompileTask* task);
276 #if INCLUDE_JVMCI
277   static bool wait_for_jvmci_completion(JVMCICompiler* comp, CompileTask* task, JavaThread* thread);
278 #endif




279 
280   static void free_buffer_blob_if_allocated(CompilerThread* thread);
281 
282   static void invoke_compiler_on_method(CompileTask* task);
283   static void handle_compile_error(CompilerThread* thread, CompileTask* task, ciEnv* ci_env,
284                                    int compilable, const char* failure_reason);
285   static void update_compile_perf_data(CompilerThread *thread, const methodHandle& method, bool is_osr);
286 
287   static void collect_statistics(CompilerThread* thread, elapsedTimer time, CompileTask* task);
288 
289   static void compile_method_base(const methodHandle& method,
290                                   int osr_bci,
291                                   int comp_level,
292                                   int hot_count,
293                                   CompileTask::CompileReason compile_reason,

294                                   bool blocking,
295                                   Thread* thread);
296 
297   static CompileQueue* compile_queue(int comp_level);
298   static bool init_compiler_runtime();
299   static void shutdown_compiler_runtime(AbstractCompiler* comp, CompilerThread* thread);
300 




301 public:
302   enum {
303     // The entry bci used for non-OSR compilations.
304     standard_entry_bci = InvocationEntryBci
305   };
306 
307   static AbstractCompiler* compiler(int comp_level) {
308     if (is_c2_compile(comp_level)) return _compilers[1]; // C2
309     if (is_c1_compile(comp_level)) return _compilers[0]; // C1
310     return nullptr;
311   }
312 
313   static bool compilation_is_complete(const methodHandle& method, int osr_bci, int comp_level);


314   static bool compilation_is_in_queue(const methodHandle& method);
315   static void print_compile_queues(outputStream* st);
316   static int queue_size(int comp_level) {
317     CompileQueue *q = compile_queue(comp_level);
318     return q != nullptr ? q->size() : 0;
319   }
320   static void compilation_init(JavaThread* THREAD);
321   static void init_compiler_thread_log();
322   static nmethod* compile_method(const methodHandle& method,
323                                  int osr_bci,
324                                  int comp_level,
325                                  int hot_count,

326                                  CompileTask::CompileReason compile_reason,
327                                  TRAPS);
328   static CompileQueue* c1_compile_queue();
329   static CompileQueue* c2_compile_queue();
330 
331 private:
332   static nmethod* compile_method(const methodHandle& method,
333                                    int osr_bci,
334                                    int comp_level,
335                                    int hot_count,

336                                    CompileTask::CompileReason compile_reason,
337                                    DirectiveSet* directive,
338                                    TRAPS);
339 
340 public:
341   // Acquire any needed locks and assign a compile id
342   static int assign_compile_id_unlocked(Thread* thread, const methodHandle& method, int osr_bci);
343 
344   static void compiler_thread_loop();
345   static int get_compilation_id() { return _compilation_id; }
346 
347   // Set _should_block.
348   // Call this from the VM, with Threads_lock held and a safepoint requested.
349   static void set_should_block();
350 
351   // Call this from the compiler at convenient points, to poll for _should_block.
352   static void maybe_block();
353 
354   enum CompilerActivity {
355     // Flags for toggling compiler activity

400 
401   // Print a detailed accounting of compilation time
402   static void print_times(bool per_compiler = true, bool aggregate = true);
403 
404   // compiler name for debugging
405   static const char* compiler_name(int comp_level);
406 
407   // Provide access to compiler thread Java objects
408   static jobject compiler1_object(int idx) {
409     assert(_compiler1_objects != nullptr, "must be initialized");
410     assert(idx < _c1_count, "oob");
411     return _compiler1_objects[idx];
412   }
413 
414   static jobject compiler2_object(int idx) {
415     assert(_compiler2_objects != nullptr, "must be initialized");
416     assert(idx < _c2_count, "oob");
417     return _compiler2_objects[idx];
418   }
419 












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

422 
423   static bool can_remove(CompilerThread *ct, bool do_it);
424 
425   static CompileLog* get_log(CompilerThread* ct);
426 
427   static int get_c1_thread_count() {                return _compilers[0]->num_compiler_threads(); }
428   static int get_c2_thread_count() {                return _compilers[1]->num_compiler_threads(); }
429   static int get_total_compile_count() {            return _total_compile_count; }
430   static int get_total_bailout_count() {            return _total_bailout_count; }
431   static int get_total_invalidated_count() {        return _total_invalidated_count; }
432   static int get_total_native_compile_count() {     return _total_native_compile_count; }
433   static int get_total_osr_compile_count() {        return _total_osr_compile_count; }
434   static int get_total_standard_compile_count() {   return _total_standard_compile_count; }
435   static int get_total_compiler_stopped_count() {   return _total_compiler_stopped_count; }
436   static int get_total_compiler_restarted_count() { return _total_compiler_restarted_count; }
437   static int get_sum_osr_bytes_compiled() {         return _sum_osr_bytes_compiled; }
438   static int get_sum_standard_bytes_compiled() {    return _sum_standard_bytes_compiled; }
439   static int get_sum_nmethod_size() {               return _sum_nmethod_size;}
440   static int get_sum_nmethod_code_size() {          return _sum_nmethod_code_size; }
441   static jlong get_peak_compilation_time() {        return _peak_compilation_time; }
442   static jlong get_total_compilation_time() {       return _t_total_compilation.milliseconds(); }
443 


444   // Log that compilation profiling is skipped because metaspace is full.
445   static void log_metaspace_failure();
446 


447   // CodeHeap State Analytics.
448   static void print_info(outputStream *out);
449   static void print_heapinfo(outputStream *out, const char* function, size_t granularity);
450 };
451 
452 // In order to achiveve a maximally fast warmup we attempt to compile important methods as soon as all
453 // the classes that they depend on are initialized. TrainingReplayThread processes a queue of InstanceKlass*
454 // that have just finished running their static initializers. We find all the methods that depend on the given class
455 // and for which the number of remaining dependencies is now zero, and eagerly compile them.
456 class TrainingReplayThread : public JavaThread {
457   static void training_replay_thread_entry(JavaThread* thread, TRAPS);
458 public:
459   TrainingReplayThread() : JavaThread(&training_replay_thread_entry) { }
460 
461   bool is_hidden_from_external_view() const      { return true; }
462 };
463 
464 #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/compilerDirectives.hpp"
 31 #include "compiler/compilerThread.hpp"
 32 #include "compiler/compileTask.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 #if defined(ASSERT) && COMPILER2_OR_JVMCI
 45 // Stress testing. Dedicated threads revert optimizations based on escape analysis concurrently to
 46 // the running java application.  Configured with vm options DeoptimizeObjectsALot*.
 47 class DeoptimizeObjectsALotThread : public JavaThread {
 48 
 49   static void deopt_objs_alot_thread_entry(JavaThread* thread, TRAPS);
 50   void deoptimize_objects_alot_loop_single();
 51   void deoptimize_objects_alot_loop_all();
 52 
 53 public:
 54   DeoptimizeObjectsALotThread() : JavaThread(&deopt_objs_alot_thread_entry) { }
 55 
 56   bool is_hidden_from_external_view() const      { return true; }

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

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

434 
435   // Print a detailed accounting of compilation time
436   static void print_times(bool per_compiler = true, bool aggregate = true);
437 
438   // compiler name for debugging
439   static const char* compiler_name(int comp_level);
440 
441   // Provide access to compiler thread Java objects
442   static jobject compiler1_object(int idx) {
443     assert(_compiler1_objects != nullptr, "must be initialized");
444     assert(idx < _c1_count, "oob");
445     return _compiler1_objects[idx];
446   }
447 
448   static jobject compiler2_object(int idx) {
449     assert(_compiler2_objects != nullptr, "must be initialized");
450     assert(idx < _c2_count, "oob");
451     return _compiler2_objects[idx];
452   }
453 
454   static jobject compiler3_object(int idx) {
455     assert(_compiler3_objects != nullptr, "must be initialized");
456     assert(idx < _c3_count, "oob");
457     return _compiler3_objects[idx];
458   }
459 
460   static jobject ac_object(int idx) {
461     assert(_ac_objects != nullptr, "must be initialized");
462     assert(idx < _ac_count, "oob");
463     return _ac_objects[idx];
464   }
465 
466   static AbstractCompiler* compiler1() { return _compilers[0]; }
467   static AbstractCompiler* compiler2() { return _compilers[1]; }
468   static AbstractCompiler* compiler3() { return _compilers[2]; }
469 
470   static bool can_remove(CompilerThread *ct, bool do_it);
471 
472   static CompileLog* get_log(CompilerThread* ct);
473 
474   static int get_c1_thread_count() {                return _compilers[0]->num_compiler_threads(); }
475   static int get_c2_thread_count() {                return _compilers[1]->num_compiler_threads(); }
476   static int get_total_compile_count() {            return _total_compile_count; }
477   static int get_total_bailout_count() {            return _total_bailout_count; }
478   static int get_total_invalidated_count() {        return _total_invalidated_count; }
479   static int get_total_native_compile_count() {     return _total_native_compile_count; }
480   static int get_total_osr_compile_count() {        return _total_osr_compile_count; }
481   static int get_total_standard_compile_count() {   return _total_standard_compile_count; }
482   static int get_total_compiler_stopped_count() {   return _total_compiler_stopped_count; }
483   static int get_total_compiler_restarted_count() { return _total_compiler_restarted_count; }
484   static int get_sum_osr_bytes_compiled() {         return _sum_osr_bytes_compiled; }
485   static int get_sum_standard_bytes_compiled() {    return _sum_standard_bytes_compiled; }
486   static int get_sum_nmethod_size() {               return _sum_nmethod_size;}
487   static int get_sum_nmethod_code_size() {          return _sum_nmethod_code_size; }
488   static jlong get_peak_compilation_time() {        return _peak_compilation_time; }
489   static jlong get_total_compilation_time() {       return _t_total_compilation.milliseconds(); }
490 
491   static void log_not_entrant(nmethod* nm);
492 
493   // Log that compilation profiling is skipped because metaspace is full.
494   static void log_metaspace_failure();
495 
496   static void print_statistics_on(outputStream* st);
497 
498   // CodeHeap State Analytics.
499   static void print_info(outputStream *out);
500   static void print_heapinfo(outputStream *out, const char* function, size_t granularity);
501 };
502 
503 // In order to achiveve a maximally fast warmup we attempt to compile important methods as soon as all
504 // the classes that they depend on are initialized. TrainingReplayThread processes a queue of InstanceKlass*
505 // that have just finished running their static initializers. We find all the methods that depend on the given class
506 // and for which the number of remaining dependencies is now zero, and eagerly compile them.
507 class TrainingReplayThread : public JavaThread {
508   static void training_replay_thread_entry(JavaThread* thread, TRAPS);
509 public:
510   TrainingReplayThread() : JavaThread(&training_replay_thread_entry) { }
511 
512   bool is_hidden_from_external_view() const      { return true; }
513 };
514 
515 #endif // SHARE_COMPILER_COMPILEBROKER_HPP
< prev index next >