src/share/vm/oops/instanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8055008_2 Sdiff src/share/vm/oops

src/share/vm/oops/instanceKlass.cpp

Print this page




2420       delete mnt;
2421       set_member_names(NULL);
2422     }
2423   }
2424 
2425   // release dependencies
2426   nmethodBucket* b = _dependencies;
2427   _dependencies = NULL;
2428   while (b != NULL) {
2429     nmethodBucket* next = b->next();
2430     delete b;
2431     b = next;
2432   }
2433 
2434   // Deallocate breakpoint records
2435   if (breakpoints() != 0x0) {
2436     methods_do(clear_all_breakpoints);
2437     assert(breakpoints() == 0x0, "should have cleared breakpoints");
2438   }
2439 
2440   // deallocate information about previous versions
2441   if (_previous_versions != NULL) {
2442     for (int i = _previous_versions->length() - 1; i >= 0; i--) {
2443       PreviousVersionNode * pv_node = _previous_versions->at(i);
2444       delete pv_node;
2445     }
2446     delete _previous_versions;
2447     _previous_versions = NULL;
2448   }
2449 
2450   // deallocate the cached class file
2451   if (_cached_class_file != NULL) {
2452     os::free(_cached_class_file, mtClass);
2453     _cached_class_file = NULL;
2454   }
2455 
2456   // Decrement symbol reference counts associated with the unloaded class.
2457   if (_name != NULL) _name->decrement_refcount();
2458   // unreference array name derived from this class name (arrays of an unloaded
2459   // class can't be referenced anymore).
2460   if (_array_name != NULL)  _array_name->decrement_refcount();
2461   if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension, mtClass);
2462 
2463   assert(_total_instanceKlass_count >= 1, "Sanity check");
2464   Atomic::dec(&_total_instanceKlass_count);
2465 }
2466 
2467 void InstanceKlass::set_source_debug_extension(char* array, int length) {
2468   if (array == NULL) {
2469     _source_debug_extension = NULL;


3003     class_loader_data()->print_value_on(st);
3004     st->cr();
3005   }
3006   st->print(BULLET"host class:        "); host_klass()->print_value_on_maybe_null(st); st->cr();
3007   if (source_file_name() != NULL) {
3008     st->print(BULLET"source file:       ");
3009     source_file_name()->print_value_on(st);
3010     st->cr();
3011   }
3012   if (source_debug_extension() != NULL) {
3013     st->print(BULLET"source debug extension:       ");
3014     st->print("%s", source_debug_extension());
3015     st->cr();
3016   }
3017   st->print(BULLET"class annotations:       "); class_annotations()->print_value_on(st); st->cr();
3018   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
3019   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
3020   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();
3021   {
3022     bool have_pv = false;
3023     PreviousVersionWalker pvw(Thread::current(), (InstanceKlass*)this);
3024     for (PreviousVersionNode * pv_node = pvw.next_previous_version();
3025          pv_node != NULL; pv_node = pvw.next_previous_version()) {

3026       if (!have_pv)
3027         st->print(BULLET"previous version:  ");
3028       have_pv = true;
3029       pv_node->prev_constant_pool()->print_value_on(st);
3030     }
3031     if (have_pv) st->cr();
3032   } // pvw is cleaned up
3033 
3034   if (generic_signature() != NULL) {
3035     st->print(BULLET"generic signature: ");
3036     generic_signature()->print_value_on(st);
3037     st->cr();
3038   }
3039   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3040   st->print(BULLET"java mirror:       "); java_mirror()->print_value_on(st);       st->cr();
3041   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable());  st->cr();
3042   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3043   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr();
3044   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3045   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3046   FieldPrinter print_static_field(st);
3047   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3048   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3049   FieldPrinter print_nonstatic_field(st);
3050   ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field);
3051 
3052   st->print(BULLET"non-static oop maps: ");


