5 Replies Latest reply on Nov 4, 2008 7:26 PM by Ales Justin

    Missing element in WeakRefVFSCache

    Ales Justin Master

      Just something I noticed, which I didn't expect.

      I'm running JBossAS with WeakRefVFSCache: -Djboss.vfs.cache=org.jboss.virtual.plugins.cache.WeakRefVFSCache
      Hence every VFSContext that doesn't have strong ref should be GCed.

      In order to prevent some of them from being GCed too soon,
      I've added the following bean:

      public class PreInitializeVFSContexts
      {
       private Logger log = Logger.getLogger(PreInitializeVFSContexts.class);
       private List<URL> initializedVFSContexts;
       private boolean holdReference;
       private List<VFS> references;
      
       /**
       * Start initializer.
       *
       * @throws Exception for any exception
       */
       public void start() throws Exception
       {
       if (initializedVFSContexts != null && initializedVFSContexts.isEmpty() == false)
       {
       if (holdReference)
       references = new ArrayList<VFS>();
      
       for (URL url : initializedVFSContexts)
       {
       VFS vfs = VFS.getVFS(url);
       log.debug("Initialized Virtual File: " + vfs.getRoot());
       if (holdReference)
       {
       references.add(vfs);
       }
       }
       }
       }
      
       /**
       * Clear possible references.
       */
       public void stop()
       {
       if (references != null)
       references.clear();
       }
      
       /**
       * Get VFS references.
       *
       * @return the VFS references
       */
       public List<VFS> getReferences()
       {
       return references;
       }
      
       /**
       * Set URLs that need to be initialized before anything else.
       *
       * @param initializedVFSContexts the URLs to be initialized
       */
       public void setInitializedVFSContexts(List<URL> initializedVFSContexts)
       {
       this.initializedVFSContexts = initializedVFSContexts;
       }
      
       /**
       * Should we hold the reference to initialized VFSs.
       *
       * @param holdReference the hold reference flag
       */
       public void setHoldReference(boolean holdReference)
       {
       this.holdReference = holdReference;
       }
      }
      

      So, if you mark this bean as holdReference, it's gonna put VFS into List,
      hence keeping the strong ref; VFS --> VFSContext

      See JBossAS/initialize.xml:
       <bean name="JBossVFSInitializer" class="org.jboss.virtual.plugins.cache.PreInitializeVFSContexts">
       <property name="initializedVFSContexts">
       <list elementClass="java.net.URL">
       <value>${jboss.lib.url}</value>
       <value>${jboss.shared.lib.url}</value>
       <value>${jboss.server.lib.url}</value>
       </list>
       </property>
       <property name="holdReference">true</property>
       </bean>
      

      But when inspecting jmx-console VFSCacheStatistics,
      I'm missing jboss.server.lib.url (it's real value) in VFSContext list.

      Where did I go wrong? :-)

        • 1. Re: Missing element in WeakRefVFSCache
          Ales Justin Master

           

          "alesj" wrote:
          Where did I go wrong? :-)

          Hmmm, I though it might be due to nobody holding a ref to JBossVFSInitializer,
          but it should be KernelControllerContext that has it:
          - http://anonsvn.jboss.org/repos/jbossas/projects/microcontainer/trunk/kernel/src/main/java/org/jboss/kernel/plugins/dependency/InstantiateAction.java
          See context.setTarget(object).

          • 2. Re: Missing element in WeakRefVFSCache
            Adrian Brock Master

             

            "alesj" wrote:

            But when inspecting jmx-console VFSCacheStatistics,
            I'm missing jboss.server.lib.url (it's real value) in VFSContext list.

            Where did I go wrong? :-)


            Simple experiment shows that you are not showing the raw config options.
            In the default config (where that directory is empty) it does not appear,
            but it appears in the all config where it contains jars.

            [ejort@warjort bin]$ ./twiddle.sh invoke jboss.vfs:service=VFSCacheStatistics listCachedContexts
            <table><tr><th>VFSContext - root URI</th></tr><tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/lib/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/default/conf/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/default/deploy/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/default/deployers/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/lib/</td></tr></table>
            
            ...
            
            [ejort@warjort bin]$ ./twiddle.sh invoke jboss.vfs:service=VFSCacheStatistics listCachedContexts
            <table><tr><th>VFSContext - root URI</th></tr><tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/lib/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/all/conf/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/all/deploy-hasingleton</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/all/deploy/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/all/deployers/</td></tr>
            
            <!-- HERE -->
            
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/all/lib/</td></tr>
            <tr><td>file:/home/ejort/jboss-head/build/output/jboss-5.0.0.GA/server/lib/</td></tr></table>
            


            • 3. Re: Missing element in WeakRefVFSCache
              Adrian Brock Master

              Looks like you broke the build:

              17:39:56,993 ERROR [AbstractKernelController] Error installing to Start: name=VFSCache state=Create
              java.lang.IllegalAccessException: Class org.jboss.reflect.plugins.introspection.ReflectionUtils can not access a member of class org.jboss.virtual.spi.cache.VFSCacheFactory$NoopVFSCache with modifiers "public"
               at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
               at java.lang.reflect.Method.invoke(Method.java:578)
               at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:59)
               at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:150)
               at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
               at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:241)
               at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
               at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
               at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:70)
               at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:221)
               at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
               at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
               at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
               at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
               at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
               at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
               at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1598)
               at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
               at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1062)
               at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
               at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
               at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
               at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBean(AbstractKernelDeployer.java:331)
               at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deployBeans(AbstractKernelDeployer.java:309)
               at org.jboss.kernel.plugins.deployment.AbstractKernelDeployer.deploy(AbstractKernelDeployer.java:130)
               at org.jboss.kernel.plugins.deployment.BasicKernelDeployer.deploy(BasicKernelDeployer.java:76)
               at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:88)
               at org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer.deploy(BasicXMLDeployer.java:158)
               at org.jboss.bootstrap.microcontainer.ServerImpl.doStart(ServerImpl.java:115)
               at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:399)
               at org.jboss.Main.boot(Main.java:209)
               at org.jboss.Main$1.run(Main.java:544)
               at java.lang.Thread.run(Thread.java:595)
              


              In jboss-vfs 2.0.0.CR2 the class is not static

              [ejort@warjort bin]$ javap -c -classpath ~/.m2/repository/org/jboss/jboss-vfs/2.0.0.CR2/jboss-vfs-2.0.0.CR2.jar org.jboss.virtual.spi.cache.VFSCacheFactory.NoopVFSCache
              Compiled from "VFSCacheFactory.java"
              class org.jboss.virtual.spi.cache.VFSCacheFactory$NoopVFSCache extends java.lang.Object implements org.jboss.virtual.spi.cache.VFSCache{
              public org.jboss.virtual.VirtualFile getFile(java.net.URI) throws java.io.IOException;
               Code:
               0: aload_1
               1: invokestatic #3; //Method org/jboss/virtual/VFS.getRoot:(Ljava/net/URI;)Lorg/jboss/virtual/VirtualFile;
               4: areturn
              
              public org.jboss.virtual.VirtualFile getFile(java.net.URL) throws java.io.IOException;
               Code:
               0: aload_1
               1: invokestatic #4; //Method org/jboss/virtual/VFS.getRoot:(Ljava/net/URL;)Lorg/jboss/virtual/VirtualFile;
               4: areturn
              
              public void putContext(org.jboss.virtual.spi.VFSContext);
               Code:
               0: return
              
              public void removeContext(org.jboss.virtual.spi.VFSContext);
               Code:
               0: return
              
              public void start() throws java.lang.Exception;
               Code:
               0: return
              
              public void stop();
               Code:
               0: return
              
              public void flush();
               Code:
               0: return
              
              HERE!!! Passing the VFSCacheFactory instance.
              
              org.jboss.virtual.spi.cache.VFSCacheFactory$NoopVFSCache(org.jboss.virtual.spi.cache.VFSCacheFactory$1);
               Code:
               0: aload_0
               1: invokespecial #1; //Method "<init>":()V
               4: return
              
              }
              


              Which also doesn't match the source????
              http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/vfs/tags/2.0.0.CR2/src/main/java/org/jboss/virtual/spi/cache/VFSCacheFactory.java?revision=80463&view=markup

              • 4. Re: Missing element in WeakRefVFSCache
                Ales Justin Master

                 

                "adrian@jboss.org" wrote:

                In the default config (where that directory is empty) it does not appear,
                but it appears in the all config where it contains jars.

                Sure, as some code depends on jars in that dir,
                hence some classloader is keeping strong ref to that VirtualFile --> VFS --> VFSContext.

                • 5. Re: Missing element in WeakRefVFSCache
                  Ales Justin Master

                   

                  "adrian@jboss.org" wrote:

                  In jboss-vfs 2.0.0.CR2 the class is not static

                  If it wasn't static, compiler would already complain. ;-)
                  The error you're seeing is about not being able to invoke start from Noop instance in -beans.xml.

                  I'll actually move NoopVFScache to be full public class,
                  this way users can actually set its usage == no caching.