2790 #endif // INCLUDE_JVMTI |
2790 #endif // INCLUDE_JVMTI |
2791 |
2791 |
2792 // On-stack replacement stuff |
2792 // On-stack replacement stuff |
2793 void InstanceKlass::add_osr_nmethod(nmethod* n) { |
2793 void InstanceKlass::add_osr_nmethod(nmethod* n) { |
2794 // only one compilation can be active |
2794 // only one compilation can be active |
2795 NEEDS_CLEANUP |
2795 { |
2796 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2796 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2797 OsrList_lock->lock_without_safepoint_check(); |
2797 MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag); |
2798 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2798 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2799 n->set_osr_link(osr_nmethods_head()); |
2799 n->set_osr_link(osr_nmethods_head()); |
2800 set_osr_nmethods_head(n); |
2800 set_osr_nmethods_head(n); |
2801 // Raise the highest osr level if necessary |
2801 // Raise the highest osr level if necessary |
2802 if (TieredCompilation) { |
2802 if (TieredCompilation) { |
2803 Method* m = n->method(); |
2803 Method* m = n->method(); |
2804 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); |
2804 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level())); |
2805 } |
2805 } |
2806 // Remember to unlock again |
2806 } |
2807 OsrList_lock->unlock(); |
|
2808 |
2807 |
2809 // Get rid of the osr methods for the same bci that have lower levels. |
2808 // Get rid of the osr methods for the same bci that have lower levels. |
2810 if (TieredCompilation) { |
2809 if (TieredCompilation) { |
2811 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) { |
2810 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) { |
2812 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true); |
2811 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true); |
2818 } |
2817 } |
2819 |
2818 |
2820 |
2819 |
2821 void InstanceKlass::remove_osr_nmethod(nmethod* n) { |
2820 void InstanceKlass::remove_osr_nmethod(nmethod* n) { |
2822 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2821 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2823 OsrList_lock->lock_without_safepoint_check(); |
2822 MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag); |
2824 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2823 assert(n->is_osr_method(), "wrong kind of nmethod"); |
2825 nmethod* last = NULL; |
2824 nmethod* last = NULL; |
2826 nmethod* cur = osr_nmethods_head(); |
2825 nmethod* cur = osr_nmethods_head(); |
2827 int max_level = CompLevel_none; // Find the max comp level excluding n |
2826 int max_level = CompLevel_none; // Find the max comp level excluding n |
2828 Method* m = n->method(); |
2827 Method* m = n->method(); |
2855 } |
2854 } |
2856 cur = cur->osr_link(); |
2855 cur = cur->osr_link(); |
2857 } |
2856 } |
2858 m->set_highest_osr_comp_level(max_level); |
2857 m->set_highest_osr_comp_level(max_level); |
2859 } |
2858 } |
2860 // Remember to unlock again |
2859 } |
2861 OsrList_lock->unlock(); |
2860 |
|
2861 int InstanceKlass::mark_osr_nmethods(const Method* m) { |
|
2862 // This is a short non-blocking critical region, so the no safepoint check is ok. |
|
2863 MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag); |
|
2864 nmethod* osr = osr_nmethods_head(); |
|
2865 int found = 0; |
|
2866 while (osr != NULL) { |
|
2867 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain"); |
|
2868 if (osr->method() == m) { |
|
2869 osr->mark_for_deoptimization(); |
|
2870 found++; |
|
2871 } |
|
2872 osr = osr->osr_link(); |
|
2873 } |
|
2874 return found; |
2862 } |
2875 } |
2863 |
2876 |
2864 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const { |
2877 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const { |
2865 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2878 // This is a short non-blocking critical region, so the no safepoint check is ok. |
2866 OsrList_lock->lock_without_safepoint_check(); |
2879 MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag); |
2867 nmethod* osr = osr_nmethods_head(); |
2880 nmethod* osr = osr_nmethods_head(); |
2868 nmethod* best = NULL; |
2881 nmethod* best = NULL; |
2869 while (osr != NULL) { |
2882 while (osr != NULL) { |
2870 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain"); |
2883 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain"); |
2871 // There can be a time when a c1 osr method exists but we are waiting |
2884 // There can be a time when a c1 osr method exists but we are waiting |
2877 if (osr->method() == m && |
2890 if (osr->method() == m && |
2878 (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) { |
2891 (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) { |
2879 if (match_level) { |
2892 if (match_level) { |
2880 if (osr->comp_level() == comp_level) { |
2893 if (osr->comp_level() == comp_level) { |
2881 // Found a match - return it. |
2894 // Found a match - return it. |
2882 OsrList_lock->unlock(); |
|
2883 return osr; |
2895 return osr; |
2884 } |
2896 } |
2885 } else { |
2897 } else { |
2886 if (best == NULL || (osr->comp_level() > best->comp_level())) { |
2898 if (best == NULL || (osr->comp_level() > best->comp_level())) { |
2887 if (osr->comp_level() == CompLevel_highest_tier) { |
2899 if (osr->comp_level() == CompLevel_highest_tier) { |
2888 // Found the best possible - return it. |
2900 // Found the best possible - return it. |
2889 OsrList_lock->unlock(); |
|
2890 return osr; |
2901 return osr; |
2891 } |
2902 } |
2892 best = osr; |
2903 best = osr; |
2893 } |
2904 } |
2894 } |
2905 } |
2895 } |
2906 } |
2896 osr = osr->osr_link(); |
2907 osr = osr->osr_link(); |
2897 } |
2908 } |
2898 OsrList_lock->unlock(); |
|
2899 if (best != NULL && best->comp_level() >= comp_level && match_level == false) { |
2909 if (best != NULL && best->comp_level() >= comp_level && match_level == false) { |
2900 return best; |
2910 return best; |
2901 } |
2911 } |
2902 return NULL; |
2912 return NULL; |
2903 } |
2913 } |