3426     }
3427 #endif
3428     current = current->next();
3429   }
3430 }
3431 
3432 
3433 #ifdef ASSERT
3434 void InstanceKlass::set_init_state(ClassState state) {
3435   bool good_state = is_shared() ? (_init_state <= state)
3436                                                : (_init_state < state);
3437   assert(good_state || state == allocated, "illegal state transition");
3438   _init_state = (u1)state;
3439 }
3440 #endif
3441 
3442 
3443 // RedefineClasses() support for previous versions:
3444 
3445 // Purge previous versions
3446 static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) {
3447   if (ik->previous_versions() != NULL) {
3448     // This klass has previous versions so see what we can cleanup
3449     // while it is safe to do so.
3450 
3451     int deleted_count = 0;    // leave debugging breadcrumbs
3452     int live_count = 0;
3453     ClassLoaderData* loader_data = ik->class_loader_data() == NULL ?
3454                        ClassLoaderData::the_null_class_loader_data() :
3455                        ik->class_loader_data();
3456 
3457     // RC_TRACE macro has an embedded ResourceMark
3458     RC_TRACE(0x00000200, ("purge: %s: previous version length=%d",
3459       ik->external_name(), ik->previous_versions()->length()));







3460 
3461     for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
3462       // check the previous versions array
3463       PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
3464       ConstantPool* cp_ref = pv_node->prev_constant_pool();
3465       assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
3466 
3467       ConstantPool* pvcp = cp_ref;
3468       if (!pvcp->on_stack()) {
3469         // If the constant pool isn't on stack, none of the methods
3470         // are executing.  Delete all the methods, the constant pool and
3471         // and this previous version node.
3472         GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods();
3473         if (method_refs != NULL) {
3474           for (int j = method_refs->length() - 1; j >= 0; j--) {
3475             Method* method = method_refs->at(j);
3476             assert(method != NULL, "method ref was unexpectedly cleared");
3477             method_refs->remove_at(j);
3478             // method will be freed with associated class.
3479           }
3480         }
3481         // Remove the constant pool
3482         delete pv_node;
3483         // Since we are traversing the array backwards, we don't have to
3484         // do anything special with the index.
3485         ik->previous_versions()->remove_at(i);
3486         deleted_count++;
3487         continue;
3488       } else {
3489         RC_TRACE(0x00000200, ("purge: previous version @%d is alive", i));

3490         assert(pvcp->pool_holder() != NULL, "Constant pool with no holder");
3491         guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack");
3492         live_count++;
3493       }
3494 
3495       // At least one method is live in this previous version, clean out
3496       // the others or mark them as obsolete.
3497       GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods();
3498       if (method_refs != NULL) {
3499         RC_TRACE(0x00000200, ("purge: previous methods length=%d",
3500           method_refs->length()));
3501         for (int j = method_refs->length() - 1; j >= 0; j--) {
3502           Method* method = method_refs->at(j);
3503           assert(method != NULL, "method ref was unexpectedly cleared");
3504 
3505           // Remove the emcp method if it's not executing
3506           // If it's been made obsolete by a redefinition of a non-emcp
3507           // method, mark it as obsolete but leave it to clean up later.
3508           if (!method->on_stack()) {
3509             method_refs->remove_at(j);
3510           } else if (emcp_method_count == 0) {
3511             method->set_is_obsolete();
3512           } else {
3513             // RC_TRACE macro has an embedded ResourceMark
3514             RC_TRACE(0x00000200,
3515               ("purge: %s(%s): prev method @%d in version @%d is alive",
3516               method->name()->as_C_string(),
3517               method->signature()->as_C_string(), j, i));
3518             if (method->method_data() != NULL) {
3519               // Clean out any weak method links

3520               method->method_data()->clean_weak_method_links();
3521             }
3522           }
3523         }
3524       }




3525     }
3526     assert(ik->previous_versions()->length() == live_count, "sanity check");
3527     RC_TRACE(0x00000200,
3528       ("purge: previous version stats: live=%d, deleted=%d", live_count,
3529       deleted_count));
3530   }
3531 


