< prev index next >

src/hotspot/share/compiler/compilationPolicy.hpp

Print this page

 68     T* value = nullptr;
 69     if (n != nullptr) {
 70       value = n->value();
 71       delete n;
 72     }
 73     return value;
 74   }
 75 public:
 76   Queue() : _head(nullptr), _tail(nullptr) { }
 77   void push(T* value, Monitor* lock, TRAPS) {
 78     MonitorLocker locker(THREAD, lock);
 79     push_unlocked(value);
 80     locker.notify_all();
 81   }
 82 
 83   bool is_empty_unlocked() const { return _head == nullptr; }
 84 
 85   T* pop(Monitor* lock, TRAPS) {
 86     MonitorLocker locker(THREAD, lock);
 87     while(is_empty_unlocked() && !CompileBroker::is_compilation_disabled_forever()) {

 88       locker.wait();
 89     }
 90     T* value = pop_unlocked();
 91     return value;
 92   }
 93 
 94   T* try_pop(Monitor* lock, TRAPS) {
 95     MonitorLocker locker(THREAD, lock);
 96     T* value = nullptr;
 97     if (!is_empty_unlocked()) {
 98       value = pop_unlocked();
 99     }
100     return value;
101   }
102 
103   void print_on(outputStream* st);
104 };
105 } // namespace CompilationPolicyUtils
106 
107 class CompileTask;

229  *
230  * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick
231  *   to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything
232  *   with pure c1.
233  *
234  * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the
235  *   0->3 predicate are already exceeded by the given percentage but the level 3 version of the
236  *   method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled
237  *   version in time. This reduces the overall transition to level 4 and decreases the startup time.
238  *   Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long
239  *   these is not reason to start profiling prematurely.
240  *
241  * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation.
242  *   Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered
243  *   to be zero if no events occurred in TieredRateUpdateMaxTime.
244  */
245 
246 class CompilationPolicy : AllStatic {
247   friend class CallPredicate;
248   friend class LoopPredicate;

249 
250   typedef CompilationPolicyUtils::Queue<InstanceKlass> TrainingReplayQueue;
251 
252   static int64_t _start_time;
253   static int _c1_count, _c2_count;
254   static double _increase_threshold_at_ratio;
255   static TrainingReplayQueue _training_replay_queue;
256 
257   // Set carry flags in the counters (in Method* and MDO).
258   inline static void handle_counter_overflow(const methodHandle& method);
259 #ifdef ASSERT
260   // Verify that a level is consistent with the compilation mode
261   static bool verify_level(CompLevel level);
262 #endif
263   // Clamp the request level according to various constraints.
264   inline static CompLevel limit_level(CompLevel level);
265   // Common transition function. Given a predicate determines if a method should transition to another level.
266   template<typename Predicate>
267   static CompLevel common(const methodHandle& method, CompLevel cur_level, JavaThread* THREAD, bool disable_feedback = false);
268 
269   template<typename Predicate>
270   static CompLevel transition_from_none(const methodHandle& method, CompLevel cur_level, bool delay_profiling, bool disable_feedback);
271   template<typename Predicate>
272   static CompLevel transition_from_limited_profile(const methodHandle& method, CompLevel cur_level, bool delay_profiling, bool disable_feedback);
273   template<typename Predicate>

283   // Transition functions.
284   // call_event determines if a method should be compiled at a different
285   // level with a regular invocation entry.
286   static CompLevel call_event(const methodHandle& method, CompLevel cur_level, JavaThread* THREAD);
287   // loop_event checks if a method should be OSR compiled at a different
288   // level.
289   static CompLevel loop_event(const methodHandle& method, CompLevel cur_level, JavaThread* THREAD);
290   static void print_counters(const char* prefix, Method* m);
291   static void print_training_data(const char* prefix, Method* method);
292   // Has a method been long around?
293   // We don't remove old methods from the compile queue even if they have
294   // very low activity (see select_task()).
295   inline static bool is_old(const methodHandle& method);
296   // Was a given method inactive for a given number of milliseconds.
297   // If it is, we would remove it from the queue (see select_task()).
298   inline static bool is_stale(int64_t t, int64_t timeout, const methodHandle& method);
299   // Compute the weight of the method for the compilation scheduling
300   inline static double weight(Method* method);
301   // Apply heuristics and return true if x should be compiled before y
302   inline static bool compare_methods(Method* x, Method* y);

303   // Compute event rate for a given method. The rate is the number of event (invocations + backedges)
304   // per millisecond.
305   inline static void update_rate(int64_t t, const methodHandle& method);
306   // Compute threshold scaling coefficient
307   inline static double threshold_scale(CompLevel level, int feedback_k);
308   // If a method is old enough and is still in the interpreter we would want to
309   // start profiling without waiting for the compiled method to arrive. This function
310   // determines whether we should do that.
311   inline static bool should_create_mdo(const methodHandle& method, CompLevel cur_level);
312   // Create MDO if necessary.
313   static void create_mdo(const methodHandle& mh, JavaThread* THREAD);
314   // Is method profiled enough?
315   static bool is_method_profiled(const methodHandle& method);
316 
317   static void set_c1_count(int x) { _c1_count = x;    }
318   static void set_c2_count(int x) { _c2_count = x;    }


319 
320   enum EventType { CALL, LOOP, COMPILE, FORCE_COMPILE, FORCE_RECOMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
321   static void print_event(EventType type, Method* m, Method* im, int bci, CompLevel level);
322   // Check if the method can be compiled, change level if necessary
323   static void compile(const methodHandle& mh, int bci, CompLevel level, TRAPS);
324   // Simple methods are as good being compiled with C1 as C2.
325   // This function tells if it's such a function.
326   inline static bool is_trivial(const methodHandle& method);
327   // Force method to be compiled at CompLevel_simple?
328   inline static bool force_comp_at_level_simple(const methodHandle& method);
329 
330   // Get a compilation level for a given method.
331   static CompLevel comp_level(Method* method);
332   static void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
333                                       CompLevel level, nmethod* nm, TRAPS);
334   static void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
335                                       int bci, CompLevel level, nmethod* nm, TRAPS);
336 
337   static void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
338   static void set_start_time(int64_t t) { _start_time = t;    }
339   static int64_t start_time()           { return _start_time; }
340 
341   // m must be compiled before executing it
342   static bool must_be_compiled(const methodHandle& m, int comp_level = CompLevel_any);
343   static void maybe_compile_early(const methodHandle& m, TRAPS);

