src/share/vm/runtime/simpleThresholdPolicy.cpp

Fri, 24 Jun 2016 17:12:13 +0800

author
aoqi<aoqi@loongson.cn>
date
Fri, 24 Jun 2016 17:12:13 +0800
changeset 25
873fd82b133d
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

[Code Reorganization] Removed GC related modifications made by Loongson, for example, UseOldNUMA.

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 "compiler/compileBroker.hpp"
aoqi@0 27 #include "memory/resourceArea.hpp"
aoqi@0 28 #include "runtime/arguments.hpp"
aoqi@0 29 #include "runtime/simpleThresholdPolicy.hpp"
aoqi@0 30 #include "runtime/simpleThresholdPolicy.inline.hpp"
aoqi@0 31 #include "code/scopeDesc.hpp"
aoqi@0 32
aoqi@0 33
aoqi@0 34 void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) {
aoqi@0 35 int invocation_count = mh->invocation_count();
aoqi@0 36 int backedge_count = mh->backedge_count();
aoqi@0 37 MethodData* mdh = mh->method_data();
aoqi@0 38 int mdo_invocations = 0, mdo_backedges = 0;
aoqi@0 39 int mdo_invocations_start = 0, mdo_backedges_start = 0;
aoqi@0 40 if (mdh != NULL) {
aoqi@0 41 mdo_invocations = mdh->invocation_count();
aoqi@0 42 mdo_backedges = mdh->backedge_count();
aoqi@0 43 mdo_invocations_start = mdh->invocation_count_start();
aoqi@0 44 mdo_backedges_start = mdh->backedge_count_start();
aoqi@0 45 }
aoqi@0 46 tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix,
aoqi@0 47 invocation_count, backedge_count, prefix,
aoqi@0 48 mdo_invocations, mdo_invocations_start,
aoqi@0 49 mdo_backedges, mdo_backedges_start);
aoqi@0 50 tty->print(" %smax levels=%d,%d", prefix,
aoqi@0 51 mh->highest_comp_level(), mh->highest_osr_comp_level());
aoqi@0 52 }
aoqi@0 53
aoqi@0 54 // Print an event.
aoqi@0 55 void SimpleThresholdPolicy::print_event(EventType type, methodHandle mh, methodHandle imh,
aoqi@0 56 int bci, CompLevel level) {
aoqi@0 57 bool inlinee_event = mh() != imh();
aoqi@0 58
aoqi@0 59 ttyLocker tty_lock;
aoqi@0 60 tty->print("%lf: [", os::elapsedTime());
aoqi@0 61
aoqi@0 62 switch(type) {
aoqi@0 63 case CALL:
aoqi@0 64 tty->print("call");
aoqi@0 65 break;
aoqi@0 66 case LOOP:
aoqi@0 67 tty->print("loop");
aoqi@0 68 break;
aoqi@0 69 case COMPILE:
aoqi@0 70 tty->print("compile");
aoqi@0 71 break;
aoqi@0 72 case REMOVE_FROM_QUEUE:
aoqi@0 73 tty->print("remove-from-queue");
aoqi@0 74 break;
aoqi@0 75 case UPDATE_IN_QUEUE:
aoqi@0 76 tty->print("update-in-queue");
aoqi@0 77 break;
aoqi@0 78 case REPROFILE:
aoqi@0 79 tty->print("reprofile");
aoqi@0 80 break;
aoqi@0 81 case MAKE_NOT_ENTRANT:
aoqi@0 82 tty->print("make-not-entrant");
aoqi@0 83 break;
aoqi@0 84 default:
aoqi@0 85 tty->print("unknown");
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 tty->print(" level=%d ", level);
aoqi@0 89
aoqi@0 90 ResourceMark rm;
aoqi@0 91 char *method_name = mh->name_and_sig_as_C_string();
aoqi@0 92 tty->print("[%s", method_name);
aoqi@0 93 if (inlinee_event) {
aoqi@0 94 char *inlinee_name = imh->name_and_sig_as_C_string();
aoqi@0 95 tty->print(" [%s]] ", inlinee_name);
aoqi@0 96 }
aoqi@0 97 else tty->print("] ");
aoqi@0 98 tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile),
aoqi@0 99 CompileBroker::queue_size(CompLevel_full_optimization));
aoqi@0 100
aoqi@0 101 print_specific(type, mh, imh, bci, level);
aoqi@0 102
aoqi@0 103 if (type != COMPILE) {
aoqi@0 104 print_counters("", mh);
aoqi@0 105 if (inlinee_event) {
aoqi@0 106 print_counters("inlinee ", imh);
aoqi@0 107 }
aoqi@0 108 tty->print(" compilable=");
aoqi@0 109 bool need_comma = false;
aoqi@0 110 if (!mh->is_not_compilable(CompLevel_full_profile)) {
aoqi@0 111 tty->print("c1");
aoqi@0 112 need_comma = true;
aoqi@0 113 }
aoqi@0 114 if (!mh->is_not_osr_compilable(CompLevel_full_profile)) {
aoqi@0 115 if (need_comma) tty->print(",");
aoqi@0 116 tty->print("c1-osr");
aoqi@0 117 need_comma = true;
aoqi@0 118 }
aoqi@0 119 if (!mh->is_not_compilable(CompLevel_full_optimization)) {
aoqi@0 120 if (need_comma) tty->print(",");
aoqi@0 121 tty->print("c2");
aoqi@0 122 need_comma = true;
aoqi@0 123 }
aoqi@0 124 if (!mh->is_not_osr_compilable(CompLevel_full_optimization)) {
aoqi@0 125 if (need_comma) tty->print(",");
aoqi@0 126 tty->print("c2-osr");
aoqi@0 127 }
aoqi@0 128 tty->print(" status=");
aoqi@0 129 if (mh->queued_for_compilation()) {
aoqi@0 130 tty->print("in-queue");
aoqi@0 131 } else tty->print("idle");
aoqi@0 132 }
aoqi@0 133 tty->print_cr("]");
aoqi@0 134 }
aoqi@0 135
aoqi@0 136 void SimpleThresholdPolicy::initialize() {
aoqi@0 137 if (FLAG_IS_DEFAULT(CICompilerCount)) {
aoqi@0 138 FLAG_SET_DEFAULT(CICompilerCount, 3);
aoqi@0 139 }
aoqi@0 140 int count = CICompilerCount;
aoqi@0 141 if (CICompilerCountPerCPU) {
aoqi@0 142 count = MAX2(log2_intptr(os::active_processor_count()), 1) * 3 / 2;
aoqi@0 143 }
aoqi@0 144 set_c1_count(MAX2(count / 3, 1));
aoqi@0 145 set_c2_count(MAX2(count - c1_count(), 1));
aoqi@0 146 FLAG_SET_ERGO(intx, CICompilerCount, c1_count() + c2_count());
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 void SimpleThresholdPolicy::set_carry_if_necessary(InvocationCounter *counter) {
aoqi@0 150 if (!counter->carry() && counter->count() > InvocationCounter::count_limit / 2) {
aoqi@0 151 counter->set_carry_flag();
aoqi@0 152 }
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 // Set carry flags on the counters if necessary
aoqi@0 156 void SimpleThresholdPolicy::handle_counter_overflow(Method* method) {
aoqi@0 157 MethodCounters *mcs = method->method_counters();
aoqi@0 158 if (mcs != NULL) {
aoqi@0 159 set_carry_if_necessary(mcs->invocation_counter());
aoqi@0 160 set_carry_if_necessary(mcs->backedge_counter());
aoqi@0 161 }
aoqi@0 162 MethodData* mdo = method->method_data();
aoqi@0 163 if (mdo != NULL) {
aoqi@0 164 set_carry_if_necessary(mdo->invocation_counter());
aoqi@0 165 set_carry_if_necessary(mdo->backedge_counter());
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 // Called with the queue locked and with at least one element
aoqi@0 170 CompileTask* SimpleThresholdPolicy::select_task(CompileQueue* compile_queue) {
aoqi@0 171 return compile_queue->first();
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 void SimpleThresholdPolicy::reprofile(ScopeDesc* trap_scope, bool is_osr) {
aoqi@0 175 for (ScopeDesc* sd = trap_scope;; sd = sd->sender()) {
aoqi@0 176 if (PrintTieredEvents) {
aoqi@0 177 methodHandle mh(sd->method());
aoqi@0 178 print_event(REPROFILE, mh, mh, InvocationEntryBci, CompLevel_none);
aoqi@0 179 }
aoqi@0 180 MethodData* mdo = sd->method()->method_data();
aoqi@0 181 if (mdo != NULL) {
aoqi@0 182 mdo->reset_start_counters();
aoqi@0 183 }
aoqi@0 184 if (sd->is_top()) break;
aoqi@0 185 }
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 nmethod* SimpleThresholdPolicy::event(methodHandle method, methodHandle inlinee,
aoqi@0 189 int branch_bci, int bci, CompLevel comp_level, nmethod* nm, JavaThread* thread) {
aoqi@0 190 if (comp_level == CompLevel_none &&
aoqi@0 191 JvmtiExport::can_post_interpreter_events() &&
aoqi@0 192 thread->is_interp_only_mode()) {
aoqi@0 193 return NULL;
aoqi@0 194 }
aoqi@0 195 if (CompileTheWorld || ReplayCompiles) {
aoqi@0 196 // Don't trigger other compiles in testing mode
aoqi@0 197 return NULL;
aoqi@0 198 }
aoqi@0 199 nmethod *osr_nm = NULL;
aoqi@0 200
aoqi@0 201 handle_counter_overflow(method());
aoqi@0 202 if (method() != inlinee()) {
aoqi@0 203 handle_counter_overflow(inlinee());
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 if (PrintTieredEvents) {
aoqi@0 207 print_event(bci == InvocationEntryBci ? CALL : LOOP, method, inlinee, bci, comp_level);
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 if (bci == InvocationEntryBci) {
aoqi@0 211 method_invocation_event(method, inlinee, comp_level, nm, thread);
aoqi@0 212 } else {
aoqi@0 213 method_back_branch_event(method, inlinee, bci, comp_level, nm, thread);
aoqi@0 214 // method == inlinee if the event originated in the main method
aoqi@0 215 int highest_level = inlinee->highest_osr_comp_level();
aoqi@0 216 if (highest_level > comp_level) {
aoqi@0 217 osr_nm = inlinee->lookup_osr_nmethod_for(bci, highest_level, false);
aoqi@0 218 }
aoqi@0 219 }
aoqi@0 220 return osr_nm;
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 // Check if the method can be compiled, change level if necessary
aoqi@0 224 void SimpleThresholdPolicy::compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) {
aoqi@0 225 assert(level <= TieredStopAtLevel, "Invalid compilation level");
aoqi@0 226 if (level == CompLevel_none) {
aoqi@0 227 return;
aoqi@0 228 }
aoqi@0 229 // Check if the method can be compiled. If it cannot be compiled with C1, continue profiling
aoqi@0 230 // in the interpreter and then compile with C2 (the transition function will request that,
aoqi@0 231 // see common() ). If the method cannot be compiled with C2 but still can with C1, compile it with
aoqi@0 232 // pure C1.
aoqi@0 233 if (!can_be_compiled(mh, level)) {
aoqi@0 234 if (level == CompLevel_full_optimization && can_be_compiled(mh, CompLevel_simple)) {
aoqi@0 235 compile(mh, bci, CompLevel_simple, thread);
aoqi@0 236 }
aoqi@0 237 return;
aoqi@0 238 }
aoqi@0 239 if (bci != InvocationEntryBci && mh->is_not_osr_compilable(level)) {
aoqi@0 240 return;
aoqi@0 241 }
aoqi@0 242 if (!CompileBroker::compilation_is_in_queue(mh, bci)) {
aoqi@0 243 if (PrintTieredEvents) {
aoqi@0 244 print_event(COMPILE, mh, mh, bci, level);
aoqi@0 245 }
aoqi@0 246 submit_compile(mh, bci, level, thread);
aoqi@0 247 }
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 // Tell the broker to compile the method
aoqi@0 251 void SimpleThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) {
aoqi@0 252 int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
aoqi@0 253 CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread);
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 // Call and loop predicates determine whether a transition to a higher
aoqi@0 257 // compilation level should be performed (pointers to predicate functions
aoqi@0 258 // are passed to common() transition function).
aoqi@0 259 bool SimpleThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
aoqi@0 260 switch(cur_level) {
aoqi@0 261 case CompLevel_none:
aoqi@0 262 case CompLevel_limited_profile: {
aoqi@0 263 return loop_predicate_helper<CompLevel_none>(i, b, 1.0);
aoqi@0 264 }
aoqi@0 265 case CompLevel_full_profile: {
aoqi@0 266 return loop_predicate_helper<CompLevel_full_profile>(i, b, 1.0);
aoqi@0 267 }
aoqi@0 268 default:
aoqi@0 269 return true;
aoqi@0 270 }
aoqi@0 271 }
aoqi@0 272
aoqi@0 273 bool SimpleThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) {
aoqi@0 274 switch(cur_level) {
aoqi@0 275 case CompLevel_none:
aoqi@0 276 case CompLevel_limited_profile: {
aoqi@0 277 return call_predicate_helper<CompLevel_none>(i, b, 1.0);
aoqi@0 278 }
aoqi@0 279 case CompLevel_full_profile: {
aoqi@0 280 return call_predicate_helper<CompLevel_full_profile>(i, b, 1.0);
aoqi@0 281 }
aoqi@0 282 default:
aoqi@0 283 return true;
aoqi@0 284 }
aoqi@0 285 }
aoqi@0 286
aoqi@0 287 // Determine is a method is mature.
aoqi@0 288 bool SimpleThresholdPolicy::is_mature(Method* method) {
aoqi@0 289 if (is_trivial(method)) return true;
aoqi@0 290 MethodData* mdo = method->method_data();
aoqi@0 291 if (mdo != NULL) {
aoqi@0 292 int i = mdo->invocation_count();
aoqi@0 293 int b = mdo->backedge_count();
aoqi@0 294 double k = ProfileMaturityPercentage / 100.0;
aoqi@0 295 return call_predicate_helper<CompLevel_full_profile>(i, b, k) ||
aoqi@0 296 loop_predicate_helper<CompLevel_full_profile>(i, b, k);
aoqi@0 297 }
aoqi@0 298 return false;
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 // Common transition function. Given a predicate determines if a method should transition to another level.
aoqi@0 302 CompLevel SimpleThresholdPolicy::common(Predicate p, Method* method, CompLevel cur_level) {
aoqi@0 303 CompLevel next_level = cur_level;
aoqi@0 304 int i = method->invocation_count();
aoqi@0 305 int b = method->backedge_count();
aoqi@0 306
aoqi@0 307 if (is_trivial(method)) {
aoqi@0 308 next_level = CompLevel_simple;
aoqi@0 309 } else {
aoqi@0 310 switch(cur_level) {
aoqi@0 311 case CompLevel_none:
aoqi@0 312 // If we were at full profile level, would we switch to full opt?
aoqi@0 313 if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
aoqi@0 314 next_level = CompLevel_full_optimization;
aoqi@0 315 } else if ((this->*p)(i, b, cur_level)) {
aoqi@0 316 next_level = CompLevel_full_profile;
aoqi@0 317 }
aoqi@0 318 break;
aoqi@0 319 case CompLevel_limited_profile:
aoqi@0 320 case CompLevel_full_profile:
aoqi@0 321 {
aoqi@0 322 MethodData* mdo = method->method_data();
aoqi@0 323 if (mdo != NULL) {
aoqi@0 324 if (mdo->would_profile()) {
aoqi@0 325 int mdo_i = mdo->invocation_count_delta();
aoqi@0 326 int mdo_b = mdo->backedge_count_delta();
aoqi@0 327 if ((this->*p)(mdo_i, mdo_b, cur_level)) {
aoqi@0 328 next_level = CompLevel_full_optimization;
aoqi@0 329 }
aoqi@0 330 } else {
aoqi@0 331 next_level = CompLevel_full_optimization;
aoqi@0 332 }
aoqi@0 333 }
aoqi@0 334 }
aoqi@0 335 break;
aoqi@0 336 }
aoqi@0 337 }
aoqi@0 338 return MIN2(next_level, (CompLevel)TieredStopAtLevel);
aoqi@0 339 }
aoqi@0 340
aoqi@0 341 // Determine if a method should be compiled with a normal entry point at a different level.
aoqi@0 342 CompLevel SimpleThresholdPolicy::call_event(Method* method, CompLevel cur_level) {
aoqi@0 343 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
aoqi@0 344 common(&SimpleThresholdPolicy::loop_predicate, method, cur_level));
aoqi@0 345 CompLevel next_level = common(&SimpleThresholdPolicy::call_predicate, method, cur_level);
aoqi@0 346
aoqi@0 347 // If OSR method level is greater than the regular method level, the levels should be
aoqi@0 348 // equalized by raising the regular method level in order to avoid OSRs during each
aoqi@0 349 // invocation of the method.
aoqi@0 350 if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
aoqi@0 351 MethodData* mdo = method->method_data();
aoqi@0 352 guarantee(mdo != NULL, "MDO should not be NULL");
aoqi@0 353 if (mdo->invocation_count() >= 1) {
aoqi@0 354 next_level = CompLevel_full_optimization;
aoqi@0 355 }
aoqi@0 356 } else {
aoqi@0 357 next_level = MAX2(osr_level, next_level);
aoqi@0 358 }
aoqi@0 359
aoqi@0 360 return next_level;
aoqi@0 361 }
aoqi@0 362
aoqi@0 363 // Determine if we should do an OSR compilation of a given method.
aoqi@0 364 CompLevel SimpleThresholdPolicy::loop_event(Method* method, CompLevel cur_level) {
aoqi@0 365 CompLevel next_level = common(&SimpleThresholdPolicy::loop_predicate, method, cur_level);
aoqi@0 366 if (cur_level == CompLevel_none) {
aoqi@0 367 // If there is a live OSR method that means that we deopted to the interpreter
aoqi@0 368 // for the transition.
aoqi@0 369 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
aoqi@0 370 if (osr_level > CompLevel_none) {
aoqi@0 371 return osr_level;
aoqi@0 372 }
aoqi@0 373 }
aoqi@0 374 return next_level;
aoqi@0 375 }
aoqi@0 376
aoqi@0 377
aoqi@0 378 // Handle the invocation event.
aoqi@0 379 void SimpleThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh,
aoqi@0 380 CompLevel level, nmethod* nm, JavaThread* thread) {
aoqi@0 381 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) {
aoqi@0 382 CompLevel next_level = call_event(mh(), level);
aoqi@0 383 if (next_level != level) {
aoqi@0 384 compile(mh, InvocationEntryBci, next_level, thread);
aoqi@0 385 }
aoqi@0 386 }
aoqi@0 387 }
aoqi@0 388
aoqi@0 389 // Handle the back branch event. Notice that we can compile the method
aoqi@0 390 // with a regular entry from here.
aoqi@0 391 void SimpleThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh,
aoqi@0 392 int bci, CompLevel level, nmethod* nm, JavaThread* thread) {
aoqi@0 393 // If the method is already compiling, quickly bail out.
aoqi@0 394 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) {
aoqi@0 395 // Use loop event as an opportinity to also check there's been
aoqi@0 396 // enough calls.
aoqi@0 397 CompLevel cur_level = comp_level(mh());
aoqi@0 398 CompLevel next_level = call_event(mh(), cur_level);
aoqi@0 399 CompLevel next_osr_level = loop_event(mh(), level);
aoqi@0 400
aoqi@0 401 next_level = MAX2(next_level,
aoqi@0 402 next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level);
aoqi@0 403 bool is_compiling = false;
aoqi@0 404 if (next_level != cur_level) {
aoqi@0 405 compile(mh, InvocationEntryBci, next_level, thread);
aoqi@0 406 is_compiling = true;
aoqi@0 407 }
aoqi@0 408
aoqi@0 409 // Do the OSR version
aoqi@0 410 if (!is_compiling && next_osr_level != level) {
aoqi@0 411 compile(mh, bci, next_osr_level, thread);
aoqi@0 412 }
aoqi@0 413 }
aoqi@0 414 }

mercurial