Class ClassInjector.UsingUnsafe.Factory

  • Enclosing class:
    ClassInjector.UsingUnsafe

    @Enhance
    public static class ClassInjector.UsingUnsafe.Factory
    extends java.lang.Object
    A factory for creating a ClassInjector that uses sun.misc.Unsafe if available but attempts a fallback to using jdk.internal.misc.Unsafe if the jdk.internal module is not resolved or unavailable.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  ClassInjector.UsingUnsafe.Factory.AccessResolver
      An access resolver that invokes AccessibleObject.setAccessible(boolean) to true in a given privilege scope.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isAvailable()
      Returns true if this factory creates a valid dispatcher.
      ClassInjector make​(java.lang.ClassLoader classLoader)
      Creates a new class injector for the given class loader without a ProtectionDomain.
      ClassInjector make​(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)
      Creates a new class injector for the given class loader and protection domain.
      static ClassInjector.UsingUnsafe.Factory resolve​(java.lang.instrument.Instrumentation instrumentation)
      Resolves an injection strategy that uses unsafe injection if available and also attempts to open and use jdk.internal.misc.Unsafe as a fallback.
      static ClassInjector.UsingUnsafe.Factory resolve​(java.lang.instrument.Instrumentation instrumentation, boolean local)
      Resolves an injection strategy that uses unsafe injection if available and also attempts to open and use jdk.internal.misc.Unsafe as a fallback.
      • Methods inherited from class java.lang.Object

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

      • Factory

        public Factory()
        Creates a new factory for an unsafe class injector that uses Byte Buddy's privileges to accessing jdk.internal.misc.Unsafe if available.
    • Method Detail

      • resolve

        public static ClassInjector.UsingUnsafe.Factory resolve​(java.lang.instrument.Instrumentation instrumentation)
        Resolves an injection strategy that uses unsafe injection if available and also attempts to open and use jdk.internal.misc.Unsafe as a fallback. This method generates a new class and module for opening the internal package to avoid its exposure to any non-trusted code.
        Parameters:
        instrumentation - The instrumentation instance to use for opening the internal package if required.
        Returns:
        An appropriate injection strategy.
      • resolve

        public static ClassInjector.UsingUnsafe.Factory resolve​(java.lang.instrument.Instrumentation instrumentation,
                                                                boolean local)
        Resolves an injection strategy that uses unsafe injection if available and also attempts to open and use jdk.internal.misc.Unsafe as a fallback.
        Parameters:
        instrumentation - The instrumentation instance to use for opening the internal package if required.
        local - false if a new class should in a separated class loader and module should be created for opening the jdk.internal.misc package. This way, the internal package is not exposed to any other classes within this class's module.
        Returns:
        An appropriate injection strategy.
      • isAvailable

        public boolean isAvailable()
        Returns true if this factory creates a valid dispatcher.
        Returns:
        true if this factory creates a valid dispatcher.
      • make

        public ClassInjector make​(java.lang.ClassLoader classLoader)
        Creates a new class injector for the given class loader without a ProtectionDomain.
        Parameters:
        classLoader - The class loader to inject into or null to inject into the bootstrap loader.
        Returns:
        An appropriate class injector.
      • make

        public ClassInjector make​(java.lang.ClassLoader classLoader,
                                  java.security.ProtectionDomain protectionDomain)
        Creates a new class injector for the given class loader and protection domain.
        Parameters:
        classLoader - The class loader to inject into or null to inject into the bootstrap loader.
        protectionDomain - The protection domain to apply or null if no protection domain should be used.
        Returns:
        An appropriate class injector.