Class UnsafeClassDefiner

java.lang.Object
com.google.inject.internal.aop.UnsafeClassDefiner
All Implemented Interfaces:
ClassDefiner

final class UnsafeClassDefiner extends Object implements ClassDefiner
ClassDefiner that defines classes using sun.misc.Unsafe.
  • Field Details

    • logger

      private static final Logger logger
    • UNSAFE_DEFINER

      private static final ClassDefiner UNSAFE_DEFINER
    • ALWAYS_DEFINE_ANONYMOUSLY

      private static final boolean ALWAYS_DEFINE_ANONYMOUSLY
    • DEFINEACCESS_BY_GUICE_MARKER

      private static final String DEFINEACCESS_BY_GUICE_MARKER
      See Also:
    • DEFINEACCESS_API

      private static final String[] DEFINEACCESS_API
    • CLASS_LOADER_TYPE

      private static final String CLASS_LOADER_TYPE
    • BYTE_ARRAY_TYPE

      private static final String BYTE_ARRAY_TYPE
  • Constructor Details

    • UnsafeClassDefiner

      UnsafeClassDefiner()
  • Method Details

    • isAccessible

      public static boolean isAccessible()
      Do we have access to sun.misc.Unsafe?
    • canLoadProxyByName

      public static boolean canLoadProxyByName(Class<?> hostClass)
      Returns true if it's possible to load by name proxies defined from the given host.
    • canDowncastToProxy

      public static boolean canDowncastToProxy(Class<?> hostClass)
      Returns true if it's possible to downcast to proxies defined from the given host.
    • define

      public Class<?> define(Class<?> hostClass, byte[] bytecode) throws Exception
      Description copied from interface: ClassDefiner
      Defines a new class relative to the host.
      Specified by:
      define in interface ClassDefiner
      Throws:
      Exception
    • findClassDefiner

      private static ClassDefiner findClassDefiner(ClassLoader hostLoader)
      Finds the appropriate class definer for the given class loader.
    • tryPrivileged

      static <T> T tryPrivileged(PrivilegedExceptionAction<T> action, String errorMessage)
    • tryAccessDefineClass

      static ClassDefiner tryAccessDefineClass(Class<?> loaderClass)
    • accessDefineClass

      static ClassDefiner accessDefineClass(Class<?> loaderClass) throws Exception
      Generates helper in same package as the ClassLoader so it can access defineClass
      Throws:
      Exception
    • buildDefineClassAccess

      private static byte[] buildDefineClassAccess(Class<?> loaderClass)
      ClassLoader helper that sits in the same package and passes on defineClass requests