Class ClassInjector.UsingJna

java.lang.Object
net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
net.bytebuddy.dynamic.loading.ClassInjector.UsingJna
All Implemented Interfaces:
ClassInjector
Enclosing interface:
ClassInjector

@Enhance public static class ClassInjector.UsingJna extends ClassInjector.AbstractBase
A class injector using JNA to invoke JNI's define class utility for defining a class. This injector is only available if JNA is available on the class loader. Some JVM implementations might not support this injection method.
  • Field Details

  • Constructor Details

    • UsingJna

      public UsingJna(@MaybeNull 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.
    • UsingJna

      public UsingJna(@MaybeNull ClassLoader classLoader, @MaybeNull ProtectionDomain protectionDomain)
      Creates a new JNA 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 Details

    • doPrivileged

      @Enhance private static <T> T doPrivileged(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.
    • isAvailable

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

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

      public static ClassInjector ofPlatformLoader()
      Returns an JNA 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 JNA class injector for the boot class loader.
      Returns:
      A class injector for the boot loader.
    • 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 Map<String,Class<?>> injectRaw(Set<String> names, ClassFileLocator classFileLocator)
      Injects the given types into the represented class loader.
      Parameters:
      names - The names of the types to load via injection.
      classFileLocator - The class file locator to use for resolving binary representations.
      Returns:
      The loaded types that were passed as arguments.