src/hotspot/share/classfile/classLoaderData.cpp
changeset 48860 5bce1b7e7800
parent 48811 58787a1708d2
child 48871 120d6893f32f
equal deleted inserted replaced
48859:5a4d08efbad9 48860:5bce1b7e7800
   327   assert(k != NULL, "invariant");
   327   assert(k != NULL, "invariant");
   328 
   328 
   329   ClassLoaderData * const from_cld = this;
   329   ClassLoaderData * const from_cld = this;
   330   ClassLoaderData * const to_cld = k->class_loader_data();
   330   ClassLoaderData * const to_cld = k->class_loader_data();
   331 
   331 
   332   // Dependency to the null class loader data doesn't need to be recorded
   332   // Do not need to record dependency if the dependency is to a class whose
   333   // because the null class loader data never goes away.
   333   // class loader data is never freed.  (i.e. the dependency's class loader
   334   if (to_cld->is_the_null_class_loader_data()) {
   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()) {
   335     return;
   337     return;
   336   }
   338   }
   337 
   339 
   338   oop to;
   340   oop to;
   339   if (to_cld->is_anonymous()) {
   341   if (to_cld->is_anonymous()) {
       
   342     // Just return if an anonymous class is attempting to record a dependency
       
   343     // to itself.  (Note that every anonymous class has its own unique class
       
   344     // loader data.)
       
   345     if (to_cld == from_cld) {
       
   346       return;
       
   347     }
   340     // Anonymous class dependencies are through the mirror.
   348     // Anonymous class dependencies are through the mirror.
   341     to = k->java_mirror();
   349     to = k->java_mirror();
   342   } else {
   350   } else {
   343     to = to_cld->class_loader();
   351     to = to_cld->class_loader();
   344 
   352     oop from = from_cld->class_loader();
   345     // If from_cld is anonymous, even if it's class_loader is a parent of 'to'
   353 
   346     // we still have to add it.  The class_loader won't keep from_cld alive.
   354     // Just return if this dependency is to a class with the same or a parent
   347     if (!from_cld->is_anonymous()) {
   355     // class_loader.
   348       // Check that this dependency isn't from the same or parent class_loader
   356     if (from == to || java_lang_ClassLoader::isAncestor(from, to)) {
   349       oop from = from_cld->class_loader();
   357       return; // this class loader is in the parent list, no need to add it.
   350 
   358     }
   351       oop curr = from;
   359   }
   352       while (curr != NULL) {
   360 
   353         if (curr == to) {
   361   // It's a dependency we won't find through GC, add it. This is relatively rare.
   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.
   362   // Must handle over GC point.
   363   Handle dependency(THREAD, to);
   363   Handle dependency(THREAD, to);
   364   from_cld->_dependencies.add(dependency, CHECK);
   364   from_cld->_dependencies.add(dependency, CHECK);
   365 
   365 
   366   // Added a potentially young gen oop to the ClassLoaderData
   366   // Added a potentially young gen oop to the ClassLoaderData
   702 bool ClassLoaderData::is_platform_class_loader_data() const {
   702 bool ClassLoaderData::is_platform_class_loader_data() const {
   703   return SystemDictionary::is_platform_class_loader(class_loader());
   703   return SystemDictionary::is_platform_class_loader(class_loader());
   704 }
   704 }
   705 
   705 
   706 // Returns true if this class loader data is one of the 3 builtin
   706 // Returns true if this class loader data is one of the 3 builtin
   707 // (boot, application/system or platform) class loaders. Note, the
   707 // (boot, application/system or platform) class loaders.  Note that
   708 // builtin loaders are not freed by a GC.
   708 // if the class loader data is for an anonymous class then it may get
       
   709 // freed by a GC even if its class loader is one of the 3 builtin
       
   710 // loaders.
   709 bool ClassLoaderData::is_builtin_class_loader_data() const {
   711 bool ClassLoaderData::is_builtin_class_loader_data() const {
   710   return (is_the_null_class_loader_data() ||
   712   return (is_the_null_class_loader_data() ||
   711           SystemDictionary::is_system_class_loader(class_loader()) ||
   713           SystemDictionary::is_system_class_loader(class_loader()) ||
   712           SystemDictionary::is_platform_class_loader(class_loader()));
   714           SystemDictionary::is_platform_class_loader(class_loader()));
       
   715 }
       
   716 
       
   717 // Returns true if this class loader data is a class loader data
       
   718 // that is not ever freed by a GC.  It must be one of the builtin
       
   719 // class loaders and not anonymous.
       
   720 bool ClassLoaderData::is_permanent_class_loader_data() const {
       
   721   return is_builtin_class_loader_data() && !is_anonymous();
   713 }
   722 }
   714 
   723 
   715 Metaspace* ClassLoaderData::metaspace_non_null() {
   724 Metaspace* ClassLoaderData::metaspace_non_null() {
   716   // If the metaspace has not been allocated, create a new one.  Might want
   725   // If the metaspace has not been allocated, create a new one.  Might want
   717   // to create smaller arena for Reflection class loaders also.
   726   // to create smaller arena for Reflection class loaders also.