Enum AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection

  • All Implemented Interfaces:
    Serializable, Comparable<AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection>, AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
    Enclosing class:
    AgentBuilder.LambdaInstrumentationStrategy

    protected static enum AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection
    extends Enum<AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection>
    implements AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
    Implements the alternative lambda meta factory. The implementation represents the following code:
     public static CallSite altMetafactory(MethodHandles.Lookup caller,
         String invokedName,
         MethodType invokedType,
         Object... args) throws Exception {
       int flags = (Integer) args[3];
       int argIndex = 4;
       Class<?>[] markerInterface;
       if ((flags & FLAG_MARKERS) != 0) {
         int markerCount = (Integer) args[argIndex++];
         markerInterface = new Class<?>[markerCount];
         System.arraycopy(args, argIndex, markerInterface, 0, markerCount);
         argIndex += markerCount;
       } else {
         markerInterface = new Class<?>[0];
       }
       MethodType[] additionalBridge;
       if ((flags & FLAG_BRIDGES) != 0) {
         int bridgeCount = (Integer) args[argIndex++];
         additionalBridge = new MethodType[bridgeCount];
         System.arraycopy(args, argIndex, additionalBridge, 0, bridgeCount);
         // argIndex += bridgeCount;
       } else {
         additionalBridge = new MethodType[0];
       }
       Unsafe unsafe = Unsafe.getUnsafe();
       Class<?> lambdaClass = unsafe.defineAnonymousClass(caller.lookupClass(),
           (byte[]) ClassLoader.getSystemClassLoader().loadClass("net.bytebuddy.agent.builder.LambdaFactory").getDeclaredMethod("make",
               Object.class,
               String.class,
               Object.class,
               Object.class,
               Object.class,
               Object.class,
               boolean.class,
               List.class,
               List.class).invoke(null,
                   caller,
                   invokedName,
                   invokedType,
                   args[0],
                   args[1],
                   args[2],
                   (flags & FLAG_SERIALIZABLE) != 0,
                   Arrays.asList(markerInterface),
                   Arrays.asList(additionalBridge)),
           null);
       unsafe.ensureClassInitialized(lambdaClass);
       return invokedType.parameterCount() == 0
         ? new ConstantCallSite(MethodHandles.constant(invokedType.returnType(), lambdaClass.getDeclaredConstructors()[0].newInstance()))
         : new ConstantCallSite(MethodHandles.Lookup.IMPL_LOOKUP.findStatic(lambdaClass, "get$Lambda", invokedType));
     }
     
    • Method Detail

      • values

        public static AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection c : AgentBuilder.LambdaInstrumentationStrategy.AlternativeMetaFactoryRedirection.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • wrap

        public org.objectweb.asm.MethodVisitor wrap​(TypeDescription instrumentedType,
                                                    MethodDescription instrumentedMethod,
                                                    org.objectweb.asm.MethodVisitor methodVisitor,
                                                    Implementation.Context implementationContext,
                                                    TypePool typePool,
                                                    int writerFlags,
                                                    int readerFlags)
        Wraps a method visitor.
        Specified by:
        wrap in interface AsmVisitorWrapper.ForDeclaredMethods.MethodVisitorWrapper
        Parameters:
        instrumentedType - The instrumented type.
        instrumentedMethod - The method that is currently being defined.
        methodVisitor - The original field visitor that defines the given method.
        implementationContext - The implementation context to use.
        typePool - The type pool to use.
        writerFlags - The ASM ClassWriter reader flags to consider.
        readerFlags - The ASM ClassReader reader flags to consider.
        Returns:
        The wrapped method visitor.