3532   Array<Method*>* methods = ik->methods();
3533   int num_methods = methods->length();
3534   for (int index2 = 0; index2 < num_methods; ++index2) {
3535     if (methods->at(index2)->method_data() != NULL) {
3536       methods->at(index2)->method_data()->clean_weak_method_links();
3537     }
3538   }
3539 }
3540 
3541 // External interface for use during class unloading.
3542 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) {
3543   // Call with >0 emcp methods since they are not currently being redefined.
3544   purge_previous_versions_internal(ik, 1);
3545 }
3546 
3547 
3548 // Potentially add an information node that contains pointers to the
3549 // interesting parts of the previous version of the_class.
3550 // This is also where we clean out any unused references.
3551 // Note that while we delete nodes from the _previous_versions
3552 // array, we never delete the array itself until the klass is
3553 // unloaded. The has_been_redefined() query depends on that fact.
3554 //
3555 void InstanceKlass::add_previous_version(instanceKlassHandle ikh,
3556        BitMap* emcp_methods, int emcp_method_count) {
3557   assert(Thread::current()->is_VM_thread(),
3558          "only VMThread can add previous versions");
3559 
3560   if (_previous_versions == NULL) {
3561     // This is the first previous version so make some space.
3562     // Start with 2 elements under the assumption that the class
3563     // won't be redefined much.
3564     _previous_versions =  new (ResourceObj::C_HEAP, mtClass)
3565                             GrowableArray<PreviousVersionNode *>(2, true);
3566   }
3567 
3568   ConstantPool* cp_ref = ikh->constants();
3569 
3570   // RC_TRACE macro has an embedded ResourceMark
3571   RC_TRACE(0x00000400, ("adding previous version ref for %s @%d, EMCP_cnt=%d "
3572                         "on_stack=%d",
3573     ikh->external_name(), _previous_versions->length(), emcp_method_count,
3574     cp_ref->on_stack()));
3575 
3576   // If the constant pool for this previous version of the class
3577   // is not marked as being on the stack, then none of the methods
3578   // in this previous version of the class are on the stack so
3579   // we don't need to create a new PreviousVersionNode. However,
3580   // we still need to examine older previous versions below.
3581   Array<Method*>* old_methods = ikh->methods();
3582 
3583   if (cp_ref->on_stack()) {
3584     PreviousVersionNode * pv_node = NULL;
3585     if (emcp_method_count == 0) {
3586       // non-shared ConstantPool gets a reference
3587       pv_node = new PreviousVersionNode(cp_ref, NULL);
3588       RC_TRACE(0x00000400,
3589           ("add: all methods are obsolete; flushing any EMCP refs"));
3590     } else {
3591       int local_count = 0;
3592       GrowableArray<Method*>* method_refs = new (ResourceObj::C_HEAP, mtClass)
3593           GrowableArray<Method*>(emcp_method_count, true);
3594       for (int i = 0; i < old_methods->length(); i++) {
3595         if (emcp_methods->at(i)) {
3596             // this old method is EMCP. Save it only if it's on the stack
3597             Method* old_method = old_methods->at(i);
3598             if (old_method->on_stack()) {
3599               method_refs->append(old_method);
3600             }
3601           if (++local_count >= emcp_method_count) {
3602             // no more EMCP methods so bail out now
3603             break;
3604           }
3605         }
3606       }
3607       // non-shared ConstantPool gets a reference
3608       pv_node = new PreviousVersionNode(cp_ref, method_refs);
3609     }
3610     // append new previous version.
3611     _previous_versions->append(pv_node);
3612   }
3613 
3614   // Since the caller is the VMThread and we are at a safepoint, this
3615   // is a good time to clear out unused references.
3616 
3617   RC_TRACE(0x00000400, ("add: previous version length=%d",
3618     _previous_versions->length()));
3619 
3620   // Purge previous versions not executing on the stack
3621   purge_previous_versions_internal(this, emcp_method_count);
3622 
3623   int obsolete_method_count = old_methods->length() - emcp_method_count;
3624 
3625   if (emcp_method_count != 0 && obsolete_method_count != 0 &&
3626       _previous_versions->length() > 0) {
3627     // We have a mix of obsolete and EMCP methods so we have to
3628     // clear out any matching EMCP method entries the hard way.
3629     int local_count = 0;
3630     for (int i = 0; i < old_methods->length(); i++) {
3631       if (!emcp_methods->at(i)) {
3632         // only obsolete methods are interesting
3633         Method* old_method = old_methods->at(i);


3634         Symbol* m_name = old_method->name();
3635         Symbol* m_signature = old_method->signature();
3636 
3637         // we might not have added the last entry
3638         for (int j = _previous_versions->length() - 1; j >= 0; j--) {
3639           // check the previous versions array for non executing obsolete methods
3640           PreviousVersionNode * pv_node = _previous_versions->at(j);
3641 
3642           GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods();
3643           if (method_refs == NULL) {
3644             // We have run into a PreviousVersion generation where
3645             // all methods were made obsolete during that generation's
3646             // RedefineClasses() operation. At the time of that
3647             // operation, all EMCP methods were flushed so we don't
3648             // have to go back any further.
3649             //
3650             // A NULL method_refs is different than an empty method_refs.
3651             // We cannot infer any optimizations about older generations
3652             // from an empty method_refs for the current generation.
3653             break;
3654           }
3655 
3656           for (int k = method_refs->length() - 1; k >= 0; k--) {

3657             Method* method = method_refs->at(k);
3658 
3659             if (!method->is_obsolete() &&
3660                 method->name() == m_name &&
3661                 method->signature() == m_signature) {
3662               // The current RedefineClasses() call has made all EMCP
3663               // versions of this method obsolete so mark it as obsolete
3664               // and remove the reference.
3665               RC_TRACE(0x00000400,
3666                 ("add: %s(%s): flush obsolete method @%d in version @%d",
3667                 m_name->as_C_string(), m_signature->as_C_string(), k, j));
3668 
3669               method->set_is_obsolete();
3670               // Leave obsolete methods on the previous version list to
3671               // clean up later.
3672               break;
3673             }
3674           }
3675 
3676           // The previous loop may not find a matching EMCP method, but
3677           // that doesn't mean that we can optimize and not go any
3678           // further back in the PreviousVersion generations. The EMCP
3679           // method for this generation could have already been deleted,
3680           // but there still may be an older EMCP method that has not
3681           // been deleted.
3682         }
3683 
3684         if (++local_count >= obsolete_method_count) {
3685           // no more obsolete methods so bail out now
3686           break;
3687         }
3688       }
3689     }
3690   }
3691 } // end add_previous_version()












