< 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                  _comp_level;
102   int                  _num_inlined_bytecodes;
103   CompileTask*         _next, *_prev;

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

106   jlong                _time_queued;  // time when task was enqueued
107   jlong                _time_started; // time when compilation started
108   Method*              _hot_method;   // which method actually triggered this task
109   jobject              _hot_method_holder;
110   int                  _hot_count;    // information about its invocation counter
111   CompileReason        _compile_reason;      // more info about the task
112   const char*          _failure_reason;
113   // Specifies if _failure_reason is on the C heap.
114   bool                 _failure_reason_on_C_heap;


115 
116  public:
117   CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {
118     // May hold MethodCompileQueue_lock
119     _lock = new Monitor(Mutex::safepoint-1, "CompileTask_lock");
120   }
121 
122   void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
123                   const methodHandle& hot_method, int hot_count,
124                   CompileTask::CompileReason compile_reason, bool is_blocking);


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





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

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





174   Monitor*     lock() const                      { return _lock; }
175 


176   void         mark_complete()                   { _is_complete = true; }
177   void         mark_success()                    { _is_success = true; }

178   void         mark_started(jlong time)          { _time_started = time; }
179 
180   int          comp_level()                      { return _comp_level;}
181   void         set_comp_level(int comp_level)    { _comp_level = comp_level;}
182 
183   AbstractCompiler* compiler() const;
184   CompileTask*      select_for_compilation();
185 
186   int          num_inlined_bytecodes() const     { return _num_inlined_bytecodes; }
187   void         set_num_inlined_bytecodes(int n)  { _num_inlined_bytecodes = n; }
188 


189   CompileTask* next() const                      { return _next; }
190   void         set_next(CompileTask* next)       { _next = next; }
191   CompileTask* prev() const                      { return _prev; }
192   void         set_prev(CompileTask* prev)       { _prev = prev; }
193   bool         is_free() const                   { return _is_free; }
194   void         set_is_free(bool val)             { _is_free = val; }
195   bool         is_unloaded() const;
196 





197   // RedefineClasses support
198   void         metadata_do(MetadataClosure* f);
199   void         mark_on_stack();
200 
201 private:
202   static void  print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
203                                       bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,


204                                       const char* msg = nullptr, bool short_form = false, bool cr = true,
205                                       jlong time_queued = 0, jlong time_started = 0);
206 
207 public:
208   void         print(outputStream* st = tty, const char* msg = nullptr, bool short_form = false, bool cr = true);
209   void         print_ul(const char* msg = nullptr);
210   static void  print(outputStream* st, const nmethod* nm, const char* msg = nullptr, bool short_form = false, bool cr = true) {
211     print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
212                            nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
213                            msg, short_form, cr);

214   }
215   static void  print_ul(const nmethod* nm, const char* msg = nullptr);
216 
217   static void  print_inline_indent(int inline_level, outputStream* st = tty);
218 
219   void         print_tty();
220   void         print_line_on_error(outputStream* st, char* buf, int buflen);
221 
222   void         log_task(xmlStream* log);
223   void         log_task_queued();
224   void         log_task_start(CompileLog* log);
225   void         log_task_done(CompileLog* log);
226 
227   void         set_failure_reason(const char* reason, bool on_C_heap = false) {
228     _failure_reason = reason;
229     _failure_reason_on_C_heap = on_C_heap;
230   }
231 
232   bool         check_break_at_flags();
233 

 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     };
 87     return reason_names[compile_reason];
 88   }
 89 
 90  private:
 91   static CompileTask*  _task_free_list;
 92   Monitor*             _lock;
 93   int                  _compile_id;
 94   Method*              _method;
 95   jobject              _method_holder;
 96   int                  _osr_bci;
 97   bool                 _is_complete;
 98   bool                 _is_success;
 99   bool                 _requires_online_compilation;
