Package net.auoeke.dycon
Class Dycon
java.lang.Object
net.auoeke.dycon.Dycon
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Dycon
public Dycon()
-
-
Method Details
-
ldc
The Dycon compiler plugin will replace each call to this method by anldcinstruction that loads the dynamic constant result of invokinginitializeronce.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 applyingConstantBootstraps.invoke(java.lang.invoke.MethodHandles.Lookup, java.lang.String, java.lang.Class<?>, java.lang.invoke.MethodHandle, java.lang.Object...)to the handle ashandle. 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 whenlazyInvokeis first called. In subsequent calls tolazyInvoke, 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)
-