3692 




























3693 
3694 // Determine if InstanceKlass has a previous version.
3695 bool InstanceKlass::has_previous_version() const {
3696   return (_previous_versions != NULL && _previous_versions->length() > 0);
3697 } // end has_previous_version()




3698 
3699 
3700 Method* InstanceKlass::method_with_idnum(int idnum) {
3701   Method* m = NULL;
3702   if (idnum < methods()->length()) {
3703     m = methods()->at(idnum);
3704   }
3705   if (m == NULL || m->method_idnum() != idnum) {
3706     for (int index = 0; index < methods()->length(); ++index) {
3707       m = methods()->at(index);
3708       if (m->method_idnum() == idnum) {
3709         return m;
3710       }
3711     }
3712     // None found, return null for the caller to handle.
3713     return NULL;
3714   }
3715   return m;
3716 }
3717 
3718 jint InstanceKlass::get_cached_class_file_len() {
3719   return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file);
3720 }
3721 
3722 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
3723   return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
3724 }
3725 
3726 
3727 // Construct a PreviousVersionNode entry for the array hung off
3728 // the InstanceKlass.
3729 PreviousVersionNode::PreviousVersionNode(ConstantPool* prev_constant_pool,
3730   GrowableArray<Method*>* prev_EMCP_methods) {
3731 
3732   _prev_constant_pool = prev_constant_pool;
3733   _prev_EMCP_methods = prev_EMCP_methods;
3734 }
3735 
3736 
3737 // Destroy a PreviousVersionNode
3738 PreviousVersionNode::~PreviousVersionNode() {
3739   if (_prev_constant_pool != NULL) {
3740     _prev_constant_pool = NULL;
3741   }
3742 
3743   if (_prev_EMCP_methods != NULL) {
3744     delete _prev_EMCP_methods;
3745   }
3746 }
3747 
3748 // Construct a helper for walking the previous versions array
3749 PreviousVersionWalker::PreviousVersionWalker(Thread* thread, InstanceKlass *ik) {
3750   _thread = thread;
3751   _previous_versions = ik->previous_versions();
3752   _current_index = 0;
3753   _current_p = NULL;
3754   _current_constant_pool_handle = constantPoolHandle(thread, ik->constants());
3755 }
3756 
3757 
3758 // Return the interesting information for the next previous version
3759 // of the klass. Returns NULL if there are no more previous versions.
3760 PreviousVersionNode* PreviousVersionWalker::next_previous_version() {
3761   if (_previous_versions == NULL) {
3762     // no previous versions so nothing to return
3763     return NULL;
3764   }
3765 
3766   _current_p = NULL;  // reset to NULL
3767   _current_constant_pool_handle = NULL;
3768 
3769   int length = _previous_versions->length();
3770 
3771   while (_current_index < length) {
3772     PreviousVersionNode * pv_node = _previous_versions->at(_current_index++);
3773 
3774     // Save a handle to the constant pool for this previous version,
3775     // which keeps all the methods from being deallocated.
3776     _current_constant_pool_handle = constantPoolHandle(_thread, pv_node->prev_constant_pool());
3777     _current_p = pv_node;
3778     return pv_node;
3779   }
3780 
3781   return NULL;
3782 } // end next_previous_version()


