Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
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 | #include "precompiled.hpp" |
aoqi@0 | 26 | #include "runtime/advancedThresholdPolicy.hpp" |
aoqi@0 | 27 | #include "runtime/simpleThresholdPolicy.inline.hpp" |
aoqi@0 | 28 | |
aoqi@0 | 29 | #ifdef TIERED |
aoqi@0 | 30 | // Print an event. |
aoqi@0 | 31 | void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh, |
aoqi@0 | 32 | int bci, CompLevel level) { |
aoqi@0 | 33 | tty->print(" rate="); |
aoqi@0 | 34 | if (mh->prev_time() == 0) tty->print("n/a"); |
aoqi@0 | 35 | else tty->print("%f", mh->rate()); |
aoqi@0 | 36 | |
aoqi@0 | 37 | tty->print(" k=%.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback), |
aoqi@0 | 38 | threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback)); |
aoqi@0 | 39 | |
aoqi@0 | 40 | } |
aoqi@0 | 41 | |
aoqi@0 | 42 | void AdvancedThresholdPolicy::initialize() { |
aoqi@0 | 43 | // Turn on ergonomic compiler count selection |
aoqi@0 | 44 | if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) { |
aoqi@0 | 45 | FLAG_SET_DEFAULT(CICompilerCountPerCPU, true); |
aoqi@0 | 46 | } |
aoqi@0 | 47 | int count = CICompilerCount; |
aoqi@0 | 48 | if (CICompilerCountPerCPU) { |
aoqi@0 | 49 | // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n |
aoqi@0 | 50 | int log_cpu = log2_intptr(os::active_processor_count()); |
aoqi@0 | 51 | int loglog_cpu = log2_intptr(MAX2(log_cpu, 1)); |
aoqi@0 | 52 | count = MAX2(log_cpu * loglog_cpu, 1) * 3 / 2; |
aoqi@0 | 53 | } |
aoqi@0 | 54 | |
aoqi@0 | 55 | set_c1_count(MAX2(count / 3, 1)); |
aoqi@0 | 56 | set_c2_count(MAX2(count - c1_count(), 1)); |
aoqi@0 | 57 | FLAG_SET_ERGO(intx, CICompilerCount, c1_count() + c2_count()); |
aoqi@0 | 58 | |
aoqi@0 | 59 | // Some inlining tuning |
aoqi@0 | 60 | #ifdef X86 |
aoqi@0 | 61 | if (FLAG_IS_DEFAULT(InlineSmallCode)) { |
aoqi@0 | 62 | FLAG_SET_DEFAULT(InlineSmallCode, 2000); |
aoqi@0 | 63 | } |
aoqi@0 | 64 | #endif |
aoqi@0 | 65 | |
aoqi@0 | 66 | #ifdef SPARC |
aoqi@0 | 67 | if (FLAG_IS_DEFAULT(InlineSmallCode)) { |
aoqi@0 | 68 | FLAG_SET_DEFAULT(InlineSmallCode, 2500); |
aoqi@0 | 69 | } |
aoqi@0 | 70 | #endif |
aoqi@0 | 71 | |
aoqi@0 | 72 | set_increase_threshold_at_ratio(); |
aoqi@0 | 73 | set_start_time(os::javaTimeMillis()); |
aoqi@0 | 74 | } |
aoqi@0 | 75 | |
aoqi@0 | 76 | // update_rate() is called from select_task() while holding a compile queue lock. |
aoqi@0 | 77 | void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) { |
aoqi@0 | 78 | JavaThread* THREAD = JavaThread::current(); |
aoqi@0 | 79 | if (is_old(m)) { |
aoqi@0 | 80 | // We don't remove old methods from the queue, |
aoqi@0 | 81 | // so we can just zero the rate. |
aoqi@0 | 82 | m->set_rate(0, THREAD); |
aoqi@0 | 83 | return; |
aoqi@0 | 84 | } |
aoqi@0 | 85 | |
aoqi@0 | 86 | // We don't update the rate if we've just came out of a safepoint. |
aoqi@0 | 87 | // delta_s is the time since last safepoint in milliseconds. |
aoqi@0 | 88 | jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint(); |
aoqi@0 | 89 | jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement |
aoqi@0 | 90 | // How many events were there since the last time? |
aoqi@0 | 91 | int event_count = m->invocation_count() + m->backedge_count(); |
aoqi@0 | 92 | int delta_e = event_count - m->prev_event_count(); |
aoqi@0 | 93 | |
aoqi@0 | 94 | // We should be running for at least 1ms. |
aoqi@0 | 95 | if (delta_s >= TieredRateUpdateMinTime) { |
aoqi@0 | 96 | // And we must've taken the previous point at least 1ms before. |
aoqi@0 | 97 | if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) { |
aoqi@0 | 98 | m->set_prev_time(t, THREAD); |
aoqi@0 | 99 | m->set_prev_event_count(event_count, THREAD); |
aoqi@0 | 100 | m->set_rate((float)delta_e / (float)delta_t, THREAD); // Rate is events per millisecond |
aoqi@0 | 101 | } else |
aoqi@0 | 102 | if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) { |
aoqi@0 | 103 | // If nothing happened for 25ms, zero the rate. Don't modify prev values. |
aoqi@0 | 104 | m->set_rate(0, THREAD); |
aoqi@0 | 105 | } |
aoqi@0 | 106 | } |
aoqi@0 | 107 | } |
aoqi@0 | 108 | |
aoqi@0 | 109 | // Check if this method has been stale from a given number of milliseconds. |
aoqi@0 | 110 | // See select_task(). |
aoqi@0 | 111 | bool AdvancedThresholdPolicy::is_stale(jlong t, jlong timeout, Method* m) { |
aoqi@0 | 112 | jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint(); |
aoqi@0 | 113 | jlong delta_t = t - m->prev_time(); |
aoqi@0 | 114 | if (delta_t > timeout && delta_s > timeout) { |
aoqi@0 | 115 | int event_count = m->invocation_count() + m->backedge_count(); |
aoqi@0 | 116 | int delta_e = event_count - m->prev_event_count(); |
aoqi@0 | 117 | // Return true if there were no events. |
aoqi@0 | 118 | return delta_e == 0; |
aoqi@0 | 119 | } |
aoqi@0 | 120 | return false; |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | // We don't remove old methods from the compile queue even if they have |
aoqi@0 | 124 | // very low activity. See select_task(). |
aoqi@0 | 125 | bool AdvancedThresholdPolicy::is_old(Method* method) { |
aoqi@0 | 126 | return method->invocation_count() > 50000 || method->backedge_count() > 500000; |
aoqi@0 | 127 | } |
aoqi@0 | 128 | |
aoqi@0 | 129 | double AdvancedThresholdPolicy::weight(Method* method) { |
aoqi@0 | 130 | return (method->rate() + 1) * ((method->invocation_count() + 1) * (method->backedge_count() + 1)); |
aoqi@0 | 131 | } |
aoqi@0 | 132 | |
aoqi@0 | 133 | // Apply heuristics and return true if x should be compiled before y |
aoqi@0 | 134 | bool AdvancedThresholdPolicy::compare_methods(Method* x, Method* y) { |
aoqi@0 | 135 | if (x->highest_comp_level() > y->highest_comp_level()) { |
aoqi@0 | 136 | // recompilation after deopt |
aoqi@0 | 137 | return true; |
aoqi@0 | 138 | } else |
aoqi@0 | 139 | if (x->highest_comp_level() == y->highest_comp_level()) { |
aoqi@0 | 140 | if (weight(x) > weight(y)) { |
aoqi@0 | 141 | return true; |
aoqi@0 | 142 | } |
aoqi@0 | 143 | } |
aoqi@0 | 144 | return false; |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | // Is method profiled enough? |
aoqi@0 | 148 | bool AdvancedThresholdPolicy::is_method_profiled(Method* method) { |
aoqi@0 | 149 | MethodData* mdo = method->method_data(); |
aoqi@0 | 150 | if (mdo != NULL) { |
aoqi@0 | 151 | int i = mdo->invocation_count_delta(); |
aoqi@0 | 152 | int b = mdo->backedge_count_delta(); |
aoqi@0 | 153 | return call_predicate_helper<CompLevel_full_profile>(i, b, 1); |
aoqi@0 | 154 | } |
aoqi@0 | 155 | return false; |
aoqi@0 | 156 | } |
aoqi@0 | 157 | |
aoqi@0 | 158 | // Called with the queue locked and with at least one element |
aoqi@0 | 159 | CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) { |
aoqi@0 | 160 | CompileTask *max_task = NULL; |
aoqi@0 | 161 | Method* max_method = NULL; |
aoqi@0 | 162 | jlong t = os::javaTimeMillis(); |
aoqi@0 | 163 | // Iterate through the queue and find a method with a maximum rate. |
aoqi@0 | 164 | for (CompileTask* task = compile_queue->first(); task != NULL;) { |
aoqi@0 | 165 | CompileTask* next_task = task->next(); |
aoqi@0 | 166 | Method* method = task->method(); |
aoqi@0 | 167 | MethodData* mdo = method->method_data(); |
aoqi@0 | 168 | update_rate(t, method); |
aoqi@0 | 169 | if (max_task == NULL) { |
aoqi@0 | 170 | max_task = task; |
aoqi@0 | 171 | max_method = method; |
aoqi@0 | 172 | } else { |
aoqi@0 | 173 | // If a method has been stale for some time, remove it from the queue. |
aoqi@0 | 174 | if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) { |
aoqi@0 | 175 | if (PrintTieredEvents) { |
aoqi@0 | 176 | print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level()); |
aoqi@0 | 177 | } |
aoqi@0 | 178 | CompileTaskWrapper ctw(task); // Frees the task |
aoqi@0 | 179 | compile_queue->remove(task); |
aoqi@0 | 180 | method->clear_queued_for_compilation(); |
aoqi@0 | 181 | task = next_task; |
aoqi@0 | 182 | continue; |
aoqi@0 | 183 | } |
aoqi@0 | 184 | |
aoqi@0 | 185 | // Select a method with a higher rate |
aoqi@0 | 186 | if (compare_methods(method, max_method)) { |
aoqi@0 | 187 | max_task = task; |
aoqi@0 | 188 | max_method = method; |
aoqi@0 | 189 | } |
aoqi@0 | 190 | } |
aoqi@0 | 191 | task = next_task; |
aoqi@0 | 192 | } |
aoqi@0 | 193 | |
aoqi@0 | 194 | if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile |
aoqi@0 | 195 | && is_method_profiled(max_method)) { |
aoqi@0 | 196 | max_task->set_comp_level(CompLevel_limited_profile); |
aoqi@0 | 197 | if (PrintTieredEvents) { |
aoqi@0 | 198 | print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level()); |
aoqi@0 | 199 | } |
aoqi@0 | 200 | } |
aoqi@0 | 201 | |
aoqi@0 | 202 | return max_task; |
aoqi@0 | 203 | } |
aoqi@0 | 204 | |
aoqi@0 | 205 | double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) { |
aoqi@0 | 206 | double queue_size = CompileBroker::queue_size(level); |
aoqi@0 | 207 | int comp_count = compiler_count(level); |
aoqi@0 | 208 | double k = queue_size / (feedback_k * comp_count) + 1; |
aoqi@0 | 209 | |
aoqi@0 | 210 | // Increase C1 compile threshold when the code cache is filled more |
aoqi@0 | 211 | // than specified by IncreaseFirstTierCompileThresholdAt percentage. |
aoqi@0 | 212 | // The main intention is to keep enough free space for C2 compiled code |
aoqi@0 | 213 | // to achieve peak performance if the code cache is under stress. |
aoqi@0 | 214 | if ((TieredStopAtLevel == CompLevel_full_optimization) && (level != CompLevel_full_optimization)) { |
aoqi@0 | 215 | double current_reverse_free_ratio = CodeCache::reverse_free_ratio(); |
aoqi@0 | 216 | if (current_reverse_free_ratio > _increase_threshold_at_ratio) { |
aoqi@0 | 217 | k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio); |
aoqi@0 | 218 | } |
aoqi@0 | 219 | } |
aoqi@0 | 220 | return k; |
aoqi@0 | 221 | } |
aoqi@0 | 222 | |
aoqi@0 | 223 | // Call and loop predicates determine whether a transition to a higher |
aoqi@0 | 224 | // compilation level should be performed (pointers to predicate functions |
aoqi@0 | 225 | // are passed to common()). |
aoqi@0 | 226 | // Tier?LoadFeedback is basically a coefficient that determines of |
aoqi@0 | 227 | // how many methods per compiler thread can be in the queue before |
aoqi@0 | 228 | // the threshold values double. |
aoqi@0 | 229 | bool AdvancedThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) { |
aoqi@0 | 230 | switch(cur_level) { |
aoqi@0 | 231 | case CompLevel_none: |
aoqi@0 | 232 | case CompLevel_limited_profile: { |
aoqi@0 | 233 | double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback); |
aoqi@0 | 234 | return loop_predicate_helper<CompLevel_none>(i, b, k); |
aoqi@0 | 235 | } |
aoqi@0 | 236 | case CompLevel_full_profile: { |
aoqi@0 | 237 | double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback); |
aoqi@0 | 238 | return loop_predicate_helper<CompLevel_full_profile>(i, b, k); |
aoqi@0 | 239 | } |
aoqi@0 | 240 | default: |
aoqi@0 | 241 | return true; |
aoqi@0 | 242 | } |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | bool AdvancedThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) { |
aoqi@0 | 246 | switch(cur_level) { |
aoqi@0 | 247 | case CompLevel_none: |
aoqi@0 | 248 | case CompLevel_limited_profile: { |
aoqi@0 | 249 | double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback); |
aoqi@0 | 250 | return call_predicate_helper<CompLevel_none>(i, b, k); |
aoqi@0 | 251 | } |
aoqi@0 | 252 | case CompLevel_full_profile: { |
aoqi@0 | 253 | double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback); |
aoqi@0 | 254 | return call_predicate_helper<CompLevel_full_profile>(i, b, k); |
aoqi@0 | 255 | } |
aoqi@0 | 256 | default: |
aoqi@0 | 257 | return true; |
aoqi@0 | 258 | } |
aoqi@0 | 259 | } |
aoqi@0 | 260 | |
aoqi@0 | 261 | // If a method is old enough and is still in the interpreter we would want to |
aoqi@0 | 262 | // start profiling without waiting for the compiled method to arrive. |
aoqi@0 | 263 | // We also take the load on compilers into the account. |
aoqi@0 | 264 | bool AdvancedThresholdPolicy::should_create_mdo(Method* method, CompLevel cur_level) { |
aoqi@0 | 265 | if (cur_level == CompLevel_none && |
aoqi@0 | 266 | CompileBroker::queue_size(CompLevel_full_optimization) <= |
aoqi@0 | 267 | Tier3DelayOn * compiler_count(CompLevel_full_optimization)) { |
aoqi@0 | 268 | int i = method->invocation_count(); |
aoqi@0 | 269 | int b = method->backedge_count(); |
aoqi@0 | 270 | double k = Tier0ProfilingStartPercentage / 100.0; |
aoqi@0 | 271 | return call_predicate_helper<CompLevel_none>(i, b, k) || loop_predicate_helper<CompLevel_none>(i, b, k); |
aoqi@0 | 272 | } |
aoqi@0 | 273 | return false; |
aoqi@0 | 274 | } |
aoqi@0 | 275 | |
aoqi@0 | 276 | // Inlining control: if we're compiling a profiled method with C1 and the callee |
aoqi@0 | 277 | // is known to have OSRed in a C2 version, don't inline it. |
aoqi@0 | 278 | bool AdvancedThresholdPolicy::should_not_inline(ciEnv* env, ciMethod* callee) { |
aoqi@0 | 279 | CompLevel comp_level = (CompLevel)env->comp_level(); |
aoqi@0 | 280 | if (comp_level == CompLevel_full_profile || |
aoqi@0 | 281 | comp_level == CompLevel_limited_profile) { |
aoqi@0 | 282 | return callee->highest_osr_comp_level() == CompLevel_full_optimization; |
aoqi@0 | 283 | } |
aoqi@0 | 284 | return false; |
aoqi@0 | 285 | } |
aoqi@0 | 286 | |
aoqi@0 | 287 | // Create MDO if necessary. |
aoqi@0 | 288 | void AdvancedThresholdPolicy::create_mdo(methodHandle mh, JavaThread* THREAD) { |
aoqi@0 | 289 | if (mh->is_native() || mh->is_abstract() || mh->is_accessor()) return; |
aoqi@0 | 290 | if (mh->method_data() == NULL) { |
aoqi@0 | 291 | Method::build_interpreter_method_data(mh, CHECK_AND_CLEAR); |
aoqi@0 | 292 | } |
aoqi@0 | 293 | } |
aoqi@0 | 294 | |
aoqi@0 | 295 | |
aoqi@0 | 296 | /* |
aoqi@0 | 297 | * Method states: |
aoqi@0 | 298 | * 0 - interpreter (CompLevel_none) |
aoqi@0 | 299 | * 1 - pure C1 (CompLevel_simple) |
aoqi@0 | 300 | * 2 - C1 with invocation and backedge counting (CompLevel_limited_profile) |
aoqi@0 | 301 | * 3 - C1 with full profiling (CompLevel_full_profile) |
aoqi@0 | 302 | * 4 - C2 (CompLevel_full_optimization) |
aoqi@0 | 303 | * |
aoqi@0 | 304 | * Common state transition patterns: |
aoqi@0 | 305 | * a. 0 -> 3 -> 4. |
aoqi@0 | 306 | * The most common path. But note that even in this straightforward case |
aoqi@0 | 307 | * profiling can start at level 0 and finish at level 3. |
aoqi@0 | 308 | * |
aoqi@0 | 309 | * b. 0 -> 2 -> 3 -> 4. |
aoqi@0 | 310 | * This case occures when the load on C2 is deemed too high. So, instead of transitioning |
aoqi@0 | 311 | * into state 3 directly and over-profiling while a method is in the C2 queue we transition to |
aoqi@0 | 312 | * level 2 and wait until the load on C2 decreases. This path is disabled for OSRs. |
aoqi@0 | 313 | * |
aoqi@0 | 314 | * c. 0 -> (3->2) -> 4. |
aoqi@0 | 315 | * In this case we enqueue a method for compilation at level 3, but the C1 queue is long enough |
aoqi@0 | 316 | * to enable the profiling to fully occur at level 0. In this case we change the compilation level |
aoqi@0 | 317 | * of the method to 2, because it'll allow it to run much faster without full profiling while c2 |
aoqi@0 | 318 | * is compiling. |
aoqi@0 | 319 | * |
aoqi@0 | 320 | * d. 0 -> 3 -> 1 or 0 -> 2 -> 1. |
aoqi@0 | 321 | * After a method was once compiled with C1 it can be identified as trivial and be compiled to |
aoqi@0 | 322 | * level 1. These transition can also occur if a method can't be compiled with C2 but can with C1. |
aoqi@0 | 323 | * |
aoqi@0 | 324 | * e. 0 -> 4. |
aoqi@0 | 325 | * This can happen if a method fails C1 compilation (it will still be profiled in the interpreter) |
aoqi@0 | 326 | * or because of a deopt that didn't require reprofiling (compilation won't happen in this case because |
aoqi@0 | 327 | * the compiled version already exists). |
aoqi@0 | 328 | * |
aoqi@0 | 329 | * Note that since state 0 can be reached from any other state via deoptimization different loops |
aoqi@0 | 330 | * are possible. |
aoqi@0 | 331 | * |
aoqi@0 | 332 | */ |
aoqi@0 | 333 | |
aoqi@0 | 334 | // Common transition function. Given a predicate determines if a method should transition to another level. |
aoqi@0 | 335 | CompLevel AdvancedThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level, bool disable_feedback) { |
aoqi@0 | 336 | CompLevel next_level = cur_level; |
aoqi@0 | 337 | int i = method->invocation_count(); |
aoqi@0 | 338 | int b = method->backedge_count(); |
aoqi@0 | 339 | |
aoqi@0 | 340 | if (is_trivial(method)) { |
aoqi@0 | 341 | next_level = CompLevel_simple; |
aoqi@0 | 342 | } else { |
aoqi@0 | 343 | switch(cur_level) { |
aoqi@0 | 344 | case CompLevel_none: |
aoqi@0 | 345 | // If we were at full profile level, would we switch to full opt? |
aoqi@0 | 346 | if (common(p, method, CompLevel_full_profile, disable_feedback) == CompLevel_full_optimization) { |
aoqi@0 | 347 | next_level = CompLevel_full_optimization; |
aoqi@0 | 348 | } else if ((this->*p)(i, b, cur_level)) { |
aoqi@0 | 349 | // C1-generated fully profiled code is about 30% slower than the limited profile |
aoqi@0 | 350 | // code that has only invocation and backedge counters. The observation is that |
aoqi@0 | 351 | // if C2 queue is large enough we can spend too much time in the fully profiled code |
aoqi@0 | 352 | // while waiting for C2 to pick the method from the queue. To alleviate this problem |
aoqi@0 | 353 | // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long |
aoqi@0 | 354 | // we choose to compile a limited profiled version and then recompile with full profiling |
aoqi@0 | 355 | // when the load on C2 goes down. |
aoqi@0 | 356 | if (!disable_feedback && CompileBroker::queue_size(CompLevel_full_optimization) > |
aoqi@0 | 357 | Tier3DelayOn * compiler_count(CompLevel_full_optimization)) { |
aoqi@0 | 358 | next_level = CompLevel_limited_profile; |
aoqi@0 | 359 | } else { |
aoqi@0 | 360 | next_level = CompLevel_full_profile; |
aoqi@0 | 361 | } |
aoqi@0 | 362 | } |
aoqi@0 | 363 | break; |
aoqi@0 | 364 | case CompLevel_limited_profile: |
aoqi@0 | 365 | if (is_method_profiled(method)) { |
aoqi@0 | 366 | // Special case: we got here because this method was fully profiled in the interpreter. |
aoqi@0 | 367 | next_level = CompLevel_full_optimization; |
aoqi@0 | 368 | } else { |
aoqi@0 | 369 | MethodData* mdo = method->method_data(); |
aoqi@0 | 370 | if (mdo != NULL) { |
aoqi@0 | 371 | if (mdo->would_profile()) { |
aoqi@0 | 372 | if (disable_feedback || (CompileBroker::queue_size(CompLevel_full_optimization) <= |
aoqi@0 | 373 | Tier3DelayOff * compiler_count(CompLevel_full_optimization) && |
aoqi@0 | 374 | (this->*p)(i, b, cur_level))) { |
aoqi@0 | 375 | next_level = CompLevel_full_profile; |
aoqi@0 | 376 | } |
aoqi@0 | 377 | } else { |
aoqi@0 | 378 | next_level = CompLevel_full_optimization; |
aoqi@0 | 379 | } |
aoqi@0 | 380 | } |
aoqi@0 | 381 | } |
aoqi@0 | 382 | break; |
aoqi@0 | 383 | case CompLevel_full_profile: |
aoqi@0 | 384 | { |
aoqi@0 | 385 | MethodData* mdo = method->method_data(); |
aoqi@0 | 386 | if (mdo != NULL) { |
aoqi@0 | 387 | if (mdo->would_profile()) { |
aoqi@0 | 388 | int mdo_i = mdo->invocation_count_delta(); |
aoqi@0 | 389 | int mdo_b = mdo->backedge_count_delta(); |
aoqi@0 | 390 | if ((this->*p)(mdo_i, mdo_b, cur_level)) { |
aoqi@0 | 391 | next_level = CompLevel_full_optimization; |
aoqi@0 | 392 | } |
aoqi@0 | 393 | } else { |
aoqi@0 | 394 | next_level = CompLevel_full_optimization; |
aoqi@0 | 395 | } |
aoqi@0 | 396 | } |
aoqi@0 | 397 | } |
aoqi@0 | 398 | break; |
aoqi@0 | 399 | } |
aoqi@0 | 400 | } |
aoqi@0 | 401 | return MIN2(next_level, (CompLevel)TieredStopAtLevel); |
aoqi@0 | 402 | } |
aoqi@0 | 403 | |
aoqi@0 | 404 | // Determine if a method should be compiled with a normal entry point at a different level. |
aoqi@0 | 405 | CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level) { |
aoqi@0 | 406 | CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(), |
aoqi@0 | 407 | common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true)); |
aoqi@0 | 408 | CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level); |
aoqi@0 | 409 | |
aoqi@0 | 410 | // If OSR method level is greater than the regular method level, the levels should be |
aoqi@0 | 411 | // equalized by raising the regular method level in order to avoid OSRs during each |
aoqi@0 | 412 | // invocation of the method. |
aoqi@0 | 413 | if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) { |
aoqi@0 | 414 | MethodData* mdo = method->method_data(); |
aoqi@0 | 415 | guarantee(mdo != NULL, "MDO should not be NULL"); |
aoqi@0 | 416 | if (mdo->invocation_count() >= 1) { |
aoqi@0 | 417 | next_level = CompLevel_full_optimization; |
aoqi@0 | 418 | } |
aoqi@0 | 419 | } else { |
aoqi@0 | 420 | next_level = MAX2(osr_level, next_level); |
aoqi@0 | 421 | } |
aoqi@0 | 422 | return next_level; |
aoqi@0 | 423 | } |
aoqi@0 | 424 | |
aoqi@0 | 425 | // Determine if we should do an OSR compilation of a given method. |
aoqi@0 | 426 | CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level) { |
aoqi@0 | 427 | CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true); |
aoqi@0 | 428 | if (cur_level == CompLevel_none) { |
aoqi@0 | 429 | // If there is a live OSR method that means that we deopted to the interpreter |
aoqi@0 | 430 | // for the transition. |
aoqi@0 | 431 | CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level); |
aoqi@0 | 432 | if (osr_level > CompLevel_none) { |
aoqi@0 | 433 | return osr_level; |
aoqi@0 | 434 | } |
aoqi@0 | 435 | } |
aoqi@0 | 436 | return next_level; |
aoqi@0 | 437 | } |
aoqi@0 | 438 | |
aoqi@0 | 439 | // Update the rate and submit compile |
aoqi@0 | 440 | void AdvancedThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { |
aoqi@0 | 441 | int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count(); |
aoqi@0 | 442 | update_rate(os::javaTimeMillis(), mh()); |
aoqi@0 | 443 | CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread); |
aoqi@0 | 444 | } |
aoqi@0 | 445 | |
aoqi@0 | 446 | // Handle the invocation event. |
aoqi@0 | 447 | void AdvancedThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh, |
aoqi@0 | 448 | CompLevel level, nmethod* nm, JavaThread* thread) { |
aoqi@0 | 449 | if (should_create_mdo(mh(), level)) { |
aoqi@0 | 450 | create_mdo(mh, thread); |
aoqi@0 | 451 | } |
aoqi@0 | 452 | if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) { |
aoqi@0 | 453 | CompLevel next_level = call_event(mh(), level); |
aoqi@0 | 454 | if (next_level != level) { |
aoqi@0 | 455 | compile(mh, InvocationEntryBci, next_level, thread); |
aoqi@0 | 456 | } |
aoqi@0 | 457 | } |
aoqi@0 | 458 | } |
aoqi@0 | 459 | |
aoqi@0 | 460 | // Handle the back branch event. Notice that we can compile the method |
aoqi@0 | 461 | // with a regular entry from here. |
aoqi@0 | 462 | void AdvancedThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh, |
aoqi@0 | 463 | int bci, CompLevel level, nmethod* nm, JavaThread* thread) { |
aoqi@0 | 464 | if (should_create_mdo(mh(), level)) { |
aoqi@0 | 465 | create_mdo(mh, thread); |
aoqi@0 | 466 | } |
aoqi@0 | 467 | // Check if MDO should be created for the inlined method |
aoqi@0 | 468 | if (should_create_mdo(imh(), level)) { |
aoqi@0 | 469 | create_mdo(imh, thread); |
aoqi@0 | 470 | } |
aoqi@0 | 471 | |
aoqi@0 | 472 | if (is_compilation_enabled()) { |
aoqi@0 | 473 | CompLevel next_osr_level = loop_event(imh(), level); |
aoqi@0 | 474 | CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level(); |
aoqi@0 | 475 | // At the very least compile the OSR version |
aoqi@0 | 476 | if (!CompileBroker::compilation_is_in_queue(imh, bci) && next_osr_level != level) { |
aoqi@0 | 477 | compile(imh, bci, next_osr_level, thread); |
aoqi@0 | 478 | } |
aoqi@0 | 479 | |
aoqi@0 | 480 | // Use loop event as an opportunity to also check if there's been |
aoqi@0 | 481 | // enough calls. |
aoqi@0 | 482 | CompLevel cur_level, next_level; |
aoqi@0 | 483 | if (mh() != imh()) { // If there is an enclosing method |
aoqi@0 | 484 | guarantee(nm != NULL, "Should have nmethod here"); |
aoqi@0 | 485 | cur_level = comp_level(mh()); |
aoqi@0 | 486 | next_level = call_event(mh(), cur_level); |
aoqi@0 | 487 | |
aoqi@0 | 488 | if (max_osr_level == CompLevel_full_optimization) { |
aoqi@0 | 489 | // The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts |
aoqi@0 | 490 | bool make_not_entrant = false; |
aoqi@0 | 491 | if (nm->is_osr_method()) { |
aoqi@0 | 492 | // This is an osr method, just make it not entrant and recompile later if needed |
aoqi@0 | 493 | make_not_entrant = true; |
aoqi@0 | 494 | } else { |
aoqi@0 | 495 | if (next_level != CompLevel_full_optimization) { |
aoqi@0 | 496 | // next_level is not full opt, so we need to recompile the |
aoqi@0 | 497 | // enclosing method without the inlinee |
aoqi@0 | 498 | cur_level = CompLevel_none; |
aoqi@0 | 499 | make_not_entrant = true; |
aoqi@0 | 500 | } |
aoqi@0 | 501 | } |
aoqi@0 | 502 | if (make_not_entrant) { |
aoqi@0 | 503 | if (PrintTieredEvents) { |
aoqi@0 | 504 | int osr_bci = nm->is_osr_method() ? nm->osr_entry_bci() : InvocationEntryBci; |
aoqi@0 | 505 | print_event(MAKE_NOT_ENTRANT, mh(), mh(), osr_bci, level); |
aoqi@0 | 506 | } |
aoqi@0 | 507 | nm->make_not_entrant(); |
aoqi@0 | 508 | } |
aoqi@0 | 509 | } |
aoqi@0 | 510 | if (!CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) { |
aoqi@0 | 511 | // Fix up next_level if necessary to avoid deopts |
aoqi@0 | 512 | if (next_level == CompLevel_limited_profile && max_osr_level == CompLevel_full_profile) { |
aoqi@0 | 513 | next_level = CompLevel_full_profile; |
aoqi@0 | 514 | } |
aoqi@0 | 515 | if (cur_level != next_level) { |
aoqi@0 | 516 | compile(mh, InvocationEntryBci, next_level, thread); |
aoqi@0 | 517 | } |
aoqi@0 | 518 | } |
aoqi@0 | 519 | } else { |
aoqi@0 | 520 | cur_level = comp_level(imh()); |
aoqi@0 | 521 | next_level = call_event(imh(), cur_level); |
aoqi@0 | 522 | if (!CompileBroker::compilation_is_in_queue(imh, bci) && next_level != cur_level) { |
aoqi@0 | 523 | compile(imh, InvocationEntryBci, next_level, thread); |
aoqi@0 | 524 | } |
aoqi@0 | 525 | } |
aoqi@0 | 526 | } |
aoqi@0 | 527 | } |
aoqi@0 | 528 | |
aoqi@0 | 529 | #endif // TIERED |