3478
3479 // On-stack replacement stuff
3480 void InstanceKlass::add_osr_nmethod(nmethod* n) {
3481 assert_lock_strong(NMethodState_lock);
3482 #ifndef PRODUCT
3483 nmethod* prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true);
3484 assert(prev == nullptr || !prev->is_in_use() COMPILER2_PRESENT(|| StressRecompilation),
3485 "redundant OSR recompilation detected. memory leak in CodeCache!");
3486 #endif
3487 // only one compilation can be active
3488 assert(n->is_osr_method(), "wrong kind of nmethod");
3489 n->set_osr_link(osr_nmethods_head());
3490 set_osr_nmethods_head(n);
3491 // Raise the highest osr level if necessary
3492 n->method()->set_highest_osr_comp_level(MAX2(n->method()->highest_osr_comp_level(), n->comp_level()));
3493
3494 // Get rid of the osr methods for the same bci that have lower levels.
3495 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
3496 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
3497 if (inv != nullptr && inv->is_in_use()) {
3498 inv->make_not_entrant(nmethod::ChangeReason::OSR_invalidation_of_lower_level);
3499 }
3500 }
3501 }
3502
3503 // Remove osr nmethod from the list. Return true if found and removed.
3504 bool InstanceKlass::remove_osr_nmethod(nmethod* n) {
3505 // This is a short non-blocking critical region, so the no safepoint check is ok.
3506 ConditionalMutexLocker ml(NMethodState_lock, !NMethodState_lock->owned_by_self(), Mutex::_no_safepoint_check_flag);
3507 assert(n->is_osr_method(), "wrong kind of nmethod");
3508 nmethod* last = nullptr;
3509 nmethod* cur = osr_nmethods_head();
3510 int max_level = CompLevel_none; // Find the max comp level excluding n
3511 Method* m = n->method();
3512 // Search for match
3513 bool found = false;
3514 while(cur != nullptr && cur != n) {
3515 if (m == cur->method()) {
3516 // Find max level before n
3517 max_level = MAX2(max_level, cur->comp_level());
3518 }
|
3478
3479 // On-stack replacement stuff
3480 void InstanceKlass::add_osr_nmethod(nmethod* n) {
3481 assert_lock_strong(NMethodState_lock);
3482 #ifndef PRODUCT
3483 nmethod* prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true);
3484 assert(prev == nullptr || !prev->is_in_use() COMPILER2_PRESENT(|| StressRecompilation),
3485 "redundant OSR recompilation detected. memory leak in CodeCache!");
3486 #endif
3487 // only one compilation can be active
3488 assert(n->is_osr_method(), "wrong kind of nmethod");
3489 n->set_osr_link(osr_nmethods_head());
3490 set_osr_nmethods_head(n);
3491 // Raise the highest osr level if necessary
3492 n->method()->set_highest_osr_comp_level(MAX2(n->method()->highest_osr_comp_level(), n->comp_level()));
3493
3494 // Get rid of the osr methods for the same bci that have lower levels.
3495 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
3496 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
3497 if (inv != nullptr && inv->is_in_use()) {
3498 inv->make_not_entrant(nmethod::InvalidationReason::OSR_INVALIDATION_OF_LOWER_LEVEL);
3499 }
3500 }
3501 }
3502
3503 // Remove osr nmethod from the list. Return true if found and removed.
3504 bool InstanceKlass::remove_osr_nmethod(nmethod* n) {
3505 // This is a short non-blocking critical region, so the no safepoint check is ok.
3506 ConditionalMutexLocker ml(NMethodState_lock, !NMethodState_lock->owned_by_self(), Mutex::_no_safepoint_check_flag);
3507 assert(n->is_osr_method(), "wrong kind of nmethod");
3508 nmethod* last = nullptr;
3509 nmethod* cur = osr_nmethods_head();
3510 int max_level = CompLevel_none; // Find the max comp level excluding n
3511 Method* m = n->method();
3512 // Search for match
3513 bool found = false;
3514 while(cur != nullptr && cur != n) {
3515 if (m == cur->method()) {
3516 // Find max level before n
3517 max_level = MAX2(max_level, cur->comp_level());
3518 }
|