src/share/vm/classfile/classLoaderData.cpp

Print this page
rev 9502 : imported patch class_loading_log


  37 // ClassLoaderData carries information related to a linkset (e.g.,
  38 // metaspace holding its klass definitions).
  39 // The System Dictionary and related data structures (e.g., placeholder table,
  40 // loader constraints table) as well as the runtime representation of classes
  41 // only reference ClassLoaderData.
  42 //
  43 // Instances of java.lang.ClassLoader holds a pointer to a ClassLoaderData that
  44 // that represent the loader's "linking domain" in the JVM.
  45 //
  46 // The bootstrap loader (represented by NULL) also has a ClassLoaderData,
  47 // the singleton class the_null_class_loader_data().
  48 
  49 #include "precompiled.hpp"
  50 #include "classfile/classLoaderData.hpp"
  51 #include "classfile/classLoaderData.inline.hpp"
  52 #include "classfile/javaClasses.hpp"
  53 #include "classfile/metadataOnStackMark.hpp"
  54 #include "classfile/systemDictionary.hpp"
  55 #include "code/codeCache.hpp"
  56 #include "gc/shared/gcLocker.hpp"

  57 #include "memory/metadataFactory.hpp"
  58 #include "memory/metaspaceShared.hpp"
  59 #include "memory/oopFactory.hpp"
  60 #include "oops/objArrayOop.inline.hpp"
  61 #include "oops/oop.inline.hpp"
  62 #include "runtime/atomic.inline.hpp"

  63 #include "runtime/jniHandles.hpp"
  64 #include "runtime/mutex.hpp"
  65 #include "runtime/safepoint.hpp"
  66 #include "runtime/synchronizer.hpp"
  67 #include "utilities/growableArray.hpp"
  68 #include "utilities/macros.hpp"
  69 #include "utilities/ostream.hpp"
  70 #if INCLUDE_TRACE
  71 #include "trace/tracing.hpp"
  72 #endif
  73 
  74 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
  75 
  76 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
  77   _class_loader(h_class_loader()),
  78   _is_anonymous(is_anonymous),
  79   // An anonymous class loader data doesn't have anything to keep
  80   // it from being unloaded during parsing of the anonymous class.
  81   // The null-class-loader should always be kept alive.
  82   _keep_alive(is_anonymous || h_class_loader.is_null()),


 265   } else {
 266     last->obj_at_put(1, new_dependency());
 267   }
 268 }
 269 
 270 void ClassLoaderDataGraph::clear_claimed_marks() {
 271   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 272     cld->clear_claimed();
 273   }
 274 }
 275 
 276 void ClassLoaderData::add_class(Klass* k) {
 277   MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 278   Klass* old_value = _klasses;
 279   k->set_next_link(old_value);
 280   // Make sure linked class is stable, since the class list is walked without a lock
 281   OrderAccess::storestore();
 282   // link the new item into the list
 283   _klasses = k;
 284 
 285   if (TraceClassLoaderData && Verbose && k->class_loader_data() != NULL) {
 286     ResourceMark rm;
 287     tty->print_cr("[TraceClassLoaderData] Adding k: " PTR_FORMAT " %s to CLD: "

 288                   PTR_FORMAT " loader: " PTR_FORMAT " %s",
 289                   p2i(k),
 290                   k->external_name(),
 291                   p2i(k->class_loader_data()),
 292                   p2i((void *)k->class_loader()),
 293                   loader_name());
 294   }
 295 }
 296 
 297 // This is called by InstanceKlass::deallocate_contents() to remove the
 298 // scratch_class for redefine classes.  We need a lock because there it may not
 299 // be called at a safepoint if there's an error.
 300 void ClassLoaderData::remove_class(Klass* scratch_class) {
 301   MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 302   Klass* prev = NULL;
 303   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
 304     if (k == scratch_class) {
 305       if (prev == NULL) {
 306         _klasses = k->next_link();
 307       } else {
 308         Klass* next = k->next_link();
 309         prev->set_next_link(next);
 310       }
 311       return;
 312     }
 313     prev = k;
 314     assert(k != k->next_link(), "no loops!");
 315   }
 316   ShouldNotReachHere();   // should have found this class!!
 317 }
 318 
 319 void ClassLoaderData::unload() {
 320   _unloading = true;
 321 
 322   // Tell serviceability tools these classes are unloading
 323   classes_do(InstanceKlass::notify_unload_class);
 324 
 325   if (TraceClassLoaderData) {
 326     ResourceMark rm;
 327     tty->print("[ClassLoaderData: unload loader data " INTPTR_FORMAT, p2i(this));
 328     tty->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)class_loader()),

 329                loader_name());
 330     if (is_anonymous()) {
 331       tty->print(" for anonymous class  " INTPTR_FORMAT " ", p2i(_klasses));
 332     }
 333     tty->print_cr("]");
 334   }
 335 }
 336 
 337 oop ClassLoaderData::keep_alive_object() const {
 338   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 339   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 340 }
 341 
 342 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 343   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 344       || is_alive_closure->do_object_b(keep_alive_object());
 345 
 346   return alive;
 347 }
 348 
 349 
 350 ClassLoaderData::~ClassLoaderData() {
 351   // Release C heap structures for all the classes.
 352   classes_do(InstanceKlass::release_C_heap_structures);
 353 


 387 bool ClassLoaderData::is_ext_class_loader_data() const {
 388   return SystemDictionary::is_ext_class_loader(class_loader());
 389 }
 390 
 391 Metaspace* ClassLoaderData::metaspace_non_null() {
 392   assert(!DumpSharedSpaces, "wrong metaspace!");
 393   // If the metaspace has not been allocated, create a new one.  Might want
 394   // to create smaller arena for Reflection class loaders also.
 395   // The reason for the delayed allocation is because some class loaders are
 396   // simply for delegating with no metadata of their own.
 397   if (_metaspace == NULL) {
 398     MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 399     // Check again if metaspace has been allocated while we were getting this lock.
 400     if (_metaspace != NULL) {
 401       return _metaspace;
 402     }
 403     if (this == the_null_class_loader_data()) {
 404       assert (class_loader() == NULL, "Must be");
 405       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType));
 406     } else if (is_anonymous()) {
 407       if (TraceClassLoaderData && Verbose && class_loader() != NULL) {
 408         tty->print_cr("is_anonymous: %s", class_loader()->klass()->internal_name());
 409       }
 410       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::AnonymousMetaspaceType));
 411     } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 412       if (TraceClassLoaderData && Verbose && class_loader() != NULL) {
 413         tty->print_cr("is_reflection: %s", class_loader()->klass()->internal_name());
 414       }
 415       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::ReflectionMetaspaceType));
 416     } else {
 417       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType));
 418     }
 419   }
 420   return _metaspace;
 421 }
 422 
 423 JNIHandleBlock* ClassLoaderData::handles() const           { return _handles; }
 424 void ClassLoaderData::set_handles(JNIHandleBlock* handles) { _handles = handles; }
 425 
 426 jobject ClassLoaderData::add_handle(Handle h) {
 427   MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 428   if (handles() == NULL) {
 429     set_handles(JNIHandleBlock::allocate_block());
 430   }
 431   return handles()->allocate_handle(h());
 432 }
 433 


 580   if (!is_anonymous) {
 581     ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader());
 582     // First, Atomically set it
 583     ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL);
 584     if (old != NULL) {
 585       delete cld;
 586       // Returns the data.
 587       return old;
 588     }
 589   }
 590 
 591   // We won the race, and therefore the task of adding the data to the list of
 592   // class loader data
 593   ClassLoaderData** list_head = &_head;
 594   ClassLoaderData* next = _head;
 595 
 596   do {
 597     cld->set_next(next);
 598     ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next);
 599     if (exchanged == next) {
 600       if (TraceClassLoaderData) {
 601         ResourceMark rm;
 602         tty->print("[ClassLoaderData: ");
 603         tty->print("create class loader data " INTPTR_FORMAT, p2i(cld));
 604         tty->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)cld->class_loader()),
 605                    cld->loader_name());
 606         tty->print_cr("]");
 607       }
 608       return cld;
 609     }
 610     next = exchanged;
 611   } while (true);
 612 
 613 }
 614 






























 615 void ClassLoaderDataGraph::oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
 616   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 617     cld->oops_do(f, klass_closure, must_claim);
 618   }
 619 }
 620 
 621 void ClassLoaderDataGraph::keep_alive_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
 622   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 623     if (cld->keep_alive()) {
 624       cld->oops_do(f, klass_closure, must_claim);
 625     }
 626   }
 627 }
 628 
 629 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
 630   if (ClassUnloading) {
 631     keep_alive_oops_do(f, klass_closure, must_claim);
 632   } else {
 633     oops_do(f, klass_closure, must_claim);
 634   }


 688 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
 689   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
 690   // Only walk the head until any clds not purged from prior unloading
 691   // (CMS doesn't purge right away).
 692   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
 693     cld->classes_do(f);
 694   }
 695 }
 696 
 697 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
 698   assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
 699 
 700   GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
 701 
 702   // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
 703   ClassLoaderData* curr = _head;
 704   while (curr != _saved_head) {
 705     if (!curr->claimed()) {
 706       array->push(curr);
 707 
 708       if (TraceClassLoaderData) {
 709         tty->print("[ClassLoaderData] found new CLD: ");
 710         curr->print_value_on(tty);
 711         tty->cr();

 712       }
 713     }
 714 
 715     curr = curr->_next;
 716   }
 717 
 718   return array;
 719 }
 720 
 721 bool ClassLoaderDataGraph::unload_list_contains(const void* x) {
 722   assert(SafepointSynchronize::is_at_safepoint(), "only safe to call at safepoint");
 723   for (ClassLoaderData* cld = _unloading; cld != NULL; cld = cld->next()) {
 724     if (cld->metaspace_or_null() != NULL && cld->metaspace_or_null()->contains(x)) {
 725       return true;
 726     }
 727   }
 728   return false;
 729 }
 730 
 731 #ifndef PRODUCT




  37 // ClassLoaderData carries information related to a linkset (e.g.,
  38 // metaspace holding its klass definitions).
  39 // The System Dictionary and related data structures (e.g., placeholder table,
  40 // loader constraints table) as well as the runtime representation of classes
  41 // only reference ClassLoaderData.
  42 //
  43 // Instances of java.lang.ClassLoader holds a pointer to a ClassLoaderData that
  44 // that represent the loader's "linking domain" in the JVM.
  45 //
  46 // The bootstrap loader (represented by NULL) also has a ClassLoaderData,
  47 // the singleton class the_null_class_loader_data().
  48 
  49 #include "precompiled.hpp"
  50 #include "classfile/classLoaderData.hpp"
  51 #include "classfile/classLoaderData.inline.hpp"
  52 #include "classfile/javaClasses.hpp"
  53 #include "classfile/metadataOnStackMark.hpp"
  54 #include "classfile/systemDictionary.hpp"
  55 #include "code/codeCache.hpp"
  56 #include "gc/shared/gcLocker.hpp"
  57 #include "logging/log.hpp"
  58 #include "memory/metadataFactory.hpp"
  59 #include "memory/metaspaceShared.hpp"
  60 #include "memory/oopFactory.hpp"
  61 #include "oops/objArrayOop.inline.hpp"
  62 #include "oops/oop.inline.hpp"
  63 #include "runtime/atomic.inline.hpp"
  64 #include "runtime/javaCalls.hpp"
  65 #include "runtime/jniHandles.hpp"
  66 #include "runtime/mutex.hpp"
  67 #include "runtime/safepoint.hpp"
  68 #include "runtime/synchronizer.hpp"
  69 #include "utilities/growableArray.hpp"
  70 #include "utilities/macros.hpp"
  71 #include "utilities/ostream.hpp"
  72 #if INCLUDE_TRACE
  73 #include "trace/tracing.hpp"
  74 #endif
  75 
  76 ClassLoaderData * ClassLoaderData::_the_null_class_loader_data = NULL;
  77 
  78 ClassLoaderData::ClassLoaderData(Handle h_class_loader, bool is_anonymous, Dependencies dependencies) :
  79   _class_loader(h_class_loader()),
  80   _is_anonymous(is_anonymous),
  81   // An anonymous class loader data doesn't have anything to keep
  82   // it from being unloaded during parsing of the anonymous class.
  83   // The null-class-loader should always be kept alive.
  84   _keep_alive(is_anonymous || h_class_loader.is_null()),


 267   } else {
 268     last->obj_at_put(1, new_dependency());
 269   }
 270 }
 271 
 272 void ClassLoaderDataGraph::clear_claimed_marks() {
 273   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 274     cld->clear_claimed();
 275   }
 276 }
 277 
 278 void ClassLoaderData::add_class(Klass* k) {
 279   MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 280   Klass* old_value = _klasses;
 281   k->set_next_link(old_value);
 282   // Make sure linked class is stable, since the class list is walked without a lock
 283   OrderAccess::storestore();
 284   // link the new item into the list
 285   _klasses = k;
 286 
 287   if (log_is_enabled(Trace, classloaderdata) && k->class_loader_data() != NULL) {
 288     ResourceMark rm;
 289     outputStream* log = LogHandle(classloaderdata)::trace_stream();
 290     log->print_cr("Adding k: " PTR_FORMAT " %s to CLD: "
 291                   PTR_FORMAT " loader: " PTR_FORMAT " %s",
 292                   p2i(k),
 293                   k->external_name(),
 294                   p2i(k->class_loader_data()),
 295                   p2i((void *)k->class_loader()),
 296                   loader_name());
 297   }
 298 }
 299 
 300 // This is called by InstanceKlass::deallocate_contents() to remove the
 301 // scratch_class for redefine classes.  We need a lock because there it may not
 302 // be called at a safepoint if there's an error.
 303 void ClassLoaderData::remove_class(Klass* scratch_class) {
 304   MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 305   Klass* prev = NULL;
 306   for (Klass* k = _klasses; k != NULL; k = k->next_link()) {
 307     if (k == scratch_class) {
 308       if (prev == NULL) {
 309         _klasses = k->next_link();
 310       } else {
 311         Klass* next = k->next_link();
 312         prev->set_next_link(next);
 313       }
 314       return;
 315     }
 316     prev = k;
 317     assert(k != k->next_link(), "no loops!");
 318   }
 319   ShouldNotReachHere();   // should have found this class!!
 320 }
 321 
 322 void ClassLoaderData::unload() {
 323   _unloading = true;
 324 
 325   // Tell serviceability tools these classes are unloading
 326   classes_do(InstanceKlass::notify_unload_class);
 327 
 328   if (log_is_enabled(Debug, classloaderdata)) {
 329     ResourceMark rm;
 330     outputStream* log = LogHandle(classloaderdata)::debug_stream();
 331     log->print(": unload loader data " INTPTR_FORMAT, p2i(this));
 332     log->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)class_loader()),
 333                loader_name());
 334     if (is_anonymous()) {
 335       log->print(" for anonymous class  " INTPTR_FORMAT " ", p2i(_klasses));
 336     }
 337     log->cr();
 338   }
 339 }
 340 
 341 oop ClassLoaderData::keep_alive_object() const {
 342   assert(!keep_alive(), "Don't use with CLDs that are artificially kept alive");
 343   return is_anonymous() ? _klasses->java_mirror() : class_loader();
 344 }
 345 
 346 bool ClassLoaderData::is_alive(BoolObjectClosure* is_alive_closure) const {
 347   bool alive = keep_alive() // null class loader and incomplete anonymous klasses.
 348       || is_alive_closure->do_object_b(keep_alive_object());
 349 
 350   return alive;
 351 }
 352 
 353 
 354 ClassLoaderData::~ClassLoaderData() {
 355   // Release C heap structures for all the classes.
 356   classes_do(InstanceKlass::release_C_heap_structures);
 357 


 391 bool ClassLoaderData::is_ext_class_loader_data() const {
 392   return SystemDictionary::is_ext_class_loader(class_loader());
 393 }
 394 
 395 Metaspace* ClassLoaderData::metaspace_non_null() {
 396   assert(!DumpSharedSpaces, "wrong metaspace!");
 397   // If the metaspace has not been allocated, create a new one.  Might want
 398   // to create smaller arena for Reflection class loaders also.
 399   // The reason for the delayed allocation is because some class loaders are
 400   // simply for delegating with no metadata of their own.
 401   if (_metaspace == NULL) {
 402     MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 403     // Check again if metaspace has been allocated while we were getting this lock.
 404     if (_metaspace != NULL) {
 405       return _metaspace;
 406     }
 407     if (this == the_null_class_loader_data()) {
 408       assert (class_loader() == NULL, "Must be");
 409       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType));
 410     } else if (is_anonymous()) {
 411       if (class_loader() != NULL) {
 412         log_trace(classloaderdata)("is_anonymous: %s", class_loader()->klass()->internal_name());
 413       }
 414       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::AnonymousMetaspaceType));
 415     } else if (class_loader()->is_a(SystemDictionary::reflect_DelegatingClassLoader_klass())) {
 416       if (class_loader() != NULL) {
 417         log_trace(classloaderdata)("is_reflection: %s", class_loader()->klass()->internal_name());
 418       }
 419       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::ReflectionMetaspaceType));
 420     } else {
 421       set_metaspace(new Metaspace(_metaspace_lock, Metaspace::StandardMetaspaceType));
 422     }
 423   }
 424   return _metaspace;
 425 }
 426 
 427 JNIHandleBlock* ClassLoaderData::handles() const           { return _handles; }
 428 void ClassLoaderData::set_handles(JNIHandleBlock* handles) { _handles = handles; }
 429 
 430 jobject ClassLoaderData::add_handle(Handle h) {
 431   MutexLockerEx ml(metaspace_lock(),  Mutex::_no_safepoint_check_flag);
 432   if (handles() == NULL) {
 433     set_handles(JNIHandleBlock::allocate_block());
 434   }
 435   return handles()->allocate_handle(h());
 436 }
 437 


 584   if (!is_anonymous) {
 585     ClassLoaderData** cld_addr = java_lang_ClassLoader::loader_data_addr(loader());
 586     // First, Atomically set it
 587     ClassLoaderData* old = (ClassLoaderData*) Atomic::cmpxchg_ptr(cld, cld_addr, NULL);
 588     if (old != NULL) {
 589       delete cld;
 590       // Returns the data.
 591       return old;
 592     }
 593   }
 594 
 595   // We won the race, and therefore the task of adding the data to the list of
 596   // class loader data
 597   ClassLoaderData** list_head = &_head;
 598   ClassLoaderData* next = _head;
 599 
 600   do {
 601     cld->set_next(next);
 602     ClassLoaderData* exchanged = (ClassLoaderData*)Atomic::cmpxchg_ptr(cld, list_head, next);
 603     if (exchanged == next) {
 604       if (log_is_enabled(Debug, classloaderdata)) {
 605         Pause_No_Safepoint_Verifier pnsv(&no_safepoints); // Need safe points for JavaCalls::call_virtual
 606         log_creation(loader, cld, CHECK_NULL);




 607       }
 608       return cld;
 609     }
 610     next = exchanged;
 611   } while (true);
 612 
 613 }
 614 
 615 void ClassLoaderDataGraph::log_creation(Handle loader, ClassLoaderData* cld, TRAPS) {
 616   Handle string;
 617   if (loader.not_null()) {
 618     // Include the result of loader.toString() in the output. This allows
 619     // the user of the log to identify the class loader instance.
 620     JavaValue result(T_OBJECT);
 621     KlassHandle spec_klass(THREAD, SystemDictionary::ClassLoader_klass());
 622     JavaCalls::call_virtual(&result,
 623                             loader,
 624                             spec_klass,
 625                             vmSymbols::toString_name(),
 626                             vmSymbols::void_string_signature(),
 627                             CHECK);
 628     assert(result.get_type() == T_OBJECT, "just checking");
 629     string = (oop)result.get_jobject();
 630   }
 631 
 632   ResourceMark rm;
 633   outputStream* log = LogHandle(classloaderdata)::debug_stream();
 634   log->print("create class loader data " INTPTR_FORMAT, p2i(cld));
 635   log->print(" for instance " INTPTR_FORMAT " of %s", p2i((void *)cld->class_loader()),
 636              cld->loader_name());
 637 
 638   if (string.not_null()) {
 639     log->print(": ");
 640     java_lang_String::print(string(), log);
 641   }
 642   log->cr();
 643 }
 644 
 645 void ClassLoaderDataGraph::oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
 646   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 647     cld->oops_do(f, klass_closure, must_claim);
 648   }
 649 }
 650 
 651 void ClassLoaderDataGraph::keep_alive_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
 652   for (ClassLoaderData* cld = _head; cld != NULL; cld = cld->next()) {
 653     if (cld->keep_alive()) {
 654       cld->oops_do(f, klass_closure, must_claim);
 655     }
 656   }
 657 }
 658 
 659 void ClassLoaderDataGraph::always_strong_oops_do(OopClosure* f, KlassClosure* klass_closure, bool must_claim) {
 660   if (ClassUnloading) {
 661     keep_alive_oops_do(f, klass_closure, must_claim);
 662   } else {
 663     oops_do(f, klass_closure, must_claim);
 664   }


 718 void ClassLoaderDataGraph::classes_unloading_do(void f(Klass* const)) {
 719   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
 720   // Only walk the head until any clds not purged from prior unloading
 721   // (CMS doesn't purge right away).
 722   for (ClassLoaderData* cld = _unloading; cld != _saved_unloading; cld = cld->next()) {
 723     cld->classes_do(f);
 724   }
 725 }
 726 
 727 GrowableArray<ClassLoaderData*>* ClassLoaderDataGraph::new_clds() {
 728   assert(_head == NULL || _saved_head != NULL, "remember_new_clds(true) not called?");
 729 
 730   GrowableArray<ClassLoaderData*>* array = new GrowableArray<ClassLoaderData*>();
 731 
 732   // The CLDs in [_head, _saved_head] were all added during last call to remember_new_clds(true);
 733   ClassLoaderData* curr = _head;
 734   while (curr != _saved_head) {
 735     if (!curr->claimed()) {
 736       array->push(curr);
 737 
 738       if (log_is_enabled(Debug, classloaderdata)) {
 739         outputStream* log = LogHandle(classloaderdata)::debug_stream();
 740         log->print("found new CLD: ");
 741         curr->print_value_on(log);
 742         log->cr();
 743       }
 744     }
 745 
 746     curr = curr->_next;
 747   }
 748 
 749   return array;
 750 }
 751 
 752 bool ClassLoaderDataGraph::unload_list_contains(const void* x) {
 753   assert(SafepointSynchronize::is_at_safepoint(), "only safe to call at safepoint");
 754   for (ClassLoaderData* cld = _unloading; cld != NULL; cld = cld->next()) {
 755     if (cld->metaspace_or_null() != NULL && cld->metaspace_or_null()->contains(x)) {
 756       return true;
 757     }
 758   }
 759   return false;
 760 }
 761 
 762 #ifndef PRODUCT