Class BytecodeGen

java.lang.Object
com.google.inject.internal.BytecodeGen

public final class BytecodeGen extends Object
Utility methods for circular proxies, faster reflection, and method interception.

This class makes heavy use of Function and BiFunction types when interacting with generated fast-classes and enhanced proxies. This is a deliberate design decision to avoid using Guice-specific types in the generated classes. This means generated classes can be defined in the same ClassLoader as their host class without needing access to Guice's own ClassLoader. (In other words it removes any need for bridge ClassLoaders.)

  • Field Details

  • Constructor Details

    • BytecodeGen

      public BytecodeGen()
  • Method Details

    • isCircularProxy

      public static boolean isCircularProxy(Object object)
      Returns true if the given object is a circular proxy.
    • newCircularProxy

      static <T> T newCircularProxy(Class<T> type, InvocationHandler handler)
      Creates a new circular proxy for the given type.
    • enhancerBuilder

      static BytecodeGen.EnhancerBuilder enhancerBuilder(Class<?> hostClass)
      Create a builder of enhancers for the given class.
    • enhancedConstructor

      static BiFunction<Object,Object[],Object> enhancedConstructor(Function<String,BiFunction<Object,Object[],Object>> enhancer, Constructor<?> constructor)
      Returns an invoker that constructs an enhanced instance. The invoker function accepts an array of invocation handlers plus an array of arguments for the original constructor.
    • superMethod

      static BiFunction<Object,Object[],Object> superMethod(Function<String,BiFunction<Object,Object[],Object>> enhancer, Method method)
      Returns an invoker that calls the original unenhanced method. The invoker function accepts an enhanced instance plus an array of arguments for the original method.
    • fastConstructor

      static BiFunction<Object,Object[],Object> fastConstructor(Constructor<?> constructor)
      Returns a fast invoker for the given constructor. The invoker function ignores the first parameter and accepts an array of arguments for the constructor in the second parameter.

      Returns null if the constructor cannot be "fast-invoked" due to visibility issues.

    • fastMethod

      static BiFunction<Object,Object[],Object> fastMethod(Method method)
      Returns a fast invoker for the given method. The invoker function accepts an instance, which will be null for static methods, and an array of arguments for the method.

      Returns null if the method cannot be "fast-invoked" due to visibility issues.

    • fastClass

      private static Function<String,BiFunction<Object,Object[],Object>> fastClass(Executable member)
      Prepares the class declaring the given member for fast invocation using bytecode generation.