< prev index next >

src/hotspot/share/compiler/compileTask.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_COMPILETASK_HPP
 26 #define SHARE_COMPILER_COMPILETASK_HPP
 27 
 28 #include "ci/ciMethod.hpp"
 29 #include "code/nmethod.hpp"
 30 #include "compiler/compileLog.hpp"
 31 #include "memory/allocation.hpp"
 32 #include "utilities/xmlstream.hpp"
 33 


 34 class DirectiveSet;

 35 
 36 JVMCI_ONLY(class JVMCICompileState;)
 37 
 38 enum class InliningResult { SUCCESS, FAILURE };
 39 
 40 inline InliningResult inlining_result_of(bool success) {
 41   return success ? InliningResult::SUCCESS : InliningResult::FAILURE;
 42 }
 43 
 44 // CompileTask
 45 //
 46 // An entry in the compile queue.  It represents a pending or current
 47 // compilation.
 48 
 49 class CompileTask : public CHeapObj<mtCompiler> {
 50   friend class VMStructs;
 51   friend class JVMCIVMStructs;
 52 
 53  public:
 54   // Different reasons for a compilation
 55   // The order is important - mapped to reason_names[]
 56   enum CompileReason {
 57       Reason_None,
 58       Reason_InvocationCount,  // Simple/StackWalk-policy
 59       Reason_BackedgeCount,    // Simple/StackWalk-policy
 60       Reason_Tiered,           // Tiered-policy
 61       Reason_Replay,           // ciReplay
 62       Reason_Whitebox,         // Whitebox API
 63       Reason_MustBeCompiled,   // Used for -Xcomp or AlwaysCompileLoopMethods (see CompilationPolicy::must_be_compiled())
 64       Reason_Bootstrap,        // JVMCI bootstrap



 65       Reason_Count
 66   };
 67 
 68   static const char* reason_name(CompileTask::CompileReason compile_reason) {
 69     static const char* reason_names[] = {
 70       "no_reason",
 71       "count",
 72       "backedge_count",
 73       "tiered",
 74       "replay",
 75       "whitebox",
 76       "must_be_compiled",
 77       "bootstrap"



 78     };
 79     return reason_names[compile_reason];
 80   }
 81 





 82  private:
 83   static CompileTask*  _task_free_list;
 84   Monitor*             _lock;
 85   int                  _compile_id;
 86   Method*              _method;
 87   jobject              _method_holder;
 88   int                  _osr_bci;
 89   bool                 _is_complete;
 90   bool                 _is_success;

 91   bool                 _is_blocking;
 92   CodeSection::csize_t _nm_content_size;
 93   CodeSection::csize_t _nm_total_size;
 94   CodeSection::csize_t _nm_insts_size;
 95   DirectiveSet*  _directive;


 96 #if INCLUDE_JVMCI
 97   bool                 _has_waiter;
 98   // Compilation state for a blocking JVMCI compilation
 99   JVMCICompileState*   _blocking_jvmci_compile_state;
100 #endif
101   int                  _waiting_count;  // See waiting_for_completion_count()
102   int                  _comp_level;
103   int                  _num_inlined_bytecodes;
104   CompileTask*         _next, *_prev;

105   bool                 _is_free;
106   // Fields used for logging why the compilation was initiated:

107   jlong                _time_queued;  // time when task was enqueued
108   jlong                _time_started; // time when compilation started

109   Method*              _hot_method;   // which method actually triggered this task
110   jobject              _hot_method_holder;
111   int                  _hot_count;    // information about its invocation counter
112   CompileReason        _compile_reason;      // more info about the task
113   const char*          _failure_reason;
114   // Specifies if _failure_reason is on the C heap.
115   bool                 _failure_reason_on_C_heap;


116   size_t               _arena_bytes;  // peak size of temporary memory during compilation (e.g. node arenas)
117 
118  public:
119   CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {
120     // May hold MethodCompileQueue_lock
121     _lock = new Monitor(Mutex::safepoint-1, "CompileTask_lock");
122   }
123 
124   void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
125                   const methodHandle& hot_method, int hot_count,
126                   CompileTask::CompileReason compile_reason, bool is_blocking);


