1 Reply Latest reply on Jun 22, 2010 3:00 AM by bosschaert

    Removing cached entry in VFSCLPolicy on load

    alesj

      Does something like this make sense to add directly, or should it be optional?

       

         public VFSClassLoaderPolicy(String name, VirtualFile[] roots, VirtualFile[] excludedRoots)
         {
              ...
      
              this.excludedRoots = excludedRoots;
      +      addClassFoundHandler(new VFSCacheRemove());
          }
       
      +
      +   private class VFSCacheRemove implements ClassFoundHandler
      +   {
      +      public void classFound(ClassFoundEvent event)
      +      {
      +         String className = event.getClassName();
      +         String path = ClassLoaderUtils.classNameToPath(className);
      +         vfsCache.remove(path); // remove the entry once we loaded the class
      +      }
      +   }
       }
      

       

      This would definitely decrease the memory, since every already loaded class's lookup cache would be released.

      And with CL cache fixed, we access the class on next invocaton directly form CL cache, hence no need to path cache.

        • 1. Re: Removing cached entry in VFSCLPolicy on load
          bosschaert

          It makes sense to me. Besides the CL cache, the Java ClassLoader that ultimately loads the class will cache it as well; the same classloader will only load the bytes for a particular class once so there shouldn't be the need to cache class resources outside that...