Class Dycon

java.lang.Object
net.auoeke.dycon.Dycon

public class Dycon extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    ldc(Supplier<T> initializer)
    The Dycon compiler plugin will replace each call to this method by an ldc instruction that loads the dynamic constant result of invoking initializer once.

    Methods inherited from class java.lang.Object

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

    • Dycon

      public Dycon()
  • Method Details

    • ldc

      public static <T> T ldc(Supplier<T> initializer)
      The Dycon compiler plugin will replace each call to this method by an ldc instruction that loads the dynamic constant result of invoking initializer once.

      First it will extract a method handle from initializer; then it will replace the call to this method by loading a dynamic constant produced by applying ConstantBootstraps.invoke(java.lang.invoke.MethodHandles.Lookup, java.lang.String, java.lang.Class<?>, java.lang.invoke.MethodHandle, java.lang.Object...) to the handle as handle. The lambda will be removed.

      As an example, in the method

      Object lazyInvoke(Object... arguments) {
              // The expensive method handle calculation will occur only once.
              return ldc(() -> getMyMethodHandleSlowly()).invokeWithArguments(arguments);
      }
      the extracted handle will be called only when lazyInvoke is first called. In subsequent calls to lazyInvoke, the result of the first call to the extracted handle will be loaded instead.
      Type Parameters:
      T - the type of the dynamic constant
      Parameters:
      initializer - a supplier of the constant value whereby to replace the call to this method
      Throws:
      RuntimeException - if invoked at runtime (for example reflectively or without the compiler plugin)