comparison src/share/vm/runtime/advancedThresholdPolicy.cpp @ 23379:24505bf61633

allow JVMCI compiler to change the compilation policy for a method (JDK-8152311)
author Doug Simon <doug.simon@oracle.com>
date Mon, 09 May 2016 16:08:16 +0200
parents 9d78d44d3aac
children 3ef45d0a6d77
comparison
equal deleted inserted replaced
23378:b11f345e4af4 23379:24505bf61633
23 */ 23 */
24 24
25 #include "precompiled.hpp" 25 #include "precompiled.hpp"
26 #include "runtime/advancedThresholdPolicy.hpp" 26 #include "runtime/advancedThresholdPolicy.hpp"
27 #include "runtime/simpleThresholdPolicy.inline.hpp" 27 #include "runtime/simpleThresholdPolicy.inline.hpp"
28 #ifdef COMPILERJVMCI
29 #include "jvmci/jvmciRuntime.hpp"
30 #endif
28 31
29 #ifdef TIERED 32 #ifdef TIERED
30 // Print an event. 33 // Print an event.
31 void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh, 34 void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh,
32 int bci, CompLevel level) { 35 int bci, CompLevel level) {
431 } 434 }
432 return MIN2(next_level, (CompLevel)TieredStopAtLevel); 435 return MIN2(next_level, (CompLevel)TieredStopAtLevel);
433 } 436 }
434 437
435 // Determine if a method should be compiled with a normal entry point at a different level. 438 // Determine if a method should be compiled with a normal entry point at a different level.
436 CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level) { 439 CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level, JavaThread * thread) {
437 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(), 440 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
438 common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true)); 441 common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true));
439 CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level); 442 CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
440 443
441 // If OSR method level is greater than the regular method level, the levels should be 444 // If OSR method level is greater than the regular method level, the levels should be
448 next_level = CompLevel_full_optimization; 451 next_level = CompLevel_full_optimization;
449 } 452 }
450 } else { 453 } else {
451 next_level = MAX2(osr_level, next_level); 454 next_level = MAX2(osr_level, next_level);
452 } 455 }
456 COMPILERJVMCI_PRESENT(next_level = JVMCIRuntime::adjust_comp_level(method, false, next_level, thread);)
453 return next_level; 457 return next_level;
454 } 458 }
455 459
456 // Determine if we should do an OSR compilation of a given method. 460 // Determine if we should do an OSR compilation of a given method.
457 CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level) { 461 CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level, JavaThread * thread) {
458 CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true); 462 CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true);
459 if (cur_level == CompLevel_none) { 463 if (cur_level == CompLevel_none) {
460 // If there is a live OSR method that means that we deopted to the interpreter 464 // If there is a live OSR method that means that we deopted to the interpreter
461 // for the transition. 465 // for the transition.
462 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level); 466 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
463 if (osr_level > CompLevel_none) { 467 if (osr_level > CompLevel_none) {
464 return osr_level; 468 return osr_level;
465 } 469 }
466 } 470 }
471 COMPILERJVMCI_PRESENT(next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);)
467 return next_level; 472 return next_level;
468 } 473 }
469 474
470 // Update the rate and submit compile 475 // Update the rate and submit compile
471 void AdvancedThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) { 476 void AdvancedThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, JavaThread* thread) {
479 CompLevel level, nmethod* nm, JavaThread* thread) { 484 CompLevel level, nmethod* nm, JavaThread* thread) {
480 if (should_create_mdo(mh(), level)) { 485 if (should_create_mdo(mh(), level)) {
481 create_mdo(mh, thread); 486 create_mdo(mh, thread);
482 } 487 }
483 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) { 488 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
484 CompLevel next_level = call_event(mh(), level); 489 CompLevel next_level = call_event(mh(), level, thread);
485 if (next_level != level) { 490 if (next_level != level) {
486 compile(mh, InvocationEntryBci, next_level, thread); 491 compile(mh, InvocationEntryBci, next_level, thread);
487 } 492 }
488 } 493 }
489 } 494 }
499 if (should_create_mdo(imh(), level)) { 504 if (should_create_mdo(imh(), level)) {
500 create_mdo(imh, thread); 505 create_mdo(imh, thread);
501 } 506 }
502 507
503 if (is_compilation_enabled()) { 508 if (is_compilation_enabled()) {
504 CompLevel next_osr_level = loop_event(imh(), level); 509 CompLevel next_osr_level = loop_event(imh(), level, thread);
505 CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level(); 510 CompLevel max_osr_level = (CompLevel)imh->highest_osr_comp_level();
506 // At the very least compile the OSR version 511 // At the very least compile the OSR version
507 if (!CompileBroker::compilation_is_in_queue(imh) && (next_osr_level != level)) { 512 if (!CompileBroker::compilation_is_in_queue(imh) && (next_osr_level != level)) {
508 compile(imh, bci, next_osr_level, thread); 513 compile(imh, bci, next_osr_level, thread);
509 } 514 }
512 // enough calls. 517 // enough calls.
513 CompLevel cur_level, next_level; 518 CompLevel cur_level, next_level;
514 if (mh() != imh()) { // If there is an enclosing method 519 if (mh() != imh()) { // If there is an enclosing method
515 guarantee(nm != NULL, "Should have nmethod here"); 520 guarantee(nm != NULL, "Should have nmethod here");
516 cur_level = comp_level(mh()); 521 cur_level = comp_level(mh());
517 next_level = call_event(mh(), cur_level); 522 next_level = call_event(mh(), cur_level, thread);
518 523
519 if (max_osr_level == CompLevel_full_optimization) { 524 if (max_osr_level == CompLevel_full_optimization) {
520 // The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts 525 // The inlinee OSRed to full opt, we need to modify the enclosing method to avoid deopts
521 bool make_not_entrant = false; 526 bool make_not_entrant = false;
522 if (nm->is_osr_method()) { 527 if (nm->is_osr_method()) {
547 compile(mh, InvocationEntryBci, next_level, thread); 552 compile(mh, InvocationEntryBci, next_level, thread);
548 } 553 }
549 } 554 }
550 } else { 555 } else {
551 cur_level = comp_level(imh()); 556 cur_level = comp_level(imh());
552 next_level = call_event(imh(), cur_level); 557 next_level = call_event(imh(), cur_level, thread);
553 if (!CompileBroker::compilation_is_in_queue(imh) && (next_level != cur_level)) { 558 if (!CompileBroker::compilation_is_in_queue(imh) && (next_level != cur_level)) {
554 compile(imh, InvocationEntryBci, next_level, thread); 559 compile(imh, InvocationEntryBci, next_level, thread);
555 } 560 }
556 } 561 }
557 } 562 }