src/share/vm/runtime/advancedThresholdPolicy.hpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
aoqi@0 26 #define SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
aoqi@0 27
aoqi@0 28 #include "runtime/simpleThresholdPolicy.hpp"
aoqi@0 29
aoqi@0 30 #ifdef TIERED
aoqi@0 31 class CompileTask;
aoqi@0 32 class CompileQueue;
aoqi@0 33
aoqi@0 34 /*
aoqi@0 35 * The system supports 5 execution levels:
aoqi@0 36 * * level 0 - interpreter
aoqi@0 37 * * level 1 - C1 with full optimization (no profiling)
aoqi@0 38 * * level 2 - C1 with invocation and backedge counters
aoqi@0 39 * * level 3 - C1 with full profiling (level 2 + MDO)
aoqi@0 40 * * level 4 - C2
aoqi@0 41 *
aoqi@0 42 * Levels 0, 2 and 3 periodically notify the runtime about the current value of the counters
aoqi@0 43 * (invocation counters and backedge counters). The frequency of these notifications is
aoqi@0 44 * different at each level. These notifications are used by the policy to decide what transition
aoqi@0 45 * to make.
aoqi@0 46 *
aoqi@0 47 * Execution starts at level 0 (interpreter), then the policy can decide either to compile the
aoqi@0 48 * method at level 3 or level 2. The decision is based on the following factors:
aoqi@0 49 * 1. The length of the C2 queue determines the next level. The observation is that level 2
aoqi@0 50 * is generally faster than level 3 by about 30%, therefore we would want to minimize the time
aoqi@0 51 * a method spends at level 3. We should only spend the time at level 3 that is necessary to get
aoqi@0 52 * adequate profiling. So, if the C2 queue is long enough it is more beneficial to go first to
aoqi@0 53 * level 2, because if we transitioned to level 3 we would be stuck there until our C2 compile
aoqi@0 54 * request makes its way through the long queue. When the load on C2 recedes we are going to
aoqi@0 55 * recompile at level 3 and start gathering profiling information.
aoqi@0 56 * 2. The length of C1 queue is used to dynamically adjust the thresholds, so as to introduce
aoqi@0 57 * additional filtering if the compiler is overloaded. The rationale is that by the time a
aoqi@0 58 * method gets compiled it can become unused, so it doesn't make sense to put too much onto the
aoqi@0 59 * queue.
aoqi@0 60 *
aoqi@0 61 * After profiling is completed at level 3 the transition is made to level 4. Again, the length
aoqi@0 62 * of the C2 queue is used as a feedback to adjust the thresholds.
aoqi@0 63 *
aoqi@0 64 * After the first C1 compile some basic information is determined about the code like the number
aoqi@0 65 * of the blocks and the number of the loops. Based on that it can be decided that a method
aoqi@0 66 * is trivial and compiling it with C1 will yield the same code. In this case the method is
aoqi@0 67 * compiled at level 1 instead of 4.
aoqi@0 68 *
aoqi@0 69 * We also support profiling at level 0. If C1 is slow enough to produce the level 3 version of
aoqi@0 70 * the code and the C2 queue is sufficiently small we can decide to start profiling in the
aoqi@0 71 * interpreter (and continue profiling in the compiled code once the level 3 version arrives).
aoqi@0 72 * If the profiling at level 0 is fully completed before level 3 version is produced, a level 2
aoqi@0 73 * version is compiled instead in order to run faster waiting for a level 4 version.
aoqi@0 74 *
aoqi@0 75 * Compile queues are implemented as priority queues - for each method in the queue we compute
aoqi@0 76 * the event rate (the number of invocation and backedge counter increments per unit of time).
aoqi@0 77 * When getting an element off the queue we pick the one with the largest rate. Maintaining the
aoqi@0 78 * rate also allows us to remove stale methods (the ones that got on the queue but stopped
aoqi@0 79 * being used shortly after that).
aoqi@0 80 */
aoqi@0 81
aoqi@0 82 /* Command line options:
aoqi@0 83 * - Tier?InvokeNotifyFreqLog and Tier?BackedgeNotifyFreqLog control the frequency of method
aoqi@0 84 * invocation and backedge notifications. Basically every n-th invocation or backedge a mutator thread
aoqi@0 85 * makes a call into the runtime.
aoqi@0 86 *
aoqi@0 87 * - Tier?CompileThreshold, Tier?BackEdgeThreshold, Tier?MinInvocationThreshold control
aoqi@0 88 * compilation thresholds.
aoqi@0 89 * Level 2 thresholds are not used and are provided for option-compatibility and potential future use.
aoqi@0 90 * Other thresholds work as follows:
aoqi@0 91 *
aoqi@0 92 * Transition from interpreter (level 0) to C1 with full profiling (level 3) happens when
aoqi@0 93 * the following predicate is true (X is the level):
aoqi@0 94 *
aoqi@0 95 * i > TierXInvocationThreshold * s || (i > TierXMinInvocationThreshold * s && i + b > TierXCompileThreshold * s),
aoqi@0 96 *
aoqi@0 97 * where $i$ is the number of method invocations, $b$ number of backedges and $s$ is the scaling
aoqi@0 98 * coefficient that will be discussed further.
aoqi@0 99 * The intuition is to equalize the time that is spend profiling each method.
aoqi@0 100 * The same predicate is used to control the transition from level 3 to level 4 (C2). It should be
aoqi@0 101 * noted though that the thresholds are relative. Moreover i and b for the 0->3 transition come
aoqi@0 102 * from Method* and for 3->4 transition they come from MDO (since profiled invocations are
aoqi@0 103 * counted separately).
aoqi@0 104 *
aoqi@0 105 * OSR transitions are controlled simply with b > TierXBackEdgeThreshold * s predicates.
aoqi@0 106 *
aoqi@0 107 * - Tier?LoadFeedback options are used to automatically scale the predicates described above depending
aoqi@0 108 * on the compiler load. The scaling coefficients are computed as follows:
aoqi@0 109 *
aoqi@0 110 * s = queue_size_X / (TierXLoadFeedback * compiler_count_X) + 1,
aoqi@0 111 *
aoqi@0 112 * where queue_size_X is the current size of the compiler queue of level X, and compiler_count_X
aoqi@0 113 * is the number of level X compiler threads.
aoqi@0 114 *
aoqi@0 115 * Basically these parameters describe how many methods should be in the compile queue
aoqi@0 116 * per compiler thread before the scaling coefficient increases by one.
aoqi@0 117 *
aoqi@0 118 * This feedback provides the mechanism to automatically control the flow of compilation requests
aoqi@0 119 * depending on the machine speed, mutator load and other external factors.
aoqi@0 120 *
aoqi@0 121 * - Tier3DelayOn and Tier3DelayOff parameters control another important feedback loop.
aoqi@0 122 * Consider the following observation: a method compiled with full profiling (level 3)
aoqi@0 123 * is about 30% slower than a method at level 2 (just invocation and backedge counters, no MDO).
aoqi@0 124 * Normally, the following transitions will occur: 0->3->4. The problem arises when the C2 queue
aoqi@0 125 * gets congested and the 3->4 transition is delayed. While the method is the C2 queue it continues
aoqi@0 126 * executing at level 3 for much longer time than is required by the predicate and at suboptimal speed.
aoqi@0 127 * The idea is to dynamically change the behavior of the system in such a way that if a substantial
aoqi@0 128 * load on C2 is detected we would first do the 0->2 transition allowing a method to run faster.
aoqi@0 129 * And then when the load decreases to allow 2->3 transitions.
aoqi@0 130 *
aoqi@0 131 * Tier3Delay* parameters control this switching mechanism.
aoqi@0 132 * Tier3DelayOn is the number of methods in the C2 queue per compiler thread after which the policy
aoqi@0 133 * no longer does 0->3 transitions but does 0->2 transitions instead.
aoqi@0 134 * Tier3DelayOff switches the original behavior back when the number of methods in the C2 queue
aoqi@0 135 * per compiler thread falls below the specified amount.
aoqi@0 136 * The hysteresis is necessary to avoid jitter.
aoqi@0 137 *
aoqi@0 138 * - TieredCompileTaskTimeout is the amount of time an idle method can spend in the compile queue.
aoqi@0 139 * Basically, since we use the event rate d(i + b)/dt as a value of priority when selecting a method to
aoqi@0 140 * compile from the compile queue, we also can detect stale methods for which the rate has been
aoqi@0 141 * 0 for some time in the same iteration. Stale methods can appear in the queue when an application
aoqi@0 142 * abruptly changes its behavior.
aoqi@0 143 *
aoqi@0 144 * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick
aoqi@0 145 * to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything
aoqi@0 146 * with pure c1.
aoqi@0 147 *
aoqi@0 148 * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the
aoqi@0 149 * 0->3 predicate are already exceeded by the given percentage but the level 3 version of the
aoqi@0 150 * method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled
aoqi@0 151 * version in time. This reduces the overall transition to level 4 and decreases the startup time.
aoqi@0 152 * Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long
aoqi@0 153 * these is not reason to start profiling prematurely.
aoqi@0 154 *
aoqi@0 155 * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation.
aoqi@0 156 * Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered
aoqi@0 157 * to be zero if no events occurred in TieredRateUpdateMaxTime.
aoqi@0 158 */
aoqi@0 159
aoqi@0 160
aoqi@0 161 class AdvancedThresholdPolicy : public SimpleThresholdPolicy {
aoqi@0 162 jlong _start_time;
aoqi@0 163
aoqi@0 164 // Call and loop predicates determine whether a transition to a higher compilation
aoqi@0 165 // level should be performed (pointers to predicate functions are passed to common().
aoqi@0 166 // Predicates also take compiler load into account.
aoqi@0 167 typedef bool (AdvancedThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level);
aoqi@0 168 bool call_predicate(int i, int b, CompLevel cur_level);
aoqi@0 169 bool loop_predicate(int i, int b, CompLevel cur_level);
aoqi@0 170 // Common transition function. Given a predicate determines if a method should transition to another level.
aoqi@0 171 CompLevel common(Predicate p, Method* method, CompLevel cur_level, bool disable_feedback = false);
aoqi@0 172 // Transition functions.
aoqi@0 173 // call_event determines if a method should be compiled at a different
aoqi@0 174 // level with a regular invocation entry.
aoqi@0 175 CompLevel call_event(Method* method, CompLevel cur_level);
aoqi@0 176 // loop_event checks if a method should be OSR compiled at a different
aoqi@0 177 // level.
aoqi@0 178 CompLevel loop_event(Method* method, CompLevel cur_level);
aoqi@0 179 // Has a method been long around?
aoqi@0 180 // We don't remove old methods from the compile queue even if they have
aoqi@0 181 // very low activity (see select_task()).
aoqi@0 182 inline bool is_old(Method* method);
aoqi@0 183 // Was a given method inactive for a given number of milliseconds.
aoqi@0 184 // If it is, we would remove it from the queue (see select_task()).
aoqi@0 185 inline bool is_stale(jlong t, jlong timeout, Method* m);
aoqi@0 186 // Compute the weight of the method for the compilation scheduling
aoqi@0 187 inline double weight(Method* method);
aoqi@0 188 // Apply heuristics and return true if x should be compiled before y
aoqi@0 189 inline bool compare_methods(Method* x, Method* y);
aoqi@0 190 // Compute event rate for a given method. The rate is the number of event (invocations + backedges)
aoqi@0 191 // per millisecond.
aoqi@0 192 inline void update_rate(jlong t, Method* m);
aoqi@0 193 // Compute threshold scaling coefficient
aoqi@0 194 inline double threshold_scale(CompLevel level, int feedback_k);
aoqi@0 195 // If a method is old enough and is still in the interpreter we would want to
aoqi@0 196 // start profiling without waiting for the compiled method to arrive. This function
aoqi@0 197 // determines whether we should do that.
aoqi@0 198 inline bool should_create_mdo(Method* method, CompLevel cur_level);
aoqi@0 199 // Create MDO if necessary.
aoqi@0 200 void create_mdo(methodHandle mh, JavaThread* thread);
aoqi@0 201 // Is method profiled enough?
aoqi@0 202 bool is_method_profiled(Method* method);
aoqi@0 203
aoqi@0 204 double _increase_threshold_at_ratio;
aoqi@0 205
aoqi@0 206 protected:
aoqi@0 207 void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level);
aoqi@0 208
aoqi@0 209 void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
aoqi@0 210 void set_start_time(jlong t) { _start_time = t; }
aoqi@0 211 jlong start_time() const { return _start_time; }
aoqi@0 212
aoqi@0 213 // Submit a given method for compilation (and update the rate).
aoqi@0 214 virtual void submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread);
aoqi@0 215 // event() from SimpleThresholdPolicy would call these.
aoqi@0 216 virtual void method_invocation_event(methodHandle method, methodHandle inlinee,
aoqi@0 217 CompLevel level, nmethod* nm, JavaThread* thread);
aoqi@0 218 virtual void method_back_branch_event(methodHandle method, methodHandle inlinee,
aoqi@0 219 int bci, CompLevel level, nmethod* nm, JavaThread* thread);
aoqi@0 220 public:
aoqi@0 221 AdvancedThresholdPolicy() : _start_time(0) { }
aoqi@0 222 // Select task is called by CompileBroker. We should return a task or NULL.
aoqi@0 223 virtual CompileTask* select_task(CompileQueue* compile_queue);
aoqi@0 224 virtual void initialize();
aoqi@0 225 virtual bool should_not_inline(ciEnv* env, ciMethod* callee);
aoqi@0 226
aoqi@0 227 };
aoqi@0 228
aoqi@0 229 #endif // TIERED
aoqi@0 230
aoqi@0 231 #endif // SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP

mercurial