2420       delete mnt;
2421       set_member_names(NULL);
2422     }
2423   }
2424 
2425   // release dependencies
2426   nmethodBucket* b = _dependencies;
2427   _dependencies = NULL;
2428   while (b != NULL) {
2429     nmethodBucket* next = b->next();
2430     delete b;
2431     b = next;
2432   }
2433 
2434   // Deallocate breakpoint records
2435   if (breakpoints() != 0x0) {
2436     methods_do(clear_all_breakpoints);
2437     assert(breakpoints() == 0x0, "should have cleared breakpoints");
2438   }
2439 










2440   // deallocate the cached class file
2441   if (_cached_class_file != NULL) {
2442     os::free(_cached_class_file, mtClass);
2443     _cached_class_file = NULL;
2444   }
2445 
2446   // Decrement symbol reference counts associated with the unloaded class.
2447   if (_name != NULL) _name->decrement_refcount();
2448   // unreference array name derived from this class name (arrays of an unloaded
2449   // class can't be referenced anymore).
2450   if (_array_name != NULL)  _array_name->decrement_refcount();
2451   if (_source_debug_extension != NULL) FREE_C_HEAP_ARRAY(char, _source_debug_extension, mtClass);
2452 
2453   assert(_total_instanceKlass_count >= 1, "Sanity check");
2454   Atomic::dec(&_total_instanceKlass_count);
2455 }
2456 
2457 void InstanceKlass::set_source_debug_extension(char* array, int length) {
2458   if (array == NULL) {
2459     _source_debug_extension = NULL;


2993     class_loader_data()->print_value_on(st);
2994     st->cr();
2995   }
2996   st->print(BULLET"host class:        "); host_klass()->print_value_on_maybe_null(st); st->cr();
2997   if (source_file_name() != NULL) {
2998     st->print(BULLET"source file:       ");
2999     source_file_name()->print_value_on(st);
3000     st->cr();
3001   }
3002   if (source_debug_extension() != NULL) {
3003     st->print(BULLET"source debug extension:       ");
3004     st->print("%s", source_debug_extension());
3005     st->cr();
3006   }
3007   st->print(BULLET"class annotations:       "); class_annotations()->print_value_on(st); st->cr();
3008   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
3009   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
3010   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();
3011   {
3012     bool have_pv = false;
3013     // previous versions are linked together through the InstanceKlass
3014     for (InstanceKlass* pv_node = _previous_versions;
3015          pv_node != NULL;
3016          pv_node = pv_node->previous_versions()) {
3017       if (!have_pv)
3018         st->print(BULLET"previous version:  ");
3019       have_pv = true;
3020       pv_node->constants()->print_value_on(st);
3021     }
3022     if (have_pv) st->cr();
3023   }
3024 
3025   if (generic_signature() != NULL) {
3026     st->print(BULLET"generic signature: ");
3027     generic_signature()->print_value_on(st);
3028     st->cr();
3029   }
3030   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
3031   st->print(BULLET"java mirror:       "); java_mirror()->print_value_on(st);       st->cr();
3032   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable());  st->cr();
3033   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
3034   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr();
3035   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
3036   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
3037   FieldPrinter print_static_field(st);
3038   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
3039   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
3040   FieldPrinter print_nonstatic_field(st);
3041   ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field);
3042 
3043   st->print(BULLET"non-static oop maps: ");