127 
128   static CompileTask* allocate();
129   static void         free(CompileTask* task);
130 
131   int          compile_id() const                { return _compile_id; }
132   Method*      method() const                    { return _method; }
133   Method*      hot_method() const                { return _hot_method; }
134   int          osr_bci() const                   { return _osr_bci; }
135   bool         is_complete() const               { return _is_complete; }
136   bool         is_blocking() const               { return _is_blocking; }
137   bool         is_success() const                { return _is_success; }
138   DirectiveSet* directive() const                { return _directive; }





139   CodeSection::csize_t nm_content_size() { return _nm_content_size; }
140   void         set_nm_content_size(CodeSection::csize_t size) { _nm_content_size = size; }
141   CodeSection::csize_t nm_insts_size() { return _nm_insts_size; }
142   void         set_nm_insts_size(CodeSection::csize_t size) { _nm_insts_size = size; }
143   CodeSection::csize_t nm_total_size() { return _nm_total_size; }
144   void         set_nm_total_size(CodeSection::csize_t size) { _nm_total_size = size; }

145   bool         can_become_stale() const          {
146     switch (_compile_reason) {
147       case Reason_BackedgeCount:
148       case Reason_InvocationCount:
149       case Reason_Tiered:
150         return !_is_blocking;
151       default:
152         return false;
153     }
154   }
155 #if INCLUDE_JVMCI
156   bool         should_wait_for_compilation() const {
157     // Wait for blocking compilation to finish.
158     switch (_compile_reason) {
159         case Reason_Replay:
160         case Reason_Whitebox:
161         case Reason_Bootstrap:
162           return _is_blocking;
163         default:
164           return false;
165     }
166   }
167 
168   bool         has_waiter() const                { return _has_waiter; }
169   void         clear_waiter()                    { _has_waiter = false; }
170   JVMCICompileState* blocking_jvmci_compile_state() const { return _blocking_jvmci_compile_state; }
171   void         set_blocking_jvmci_compile_state(JVMCICompileState* state) {
172     _blocking_jvmci_compile_state = state;
173   }
174 #endif
175 




176   Monitor*     lock() const                      { return _lock; }

177 
178   // See how many threads are waiting for this task. Must have lock to read this.
179   int waiting_for_completion_count() {
180     assert(_lock->owned_by_self(), "must have lock to use waiting_for_completion_count()");
181     return _waiting_count;
182   }
183   // Indicates that a thread is waiting for this task to complete. Must have lock to use this.
184   void inc_waiting_for_completion() {
185     assert(_lock->owned_by_self(), "must have lock to use inc_waiting_for_completion()");
186     _waiting_count++;
187   }
188   // Indicates that a thread stopped waiting for this task to complete. Must have lock to use this.
189   void dec_waiting_for_completion() {
190     assert(_lock->owned_by_self(), "must have lock to use dec_waiting_for_completion()");
191     assert(_waiting_count > 0, "waiting count is not positive");
192     _waiting_count--;
193   }
194 
195   void         mark_complete()                   { _is_complete = true; }
196   void         mark_success()                    { _is_success = true; }

197   void         mark_started(jlong time)          { _time_started = time; }

198 
199   int          comp_level()                      { return _comp_level;}
200   void         set_comp_level(int comp_level)    { _comp_level = comp_level;}
201 
202   CompileReason compile_reason()                 { return _compile_reason; }
203 
204   AbstractCompiler* compiler() const;
205   CompileTask*      select_for_compilation();
206 
207   int          num_inlined_bytecodes() const     { return _num_inlined_bytecodes; }
208   void         set_num_inlined_bytecodes(int n)  { _num_inlined_bytecodes = n; }
209 


210   CompileTask* next() const                      { return _next; }
211   void         set_next(CompileTask* next)       { _next = next; }
212   CompileTask* prev() const                      { return _prev; }
213   void         set_prev(CompileTask* prev)       { _prev = prev; }
214   bool         is_free() const                   { return _is_free; }
215   void         set_is_free(bool val)             { _is_free = val; }
216   bool         is_unloaded() const;
217 



218   // RedefineClasses support
219   void         metadata_do(MetadataClosure* f);
220   void         mark_on_stack();
221 
222   void         set_arena_bytes(size_t s)         { _arena_bytes = s; }
223   size_t       arena_bytes() const               { return _arena_bytes; }
224 
225 private:
226   static void  print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
227                                       bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,


