Class ClassInjector.UsingUnsafe

  • All Implemented Interfaces:
    ClassInjector
    Enclosing interface:
    ClassInjector

    public static class ClassInjector.UsingUnsafe
    extends java.lang.Object
    implements ClassInjector
    A class injector that uses sun.misc.Unsafe to inject classes.
    • Constructor Detail

      • UsingUnsafe

        public UsingUnsafe​(java.lang.ClassLoader classLoader)
        Creates a new unsafe injector for the given class loader with a default protection domain.
        Parameters:
        classLoader - The class loader to inject classes into or null for the bootstrap loader.
      • UsingUnsafe

        public UsingUnsafe​(java.lang.ClassLoader classLoader,
                           java.security.ProtectionDomain protectionDomain)
        Creates a new unsafe injector for the given class loader with a default protection domain.
        Parameters:
        classLoader - The class loader to inject classes into or null for the bootstrap loader.
        protectionDomain - The protection domain to use or null for no protection domain.
    • Method Detail

      • isAvailable

        public static boolean isAvailable()
        Checks if unsafe class injection is available on the current VM.
        Returns:
        true if unsafe class injection is available on the current VM.
      • ofBootstrapLoader

        public static ClassInjector ofBootstrapLoader()
        Returns an unsafe class injector for the bootstrap class loader.
        Returns:
        A class injector for the bootstrap loader.
      • ofClassPath

        public static ClassInjector ofClassPath()
        Returns an unsafe class injector for the class path.
        Returns:
        A class injector for the system class loader.
      • inject

        public java.util.Map<TypeDescription,​java.lang.Class<?>> inject​(java.util.Map<? extends TypeDescription,​byte[]> types)
        Description copied from interface: ClassInjector
        Injects the given types into the represented class loader.
        Specified by:
        inject in interface ClassInjector
        Parameters:
        types - The types to load via injection.
        Returns:
        The loaded types that were passed as arguments.