3417     }
3418 #endif
3419     current = current->next();
3420   }
3421 }
3422 
3423 
3424 #ifdef ASSERT
3425 void InstanceKlass::set_init_state(ClassState state) {
3426   bool good_state = is_shared() ? (_init_state <= state)
3427                                                : (_init_state < state);
3428   assert(good_state || state == allocated, "illegal state transition");
3429   _init_state = (u1)state;
3430 }
3431 #endif
3432 
3433 
3434 // RedefineClasses() support for previous versions:
3435 
3436 // Purge previous versions
3437 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) {
3438   if (ik->previous_versions() != NULL) {
3439     // This klass has previous versions so see what we can cleanup
3440     // while it is safe to do so.
3441 
3442     int deleted_count = 0;    // leave debugging breadcrumbs
3443     int live_count = 0;
3444     ClassLoaderData* loader_data = ik->class_loader_data();
3445     assert(loader_data != NULL, "should never be null");

3446 
3447     // RC_TRACE macro has an embedded ResourceMark
3448     RC_TRACE(0x00000200, ("purge: %s: previous versions", ik->external_name()));
3449 
3450     // previous versions are linked together through the InstanceKlass
3451     InstanceKlass* pv_node = ik->previous_versions();
3452     InstanceKlass* last = ik;
3453     int version = 0;
3454 
3455     // check the previous versions list
3456     for (; pv_node != NULL; ) {
3457 
3458       ConstantPool* pvcp = pv_node->constants();
3459       assert(pvcp != NULL, "cp ref was unexpectedly cleared");



3460 

3461       if (!pvcp->on_stack()) {
3462         // If the constant pool isn't on stack, none of the methods
3463         // are executing.  Unlink this previous_version.
3464         // The previous version InstanceKlass is on the ClassLoaderData deallocate list
3465         // so will be deallocated during the next phase of class unloading.
3466         pv_node = pv_node->previous_versions();
3467         last->link_previous_versions(pv_node);











3468         deleted_count++;
3469         continue;
3470       } else {
3471         RC_TRACE(0x00000200, ("purge: previous version " INTPTR_FORMAT " is alive",
3472                               pv_node));
3473         assert(pvcp->pool_holder() != NULL, "Constant pool with no holder");
3474         guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack");
3475         live_count++;
3476       }
3477 
3478       // At least one method is live in this previous version so clean its MethodData.
3479       // Reset dead EMCP methods not to get breakpoints.
3480       Array<Method*>* method_refs = pv_node->methods();
3481       if (method_refs != NULL) {
3482         RC_TRACE(0x00000200, ("purge: previous methods length=%d",
3483           method_refs->length()));
3484         for (int j = 0; j < method_refs->length(); j++) {
3485           Method* method = method_refs->at(j);

3486 



3487           if (!method->on_stack()) {
3488             if (method->is_running_emcp()) {
3489               method->set_running_emcp(false);  // no breakpoints for non-running methods
3490             }
3491           } else {
3492             // RC_TRACE macro has an embedded ResourceMark
3493             RC_TRACE(0x00000200,
3494               ("purge: %s(%s): prev method @%d in version @%d is alive",
3495               method->name()->as_C_string(),
3496               method->signature()->as_C_string(), j, version));
3497             if (method->method_data() != NULL) {
3498               // Clean out any weak method links for running methods
3499               // (also should include not EMCP methods)
3500               method->method_data()->clean_weak_method_links();
3501             }
3502           }
3503         }
3504       }
3505       // next previous version
3506       last = pv_node;
3507       pv_node = pv_node->previous_versions();
3508       version++;
3509     }

3510     RC_TRACE(0x00000200,
3511       ("purge: previous version stats: live=%d, deleted=%d", live_count,
3512       deleted_count));
3513   }
3514 
3515   // Clean MethodData of this class's methods so they don't refer to
3516   // old methods that are no longer running.
3517   Array<Method*>* methods = ik->methods();
3518   int num_methods = methods->length();
3519   for (int index2 = 0; index2 < num_methods; ++index2) {
3520     if (methods->at(index2)->method_data() != NULL) {
3521       methods->at(index2)->method_data()->clean_weak_method_links();
3522     }
3523   }
3524 }
3525 
3526 void InstanceKlass::mark_newly_obsolete_methods(Array<Method*>* old_methods,
3527                                                 int emcp_method_count) {
















































































3528   int obsolete_method_count = old_methods->length() - emcp_method_count;
3529 
3530   if (emcp_method_count != 0 && obsolete_method_count != 0 &&
3531       _previous_versions != NULL) {
3532     // We have a mix of obsolete and EMCP methods so we have to
3533     // clear out any matching EMCP method entries the hard way.
3534     int local_count = 0;
3535     for (int i = 0; i < old_methods->length(); i++) {


3536       Method* old_method = old_methods->at(i);
3537       if (old_method->is_obsolete()) {
3538         // only obsolete methods are interesting
3539         Symbol* m_name = old_method->name();
3540         Symbol* m_signature = old_method->signature();
3541 
3542         // previous versions are linked together through the InstanceKlass
3543         int j = 0;
3544         for (InstanceKlass* prev_version = _previous_versions;
3545              prev_version != NULL;
3546              prev_version = prev_version->previous_versions(), j++) {













3547 
3548           Array<Method*>* method_refs = prev_version->methods();
3549           for (int k = 0; k < method_refs->length(); k++) {
3550             Method* method = method_refs->at(k);
3551 
3552             if (!method->is_obsolete() &&
3553                 method->name() == m_name &&
3554                 method->signature() == m_signature) {
3555               // The current RedefineClasses() call has made all EMCP
3556               // versions of this method obsolete so mark it as obsolete

3557               RC_TRACE(0x00000400,
3558                 ("add: %s(%s): flush obsolete method @%d in version @%d",
3559                 m_name->as_C_string(), m_signature->as_C_string(), k, j));
3560 
3561               method->set_is_obsolete();


3562               break;
3563             }
3564           }
3565 
3566           // The previous loop may not find a matching EMCP method, but
3567           // that doesn't mean that we can optimize and not go any
3568           // further back in the PreviousVersion generations. The EMCP
3569           // method for this generation could have already been made obsolete,
3570           // but there still may be an older EMCP method that has not
3571           // been made obsolete.
3572         }
3573 
3574         if (++local_count >= obsolete_method_count) {
3575           // no more obsolete methods so bail out now
3576           break;
3577         }
3578       }
3579     }
3580   }
3581 }
3582 
3583 // Save the scratch_class as the previous version if any of the methods are running.
3584 // The previous_versions are used to set breakpoints in EMCP methods and they are
3585 // also used to clean MethodData links to redefined methods that are no longer running.
3586 void InstanceKlass::add_previous_version(instanceKlassHandle scratch_class,
3587                                          int emcp_method_count) {
3588   assert(Thread::current()->is_VM_thread(),
3589          "only VMThread can add previous versions");
3590 
3591   // RC_TRACE macro has an embedded ResourceMark
3592   RC_TRACE(0x00000400, ("adding previous version ref for %s, EMCP_cnt=%d",
3593     scratch_class->external_name(), emcp_method_count));
3594 
3595   // Clean out old previous versions
3596   purge_previous_versions(this);
3597 
3598   // Mark newly obsolete methods in remaining previous versions.  An EMCP method from
3599   // a previous redefinition may be made obsolete by this redefinition.
3600   Array<Method*>* old_methods = scratch_class->methods();
3601   mark_newly_obsolete_methods(old_methods, emcp_method_count);
3602 
3603   // If the constant pool for this previous version of the class
3604   // is not marked as being on the stack, then none of the methods
3605   // in this previous version of the class are on the stack so
3606   // we don't need to add this as a previous version.
3607   ConstantPool* cp_ref = scratch_class->constants();
3608   if (cp_ref->on_stack()) {
3609     if (emcp_method_count == 0) {
3610       RC_TRACE(0x00000400, ("add: all methods are obsolete; no added EMCP refs"));
3611     } else {
3612       for (int i = 0; i < old_methods->length(); i++) {
3613         Method* old_method = old_methods->at(i);
3614         if (!old_method->is_obsolete() && old_method->on_stack()) {
3615           // if EMCP method (not obsolete) is on the stack, mark as EMCP so that
3616           // we add breakpoints for it.
3617           old_method->set_running_emcp(true);
3618           // At least one emcp method is still running
3619           RC_TRACE(0x00000400, ("add: EMCP method %s is on_stack", old_method->name_and_sig_as_C_string()));
3620         }
3621       }
3622     }
3623 
3624     RC_TRACE(0x00000400, ("add: scratch class added; one of its methods is on_stack"));
3625     assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version");
3626     scratch_class->link_previous_versions(previous_versions());
3627     link_previous_versions(scratch_class()); 
3628   } else {
3629     RC_TRACE(0x00000400, ("add: scratch class not added; no methods are running"));
3630   }
3631 } // end add_previous_version()
3632 
3633 
3634 Method* InstanceKlass::method_with_idnum(int idnum) {
3635   Method* m = NULL;
3636   if (idnum < methods()->length()) { 
3637     m = methods()->at(idnum);
3638   }
3639   if (m == NULL || m->method_idnum() != idnum) {
3640     for (int index = 0; index < methods()->length(); ++index) {
3641       m = methods()->at(index);
3642       if (m->method_idnum() == idnum) {
3643         return m;
3644       }
3645     }
3646     // None found, return null for the caller to handle.
3647     return NULL;
3648   }
3649   return m;
3650 }
3651 
3652 jint InstanceKlass::get_cached_class_file_len() {
3653   return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file);
3654 }
3655 
3656 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
3657   return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
3658 }


























































src/share/vm/oops/instanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File