< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page
rev 56252 : imported patch 8226705-v2


2956 
2957       if (log_is_enabled(Info, redefine, class, update)) {
2958         ResourceMark rm;
2959         if (!(*trace_name_printed)) {
2960           log_info(redefine, class, update)
2961             ("adjust: klassname=%s default methods from name=%s",
2962              external_name(), old_method->method_holder()->external_name());
2963           *trace_name_printed = true;
2964         }
2965         log_debug(redefine, class, update, vtables)
2966           ("default method update: %s(%s) ",
2967            new_method->name()->as_C_string(), new_method->signature()->as_C_string());
2968       }
2969     }
2970   }
2971 }
2972 #endif // INCLUDE_JVMTI
2973 
2974 // On-stack replacement stuff
2975 void InstanceKlass::add_osr_nmethod(nmethod* n) {

2976 #ifndef PRODUCT
2977   if (TieredCompilation) {
2978       nmethod * prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true);
2979       assert(prev == NULL || !prev->is_in_use(),
2980       "redundunt OSR recompilation detected. memory leak in CodeCache!");
2981   }
2982 #endif
2983   // only one compilation can be active
2984   {
2985     // This is a short non-blocking critical region, so the no safepoint check is ok.
2986     MutexLocker ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
2987     assert(n->is_osr_method(), "wrong kind of nmethod");
2988     n->set_osr_link(osr_nmethods_head());
2989     set_osr_nmethods_head(n);
2990     // Raise the highest osr level if necessary
2991     if (TieredCompilation) {
2992       Method* m = n->method();
2993       m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
2994     }
2995   }
2996 
2997   // Get rid of the osr methods for the same bci that have lower levels.
2998   if (TieredCompilation) {
2999     for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
3000       nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
3001       if (inv != NULL && inv->is_in_use()) {
3002         inv->make_not_entrant();
3003       }
3004     }
3005   }
3006 }
3007 
3008 // Remove osr nmethod from the list. Return true if found and removed.
3009 bool InstanceKlass::remove_osr_nmethod(nmethod* n) {
3010   // This is a short non-blocking critical region, so the no safepoint check is ok.
3011   MutexLocker ml(OsrList_lock, Mutex::_no_safepoint_check_flag);

3012   assert(n->is_osr_method(), "wrong kind of nmethod");
3013   nmethod* last = NULL;
3014   nmethod* cur  = osr_nmethods_head();
3015   int max_level = CompLevel_none;  // Find the max comp level excluding n
3016   Method* m = n->method();
3017   // Search for match
3018   bool found = false;
3019   while(cur != NULL && cur != n) {
3020     if (TieredCompilation && m == cur->method()) {
3021       // Find max level before n
3022       max_level = MAX2(max_level, cur->comp_level());
3023     }
3024     last = cur;
3025     cur = cur->osr_link();
3026   }
3027   nmethod* next = NULL;
3028   if (cur == n) {
3029     found = true;
3030     next = cur->osr_link();
3031     if (last == NULL) {


3034     } else {
3035       last->set_osr_link(next);
3036     }
3037   }
3038   n->set_osr_link(NULL);
3039   if (TieredCompilation) {
3040     cur = next;
3041     while (cur != NULL) {
3042       // Find max level after n
3043       if (m == cur->method()) {
3044         max_level = MAX2(max_level, cur->comp_level());
3045       }
3046       cur = cur->osr_link();
3047     }
3048     m->set_highest_osr_comp_level(max_level);
3049   }
3050   return found;
3051 }
3052 
3053 int InstanceKlass::mark_osr_nmethods(const Method* m) {
3054   // This is a short non-blocking critical region, so the no safepoint check is ok.
3055   MutexLocker ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
3056   nmethod* osr = osr_nmethods_head();
3057   int found = 0;
3058   while (osr != NULL) {
3059     assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
3060     if (osr->method() == m) {
3061       osr->mark_for_deoptimization();
3062       found++;
3063     }
3064     osr = osr->osr_link();
3065   }
3066   return found;
3067 }
3068 
3069 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
3070   // This is a short non-blocking critical region, so the no safepoint check is ok.
3071   MutexLocker ml(OsrList_lock, Mutex::_no_safepoint_check_flag);
3072   nmethod* osr = osr_nmethods_head();
3073   nmethod* best = NULL;
3074   while (osr != NULL) {
3075     assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
3076     // There can be a time when a c1 osr method exists but we are waiting
3077     // for a c2 version. When c2 completes its osr nmethod we will trash
3078     // the c1 version and only be able to find the c2 version. However
3079     // while we overflow in the c1 code at back branches we don't want to
3080     // try and switch to the same code as we are already running
3081 
3082     if (osr->method() == m &&
3083         (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
3084       if (match_level) {
3085         if (osr->comp_level() == comp_level) {
3086           // Found a match - return it.
3087           return osr;
3088         }
3089       } else {
3090         if (best == NULL || (osr->comp_level() > best->comp_level())) {
3091           if (osr->comp_level() == CompLevel_highest_tier) {




2956 
2957       if (log_is_enabled(Info, redefine, class, update)) {
2958         ResourceMark rm;
2959         if (!(*trace_name_printed)) {
2960           log_info(redefine, class, update)
2961             ("adjust: klassname=%s default methods from name=%s",
2962              external_name(), old_method->method_holder()->external_name());
2963           *trace_name_printed = true;
2964         }
2965         log_debug(redefine, class, update, vtables)
2966           ("default method update: %s(%s) ",
2967            new_method->name()->as_C_string(), new_method->signature()->as_C_string());
2968       }
2969     }
2970   }
2971 }
2972 #endif // INCLUDE_JVMTI
2973 
2974 // On-stack replacement stuff
2975 void InstanceKlass::add_osr_nmethod(nmethod* n) {
2976   assert_lock_strong(CompiledMethod_lock);
2977 #ifndef PRODUCT
2978   if (TieredCompilation) {
2979       nmethod * prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true);
2980       assert(prev == NULL || !prev->is_in_use(),
2981       "redundunt OSR recompilation detected. memory leak in CodeCache!");
2982   }
2983 #endif
2984   // only one compilation can be active
2985   {


2986     assert(n->is_osr_method(), "wrong kind of nmethod");
2987     n->set_osr_link(osr_nmethods_head());
2988     set_osr_nmethods_head(n);
2989     // Raise the highest osr level if necessary
2990     if (TieredCompilation) {
2991       Method* m = n->method();
2992       m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
2993     }
2994   }
2995 
2996   // Get rid of the osr methods for the same bci that have lower levels.
2997   if (TieredCompilation) {
2998     for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
2999       nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
3000       if (inv != NULL && inv->is_in_use()) {
3001         inv->make_not_entrant();
3002       }
3003     }
3004   }
3005 }
3006 
3007 // Remove osr nmethod from the list. Return true if found and removed.
3008 bool InstanceKlass::remove_osr_nmethod(nmethod* n) {
3009   // This is a short non-blocking critical region, so the no safepoint check is ok.
3010   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock
3011                  , Mutex::_no_safepoint_check_flag);
3012   assert(n->is_osr_method(), "wrong kind of nmethod");
3013   nmethod* last = NULL;
3014   nmethod* cur  = osr_nmethods_head();
3015   int max_level = CompLevel_none;  // Find the max comp level excluding n
3016   Method* m = n->method();
3017   // Search for match
3018   bool found = false;
3019   while(cur != NULL && cur != n) {
3020     if (TieredCompilation && m == cur->method()) {
3021       // Find max level before n
3022       max_level = MAX2(max_level, cur->comp_level());
3023     }
3024     last = cur;
3025     cur = cur->osr_link();
3026   }
3027   nmethod* next = NULL;
3028   if (cur == n) {
3029     found = true;
3030     next = cur->osr_link();
3031     if (last == NULL) {


3034     } else {
3035       last->set_osr_link(next);
3036     }
3037   }
3038   n->set_osr_link(NULL);
3039   if (TieredCompilation) {
3040     cur = next;
3041     while (cur != NULL) {
3042       // Find max level after n
3043       if (m == cur->method()) {
3044         max_level = MAX2(max_level, cur->comp_level());
3045       }
3046       cur = cur->osr_link();
3047     }
3048     m->set_highest_osr_comp_level(max_level);
3049   }
3050   return found;
3051 }
3052 
3053 int InstanceKlass::mark_osr_nmethods(const Method* m) {
3054   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock,
3055                  Mutex::_no_safepoint_check_flag);
3056   nmethod* osr = osr_nmethods_head();
3057   int found = 0;
3058   while (osr != NULL) {
3059     assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
3060     if (osr->method() == m) {
3061       osr->mark_for_deoptimization();
3062       found++;
3063     }
3064     osr = osr->osr_link();
3065   }
3066   return found;
3067 }
3068 
3069 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
3070   MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock,
3071                  Mutex::_no_safepoint_check_flag);
3072   nmethod* osr = osr_nmethods_head();
3073   nmethod* best = NULL;
3074   while (osr != NULL) {
3075     assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
3076     // There can be a time when a c1 osr method exists but we are waiting
3077     // for a c2 version. When c2 completes its osr nmethod we will trash
3078     // the c1 version and only be able to find the c2 version. However
3079     // while we overflow in the c1 code at back branches we don't want to
3080     // try and switch to the same code as we are already running
3081 
3082     if (osr->method() == m &&
3083         (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
3084       if (match_level) {
3085         if (osr->comp_level() == comp_level) {
3086           // Found a match - return it.
3087           return osr;
3088         }
3089       } else {
3090         if (best == NULL || (osr->comp_level() > best->comp_level())) {
3091           if (osr->comp_level() == CompLevel_highest_tier) {


< prev index next >