344   static void replay_training_at_init_impl(InstanceKlass* klass, TRAPS);
345  public:
346   static int min_invocations() { return Tier4MinInvocationThreshold; }
347   static int c1_count() { return _c1_count; }
348   static int c2_count() { return _c2_count; }


349   static int compiler_count(CompLevel comp_level);
350   // If m must_be_compiled then request a compilation from the CompileBroker.
351   // This supports the -Xcomp option.
352   static void compile_if_required(const methodHandle& m, TRAPS);
353 

354   static void replay_training_at_init(InstanceKlass* klass, TRAPS);
355   static void replay_training_at_init_loop(TRAPS);
356 
357   // m is allowed to be compiled
358   static bool can_be_compiled(const methodHandle& m, int comp_level = CompLevel_any);
359   // m is allowed to be osr compiled
360   static bool can_be_osr_compiled(const methodHandle& m, int comp_level = CompLevel_any);
361   static bool is_compilation_enabled();
362 
363   static CompileTask* select_task_helper(CompileQueue* compile_queue);
364   // Return initial compile level to use with Xcomp (depends on compilation mode).
365   static void reprofile(ScopeDesc* trap_scope, bool is_osr);
366   static nmethod* event(const methodHandle& method, const methodHandle& inlinee,
367                         int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS);
368   // Select task is called by CompileBroker. We should return a task or nullptr.
369   static CompileTask* select_task(CompileQueue* compile_queue, JavaThread* THREAD);
370   // Tell the runtime if we think a given method is adequately profiled.
371   static bool is_mature(MethodData* mdo);
372   // Initialize: set compiler thread count
373   static void initialize();
374   static bool should_not_inline(ciEnv* env, ciMethod* callee);
375 
376   // Return desired initial compilation level for Xcomp
377   static CompLevel initial_compile_level(const methodHandle& method);
378   // Return highest level possible
379   static CompLevel highest_compile_level();
380   static void dump();