228                                       const char* msg = nullptr, bool short_form = false, bool cr = true,
229                                       jlong time_queued = 0, jlong time_started = 0);
230 
231 public:
232   void         print(outputStream* st = tty, const char* msg = nullptr, bool short_form = false, bool cr = true);
233   void         print_ul(const char* msg = nullptr);
234   static void  print(outputStream* st, const nmethod* nm, const char* msg = nullptr, bool short_form = false, bool cr = true) {
235     print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
236                            nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
237                            msg, short_form, cr);

238   }
239   static void  print_ul(const nmethod* nm, const char* msg = nullptr);
240 
241   /**
242    * @deprecated Please rely on Compile::inline_printer. Do not directly write inlining information to tty.
243    */
244   static void  print_inline_indent(int inline_level, outputStream* st = tty);
245 
246   void         print_tty();
247   void         print_line_on_error(outputStream* st, char* buf, int buflen);
248 
249   void         log_task(xmlStream* log);
250   void         log_task_queued();
251   void         log_task_start(CompileLog* log);
252   void         log_task_done(CompileLog* log);
253 
254   void         set_failure_reason(const char* reason, bool on_C_heap = false) {
255     _failure_reason = reason;
256     _failure_reason_on_C_heap = on_C_heap;
257   }

 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_COMPILETASK_HPP
 26 #define SHARE_COMPILER_COMPILETASK_HPP
 27 
 28 #include "ci/ciMethod.hpp"
 29 #include "code/nmethod.hpp"
 30 #include "compiler/compileLog.hpp"
 31 #include "memory/allocation.hpp"
 32 #include "utilities/xmlstream.hpp"
 33 
 34 class CompileQueue;
 35 class CompileTrainingData;
 36 class DirectiveSet;
 37 class SCCEntry;
 38 
 39 JVMCI_ONLY(class JVMCICompileState;)
 40 
 41 enum class InliningResult { SUCCESS, FAILURE };
 42 
 43 inline InliningResult inlining_result_of(bool success) {
 44   return success ? InliningResult::SUCCESS : InliningResult::FAILURE;
 45 }
 46 
 47 // CompileTask
 48 //
 49 // An entry in the compile queue.  It represents a pending or current
 50 // compilation.
 51 
 52 class CompileTask : public CHeapObj<mtCompiler> {
 53   friend class VMStructs;
 54   friend class JVMCIVMStructs;
 55 
 56  public:
 57   // Different reasons for a compilation
 58   // The order is important - mapped to reason_names[]
 59   enum CompileReason {
 60       Reason_None,
 61       Reason_InvocationCount,  // Simple/StackWalk-policy
 62       Reason_BackedgeCount,    // Simple/StackWalk-policy
 63       Reason_Tiered,           // Tiered-policy
 64       Reason_Replay,           // ciReplay
 65       Reason_Whitebox,         // Whitebox API
 66       Reason_MustBeCompiled,   // Used for -Xcomp or AlwaysCompileLoopMethods (see CompilationPolicy::must_be_compiled())
 67       Reason_Bootstrap,        // JVMCI bootstrap
 68       Reason_Preload,          // pre-load SC code
 69       Reason_Precompile,
 70       Reason_PrecompileForPreload,
 71       Reason_Count
 72   };
 73 
 74   static const char* reason_name(CompileTask::CompileReason compile_reason) {
 75     static const char* reason_names[] = {
 76       "no_reason",
 77       "count",
 78       "backedge_count",
 79       "tiered",
 80       "replay",
 81       "whitebox",
 82       "must_be_compiled",
 83       "bootstrap",
 84       "preload",
 85       "precompile",
 86       "precompile_for_preload",
 87     };
 88     return reason_names[compile_reason];
 89   }
 90 
 91   static bool reason_is_precompiled(CompileTask::CompileReason compile_reason) {
 92     return (compile_reason == CompileTask::Reason_Precompile) ||
 93            (compile_reason == CompileTask::Reason_PrecompileForPreload);
 94   }
 95 
 96  private:
 97   static CompileTask*  _task_free_list;
 98   Monitor*             _lock;
 99   int                  _compile_id;
100   Method*              _method;
101   jobject              _method_holder;
102   int                  _osr_bci;
103   bool                 _is_complete;
104   bool                 _is_success;
105   bool                 _requires_online_compilation;
106   bool                 _is_blocking;
107   CodeSection::csize_t _nm_content_size;
108   CodeSection::csize_t _nm_total_size;
109   CodeSection::csize_t _nm_insts_size;
110   DirectiveSet*  _directive;
111   AbstractCompiler*    _compiler;
112   SCCEntry*            _scc_entry;
113 #if INCLUDE_JVMCI
114   bool                 _has_waiter;
115   // Compilation state for a blocking JVMCI compilation
116   JVMCICompileState*   _blocking_jvmci_compile_state;
117 #endif
118   int                  _waiting_count;  // See waiting_for_completion_count()
119   int                  _comp_level;
120   int                  _num_inlined_bytecodes;
121   CompileTask*         _next;
122   CompileTask*         _prev;
123   bool                 _is_free;
124   // Fields used for logging why the compilation was initiated:
125   jlong                _time_created; // time when task was created
126   jlong                _time_queued;  // time when task was enqueued
127   jlong                _time_started; // time when compilation started
128   jlong                _time_finished; // time when compilation finished
129   Method*              _hot_method;   // which method actually triggered this task
130   jobject              _hot_method_holder;
131   int                  _hot_count;    // information about its invocation counter
132   CompileReason        _compile_reason;      // more info about the task
133   const char*          _failure_reason;
134   // Specifies if _failure_reason is on the C heap.
135   bool                 _failure_reason_on_C_heap;
136   CompileTrainingData* _training_data;
137   CompileQueue*        _compile_queue;
138   size_t               _arena_bytes;  // peak size of temporary memory during compilation (e.g. node arenas)
139 
140  public:
141   CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {
142     // May hold MethodCompileQueue_lock
143     _lock = new Monitor(Mutex::safepoint-1, "CompileTask_lock");
144   }
145 
146   void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
147                   const methodHandle& hot_method, int hot_count, SCCEntry* scc_entry,
148                   CompileTask::CompileReason compile_reason,
149                   CompileQueue* compile_queue,
150                   bool requires_online_compilation, bool is_blocking);
151 
152   static CompileTask* allocate();
153   static void         free(CompileTask* task);
154 
155   int          compile_id() const                   { return _compile_id; }
156   Method*      method() const                       { return _method; }
157   Method*      hot_method() const                   { return _hot_method; }
158   int          osr_bci() const                      { return _osr_bci; }
159   bool         is_complete() const                  { return _is_complete; }
160   bool         is_blocking() const                  { return _is_blocking; }
161   bool         is_success() const                   { return _is_success; }
162   bool         is_scc() const                       { return _scc_entry != nullptr; }
163   void         clear_scc()                          { _scc_entry = nullptr; }
164   SCCEntry*    scc_entry()                          { return _scc_entry; }
165   bool         requires_online_compilation() const  { return _requires_online_compilation; }
166   DirectiveSet* directive() const                   { return _directive; }
167   CompileReason compile_reason() const              { return _compile_reason; }
168   CodeSection::csize_t nm_content_size() { return _nm_content_size; }
169   void         set_nm_content_size(CodeSection::csize_t size) { _nm_content_size = size; }
170   CodeSection::csize_t nm_insts_size() { return _nm_insts_size; }
171   void         set_nm_insts_size(CodeSection::csize_t size) { _nm_insts_size = size; }
172   CodeSection::csize_t nm_total_size() { return _nm_total_size; }
173   void         set_nm_total_size(CodeSection::csize_t size) { _nm_total_size = size; }
174   bool         preload() const                   { return (_compile_reason == Reason_Preload); }
175   bool         can_become_stale() const          {
176     switch (_compile_reason) {
177       case Reason_BackedgeCount:
178       case Reason_InvocationCount:
179       case Reason_Tiered:
180         return !_is_blocking;
181       default:
182         return false;
183     }
184   }
185 #if INCLUDE_JVMCI
186   bool         should_wait_for_compilation() const {
187     // Wait for blocking compilation to finish.
188     switch (_compile_reason) {
189         case Reason_Replay:
190         case Reason_Whitebox:
191         case Reason_Bootstrap:
192           return _is_blocking;
193         default:
194           return false;
195     }
196   }
197 
198   bool         has_waiter() const                { return _has_waiter; }
199   void         clear_waiter()                    { _has_waiter = false; }
200   JVMCICompileState* blocking_jvmci_compile_state() const { return _blocking_jvmci_compile_state; }
201   void         set_blocking_jvmci_compile_state(JVMCICompileState* state) {
202     _blocking_jvmci_compile_state = state;
203   }
204 #endif
205 
206   bool is_precompiled() {
207     return reason_is_precompiled(compile_reason());
208   }
209 
210   Monitor*     lock() const                      { return _lock; }
211   CompileQueue* compile_queue() const            { return _compile_queue; }
212 
213   // See how many threads are waiting for this task. Must have lock to read this.
214   int waiting_for_completion_count() {
215     assert(_lock->owned_by_self(), "must have lock to use waiting_for_completion_count()");
216     return _waiting_count;
217   }
218   // Indicates that a thread is waiting for this task to complete. Must have lock to use this.
219   void inc_waiting_for_completion() {
220     assert(_lock->owned_by_self(), "must have lock to use inc_waiting_for_completion()");
221     _waiting_count++;
222   }
223   // Indicates that a thread stopped waiting for this task to complete. Must have lock to use this.
224   void dec_waiting_for_completion() {
225     assert(_lock->owned_by_self(), "must have lock to use dec_waiting_for_completion()");
226     assert(_waiting_count > 0, "waiting count is not positive");
227     _waiting_count--;
228   }
229 
230   void         mark_complete()                   { _is_complete = true; }
231   void         mark_success()                    { _is_success = true; }
232   void         mark_queued(jlong time)           { _time_queued = time; }
233   void         mark_started(jlong time)          { _time_started = time; }
234   void         mark_finished(jlong time)         { _time_finished = time; }
235 
236   int          comp_level()                      { return _comp_level;}
237   void         set_comp_level(int comp_level)    { _comp_level = comp_level;}
238 
239   CompileReason compile_reason()                 { return _compile_reason; }
240 
241   AbstractCompiler* compiler() const;
242   CompileTask*      select_for_compilation();
243 
244   int          num_inlined_bytecodes() const     { return _num_inlined_bytecodes; }
245   void         set_num_inlined_bytecodes(int n)  { _num_inlined_bytecodes = n; }
246 
247   static CompileTask* volatile* next_ptr(CompileTask& task) { return &task._next; }
248 
249   CompileTask* next() const                      { return _next; }
250   void         set_next(CompileTask* next)       { _next = next; }
251   CompileTask* prev() const                      { return _prev; }
252   void         set_prev(CompileTask* prev)       { _prev = prev; }
253   bool         is_free() const                   { return _is_free; }
254   void         set_is_free(bool val)             { _is_free = val; }
255   bool         is_unloaded() const;
256 
257   CompileTrainingData* training_data() const     { return _training_data; }
258   void set_training_data(CompileTrainingData*td) { _training_data = td; }
259 
260   // RedefineClasses support
261   void         metadata_do(MetadataClosure* f);
262   void         mark_on_stack();
263 
264   void         set_arena_bytes(size_t s)         { _arena_bytes = s; }
265   size_t       arena_bytes() const               { return _arena_bytes; }
266 
267 private:
268   static void  print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
269                                       bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,
270                                       bool is_scc = false, bool is_preload = false,
271                                       const char* compiler_name = nullptr,
272                                       const char* msg = nullptr, bool short_form = false, bool cr = true,
273                                       jlong time_created = 0, jlong time_queued = 0, jlong time_started = 0, jlong time_finished = 0);
274 
275 public:
276   void         print(outputStream* st = tty, const char* msg = nullptr, bool short_form = false, bool cr = true);
277   void         print_ul(const char* msg = nullptr);
278   static void  print(outputStream* st, const nmethod* nm, const char* msg = nullptr, bool short_form = false, bool cr = true) {
279     print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
280                            nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
281                            nm->scc_entry() != nullptr, nm->preloaded(),
282                            nm->compiler_name(), msg, short_form, cr);
283   }
284   static void  print_ul(const nmethod* nm, const char* msg = nullptr);
285 
286   /**
287    * @deprecated Please rely on Compile::inline_printer. Do not directly write inlining information to tty.
288    */
289   static void  print_inline_indent(int inline_level, outputStream* st = tty);
290 
291   void         print_tty();
292   void         print_line_on_error(outputStream* st, char* buf, int buflen);
293 
294   void         log_task(xmlStream* log);
295   void         log_task_queued();
296   void         log_task_start(CompileLog* log);
297   void         log_task_done(CompileLog* log);
298 
299   void         set_failure_reason(const char* reason, bool on_C_heap = false) {
300     _failure_reason = reason;
301     _failure_reason_on_C_heap = on_C_heap;
302   }
< prev index next >