Package kilim

Class WeavingClassLoader


  • public class WeavingClassLoader
    extends KilimClassLoader
    Classloader that loads classes from the classpath spec given by the system property "kilim.class.path" and weaves them dynamically.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashMap<java.net.URL,​java.security.ProtectionDomain> cache  
      private WeavingClassLoader.Excludable checker  
      static java.lang.String KILIM_CLASSPATH  
      (package private) java.lang.ClassLoader pcl  
      (package private) static java.lang.ClassLoader platform  
      (package private) java.net.URLClassLoader proxy  
      (package private) Weaver weaver  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Class<?> define​(java.lang.String name, byte[] code)  
      private java.lang.Class defineAll​(java.lang.String name, ClassWeaver cw)  
      WeavingClassLoader exclude​(WeavingClassLoader.Excludable exclude)
      replace the exclude filter which determines whether a named class should be defined definitively by this loader or instead delegated to the parent loader.
      protected java.lang.Class<?> findClass​(java.lang.String name)  
      static byte[] findCode​(java.lang.ClassLoader loader, java.lang.String name)
      read bytecode for the named class from a source classloader
      private java.security.ProtectionDomain get​(java.lang.String name)  
      static java.io.InputStream getByteStream​(java.lang.ClassLoader cl, java.lang.String name, java.lang.String cname, boolean system)  
      private static java.net.URLClassLoader getProxy()  
      java.io.InputStream getResourceAsStream​(java.lang.String cname)  
      static java.net.URL[] getURLs​(java.lang.String[] classPaths)  
      java.lang.Class<?> loadClass​(java.lang.String name, boolean resolve)  
      static java.lang.String makeResourceName​(java.lang.String name)
      convert a fully qualified class name to a resource name.
      private boolean proxy​(java.lang.String cname)  
      static byte[] readFully​(java.io.InputStream is)  
      static byte[] readFully​(FileLister.Entry fe)  
      void run​(java.lang.String className, java.lang.String method, java.lang.String... args)
      run static method className.method(args) using reflection and this WeavingClassLoader
      static java.lang.String unmakeResourceName​(java.lang.String cname)  
      java.net.URL url​(java.lang.String name)  
      ClassWeaver weaveClass​(java.lang.String name)
      load the bytecode for a class of a given name from the classpath and weave it
      • Methods inherited from class java.lang.ClassLoader

        clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • proxy

        java.net.URLClassLoader proxy
      • pcl

        java.lang.ClassLoader pcl
      • platform

        static java.lang.ClassLoader platform
      • cache

        private final java.util.HashMap<java.net.URL,​java.security.ProtectionDomain> cache
    • Constructor Detail

      • WeavingClassLoader

        public WeavingClassLoader()
      • WeavingClassLoader

        public WeavingClassLoader​(java.lang.ClassLoader loader,
                                  java.net.URLClassLoader $proxy)
    • Method Detail

      • readFully

        public static byte[] readFully​(java.io.InputStream is)
      • getResourceAsStream

        public java.io.InputStream getResourceAsStream​(java.lang.String cname)
        Overrides:
        getResourceAsStream in class java.lang.ClassLoader
      • getURLs

        public static java.net.URL[] getURLs​(java.lang.String[] classPaths)
      • getProxy

        private static java.net.URLClassLoader getProxy()
      • run

        public void run​(java.lang.String className,
                        java.lang.String method,
                        java.lang.String... args)
                 throws java.lang.Exception
        run static method className.method(args) using reflection and this WeavingClassLoader
        Throws:
        java.lang.Exception
      • exclude

        public WeavingClassLoader exclude​(WeavingClassLoader.Excludable exclude)
        replace the exclude filter which determines whether a named class should be defined definitively by this loader or instead delegated to the parent loader. this is sometimes necessary to work with classes that may have been previously loaded, eg because they were used as a java agent
        Parameters:
        exclude - the filter to run
        Returns:
      • loadClass

        public java.lang.Class<?> loadClass​(java.lang.String name,
                                            boolean resolve)
                                     throws java.lang.ClassNotFoundException
        Overrides:
        loadClass in class java.lang.ClassLoader
        Throws:
        java.lang.ClassNotFoundException
      • proxy

        private boolean proxy​(java.lang.String cname)
      • defineAll

        private java.lang.Class defineAll​(java.lang.String name,
                                          ClassWeaver cw)
      • getByteStream

        public static java.io.InputStream getByteStream​(java.lang.ClassLoader cl,
                                                        java.lang.String name,
                                                        java.lang.String cname,
                                                        boolean system)
      • weaveClass

        public ClassWeaver weaveClass​(java.lang.String name)
        load the bytecode for a class of a given name from the classpath and weave it
        Parameters:
        name - the fully qualified class name
        Returns:
        the weaver
      • findClass

        protected java.lang.Class<?> findClass​(java.lang.String name)
                                        throws java.lang.ClassNotFoundException
        Overrides:
        findClass in class java.lang.ClassLoader
        Throws:
        java.lang.ClassNotFoundException
      • get

        private java.security.ProtectionDomain get​(java.lang.String name)
      • define

        public java.lang.Class<?> define​(java.lang.String name,
                                         byte[] code)
      • makeResourceName

        public static java.lang.String makeResourceName​(java.lang.String name)
        convert a fully qualified class name to a resource name. Note: the Class and ClassLoader javadocs don't explicitly specify the string formats used for the various methods, so this conversion is potentially fragile
        Parameters:
        name - as returned by Class.getName
        Returns:
        the name in a format suitable for use with the various ClassLoader.getResource methods
      • unmakeResourceName

        public static java.lang.String unmakeResourceName​(java.lang.String cname)
      • findCode

        public static byte[] findCode​(java.lang.ClassLoader loader,
                                      java.lang.String name)
        read bytecode for the named class from a source classloader
        Parameters:
        loader - the classloader to get the bytecode from, or null for the current classloader
        name - the internal name for the class as would be passed to loadClass
        Returns:
        a new instance, or null if the bytecode is not found
      • url

        public java.net.URL url​(java.lang.String name)
      • readFully

        public static byte[] readFully​(FileLister.Entry fe)
                                throws java.io.IOException
        Throws:
        java.io.IOException