381 };
382 
383 #endif // SHARE_COMPILER_COMPILATIONPOLICY_HPP

 68     T* value = nullptr;
 69     if (n != nullptr) {
 70       value = n->value();
 71       delete n;
 72     }
 73     return value;
 74   }
 75 public:
 76   Queue() : _head(nullptr), _tail(nullptr) { }
 77   void push(T* value, Monitor* lock, TRAPS) {
 78     MonitorLocker locker(THREAD, lock);
 79     push_unlocked(value);
 80     locker.notify_all();
 81   }
 82 
 83   bool is_empty_unlocked() const { return _head == nullptr; }
 84 
 85   T* pop(Monitor* lock, TRAPS) {
 86     MonitorLocker locker(THREAD, lock);
 87     while(is_empty_unlocked() && !CompileBroker::is_compilation_disabled_forever()) {
 88       locker.notify_all(); // notify that queue is empty
 89       locker.wait();
 90     }
 91     T* value = pop_unlocked();
 92     return value;
 93   }
 94 
 95   T* try_pop(Monitor* lock, TRAPS) {
 96     MonitorLocker locker(THREAD, lock);
 97     T* value = nullptr;
 98     if (!is_empty_unlocked()) {
 99       value = pop_unlocked();
100     }
101     return value;
102   }
103 
104   void print_on(outputStream* st);
105 };
106 } // namespace CompilationPolicyUtils
107 
108 class CompileTask;

