Class ClassInjector.UsingUnsafe

    • Field Detail

      • SAFE_PROPERTY

        public static final java.lang.String SAFE_PROPERTY
        If this property is set, Byte Buddy does not make use of any Unsafe class.
        See Also:
        Constant Field Values
      • CHECK_PERMISSION

        private static final java.lang.reflect.Method CHECK_PERMISSION
        The java.lang.SecurityManager#checkPermission method or null if not available.
      • BOOTSTRAP_LOADER_LOCK

        private static final java.lang.Object BOOTSTRAP_LOADER_LOCK
        A lock for the bootstrap loader when injecting.
      • classLoader

        @ValueHandling(REVERSE_NULLABILITY)
        private final java.lang.ClassLoader classLoader
        The class loader to inject classes into or null for the bootstrap loader.
      • protectionDomain

        @ValueHandling(REVERSE_NULLABILITY)
        private final java.security.ProtectionDomain protectionDomain
        The protection domain to use or null for no protection domain.
    • 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.
      • UsingUnsafe

        protected UsingUnsafe​(java.lang.ClassLoader classLoader,
                              java.security.ProtectionDomain protectionDomain,
                              ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher)
        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.
        dispatcher - The dispatcher to use.
    • Method Detail

      • doPrivileged

        @Enhance
        private static <T> T doPrivileged​(java.security.PrivilegedAction<T> action)
        A proxy for java.security.AccessController#doPrivileged that is activated if available.
        Type Parameters:
        T - The type of the action's resolved value.
        Parameters:
        action - The action to execute from a privileged context.
        Returns:
        The action's resolved value.
      • isAlive

        public boolean isAlive()
        Indicates if this class injector is available on the current VM.
        Returns:
        true if this injector is available on the current VM.
      • injectRaw

        public java.util.Map<java.lang.String,​java.lang.Class<?>> injectRaw​(java.util.Map<? extends java.lang.String,​byte[]> types)
        Injects the given types into the represented class loader using a mapping from name to binary representation.
        Parameters:
        types - The types to load via injection.
        Returns:
        The loaded types that were passed as arguments.
      • 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.
      • ofSystemLoader

        public static ClassInjector ofSystemLoader()
        Returns an unsafe class injector for the system class loader.
        Returns:
        A class injector for the system class loader.
      • ofPlatformLoader

        public static ClassInjector ofPlatformLoader()
        Returns an unsafe class injector for the platform class loader. For VMs of version 8 or older, the extension class loader is represented instead.
        Returns:
        A class injector for the platform class loader.
      • ofBootLoader

        public static ClassInjector ofBootLoader()
        Returns an unsafe class injector for the boot class loader.
        Returns:
        A class injector for the boot loader.