100   bool                 _is_blocking;
101   CodeSection::csize_t _nm_content_size;
102   CodeSection::csize_t _nm_total_size;
103   CodeSection::csize_t _nm_insts_size;
104   DirectiveSet*  _directive;
105   AbstractCompiler*    _compiler;
106   SCCEntry*            _scc_entry;
107 #if INCLUDE_JVMCI
108   bool                 _has_waiter;
109   // Compilation state for a blocking JVMCI compilation
110   JVMCICompileState*   _blocking_jvmci_compile_state;
111 #endif
112   int                  _comp_level;
113   int                  _num_inlined_bytecodes;
114   CompileTask*         _next;
115   CompileTask*         _prev;
116   bool                 _is_free;
117   // Fields used for logging why the compilation was initiated:
118   jlong                _time_created; // time when task was enqueued
119   jlong                _time_queued;  // time when task was enqueued
120   jlong                _time_started; // time when compilation started
121   Method*              _hot_method;   // which method actually triggered this task
122   jobject              _hot_method_holder;
123   int                  _hot_count;    // information about its invocation counter
124   CompileReason        _compile_reason;      // more info about the task
125   const char*          _failure_reason;
126   // Specifies if _failure_reason is on the C heap.
127   bool                 _failure_reason_on_C_heap;
128   CompileTrainingData* _training_data;
129   CompileQueue*        _compile_queue;
130 
131  public:
132   CompileTask() : _failure_reason(nullptr), _failure_reason_on_C_heap(false) {
133     // May hold MethodCompileQueue_lock
134     _lock = new Monitor(Mutex::safepoint-1, "CompileTask_lock");
135   }
136 
137   void initialize(int compile_id, const methodHandle& method, int osr_bci, int comp_level,
138                   const methodHandle& hot_method, int hot_count, SCCEntry* scc_entry,
139                   CompileTask::CompileReason compile_reason,
140                   CompileQueue* compile_queue,
141                   bool requires_online_compilation, bool is_blocking);
142 
143   static CompileTask* allocate();
144   static void         free(CompileTask* task);
145 
146   int          compile_id() const                   { return _compile_id; }
147   Method*      method() const                       { return _method; }
148   Method*      hot_method() const                   { return _hot_method; }
149   int          osr_bci() const                      { return _osr_bci; }
150   bool         is_complete() const                  { return _is_complete; }
151   bool         is_blocking() const                  { return _is_blocking; }
152   bool         is_success() const                   { return _is_success; }
153   bool         is_scc() const                       { return _scc_entry != nullptr; }
154   void         clear_scc()                          { _scc_entry = nullptr; }
155   SCCEntry*    scc_entry()                          { return _scc_entry; }
156   bool         requires_online_compilation() const  { return _requires_online_compilation; }
157   DirectiveSet* directive() const                   { return _directive; }
158   CompileReason compile_reason() const              { return _compile_reason; }
159   CodeSection::csize_t nm_content_size() { return _nm_content_size; }
160   void         set_nm_content_size(CodeSection::csize_t size) { _nm_content_size = size; }
161   CodeSection::csize_t nm_insts_size() { return _nm_insts_size; }
162   void         set_nm_insts_size(CodeSection::csize_t size) { _nm_insts_size = size; }
163   CodeSection::csize_t nm_total_size() { return _nm_total_size; }
164   void         set_nm_total_size(CodeSection::csize_t size) { _nm_total_size = size; }
165   bool         preload() const                   { return (_compile_reason == Reason_Preload); }
166   bool         can_become_stale() const          {
167     switch (_compile_reason) {
168       case Reason_BackedgeCount:
169       case Reason_InvocationCount:
170       case Reason_Tiered:
171         return !_is_blocking;
172       default:
173         return false;
174     }
175   }
176 #if INCLUDE_JVMCI
177   bool         should_wait_for_compilation() const {
178     // Wait for blocking compilation to finish.
179     switch (_compile_reason) {
180         case Reason_Replay:
181         case Reason_Whitebox:
182         case Reason_Bootstrap:
183           return _is_blocking;
184         default:
185           return false;
186     }
187   }
188 
189   bool         has_waiter() const                { return _has_waiter; }
190   void         clear_waiter()                    { _has_waiter = false; }
191   JVMCICompileState* blocking_jvmci_compile_state() const { return _blocking_jvmci_compile_state; }
192   void         set_blocking_jvmci_compile_state(JVMCICompileState* state) {
193     _blocking_jvmci_compile_state = state;
194   }
195 #endif
196 
197   bool is_precompiled() {
198     return (compile_reason() == CompileTask::Reason_Precompile)         ||
199            (compile_reason() == CompileTask::Reason_PrecompileForPreload);
200   }
201 
202   Monitor*     lock() const                      { return _lock; }
203 
204   CompileQueue* compile_queue() const            { return _compile_queue; }
205 
206   void         mark_complete()                   { _is_complete = true; }
207   void         mark_success()                    { _is_success = true; }
208   void         mark_queued(jlong time)           { _time_queued = time; }
209   void         mark_started(jlong time)          { _time_started = time; }
210 
211   int          comp_level()                      { return _comp_level;}
212   void         set_comp_level(int comp_level)    { _comp_level = comp_level;}
213 
214   AbstractCompiler* compiler() const;
215   CompileTask*      select_for_compilation();
216 
217   int          num_inlined_bytecodes() const     { return _num_inlined_bytecodes; }
218   void         set_num_inlined_bytecodes(int n)  { _num_inlined_bytecodes = n; }
219 
220   static CompileTask* volatile* next_ptr(CompileTask& task) { return &task._next; }
221 
222   CompileTask* next() const                      { return _next; }
223   void         set_next(CompileTask* next)       { _next = next; }
224   CompileTask* prev() const                      { return _prev; }
225   void         set_prev(CompileTask* prev)       { _prev = prev; }
226   bool         is_free() const                   { return _is_free; }
227   void         set_is_free(bool val)             { _is_free = val; }
228   bool         is_unloaded() const;
229 
230   CompileTrainingData* training_data() const     { return _training_data; }
231   void set_training_data(CompileTrainingData*td) { _training_data = td; }
232 
233   CompileReason compile_reason()                 { return _compile_reason; }
234 
235   // RedefineClasses support
236   void         metadata_do(MetadataClosure* f);
237   void         mark_on_stack();
238 
239 private:
240   static void  print_impl(outputStream* st, Method* method, int compile_id, int comp_level,
241                                       bool is_osr_method = false, int osr_bci = -1, bool is_blocking = false,
242                                       bool is_scc = false, bool is_preload = false,
243                                       const char* compiler_name = nullptr,
244                                       const char* msg = nullptr, bool short_form = false, bool cr = true,
245                                       jlong time_created = 0, jlong time_queued = 0, jlong time_started = 0);
246 
247 public:
248   void         print(outputStream* st = tty, const char* msg = nullptr, bool short_form = false, bool cr = true);
249   void         print_ul(const char* msg = nullptr);
250   static void  print(outputStream* st, const nmethod* nm, const char* msg = nullptr, bool short_form = false, bool cr = true) {
251     print_impl(st, nm->method(), nm->compile_id(), nm->comp_level(),
252                            nm->is_osr_method(), nm->is_osr_method() ? nm->osr_entry_bci() : -1, /*is_blocking*/ false,
253                            nm->scc_entry() != nullptr, nm->preloaded(),
254                            nm->compiler_name(), msg, short_form, cr);
255   }
256   static void  print_ul(const nmethod* nm, const char* msg = nullptr);
257 
258   static void  print_inline_indent(int inline_level, outputStream* st = tty);
259 
260   void         print_tty();
261   void         print_line_on_error(outputStream* st, char* buf, int buflen);
262 
263   void         log_task(xmlStream* log);
264   void         log_task_queued();
265   void         log_task_start(CompileLog* log);
266   void         log_task_done(CompileLog* log);
267 
268   void         set_failure_reason(const char* reason, bool on_C_heap = false) {
269     _failure_reason = reason;
270     _failure_reason_on_C_heap = on_C_heap;
271   }
272 
273   bool         check_break_at_flags();
274 
< prev index next >