60 Array<Method*>* VM_RedefineClasses::_new_methods = NULL; |
60 Array<Method*>* VM_RedefineClasses::_new_methods = NULL; |
61 Method** VM_RedefineClasses::_matching_old_methods = NULL; |
61 Method** VM_RedefineClasses::_matching_old_methods = NULL; |
62 Method** VM_RedefineClasses::_matching_new_methods = NULL; |
62 Method** VM_RedefineClasses::_matching_new_methods = NULL; |
63 Method** VM_RedefineClasses::_deleted_methods = NULL; |
63 Method** VM_RedefineClasses::_deleted_methods = NULL; |
64 Method** VM_RedefineClasses::_added_methods = NULL; |
64 Method** VM_RedefineClasses::_added_methods = NULL; |
65 int VM_RedefineClasses::_matching_methods_length = 0; |
65 int VM_RedefineClasses::_matching_methods_length = 0; |
66 int VM_RedefineClasses::_deleted_methods_length = 0; |
66 int VM_RedefineClasses::_deleted_methods_length = 0; |
67 int VM_RedefineClasses::_added_methods_length = 0; |
67 int VM_RedefineClasses::_added_methods_length = 0; |
68 Klass* VM_RedefineClasses::_the_class = NULL; |
68 bool VM_RedefineClasses::_has_redefined_Object = false; |
|
69 bool VM_RedefineClasses::_has_null_class_loader = false; |
69 |
70 |
70 |
71 |
71 VM_RedefineClasses::VM_RedefineClasses(jint class_count, |
72 VM_RedefineClasses::VM_RedefineClasses(jint class_count, |
72 const jvmtiClassDefinition *class_defs, |
73 const jvmtiClassDefinition *class_defs, |
73 JvmtiClassLoadKind class_load_kind) { |
74 JvmtiClassLoadKind class_load_kind) { |
74 _class_count = class_count; |
75 _class_count = class_count; |
75 _class_defs = class_defs; |
76 _class_defs = class_defs; |
76 _class_load_kind = class_load_kind; |
77 _class_load_kind = class_load_kind; |
77 _any_class_has_resolved_methods = false; |
78 _any_class_has_resolved_methods = false; |
78 _res = JVMTI_ERROR_NONE; |
79 _res = JVMTI_ERROR_NONE; |
|
80 _the_class = NULL; |
|
81 _has_redefined_Object = false; |
|
82 _has_null_class_loader = false; |
79 } |
83 } |
80 |
84 |
81 static inline InstanceKlass* get_ik(jclass def) { |
85 static inline InstanceKlass* get_ik(jclass def) { |
82 oop mirror = JNIHandles::resolve_non_null(def); |
86 oop mirror = JNIHandles::resolve_non_null(def); |
83 return InstanceKlass::cast(java_lang_Class::as_Klass(mirror)); |
87 return InstanceKlass::cast(java_lang_Class::as_Klass(mirror)); |
3413 |
3418 |
3414 |
3419 |
3415 // Unevolving classes may point to methods of the_class directly |
3420 // Unevolving classes may point to methods of the_class directly |
3416 // from their constant pool caches, itables, and/or vtables. We |
3421 // from their constant pool caches, itables, and/or vtables. We |
3417 // use the ClassLoaderDataGraph::classes_do() facility and this helper |
3422 // use the ClassLoaderDataGraph::classes_do() facility and this helper |
3418 // to fix up these pointers. |
3423 // to fix up these pointers. MethodData also points to old methods and |
|
3424 // must be cleaned. |
3419 |
3425 |
3420 // Adjust cpools and vtables closure |
3426 // Adjust cpools and vtables closure |
3421 void VM_RedefineClasses::AdjustCpoolCacheAndVtable::do_klass(Klass* k) { |
3427 void VM_RedefineClasses::AdjustAndCleanMetadata::do_klass(Klass* k) { |
3422 |
3428 |
3423 // This is a very busy routine. We don't want too much tracing |
3429 // This is a very busy routine. We don't want too much tracing |
3424 // printed out. |
3430 // printed out. |
3425 bool trace_name_printed = false; |
3431 bool trace_name_printed = false; |
3426 InstanceKlass *the_class = InstanceKlass::cast(_the_class); |
|
3427 |
3432 |
3428 // If the class being redefined is java.lang.Object, we need to fix all |
3433 // If the class being redefined is java.lang.Object, we need to fix all |
3429 // array class vtables also |
3434 // array class vtables also |
3430 if (k->is_array_klass() && _the_class == SystemDictionary::Object_klass()) { |
3435 if (k->is_array_klass() && _has_redefined_Object) { |
3431 k->vtable().adjust_method_entries(the_class, &trace_name_printed); |
3436 k->vtable().adjust_method_entries(&trace_name_printed); |
3432 |
3437 |
3433 } else if (k->is_instance_klass()) { |
3438 } else if (k->is_instance_klass()) { |
3434 HandleMark hm(_thread); |
3439 HandleMark hm(_thread); |
3435 InstanceKlass *ik = InstanceKlass::cast(k); |
3440 InstanceKlass *ik = InstanceKlass::cast(k); |
|
3441 |
|
3442 // Clean MethodData of this class's methods so they don't refer to |
|
3443 // old methods that are no longer running. |
|
3444 Array<Method*>* methods = ik->methods(); |
|
3445 int num_methods = methods->length(); |
|
3446 for (int index = 0; index < num_methods; ++index) { |
|
3447 if (methods->at(index)->method_data() != NULL) { |
|
3448 methods->at(index)->method_data()->clean_weak_method_links(); |
|
3449 } |
|
3450 } |
3436 |
3451 |
3437 // HotSpot specific optimization! HotSpot does not currently |
3452 // HotSpot specific optimization! HotSpot does not currently |
3438 // support delegation from the bootstrap class loader to a |
3453 // support delegation from the bootstrap class loader to a |
3439 // user-defined class loader. This means that if the bootstrap |
3454 // user-defined class loader. This means that if the bootstrap |
3440 // class loader is the initiating class loader, then it will also |
3455 // class loader is the initiating class loader, then it will also |
3444 // class loader can delegate to the bootstrap class loader. |
3459 // class loader can delegate to the bootstrap class loader. |
3445 // |
3460 // |
3446 // If the current class being redefined has a user-defined class |
3461 // If the current class being redefined has a user-defined class |
3447 // loader as its defining class loader, then we can skip all |
3462 // loader as its defining class loader, then we can skip all |
3448 // classes loaded by the bootstrap class loader. |
3463 // classes loaded by the bootstrap class loader. |
3449 bool is_user_defined = (_the_class->class_loader() != NULL); |
3464 if (!_has_null_class_loader && ik->class_loader() == NULL) { |
3450 if (is_user_defined && ik->class_loader() == NULL) { |
|
3451 return; |
3465 return; |
3452 } |
3466 } |
3453 |
3467 |
3454 // Fix the vtable embedded in the_class and subclasses of the_class, |
3468 // Adjust all vtables, default methods and itables, to clean out old methods. |
3455 // if one exists. We discard scratch_class and we don't keep an |
3469 ResourceMark rm(_thread); |
3456 // InstanceKlass around to hold obsolete methods so we don't have |
3470 if (ik->vtable_length() > 0) { |
3457 // any other InstanceKlass embedded vtables to update. The vtable |
3471 ik->vtable().adjust_method_entries(&trace_name_printed); |
3458 // holds the Method*s for virtual (but not final) methods. |
3472 ik->adjust_default_methods(&trace_name_printed); |
3459 // Default methods, or concrete methods in interfaces are stored |
3473 } |
3460 // in the vtable, so if an interface changes we need to check |
3474 |
3461 // adjust_method_entries() for every InstanceKlass, which will also |
3475 if (ik->itable_length() > 0) { |
3462 // adjust the default method vtable indices. |
3476 ik->itable().adjust_method_entries(&trace_name_printed); |
3463 // We also need to adjust any default method entries that are |
|
3464 // not yet in the vtable, because the vtable setup is in progress. |
|
3465 // This must be done after we adjust the default_methods and |
|
3466 // default_vtable_indices for methods already in the vtable. |
|
3467 // If redefining Unsafe, walk all the vtables looking for entries. |
|
3468 if (ik->vtable_length() > 0 && (_the_class->is_interface() |
|
3469 || _the_class == SystemDictionary::internal_Unsafe_klass() |
|
3470 || ik->is_subtype_of(_the_class))) { |
|
3471 // ik->vtable() creates a wrapper object; rm cleans it up |
|
3472 ResourceMark rm(_thread); |
|
3473 |
|
3474 ik->vtable().adjust_method_entries(the_class, &trace_name_printed); |
|
3475 ik->adjust_default_methods(the_class, &trace_name_printed); |
|
3476 } |
|
3477 |
|
3478 // If the current class has an itable and we are either redefining an |
|
3479 // interface or if the current class is a subclass of the_class, then |
|
3480 // we potentially have to fix the itable. If we are redefining an |
|
3481 // interface, then we have to call adjust_method_entries() for |
|
3482 // every InstanceKlass that has an itable since there isn't a |
|
3483 // subclass relationship between an interface and an InstanceKlass. |
|
3484 // If redefining Unsafe, walk all the itables looking for entries. |
|
3485 if (ik->itable_length() > 0 && (_the_class->is_interface() |
|
3486 || _the_class == SystemDictionary::internal_Unsafe_klass() |
|
3487 || ik->is_subclass_of(_the_class))) { |
|
3488 ResourceMark rm(_thread); |
|
3489 ik->itable().adjust_method_entries(the_class, &trace_name_printed); |
|
3490 } |
3477 } |
3491 |
3478 |
3492 // The constant pools in other classes (other_cp) can refer to |
3479 // The constant pools in other classes (other_cp) can refer to |
3493 // methods in the_class. We have to update method information in |
3480 // old methods. We have to update method information in |
3494 // other_cp's cache. If other_cp has a previous version, then we |
3481 // other_cp's cache. If other_cp has a previous version, then we |
3495 // have to repeat the process for each previous version. The |
3482 // have to repeat the process for each previous version. The |
3496 // constant pool cache holds the Method*s for non-virtual |
3483 // constant pool cache holds the Method*s for non-virtual |
3497 // methods and for virtual, final methods. |
3484 // methods and for virtual, final methods. |
3498 // |
3485 // |
3499 // Special case: if the current class is the_class, then new_cp |
3486 // Special case: if the current class being redefined, then new_cp |
3500 // has already been attached to the_class and old_cp has already |
3487 // has already been attached to the_class and old_cp has already |
3501 // been added as a previous version. The new_cp doesn't have any |
3488 // been added as a previous version. The new_cp doesn't have any |
3502 // cached references to old methods so it doesn't need to be |
3489 // cached references to old methods so it doesn't need to be |
3503 // updated. We can simply start with the previous version(s) in |
3490 // updated. We can simply start with the previous version(s) in |
3504 // that case. |
3491 // that case. |
3505 constantPoolHandle other_cp; |
3492 constantPoolHandle other_cp; |
3506 ConstantPoolCache* cp_cache; |
3493 ConstantPoolCache* cp_cache; |
3507 |
3494 |
3508 if (ik != _the_class) { |
3495 if (!ik->is_being_redefined()) { |
3509 // this klass' constant pool cache may need adjustment |
3496 // this klass' constant pool cache may need adjustment |
3510 other_cp = constantPoolHandle(ik->constants()); |
3497 other_cp = constantPoolHandle(ik->constants()); |
3511 cp_cache = other_cp->cache(); |
3498 cp_cache = other_cp->cache(); |
3512 if (cp_cache != NULL) { |
3499 if (cp_cache != NULL) { |
3513 cp_cache->adjust_method_entries(the_class, &trace_name_printed); |
3500 cp_cache->adjust_method_entries(&trace_name_printed); |
3514 } |
3501 } |
3515 } |
3502 } |
3516 |
3503 |
3517 // the previous versions' constant pool caches may need adjustment |
3504 // the previous versions' constant pool caches may need adjustment |
3518 for (InstanceKlass* pv_node = ik->previous_versions(); |
3505 for (InstanceKlass* pv_node = ik->previous_versions(); |
3519 pv_node != NULL; |
3506 pv_node != NULL; |
3520 pv_node = pv_node->previous_versions()) { |
3507 pv_node = pv_node->previous_versions()) { |
3521 cp_cache = pv_node->constants()->cache(); |
3508 cp_cache = pv_node->constants()->cache(); |
3522 if (cp_cache != NULL) { |
3509 if (cp_cache != NULL) { |
3523 cp_cache->adjust_method_entries(pv_node, &trace_name_printed); |
3510 cp_cache->adjust_method_entries(&trace_name_printed); |
3524 } |
|
3525 } |
|
3526 } |
|
3527 } |
|
3528 |
|
3529 // Clean method data for this class |
|
3530 void VM_RedefineClasses::MethodDataCleaner::do_klass(Klass* k) { |
|
3531 if (k->is_instance_klass()) { |
|
3532 InstanceKlass *ik = InstanceKlass::cast(k); |
|
3533 // Clean MethodData of this class's methods so they don't refer to |
|
3534 // old methods that are no longer running. |
|
3535 Array<Method*>* methods = ik->methods(); |
|
3536 int num_methods = methods->length(); |
|
3537 for (int index = 0; index < num_methods; ++index) { |
|
3538 if (methods->at(index)->method_data() != NULL) { |
|
3539 methods->at(index)->method_data()->clean_weak_method_links(); |
|
3540 } |
3511 } |
3541 } |
3512 } |
3542 } |
3513 } |
3543 } |
3514 } |
3544 |
3515 |