230  *
231  * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick
232  *   to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything
233  *   with pure c1.
234  *
235  * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the
236  *   0->3 predicate are already exceeded by the given percentage but the level 3 version of the
237  *   method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled
238  *   version in time. This reduces the overall transition to level 4 and decreases the startup time.
239  *   Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long
240  *   these is not reason to start profiling prematurely.
241  *
242  * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation.
243  *   Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered
244  *   to be zero if no events occurred in TieredRateUpdateMaxTime.
245  */
246 
247 class CompilationPolicy : AllStatic {
248   friend class CallPredicate;
249   friend class LoopPredicate;
250   friend class RecompilationPolicy;
251 
252   typedef CompilationPolicyUtils::Queue<InstanceKlass> TrainingReplayQueue;
253 
254   static int64_t _start_time;
255   static int _c1_count, _c2_count, _c3_count, _ac_count;
256   static double _increase_threshold_at_ratio;
257   static TrainingReplayQueue _training_replay_queue;
258 
259   // Set carry flags in the counters (in Method* and MDO).
260   inline static void handle_counter_overflow(const methodHandle& method);
261 #ifdef ASSERT
262   // Verify that a level is consistent with the compilation mode
263   static bool verify_level(CompLevel level);
264 #endif
265   // Clamp the request level according to various constraints.
266   inline static CompLevel limit_level(CompLevel level);
267   // Common transition function. Given a predicate determines if a method should transition to another level.
268   template<typename Predicate>
269   static CompLevel common(const methodHandle& method, CompLevel cur_level, JavaThread* THREAD, bool disable_feedback = false);
270 
271   template<typename Predicate>
272   static CompLevel transition_from_none(const methodHandle& method, CompLevel cur_level, bool delay_profiling, bool disable_feedback);
273   template<typename Predicate>
274   static CompLevel transition_from_limited_profile(const methodHandle& method, CompLevel cur_level, bool delay_profiling, bool disable_feedback);
275   template<typename Predicate>

285   // Transition functions.
286   // call_event determines if a method should be compiled at a different
287   // level with a regular invocation entry.
288   static CompLevel call_event(const methodHandle& method, CompLevel cur_level, JavaThread* THREAD);
289   // loop_event checks if a method should be OSR compiled at a different
290   // level.
291   static CompLevel loop_event(const methodHandle& method, CompLevel cur_level, JavaThread* THREAD);
292   static void print_counters(const char* prefix, Method* m);
293   static void print_training_data(const char* prefix, Method* method);
294   // Has a method been long around?
295   // We don't remove old methods from the compile queue even if they have
296   // very low activity (see select_task()).
297   inline static bool is_old(const methodHandle& method);
298   // Was a given method inactive for a given number of milliseconds.
299   // If it is, we would remove it from the queue (see select_task()).
300   inline static bool is_stale(int64_t t, int64_t timeout, const methodHandle& method);
301   // Compute the weight of the method for the compilation scheduling
302   inline static double weight(Method* method);
303   // Apply heuristics and return true if x should be compiled before y
304   inline static bool compare_methods(Method* x, Method* y);
305   inline static bool compare_tasks(CompileTask* x, CompileTask* y);
306   // Compute event rate for a given method. The rate is the number of event (invocations + backedges)
307   // per millisecond.
308   inline static void update_rate(int64_t t, const methodHandle& method);
309   // Compute threshold scaling coefficient
310   inline static double threshold_scale(CompLevel level, int feedback_k);
311   // If a method is old enough and is still in the interpreter we would want to
312   // start profiling without waiting for the compiled method to arrive. This function
313   // determines whether we should do that.
314   inline static bool should_create_mdo(const methodHandle& method, CompLevel cur_level);
315   // Create MDO if necessary.
316   static void create_mdo(const methodHandle& mh, JavaThread* THREAD);
317   // Is method profiled enough?
318   static bool is_method_profiled(const methodHandle& method);
319 
320   static void set_c1_count(int x) { _c1_count = x;    }
321   static void set_c2_count(int x) { _c2_count = x;    }
322   static void set_c3_count(int x) { _c3_count = x;    }
323   static void set_ac_count(int x) { _ac_count = x;    }
324 
325   enum EventType { CALL, LOOP, COMPILE, FORCE_COMPILE, FORCE_RECOMPILE, REMOVE_FROM_QUEUE, UPDATE_IN_QUEUE, REPROFILE, MAKE_NOT_ENTRANT };
326   static void print_event(EventType type, Method* m, Method* im, int bci, CompLevel level);
327   // Check if the method can be compiled, change level if necessary
328   static void compile(const methodHandle& mh, int bci, CompLevel level, TRAPS);
329   // Simple methods are as good being compiled with C1 as C2.
330   // This function tells if it's such a function.
331   inline static bool is_trivial(const methodHandle& method);
332   // Force method to be compiled at CompLevel_simple?
333   inline static bool force_comp_at_level_simple(const methodHandle& method);
334 
335   // Get a compilation level for a given method.
336   static CompLevel comp_level(Method* method);
337   static void method_invocation_event(const methodHandle& method, const methodHandle& inlinee,
338                                       CompLevel level, nmethod* nm, TRAPS);
339   static void method_back_branch_event(const methodHandle& method, const methodHandle& inlinee,
340                                       int bci, CompLevel level, nmethod* nm, TRAPS);
341 
342   static void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
343   static void set_start_time(int64_t t) { _start_time = t;    }
344   static int64_t start_time()           { return _start_time; }
345 
346   // m must be compiled before executing it
347   static bool must_be_compiled(const methodHandle& m, int comp_level = CompLevel_any);
348   static void maybe_compile_early(const methodHandle& m, TRAPS);
349   static void maybe_compile_early_after_init(const methodHandle& m, TRAPS);
350   static void replay_training_at_init_impl(InstanceKlass* klass, TRAPS);
351  public:
352   static int min_invocations() { return Tier4MinInvocationThreshold; }
353   static int c1_count() { return _c1_count; }
354   static int c2_count() { return _c2_count; }
355   static int c3_count() { return _c3_count; }
356   static int ac_count() { return _ac_count; }
357   static int compiler_count(CompLevel comp_level);
358   // If m must_be_compiled then request a compilation from the CompileBroker.
359   // This supports the -Xcomp option.
360   static void compile_if_required(const methodHandle& m, TRAPS);
361 
362   static void flush_replay_training_at_init(TRAPS);
363   static void replay_training_at_init(InstanceKlass* klass, TRAPS);
364   static void replay_training_at_init_loop(TRAPS);
365 
366   // m is allowed to be compiled
367   static bool can_be_compiled(const methodHandle& m, int comp_level = CompLevel_any);
368   // m is allowed to be osr compiled
369   static bool can_be_osr_compiled(const methodHandle& m, int comp_level = CompLevel_any);
370   static bool is_compilation_enabled();
371 
372   static CompileTask* select_task_helper(CompileQueue* compile_queue);
373   // Return initial compile level to use with Xcomp (depends on compilation mode).
374   static void reprofile(ScopeDesc* trap_scope, bool is_osr);
375   static nmethod* event(const methodHandle& method, const methodHandle& inlinee,
376                         int branch_bci, int bci, CompLevel comp_level, nmethod* nm, TRAPS);
377   // Select task is called by CompileBroker. We should return a task or nullptr.
378   static CompileTask* select_task(CompileQueue* compile_queue, JavaThread* THREAD);
379   // Tell the runtime if we think a given method is adequately profiled.
380   static bool is_mature(MethodData* mdo);
381   // Initialize: set compiler thread count
382   static void initialize();
383   static bool should_not_inline(ciEnv* env, ciMethod* callee);
384 
385   // Return desired initial compilation level for Xcomp
386   static CompLevel initial_compile_level(const methodHandle& method);
387   // Return highest level possible
388   static CompLevel highest_compile_level();
389   static void dump();
390 
391   static void sample_load_average();
392   static bool have_recompilation_work();
393   static bool recompilation_step(int step, TRAPS);
394 };
395 
396 #endif // SHARE_COMPILER_COMPILATIONPOLICY_HPP
< prev index next >