hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 26558 b7df27df6384
parent 26556 72da4c813e44
child 27409 03622fc45677
child 27402 5c4675ddc00c
equal deleted inserted replaced
26557:e399effe36f9 26558:b7df27df6384
  2437   if (breakpoints() != 0x0) {
  2437   if (breakpoints() != 0x0) {
  2438     methods_do(clear_all_breakpoints);
  2438     methods_do(clear_all_breakpoints);
  2439     assert(breakpoints() == 0x0, "should have cleared breakpoints");
  2439     assert(breakpoints() == 0x0, "should have cleared breakpoints");
  2440   }
  2440   }
  2441 
  2441 
  2442   // deallocate information about previous versions
       
  2443   if (_previous_versions != NULL) {
       
  2444     for (int i = _previous_versions->length() - 1; i >= 0; i--) {
       
  2445       PreviousVersionNode * pv_node = _previous_versions->at(i);
       
  2446       delete pv_node;
       
  2447     }
       
  2448     delete _previous_versions;
       
  2449     _previous_versions = NULL;
       
  2450   }
       
  2451 
       
  2452   // deallocate the cached class file
  2442   // deallocate the cached class file
  2453   if (_cached_class_file != NULL) {
  2443   if (_cached_class_file != NULL) {
  2454     os::free(_cached_class_file, mtClass);
  2444     os::free(_cached_class_file, mtClass);
  2455     _cached_class_file = NULL;
  2445     _cached_class_file = NULL;
  2456   }
  2446   }
  3020   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
  3010   st->print(BULLET"class type annotations:  "); class_type_annotations()->print_value_on(st); st->cr();
  3021   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
  3011   st->print(BULLET"field annotations:       "); fields_annotations()->print_value_on(st); st->cr();
  3022   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();
  3012   st->print(BULLET"field type annotations:  "); fields_type_annotations()->print_value_on(st); st->cr();
  3023   {
  3013   {
  3024     bool have_pv = false;
  3014     bool have_pv = false;
  3025     PreviousVersionWalker pvw(Thread::current(), (InstanceKlass*)this);
  3015     // previous versions are linked together through the InstanceKlass
  3026     for (PreviousVersionNode * pv_node = pvw.next_previous_version();
  3016     for (InstanceKlass* pv_node = _previous_versions;
  3027          pv_node != NULL; pv_node = pvw.next_previous_version()) {
  3017          pv_node != NULL;
       
  3018          pv_node = pv_node->previous_versions()) {
  3028       if (!have_pv)
  3019       if (!have_pv)
  3029         st->print(BULLET"previous version:  ");
  3020         st->print(BULLET"previous version:  ");
  3030       have_pv = true;
  3021       have_pv = true;
  3031       pv_node->prev_constant_pool()->print_value_on(st);
  3022       pv_node->constants()->print_value_on(st);
  3032     }
  3023     }
  3033     if (have_pv) st->cr();
  3024     if (have_pv) st->cr();
  3034   } // pvw is cleaned up
  3025   }
  3035 
  3026 
  3036   if (generic_signature() != NULL) {
  3027   if (generic_signature() != NULL) {
  3037     st->print(BULLET"generic signature: ");
  3028     st->print(BULLET"generic signature: ");
  3038     generic_signature()->print_value_on(st);
  3029     generic_signature()->print_value_on(st);
  3039     st->cr();
  3030     st->cr();
  3443 
  3434 
  3444 
  3435 
  3445 // RedefineClasses() support for previous versions:
  3436 // RedefineClasses() support for previous versions:
  3446 
  3437 
  3447 // Purge previous versions
  3438 // Purge previous versions
  3448 static void purge_previous_versions_internal(InstanceKlass* ik, int emcp_method_count) {
  3439 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) {
  3449   if (ik->previous_versions() != NULL) {
  3440   if (ik->previous_versions() != NULL) {
  3450     // This klass has previous versions so see what we can cleanup
  3441     // This klass has previous versions so see what we can cleanup
  3451     // while it is safe to do so.
  3442     // while it is safe to do so.
  3452 
  3443 
  3453     int deleted_count = 0;    // leave debugging breadcrumbs
  3444     int deleted_count = 0;    // leave debugging breadcrumbs
  3454     int live_count = 0;
  3445     int live_count = 0;
  3455     ClassLoaderData* loader_data = ik->class_loader_data() == NULL ?
  3446     ClassLoaderData* loader_data = ik->class_loader_data();
  3456                        ClassLoaderData::the_null_class_loader_data() :
  3447     assert(loader_data != NULL, "should never be null");
  3457                        ik->class_loader_data();
       
  3458 
  3448 
  3459     // RC_TRACE macro has an embedded ResourceMark
  3449     // RC_TRACE macro has an embedded ResourceMark
  3460     RC_TRACE(0x00000200, ("purge: %s: previous version length=%d",
  3450     RC_TRACE(0x00000200, ("purge: %s: previous versions", ik->external_name()));
  3461       ik->external_name(), ik->previous_versions()->length()));
  3451 
  3462 
  3452     // previous versions are linked together through the InstanceKlass
  3463     for (int i = ik->previous_versions()->length() - 1; i >= 0; i--) {
  3453     InstanceKlass* pv_node = ik->previous_versions();
  3464       // check the previous versions array
  3454     InstanceKlass* last = ik;
  3465       PreviousVersionNode * pv_node = ik->previous_versions()->at(i);
  3455     int version = 0;
  3466       ConstantPool* cp_ref = pv_node->prev_constant_pool();
  3456 
  3467       assert(cp_ref != NULL, "cp ref was unexpectedly cleared");
  3457     // check the previous versions list
  3468 
  3458     for (; pv_node != NULL; ) {
  3469       ConstantPool* pvcp = cp_ref;
  3459 
       
  3460       ConstantPool* pvcp = pv_node->constants();
       
  3461       assert(pvcp != NULL, "cp ref was unexpectedly cleared");
       
  3462 
  3470       if (!pvcp->on_stack()) {
  3463       if (!pvcp->on_stack()) {
  3471         // If the constant pool isn't on stack, none of the methods
  3464         // If the constant pool isn't on stack, none of the methods
  3472         // are executing.  Delete all the methods, the constant pool and
  3465         // are executing.  Unlink this previous_version.
  3473         // and this previous version node.
  3466         // The previous version InstanceKlass is on the ClassLoaderData deallocate list
  3474         GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods();
  3467         // so will be deallocated during the next phase of class unloading.
  3475         if (method_refs != NULL) {
  3468         pv_node = pv_node->previous_versions();
  3476           for (int j = method_refs->length() - 1; j >= 0; j--) {
  3469         last->link_previous_versions(pv_node);
  3477             Method* method = method_refs->at(j);
       
  3478             assert(method != NULL, "method ref was unexpectedly cleared");
       
  3479             method_refs->remove_at(j);
       
  3480             // method will be freed with associated class.
       
  3481           }
       
  3482         }
       
  3483         // Remove the constant pool
       
  3484         delete pv_node;
       
  3485         // Since we are traversing the array backwards, we don't have to
       
  3486         // do anything special with the index.
       
  3487         ik->previous_versions()->remove_at(i);
       
  3488         deleted_count++;
  3470         deleted_count++;
       
  3471         version++;
  3489         continue;
  3472         continue;
  3490       } else {
  3473       } else {
  3491         RC_TRACE(0x00000200, ("purge: previous version @%d is alive", i));
  3474         RC_TRACE(0x00000200, ("purge: previous version " INTPTR_FORMAT " is alive",
       
  3475                               pv_node));
  3492         assert(pvcp->pool_holder() != NULL, "Constant pool with no holder");
  3476         assert(pvcp->pool_holder() != NULL, "Constant pool with no holder");
  3493         guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack");
  3477         guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack");
  3494         live_count++;
  3478         live_count++;
  3495       }
  3479       }
  3496 
  3480 
  3497       // At least one method is live in this previous version, clean out
  3481       // At least one method is live in this previous version so clean its MethodData.
  3498       // the others or mark them as obsolete.
  3482       // Reset dead EMCP methods not to get breakpoints.
  3499       GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods();
  3483       // All methods are deallocated when all of the methods for this class are no
       
  3484       // longer running.
       
  3485       Array<Method*>* method_refs = pv_node->methods();
  3500       if (method_refs != NULL) {
  3486       if (method_refs != NULL) {
  3501         RC_TRACE(0x00000200, ("purge: previous methods length=%d",
  3487         RC_TRACE(0x00000200, ("purge: previous methods length=%d",
  3502           method_refs->length()));
  3488           method_refs->length()));
  3503         for (int j = method_refs->length() - 1; j >= 0; j--) {
  3489         for (int j = 0; j < method_refs->length(); j++) {
  3504           Method* method = method_refs->at(j);
  3490           Method* method = method_refs->at(j);
  3505           assert(method != NULL, "method ref was unexpectedly cleared");
  3491 
  3506 
       
  3507           // Remove the emcp method if it's not executing
       
  3508           // If it's been made obsolete by a redefinition of a non-emcp
       
  3509           // method, mark it as obsolete but leave it to clean up later.
       
  3510           if (!method->on_stack()) {
  3492           if (!method->on_stack()) {
  3511             method_refs->remove_at(j);
  3493             // no breakpoints for non-running methods
  3512           } else if (emcp_method_count == 0) {
  3494             if (method->is_running_emcp()) {
  3513             method->set_is_obsolete();
  3495               method->set_running_emcp(false);
       
  3496             }
  3514           } else {
  3497           } else {
       
  3498             assert (method->is_obsolete() || method->is_running_emcp(),
       
  3499                     "emcp method cannot run after emcp bit is cleared");
  3515             // RC_TRACE macro has an embedded ResourceMark
  3500             // RC_TRACE macro has an embedded ResourceMark
  3516             RC_TRACE(0x00000200,
  3501             RC_TRACE(0x00000200,
  3517               ("purge: %s(%s): prev method @%d in version @%d is alive",
  3502               ("purge: %s(%s): prev method @%d in version @%d is alive",
  3518               method->name()->as_C_string(),
  3503               method->name()->as_C_string(),
  3519               method->signature()->as_C_string(), j, i));
  3504               method->signature()->as_C_string(), j, version));
  3520             if (method->method_data() != NULL) {
  3505             if (method->method_data() != NULL) {
  3521               // Clean out any weak method links
  3506               // Clean out any weak method links for running methods
       
  3507               // (also should include not EMCP methods)
  3522               method->method_data()->clean_weak_method_links();
  3508               method->method_data()->clean_weak_method_links();
  3523             }
  3509             }
  3524           }
  3510           }
  3525         }
  3511         }
  3526       }
  3512       }
  3527     }
  3513       // next previous version
  3528     assert(ik->previous_versions()->length() == live_count, "sanity check");
  3514       last = pv_node;
       
  3515       pv_node = pv_node->previous_versions();
       
  3516       version++;
       
  3517     }
  3529     RC_TRACE(0x00000200,
  3518     RC_TRACE(0x00000200,
  3530       ("purge: previous version stats: live=%d, deleted=%d", live_count,
  3519       ("purge: previous version stats: live=%d, deleted=%d", live_count,
  3531       deleted_count));
  3520       deleted_count));
  3532   }
  3521   }
  3533 
  3522 
       
  3523   // Clean MethodData of this class's methods so they don't refer to
       
  3524   // old methods that are no longer running.
  3534   Array<Method*>* methods = ik->methods();
  3525   Array<Method*>* methods = ik->methods();
  3535   int num_methods = methods->length();
  3526   int num_methods = methods->length();
  3536   for (int index2 = 0; index2 < num_methods; ++index2) {
  3527   for (int index2 = 0; index2 < num_methods; ++index2) {
  3537     if (methods->at(index2)->method_data() != NULL) {
  3528     if (methods->at(index2)->method_data() != NULL) {
  3538       methods->at(index2)->method_data()->clean_weak_method_links();
  3529       methods->at(index2)->method_data()->clean_weak_method_links();
  3539     }
  3530     }
  3540   }
  3531   }
  3541 }
  3532 }
  3542 
  3533 
  3543 // External interface for use during class unloading.
  3534 void InstanceKlass::mark_newly_obsolete_methods(Array<Method*>* old_methods,
  3544 void InstanceKlass::purge_previous_versions(InstanceKlass* ik) {
  3535                                                 int emcp_method_count) {
  3545   // Call with >0 emcp methods since they are not currently being redefined.
       
  3546   purge_previous_versions_internal(ik, 1);
       
  3547 }
       
  3548 
       
  3549 
       
  3550 // Potentially add an information node that contains pointers to the
       
  3551 // interesting parts of the previous version of the_class.
       
  3552 // This is also where we clean out any unused references.
       
  3553 // Note that while we delete nodes from the _previous_versions
       
  3554 // array, we never delete the array itself until the klass is
       
  3555 // unloaded. The has_been_redefined() query depends on that fact.
       
  3556 //
       
  3557 void InstanceKlass::add_previous_version(instanceKlassHandle ikh,
       
  3558        BitMap* emcp_methods, int emcp_method_count) {
       
  3559   assert(Thread::current()->is_VM_thread(),
       
  3560          "only VMThread can add previous versions");
       
  3561 
       
  3562   if (_previous_versions == NULL) {
       
  3563     // This is the first previous version so make some space.
       
  3564     // Start with 2 elements under the assumption that the class
       
  3565     // won't be redefined much.
       
  3566     _previous_versions =  new (ResourceObj::C_HEAP, mtClass)
       
  3567                             GrowableArray<PreviousVersionNode *>(2, true);
       
  3568   }
       
  3569 
       
  3570   ConstantPool* cp_ref = ikh->constants();
       
  3571 
       
  3572   // RC_TRACE macro has an embedded ResourceMark
       
  3573   RC_TRACE(0x00000400, ("adding previous version ref for %s @%d, EMCP_cnt=%d "
       
  3574                         "on_stack=%d",
       
  3575     ikh->external_name(), _previous_versions->length(), emcp_method_count,
       
  3576     cp_ref->on_stack()));
       
  3577 
       
  3578   // If the constant pool for this previous version of the class
       
  3579   // is not marked as being on the stack, then none of the methods
       
  3580   // in this previous version of the class are on the stack so
       
  3581   // we don't need to create a new PreviousVersionNode. However,
       
  3582   // we still need to examine older previous versions below.
       
  3583   Array<Method*>* old_methods = ikh->methods();
       
  3584 
       
  3585   if (cp_ref->on_stack()) {
       
  3586     PreviousVersionNode * pv_node = NULL;
       
  3587     if (emcp_method_count == 0) {
       
  3588       // non-shared ConstantPool gets a reference
       
  3589       pv_node = new PreviousVersionNode(cp_ref, NULL);
       
  3590       RC_TRACE(0x00000400,
       
  3591           ("add: all methods are obsolete; flushing any EMCP refs"));
       
  3592     } else {
       
  3593       int local_count = 0;
       
  3594       GrowableArray<Method*>* method_refs = new (ResourceObj::C_HEAP, mtClass)
       
  3595           GrowableArray<Method*>(emcp_method_count, true);
       
  3596       for (int i = 0; i < old_methods->length(); i++) {
       
  3597         if (emcp_methods->at(i)) {
       
  3598             // this old method is EMCP. Save it only if it's on the stack
       
  3599             Method* old_method = old_methods->at(i);
       
  3600             if (old_method->on_stack()) {
       
  3601               method_refs->append(old_method);
       
  3602             }
       
  3603           if (++local_count >= emcp_method_count) {
       
  3604             // no more EMCP methods so bail out now
       
  3605             break;
       
  3606           }
       
  3607         }
       
  3608       }
       
  3609       // non-shared ConstantPool gets a reference
       
  3610       pv_node = new PreviousVersionNode(cp_ref, method_refs);
       
  3611     }
       
  3612     // append new previous version.
       
  3613     _previous_versions->append(pv_node);
       
  3614   }
       
  3615 
       
  3616   // Since the caller is the VMThread and we are at a safepoint, this
       
  3617   // is a good time to clear out unused references.
       
  3618 
       
  3619   RC_TRACE(0x00000400, ("add: previous version length=%d",
       
  3620     _previous_versions->length()));
       
  3621 
       
  3622   // Purge previous versions not executing on the stack
       
  3623   purge_previous_versions_internal(this, emcp_method_count);
       
  3624 
       
  3625   int obsolete_method_count = old_methods->length() - emcp_method_count;
  3536   int obsolete_method_count = old_methods->length() - emcp_method_count;
  3626 
  3537 
  3627   if (emcp_method_count != 0 && obsolete_method_count != 0 &&
  3538   if (emcp_method_count != 0 && obsolete_method_count != 0 &&
  3628       _previous_versions->length() > 0) {
  3539       _previous_versions != NULL) {
  3629     // We have a mix of obsolete and EMCP methods so we have to
  3540     // We have a mix of obsolete and EMCP methods so we have to
  3630     // clear out any matching EMCP method entries the hard way.
  3541     // clear out any matching EMCP method entries the hard way.
  3631     int local_count = 0;
  3542     int local_count = 0;
  3632     for (int i = 0; i < old_methods->length(); i++) {
  3543     for (int i = 0; i < old_methods->length(); i++) {
  3633       if (!emcp_methods->at(i)) {
  3544       Method* old_method = old_methods->at(i);
       
  3545       if (old_method->is_obsolete()) {
  3634         // only obsolete methods are interesting
  3546         // only obsolete methods are interesting
  3635         Method* old_method = old_methods->at(i);
       
  3636         Symbol* m_name = old_method->name();
  3547         Symbol* m_name = old_method->name();
  3637         Symbol* m_signature = old_method->signature();
  3548         Symbol* m_signature = old_method->signature();
  3638 
  3549 
  3639         // we might not have added the last entry
  3550         // previous versions are linked together through the InstanceKlass
  3640         for (int j = _previous_versions->length() - 1; j >= 0; j--) {
  3551         int j = 0;
  3641           // check the previous versions array for non executing obsolete methods
  3552         for (InstanceKlass* prev_version = _previous_versions;
  3642           PreviousVersionNode * pv_node = _previous_versions->at(j);
  3553              prev_version != NULL;
  3643 
  3554              prev_version = prev_version->previous_versions(), j++) {
  3644           GrowableArray<Method*>* method_refs = pv_node->prev_EMCP_methods();
  3555 
  3645           if (method_refs == NULL) {
  3556           Array<Method*>* method_refs = prev_version->methods();
  3646             // We have run into a PreviousVersion generation where
  3557           for (int k = 0; k < method_refs->length(); k++) {
  3647             // all methods were made obsolete during that generation's
       
  3648             // RedefineClasses() operation. At the time of that
       
  3649             // operation, all EMCP methods were flushed so we don't
       
  3650             // have to go back any further.
       
  3651             //
       
  3652             // A NULL method_refs is different than an empty method_refs.
       
  3653             // We cannot infer any optimizations about older generations
       
  3654             // from an empty method_refs for the current generation.
       
  3655             break;
       
  3656           }
       
  3657 
       
  3658           for (int k = method_refs->length() - 1; k >= 0; k--) {
       
  3659             Method* method = method_refs->at(k);
  3558             Method* method = method_refs->at(k);
  3660 
  3559 
  3661             if (!method->is_obsolete() &&
  3560             if (!method->is_obsolete() &&
  3662                 method->name() == m_name &&
  3561                 method->name() == m_name &&
  3663                 method->signature() == m_signature) {
  3562                 method->signature() == m_signature) {
  3664               // The current RedefineClasses() call has made all EMCP
  3563               // The current RedefineClasses() call has made all EMCP
  3665               // versions of this method obsolete so mark it as obsolete
  3564               // versions of this method obsolete so mark it as obsolete
  3666               // and remove the reference.
       
  3667               RC_TRACE(0x00000400,
  3565               RC_TRACE(0x00000400,
  3668                 ("add: %s(%s): flush obsolete method @%d in version @%d",
  3566                 ("add: %s(%s): flush obsolete method @%d in version @%d",
  3669                 m_name->as_C_string(), m_signature->as_C_string(), k, j));
  3567                 m_name->as_C_string(), m_signature->as_C_string(), k, j));
  3670 
  3568 
  3671               method->set_is_obsolete();
  3569               method->set_is_obsolete();
  3672               // Leave obsolete methods on the previous version list to
       
  3673               // clean up later.
       
  3674               break;
  3570               break;
  3675             }
  3571             }
  3676           }
  3572           }
  3677 
  3573 
  3678           // The previous loop may not find a matching EMCP method, but
  3574           // The previous loop may not find a matching EMCP method, but
  3679           // that doesn't mean that we can optimize and not go any
  3575           // that doesn't mean that we can optimize and not go any
  3680           // further back in the PreviousVersion generations. The EMCP
  3576           // further back in the PreviousVersion generations. The EMCP
  3681           // method for this generation could have already been deleted,
  3577           // method for this generation could have already been made obsolete,
  3682           // but there still may be an older EMCP method that has not
  3578           // but there still may be an older EMCP method that has not
  3683           // been deleted.
  3579           // been made obsolete.
  3684         }
  3580         }
  3685 
  3581 
  3686         if (++local_count >= obsolete_method_count) {
  3582         if (++local_count >= obsolete_method_count) {
  3687           // no more obsolete methods so bail out now
  3583           // no more obsolete methods so bail out now
  3688           break;
  3584           break;
  3689         }
  3585         }
  3690       }
  3586       }
  3691     }
  3587     }
  3692   }
  3588   }
       
  3589 }
       
  3590 
       
  3591 // Save the scratch_class as the previous version if any of the methods are running.
       
  3592 // The previous_versions are used to set breakpoints in EMCP methods and they are
       
  3593 // also used to clean MethodData links to redefined methods that are no longer running.
       
  3594 void InstanceKlass::add_previous_version(instanceKlassHandle scratch_class,
       
  3595                                          int emcp_method_count) {
       
  3596   assert(Thread::current()->is_VM_thread(),
       
  3597          "only VMThread can add previous versions");
       
  3598 
       
  3599   // RC_TRACE macro has an embedded ResourceMark
       
  3600   RC_TRACE(0x00000400, ("adding previous version ref for %s, EMCP_cnt=%d",
       
  3601     scratch_class->external_name(), emcp_method_count));
       
  3602 
       
  3603   // Clean out old previous versions
       
  3604   purge_previous_versions(this);
       
  3605 
       
  3606   // Mark newly obsolete methods in remaining previous versions.  An EMCP method from
       
  3607   // a previous redefinition may be made obsolete by this redefinition.
       
  3608   Array<Method*>* old_methods = scratch_class->methods();
       
  3609   mark_newly_obsolete_methods(old_methods, emcp_method_count);
       
  3610 
       
  3611   // If the constant pool for this previous version of the class
       
  3612   // is not marked as being on the stack, then none of the methods
       
  3613   // in this previous version of the class are on the stack so
       
  3614   // we don't need to add this as a previous version.
       
  3615   ConstantPool* cp_ref = scratch_class->constants();
       
  3616   if (!cp_ref->on_stack()) {
       
  3617     RC_TRACE(0x00000400, ("add: scratch class not added; no methods are running"));
       
  3618     return;
       
  3619   }
       
  3620 
       
  3621   if (emcp_method_count != 0) {
       
  3622     // At least one method is still running, check for EMCP methods
       
  3623     for (int i = 0; i < old_methods->length(); i++) {
       
  3624       Method* old_method = old_methods->at(i);
       
  3625       if (!old_method->is_obsolete() && old_method->on_stack()) {
       
  3626         // if EMCP method (not obsolete) is on the stack, mark as EMCP so that
       
  3627         // we can add breakpoints for it.
       
  3628 
       
  3629         // We set the method->on_stack bit during safepoints for class redefinition and
       
  3630         // class unloading and use this bit to set the is_running_emcp bit.
       
  3631         // After the safepoint, the on_stack bit is cleared and the running emcp
       
  3632         // method may exit.   If so, we would set a breakpoint in a method that
       
  3633         // is never reached, but this won't be noticeable to the programmer.
       
  3634         old_method->set_running_emcp(true);
       
  3635         RC_TRACE(0x00000400, ("add: EMCP method %s is on_stack " INTPTR_FORMAT,
       
  3636                               old_method->name_and_sig_as_C_string(), old_method));
       
  3637       } else if (!old_method->is_obsolete()) {
       
  3638         RC_TRACE(0x00000400, ("add: EMCP method %s is NOT on_stack " INTPTR_FORMAT,
       
  3639                               old_method->name_and_sig_as_C_string(), old_method));
       
  3640       }
       
  3641     }
       
  3642   }
       
  3643 
       
  3644   // Add previous version if any methods are still running.
       
  3645   RC_TRACE(0x00000400, ("add: scratch class added; one of its methods is on_stack"));
       
  3646   assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version");
       
  3647   scratch_class->link_previous_versions(previous_versions());
       
  3648   link_previous_versions(scratch_class());
  3693 } // end add_previous_version()
  3649 } // end add_previous_version()
  3694 
       
  3695 
       
  3696 // Determine if InstanceKlass has a previous version.
       
  3697 bool InstanceKlass::has_previous_version() const {
       
  3698   return (_previous_versions != NULL && _previous_versions->length() > 0);
       
  3699 } // end has_previous_version()
       
  3700 
  3650 
  3701 
  3651 
  3702 Method* InstanceKlass::method_with_idnum(int idnum) {
  3652 Method* InstanceKlass::method_with_idnum(int idnum) {
  3703   Method* m = NULL;
  3653   Method* m = NULL;
  3704   if (idnum < methods()->length()) {
  3654   if (idnum < methods()->length()) {
  3722 }
  3672 }
  3723 
  3673 
  3724 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
  3674 unsigned char * InstanceKlass::get_cached_class_file_bytes() {
  3725   return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
  3675   return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file);
  3726 }
  3676 }
  3727 
       
  3728 
       
  3729 // Construct a PreviousVersionNode entry for the array hung off
       
  3730 // the InstanceKlass.
       
  3731 PreviousVersionNode::PreviousVersionNode(ConstantPool* prev_constant_pool,
       
  3732   GrowableArray<Method*>* prev_EMCP_methods) {
       
  3733 
       
  3734   _prev_constant_pool = prev_constant_pool;
       
  3735   _prev_EMCP_methods = prev_EMCP_methods;
       
  3736 }
       
  3737 
       
  3738 
       
  3739 // Destroy a PreviousVersionNode
       
  3740 PreviousVersionNode::~PreviousVersionNode() {
       
  3741   if (_prev_constant_pool != NULL) {
       
  3742     _prev_constant_pool = NULL;
       
  3743   }
       
  3744 
       
  3745   if (_prev_EMCP_methods != NULL) {
       
  3746     delete _prev_EMCP_methods;
       
  3747   }
       
  3748 }
       
  3749 
       
  3750 // Construct a helper for walking the previous versions array
       
  3751 PreviousVersionWalker::PreviousVersionWalker(Thread* thread, InstanceKlass *ik) {
       
  3752   _thread = thread;
       
  3753   _previous_versions = ik->previous_versions();
       
  3754   _current_index = 0;
       
  3755   _current_p = NULL;
       
  3756   _current_constant_pool_handle = constantPoolHandle(thread, ik->constants());
       
  3757 }
       
  3758 
       
  3759 
       
  3760 // Return the interesting information for the next previous version
       
  3761 // of the klass. Returns NULL if there are no more previous versions.
       
  3762 PreviousVersionNode* PreviousVersionWalker::next_previous_version() {
       
  3763   if (_previous_versions == NULL) {
       
  3764     // no previous versions so nothing to return
       
  3765     return NULL;
       
  3766   }
       
  3767 
       
  3768   _current_p = NULL;  // reset to NULL
       
  3769   _current_constant_pool_handle = NULL;
       
  3770 
       
  3771   int length = _previous_versions->length();
       
  3772 
       
  3773   while (_current_index < length) {
       
  3774     PreviousVersionNode * pv_node = _previous_versions->at(_current_index++);
       
  3775 
       
  3776     // Save a handle to the constant pool for this previous version,
       
  3777     // which keeps all the methods from being deallocated.
       
  3778     _current_constant_pool_handle = constantPoolHandle(_thread, pv_node->prev_constant_pool());
       
  3779     _current_p = pv_node;
       
  3780     return pv_node;
       
  3781   }
       
  3782 
       
  3783   return NULL;
       
  3784 } // end next_previous_version()