312 313 void ClassLoaderData::packages_do(void f(PackageEntry*)) { 314 assert_locked_or_safepoint(Module_lock); 315 if (_packages != NULL) { 316 for (int i = 0; i < _packages->table_size(); i++) { 317 for (PackageEntry* entry = _packages->bucket(i); 318 entry != NULL; 319 entry = entry->next()) { 320 f(entry); 321 } 322 } 323 } 324 } 325 326 void ClassLoaderData::record_dependency(const Klass* k, TRAPS) { 327 assert(k != NULL, "invariant"); 328 329 ClassLoaderData * const from_cld = this; 330 ClassLoaderData * const to_cld = k->class_loader_data(); 331 332 // Dependency to the null class loader data doesn't need to be recorded 333 // because the null class loader data never goes away. 334 if (to_cld->is_the_null_class_loader_data()) { 335 return; 336 } 337 338 oop to; 339 if (to_cld->is_anonymous()) { 340 // Anonymous class dependencies are through the mirror. 341 to = k->java_mirror(); 342 } else { 343 to = to_cld->class_loader(); 344 345 // If from_cld is anonymous, even if it's class_loader is a parent of 'to' 346 // we still have to add it. The class_loader won't keep from_cld alive. 347 if (!from_cld->is_anonymous()) { 348 // Check that this dependency isn't from the same or parent class_loader 349 oop from = from_cld->class_loader(); 350 351 oop curr = from; 352 while (curr != NULL) { 353 if (curr == to) { 354 return; // this class loader is in the parent list, no need to add it. 355 } 356 curr = java_lang_ClassLoader::parent(curr); 357 } 358 } 359 } 360 361 // It's a dependency we won't find through GC, add it. This is relatively rare 362 // Must handle over GC point. 363 Handle dependency(THREAD, to); 364 from_cld->_dependencies.add(dependency, CHECK); 365 366 // Added a potentially young gen oop to the ClassLoaderData 367 record_modified_oops(); 368 } 369 370 371 void ClassLoaderData::Dependencies::add(Handle dependency, TRAPS) { 372 // Check first if this dependency is already in the list. 373 // Save a pointer to the last to add to under the lock. 374 objArrayOop ok = _list_head; 375 objArrayOop last = NULL; 376 while (ok != NULL) { 377 last = ok; 378 if (ok->obj_at(0) == dependency()) { 379 // Don't need to add it 380 return; 381 } 687 // Delete lock 688 delete _metaspace_lock; 689 690 // Delete free list 691 if (_deallocate_list != NULL) { 692 delete _deallocate_list; 693 } 694 } 695 696 // Returns true if this class loader data is for the system class loader. 697 bool ClassLoaderData::is_system_class_loader_data() const { 698 return SystemDictionary::is_system_class_loader(class_loader()); 699 } 700 701 // Returns true if this class loader data is for the platform class loader. 702 bool ClassLoaderData::is_platform_class_loader_data() const { 703 return SystemDictionary::is_platform_class_loader(class_loader()); 704 } 705 706 // Returns true if this class loader data is one of the 3 builtin 707 // (boot, application/system or platform) class loaders. Note, the 708 // builtin loaders are not freed by a GC. 709 bool ClassLoaderData::is_builtin_class_loader_data() const { 710 return (is_the_null_class_loader_data() || 711 SystemDictionary::is_system_class_loader(class_loader()) || 712 SystemDictionary::is_platform_class_loader(class_loader())); 713 } 714 715 Metaspace* ClassLoaderData::metaspace_non_null() { 716 // If the metaspace has not been allocated, create a new one. Might want 717 // to create smaller arena for Reflection class loaders also. 718 // The reason for the delayed allocation is because some class loaders are 719 // simply for delegating with no metadata of their own. 720 // Lock-free access requires load_acquire. 721 Metaspace* metaspace = OrderAccess::load_acquire(&_metaspace); 722 if (metaspace == NULL) { 723 MutexLockerEx ml(_metaspace_lock, Mutex::_no_safepoint_check_flag); 724 // Check if _metaspace got allocated while we were waiting for this lock. 725 if ((metaspace = _metaspace) == NULL) { 726 if (this == the_null_class_loader_data()) { 727 assert (class_loader() == NULL, "Must be"); 728 metaspace = new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType); 729 } else if (is_anonymous()) { 730 if (class_loader() != NULL) { 731 log_trace(class, loader, data)("is_anonymous: %s", class_loader()->klass()->internal_name()); 732 } | 312 313 void ClassLoaderData::packages_do(void f(PackageEntry*)) { 314 assert_locked_or_safepoint(Module_lock); 315 if (_packages != NULL) { 316 for (int i = 0; i < _packages->table_size(); i++) { 317 for (PackageEntry* entry = _packages->bucket(i); 318 entry != NULL; 319 entry = entry->next()) { 320 f(entry); 321 } 322 } 323 } 324 } 325 326 void ClassLoaderData::record_dependency(const Klass* k, TRAPS) { 327 assert(k != NULL, "invariant"); 328 329 ClassLoaderData * const from_cld = this; 330 ClassLoaderData * const to_cld = k->class_loader_data(); 331 332 // Do not need to record dependency if the dependency is to a class whose 333 // class loader data is never freed. (i.e. the dependency's class loader 334 // is one of the three builtin class loaders and the dependency is not 335 // anonymous.) 336 if (to_cld->is_permanent_class_loader_data()) { 337 return; 338 } 339 340 oop to; 341 if (to_cld->is_anonymous()) { 342 // Anonymous class dependencies are through the mirror. 343 to = k->java_mirror(); 344 } else { 345 to = to_cld->class_loader(); 346 oop from = from_cld->class_loader(); 347 348 // Just return if this dependency is to a class with the same or a parent 349 // class_loader. 350 if (from == to || java_lang_ClassLoader::isAncestor(from, to)) { 351 return; // this class loader is in the parent list, no need to add it. 352 } 353 } 354 355 // It's a dependency we won't find through GC, add it. This is relatively rare. 356 // Must handle over GC point. 357 Handle dependency(THREAD, to); 358 from_cld->_dependencies.add(dependency, CHECK); 359 360 // Added a potentially young gen oop to the ClassLoaderData 361 record_modified_oops(); 362 } 363 364 365 void ClassLoaderData::Dependencies::add(Handle dependency, TRAPS) { 366 // Check first if this dependency is already in the list. 367 // Save a pointer to the last to add to under the lock. 368 objArrayOop ok = _list_head; 369 objArrayOop last = NULL; 370 while (ok != NULL) { 371 last = ok; 372 if (ok->obj_at(0) == dependency()) { 373 // Don't need to add it 374 return; 375 } 681 // Delete lock 682 delete _metaspace_lock; 683 684 // Delete free list 685 if (_deallocate_list != NULL) { 686 delete _deallocate_list; 687 } 688 } 689 690 // Returns true if this class loader data is for the system class loader. 691 bool ClassLoaderData::is_system_class_loader_data() const { 692 return SystemDictionary::is_system_class_loader(class_loader()); 693 } 694 695 // Returns true if this class loader data is for the platform class loader. 696 bool ClassLoaderData::is_platform_class_loader_data() const { 697 return SystemDictionary::is_platform_class_loader(class_loader()); 698 } 699 700 // Returns true if this class loader data is one of the 3 builtin 701 // (boot, application/system or platform) class loaders. Note that 702 // if the class loader data is for an anonymous class then it may get 703 // freed by a GC even if its class loader is one of the 3 builtin 704 // loaders. 705 bool ClassLoaderData::is_builtin_class_loader_data() const { 706 return (is_the_null_class_loader_data() || 707 SystemDictionary::is_system_class_loader(class_loader()) || 708 SystemDictionary::is_platform_class_loader(class_loader())); 709 } 710 711 // Returns true if this class loader data is a class loader data 712 // that is not ever freed by a GC. It must be one of the builtin 713 // class loaders and not anonymous. 714 bool ClassLoaderData::is_permanent_class_loader_data() const { 715 return is_builtin_class_loader_data() && !is_anonymous(); 716 } 717 718 Metaspace* ClassLoaderData::metaspace_non_null() { 719 // If the metaspace has not been allocated, create a new one. Might want 720 // to create smaller arena for Reflection class loaders also. 721 // The reason for the delayed allocation is because some class loaders are 722 // simply for delegating with no metadata of their own. 723 // Lock-free access requires load_acquire. 724 Metaspace* metaspace = OrderAccess::load_acquire(&_metaspace); 725 if (metaspace == NULL) { 726 MutexLockerEx ml(_metaspace_lock, Mutex::_no_safepoint_check_flag); 727 // Check if _metaspace got allocated while we were waiting for this lock. 728 if ((metaspace = _metaspace) == NULL) { 729 if (this == the_null_class_loader_data()) { 730 assert (class_loader() == NULL, "Must be"); 731 metaspace = new Metaspace(_metaspace_lock, Metaspace::BootMetaspaceType); 732 } else if (is_anonymous()) { 733 if (class_loader() != NULL) { 734 log_trace(class, loader, data)("is_anonymous: %s", class_loader()->klass()->internal_name()); 735 } |