hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 27409 03622fc45677
parent 26558 b7df27df6384
child 27434 b4b185d05bb5
equal deleted inserted replaced
27148:a4b542d56e01 27409:03622fc45677
  2777 #endif // INCLUDE_JVMTI
  2777 #endif // INCLUDE_JVMTI
  2778 
  2778 
  2779 // On-stack replacement stuff
  2779 // On-stack replacement stuff
  2780 void InstanceKlass::add_osr_nmethod(nmethod* n) {
  2780 void InstanceKlass::add_osr_nmethod(nmethod* n) {
  2781   // only one compilation can be active
  2781   // only one compilation can be active
  2782   NEEDS_CLEANUP
  2782   {
  2783   // This is a short non-blocking critical region, so the no safepoint check is ok.
  2783     // This is a short non-blocking critical region, so the no safepoint check is ok.
  2784   OsrList_lock->lock_without_safepoint_check();
  2784     MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
  2785   assert(n->is_osr_method(), "wrong kind of nmethod");
  2785     assert(n->is_osr_method(), "wrong kind of nmethod");
  2786   n->set_osr_link(osr_nmethods_head());
  2786     n->set_osr_link(osr_nmethods_head());
  2787   set_osr_nmethods_head(n);
  2787     set_osr_nmethods_head(n);
  2788   // Raise the highest osr level if necessary
  2788     // Raise the highest osr level if necessary
  2789   if (TieredCompilation) {
  2789     if (TieredCompilation) {
  2790     Method* m = n->method();
  2790       Method* m = n->method();
  2791     m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
  2791       m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
  2792   }
  2792     }
  2793   // Remember to unlock again
  2793   }
  2794   OsrList_lock->unlock();
       
  2795 
  2794 
  2796   // Get rid of the osr methods for the same bci that have lower levels.
  2795   // Get rid of the osr methods for the same bci that have lower levels.
  2797   if (TieredCompilation) {
  2796   if (TieredCompilation) {
  2798     for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
  2797     for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
  2799       nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
  2798       nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
  2805 }
  2804 }
  2806 
  2805 
  2807 
  2806 
  2808 void InstanceKlass::remove_osr_nmethod(nmethod* n) {
  2807 void InstanceKlass::remove_osr_nmethod(nmethod* n) {
  2809   // This is a short non-blocking critical region, so the no safepoint check is ok.
  2808   // This is a short non-blocking critical region, so the no safepoint check is ok.
  2810   OsrList_lock->lock_without_safepoint_check();
  2809   MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
  2811   assert(n->is_osr_method(), "wrong kind of nmethod");
  2810   assert(n->is_osr_method(), "wrong kind of nmethod");
  2812   nmethod* last = NULL;
  2811   nmethod* last = NULL;
  2813   nmethod* cur  = osr_nmethods_head();
  2812   nmethod* cur  = osr_nmethods_head();
  2814   int max_level = CompLevel_none;  // Find the max comp level excluding n
  2813   int max_level = CompLevel_none;  // Find the max comp level excluding n
  2815   Method* m = n->method();
  2814   Method* m = n->method();
  2842       }
  2841       }
  2843       cur = cur->osr_link();
  2842       cur = cur->osr_link();
  2844     }
  2843     }
  2845     m->set_highest_osr_comp_level(max_level);
  2844     m->set_highest_osr_comp_level(max_level);
  2846   }
  2845   }
  2847   // Remember to unlock again
       
  2848   OsrList_lock->unlock();
       
  2849 }
  2846 }
  2850 
  2847 
  2851 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
  2848 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
  2852   // This is a short non-blocking critical region, so the no safepoint check is ok.
  2849   // This is a short non-blocking critical region, so the no safepoint check is ok.
  2853   OsrList_lock->lock_without_safepoint_check();
  2850   MutexLockerEx ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
  2854   nmethod* osr = osr_nmethods_head();
  2851   nmethod* osr = osr_nmethods_head();
  2855   nmethod* best = NULL;
  2852   nmethod* best = NULL;
  2856   while (osr != NULL) {
  2853   while (osr != NULL) {
  2857     assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
  2854     assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
  2858     // There can be a time when a c1 osr method exists but we are waiting
  2855     // There can be a time when a c1 osr method exists but we are waiting
  2864     if (osr->method() == m &&
  2861     if (osr->method() == m &&
  2865         (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
  2862         (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
  2866       if (match_level) {
  2863       if (match_level) {
  2867         if (osr->comp_level() == comp_level) {
  2864         if (osr->comp_level() == comp_level) {
  2868           // Found a match - return it.
  2865           // Found a match - return it.
  2869           OsrList_lock->unlock();
       
  2870           return osr;
  2866           return osr;
  2871         }
  2867         }
  2872       } else {
  2868       } else {
  2873         if (best == NULL || (osr->comp_level() > best->comp_level())) {
  2869         if (best == NULL || (osr->comp_level() > best->comp_level())) {
  2874           if (osr->comp_level() == CompLevel_highest_tier) {
  2870           if (osr->comp_level() == CompLevel_highest_tier) {
  2875             // Found the best possible - return it.
  2871             // Found the best possible - return it.
  2876             OsrList_lock->unlock();
       
  2877             return osr;
  2872             return osr;
  2878           }
  2873           }
  2879           best = osr;
  2874           best = osr;
  2880         }
  2875         }
  2881       }
  2876       }
  2882     }
  2877     }
  2883     osr = osr->osr_link();
  2878     osr = osr->osr_link();
  2884   }
  2879   }
  2885   OsrList_lock->unlock();
       
  2886   if (best != NULL && best->comp_level() >= comp_level && match_level == false) {
  2880   if (best != NULL && best->comp_level() >= comp_level && match_level == false) {
  2887     return best;
  2881     return best;
  2888   }
  2882   }
  2889   return NULL;
  2883   return NULL;
  2890 }
  2884 }