hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp
changeset 29316 5287df8a8972
parent 29081 c61eb4914428
child 29580 a67a581cfe11
child 29576 c223b0a9872e
equal deleted inserted replaced
29198:c1e6bf2dad41 29316:5287df8a8972
   780         u2 old_num = k_old_method->method_idnum();
   780         u2 old_num = k_old_method->method_idnum();
   781         if (new_num != old_num) {
   781         if (new_num != old_num) {
   782           Method* idnum_owner = scratch_class->method_with_idnum(old_num);
   782           Method* idnum_owner = scratch_class->method_with_idnum(old_num);
   783           if (idnum_owner != NULL) {
   783           if (idnum_owner != NULL) {
   784             // There is already a method assigned this idnum -- switch them
   784             // There is already a method assigned this idnum -- switch them
       
   785             // Take current and original idnum from the new_method
   785             idnum_owner->set_method_idnum(new_num);
   786             idnum_owner->set_method_idnum(new_num);
       
   787             idnum_owner->set_orig_method_idnum(k_new_method->orig_method_idnum());
   786           }
   788           }
       
   789           // Take current and original idnum from the old_method
   787           k_new_method->set_method_idnum(old_num);
   790           k_new_method->set_method_idnum(old_num);
       
   791           k_new_method->set_orig_method_idnum(k_old_method->orig_method_idnum());
   788           if (thread->has_pending_exception()) {
   792           if (thread->has_pending_exception()) {
   789             return JVMTI_ERROR_OUT_OF_MEMORY;
   793             return JVMTI_ERROR_OUT_OF_MEMORY;
   790           }
   794           }
   791         }
   795         }
   792       }
   796       }
   815         }
   819         }
   816         u2 new_num = k_new_method->method_idnum();
   820         u2 new_num = k_new_method->method_idnum();
   817         Method* idnum_owner = scratch_class->method_with_idnum(num);
   821         Method* idnum_owner = scratch_class->method_with_idnum(num);
   818         if (idnum_owner != NULL) {
   822         if (idnum_owner != NULL) {
   819           // There is already a method assigned this idnum -- switch them
   823           // There is already a method assigned this idnum -- switch them
       
   824           // Take current and original idnum from the new_method
   820           idnum_owner->set_method_idnum(new_num);
   825           idnum_owner->set_method_idnum(new_num);
       
   826           idnum_owner->set_orig_method_idnum(k_new_method->orig_method_idnum());
   821         }
   827         }
   822         k_new_method->set_method_idnum(num);
   828         k_new_method->set_method_idnum(num);
       
   829         k_new_method->set_orig_method_idnum(num);
   823         if (thread->has_pending_exception()) {
   830         if (thread->has_pending_exception()) {
   824           return JVMTI_ERROR_OUT_OF_MEMORY;
   831           return JVMTI_ERROR_OUT_OF_MEMORY;
   825         }
   832         }
   826       }
   833       }
   827       RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
   834       RC_TRACE(0x00008000, ("Method added: new: %s [%d]",
  3325 void VM_RedefineClasses::AdjustCpoolCacheAndVtable::do_klass(Klass* k) {
  3332 void VM_RedefineClasses::AdjustCpoolCacheAndVtable::do_klass(Klass* k) {
  3326 
  3333 
  3327   // This is a very busy routine. We don't want too much tracing
  3334   // This is a very busy routine. We don't want too much tracing
  3328   // printed out.
  3335   // printed out.
  3329   bool trace_name_printed = false;
  3336   bool trace_name_printed = false;
       
  3337   InstanceKlass *the_class = InstanceKlass::cast(_the_class_oop);
  3330 
  3338 
  3331   // Very noisy: only enable this call if you are trying to determine
  3339   // Very noisy: only enable this call if you are trying to determine
  3332   // that a specific class gets found by this routine.
  3340   // that a specific class gets found by this routine.
  3333   // RC_TRACE macro has an embedded ResourceMark
  3341   // RC_TRACE macro has an embedded ResourceMark
  3334   // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  3342   // RC_TRACE_WITH_THREAD(0x00100000, THREAD,
  3336   // trace_name_printed = true;
  3344   // trace_name_printed = true;
  3337 
  3345 
  3338   // If the class being redefined is java.lang.Object, we need to fix all
  3346   // If the class being redefined is java.lang.Object, we need to fix all
  3339   // array class vtables also
  3347   // array class vtables also
  3340   if (k->oop_is_array() && _the_class_oop == SystemDictionary::Object_klass()) {
  3348   if (k->oop_is_array() && _the_class_oop == SystemDictionary::Object_klass()) {
  3341     k->vtable()->adjust_method_entries(_matching_old_methods,
  3349     k->vtable()->adjust_method_entries(the_class, &trace_name_printed);
  3342                                        _matching_new_methods,
  3350 
  3343                                        _matching_methods_length,
       
  3344                                        &trace_name_printed);
       
  3345   } else if (k->oop_is_instance()) {
  3351   } else if (k->oop_is_instance()) {
  3346     HandleMark hm(_thread);
  3352     HandleMark hm(_thread);
  3347     InstanceKlass *ik = InstanceKlass::cast(k);
  3353     InstanceKlass *ik = InstanceKlass::cast(k);
  3348 
  3354 
  3349     // HotSpot specific optimization! HotSpot does not currently
  3355     // HotSpot specific optimization! HotSpot does not currently
  3381     if (ik->vtable_length() > 0 && (_the_class_oop->is_interface()
  3387     if (ik->vtable_length() > 0 && (_the_class_oop->is_interface()
  3382         || _the_class_oop == SystemDictionary::misc_Unsafe_klass()
  3388         || _the_class_oop == SystemDictionary::misc_Unsafe_klass()
  3383         || ik->is_subtype_of(_the_class_oop))) {
  3389         || ik->is_subtype_of(_the_class_oop))) {
  3384       // ik->vtable() creates a wrapper object; rm cleans it up
  3390       // ik->vtable() creates a wrapper object; rm cleans it up
  3385       ResourceMark rm(_thread);
  3391       ResourceMark rm(_thread);
  3386       ik->vtable()->adjust_method_entries(_matching_old_methods,
  3392 
  3387                                           _matching_new_methods,
  3393       ik->vtable()->adjust_method_entries(the_class, &trace_name_printed);
  3388                                           _matching_methods_length,
  3394       ik->adjust_default_methods(the_class, &trace_name_printed);
  3389                                           &trace_name_printed);
       
  3390       ik->adjust_default_methods(_matching_old_methods,
       
  3391                                  _matching_new_methods,
       
  3392                                  _matching_methods_length,
       
  3393                                  &trace_name_printed);
       
  3394     }
  3395     }
  3395 
  3396 
  3396     // If the current class has an itable and we are either redefining an
  3397     // If the current class has an itable and we are either redefining an
  3397     // interface or if the current class is a subclass of the_class, then
  3398     // interface or if the current class is a subclass of the_class, then
  3398     // we potentially have to fix the itable. If we are redefining an
  3399     // we potentially have to fix the itable. If we are redefining an
  3403     if (ik->itable_length() > 0 && (_the_class_oop->is_interface()
  3404     if (ik->itable_length() > 0 && (_the_class_oop->is_interface()
  3404         || _the_class_oop == SystemDictionary::misc_Unsafe_klass()
  3405         || _the_class_oop == SystemDictionary::misc_Unsafe_klass()
  3405         || ik->is_subclass_of(_the_class_oop))) {
  3406         || ik->is_subclass_of(_the_class_oop))) {
  3406       // ik->itable() creates a wrapper object; rm cleans it up
  3407       // ik->itable() creates a wrapper object; rm cleans it up
  3407       ResourceMark rm(_thread);
  3408       ResourceMark rm(_thread);
  3408       ik->itable()->adjust_method_entries(_matching_old_methods,
  3409 
  3409                                           _matching_new_methods,
  3410       ik->itable()->adjust_method_entries(the_class, &trace_name_printed);
  3410                                           _matching_methods_length,
       
  3411                                           &trace_name_printed);
       
  3412     }
  3411     }
  3413 
  3412 
  3414     // The constant pools in other classes (other_cp) can refer to
  3413     // The constant pools in other classes (other_cp) can refer to
  3415     // methods in the_class. We have to update method information in
  3414     // methods in the_class. We have to update method information in
  3416     // other_cp's cache. If other_cp has a previous version, then we
  3415     // other_cp's cache. If other_cp has a previous version, then we
  3430     if (ik != _the_class_oop) {
  3429     if (ik != _the_class_oop) {
  3431       // this klass' constant pool cache may need adjustment
  3430       // this klass' constant pool cache may need adjustment
  3432       other_cp = constantPoolHandle(ik->constants());
  3431       other_cp = constantPoolHandle(ik->constants());
  3433       cp_cache = other_cp->cache();
  3432       cp_cache = other_cp->cache();
  3434       if (cp_cache != NULL) {
  3433       if (cp_cache != NULL) {
  3435         cp_cache->adjust_method_entries(_matching_old_methods,
  3434         cp_cache->adjust_method_entries(the_class, &trace_name_printed);
  3436                                         _matching_new_methods,
       
  3437                                         _matching_methods_length,
       
  3438                                         &trace_name_printed);
       
  3439       }
  3435       }
  3440     }
  3436     }
  3441 
  3437 
  3442     // the previous versions' constant pool caches may need adjustment
  3438     // the previous versions' constant pool caches may need adjustment
  3443     for (InstanceKlass* pv_node = ik->previous_versions();
  3439     for (InstanceKlass* pv_node = ik->previous_versions();
  3576       old_method->set_is_obsolete();
  3572       old_method->set_is_obsolete();
  3577       obsolete_count++;
  3573       obsolete_count++;
  3578 
  3574 
  3579       // obsolete methods need a unique idnum so they become new entries in
  3575       // obsolete methods need a unique idnum so they become new entries in
  3580       // the jmethodID cache in InstanceKlass
  3576       // the jmethodID cache in InstanceKlass
       
  3577       assert(old_method->method_idnum() == new_method->method_idnum(), "must match");
  3581       u2 num = InstanceKlass::cast(_the_class_oop)->next_method_idnum();
  3578       u2 num = InstanceKlass::cast(_the_class_oop)->next_method_idnum();
  3582       if (num != ConstMethod::UNSET_IDNUM) {
  3579       if (num != ConstMethod::UNSET_IDNUM) {
  3583         old_method->set_method_idnum(num);
  3580         old_method->set_method_idnum(num);
  3584       }
  3581       }
  3585 
  3582