6 Replies Latest reply on Feb 10, 2010 5:43 PM by flavia.rainone

    Modules with null ClassLoaders

    flavia.rainone

      I have just found out that ClassPoolRepository is registering null class loaders.

      JBossClDelegatingClassPoolFactory.create method has a call to registerBootstrapClassLoaders

       

      public synchronized AbstractClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
         {
            if (this.currentClassLoaders.contains(cl))
            {
               return null;
            }
            currentClassLoaders.add(cl);
            try
            {
               ClassPool parent = getCreateParentClassPools(cl, src, repository);
               
               if (cl instanceof RealClassLoader)
               {
                  Module module = registry.getModule(cl);
                  if (module == null)
                  {
                     module = getModuleForClassLoader(cl);
                  }
                  registerModuleCallback.registerModule(module);
       --->           registerBootstrapLoaders(module, repository);
      ...
      }
      

       

      This is the implementation of registerBootstrapLoaders:

       

      private void registerBootstrapLoaders(Module skip, ScopedClassPoolRepository repository)
         {
            Collection<Module> unregistered = registerModuleCallback.getUnregisteredModules();
            if (unregistered.size() > 0)
            {
               for (Module module : unregistered)
               {
                  if (module == skip)
                  {
                     continue;
                  }
                  ClassLoader loader = getClassLoaderForModule(module);
                  if (this.currentClassLoaders.contains(loader))
                  {
                     continue;
                  }
                  ClassPool classPool = repository.registerClassLoader(loader);
                  if (classPool == null)
                  {
                     repository.unregisterClassLoader(loader);
                  }
               }
            }
         }
      

       

      The problem is that many of those modules, if not all, have a null class loader at this point.

       

      I'll try skipping the registration of such modules to see if any test breaks. Does anybody has a better idea on how to fix this?

        • 1. Re: Modules with null ClassLoaders
          flavia.rainone

          flavia.rainone@jboss.com wrote:

           

          I'll try skipping the registration of such modules to see if any test breaks. Does anybody has a better idea on how to fix this?

          That didn't break of the tests. Thinking again, it makes a lot of sense to skip the registration of such modules. Given that the newly created class pool will be mapped to a null class loader, it is useless. We are just generating overhead that way.

          Now I wonder which scenarios registerBootstrapLoaders is really needed for.

          • 2. Re: Modules with null ClassLoaders
            kabirkhan

            flavia.rainone@jboss.com wrote:

             

            flavia.rainone@jboss.com wrote:

             

            I'll try skipping the registration of such modules to see if any test breaks. Does anybody has a better idea on how to fix this?

            That didn't break of the tests. Thinking again, it makes a lot of sense to skip the registration of such modules. Given that the newly created class pool will be mapped to a null class loader, it is useless. We are just generating overhead that way.

            Now I wonder which scenarios registerBootstrapLoaders is really needed for.

            That was probably just me fumbling in the dark :-) If some of them are not null, the purpose is probably to register those. Or are all of them null? I'm not familiar enough with the classloading/Module stuff to really know why the modules would have null classloaders

            • 3. Re: Modules with null ClassLoaders
              flavia.rainone
              I created a Jira for this issue: JBREFLECT-95
              • 4. Re: Modules with null ClassLoaders
                flavia.rainone

                kabir.khan@jboss.com wrote:

                 

                That was probably just me fumbling in the dark :-) If some of them are not null, the purpose is probably to register those. Or are all of them null? I'm not familiar enough with the classloading/Module stuff to really know why the modules would have null classloaders

                Thanks for the response!

                I'll check that to see if this method is reallly needed.

                • 5. Re: Modules with null ClassLoaders
                  flavia.rainone

                  flavia.rainone@jboss.com wrote:

                   

                  I'll check that to see if this method is reallly needed.

                  I'll wait until all tests are passing before I try to remove that method.

                  • 6. Re: Modules with null ClassLoaders
                    flavia.rainone

                    kabir.khan@jboss.com wrote:

                     

                    That was probably just me fumbling in the dark :-) If some of them are not null, the purpose is probably to register those. Or are all of them null? I'm not familiar enough with the classloading/Module stuff to really know why the modules would have null classloaders

                    I just removed registerBootstrapLoaders body to test that. And it turns out that there are modules that are not null and that should be registered. I'm getting several failures at the AOP/AS tests with registerBootstrapLoaders disabled. So, I'll keep things the way they are.