@@ -4726,6 +4726,11 @@ class ForDynamicConstant implements OffsetMapping {
47264726 */
47274727 private final List <JavaConstant > arguments ;
47284728
4729+ /**
4730+ * {@code true} if invokedynamic should be used to bind the constant.
4731+ */
4732+ private final boolean invokedynamic ;
4733+
47294734 /**
47304735 * Creates an offset mapping for a dynamic constant.
47314736 *
@@ -4737,6 +4742,7 @@ class ForDynamicConstant implements OffsetMapping {
47374742 * @param bootstrapReturnType The return type of the boostrap method.
47384743 * @param bootstrapParameterTypes The parameter types of the boostrap method.
47394744 * @param arguments The constant arguments to the bootstrap method.
4745+ * @param invokedynamic {@code true} if invokedynamic should be used to bind the constant.
47404746 */
47414747 public ForDynamicConstant (String name ,
47424748 TypeDescription typeDescription ,
@@ -4745,7 +4751,8 @@ public ForDynamicConstant(String name,
47454751 String bootstrapName ,
47464752 TypeDescription bootstrapReturnType ,
47474753 List <? extends TypeDescription > bootstrapParameterTypes ,
4748- List <JavaConstant > arguments ) {
4754+ List <JavaConstant > arguments ,
4755+ boolean invokedynamic ) {
47494756 this .name = name ;
47504757 this .typeDescription = typeDescription ;
47514758 this .bootstrapType = bootstrapType ;
@@ -4754,6 +4761,7 @@ public ForDynamicConstant(String name,
47544761 this .bootstrapReturnType = bootstrapReturnType ;
47554762 this .bootstrapParameterTypes = bootstrapParameterTypes ;
47564763 this .arguments = arguments ;
4764+ this .invokedynamic = invokedynamic ;
47574765 }
47584766
47594767 /**
@@ -4763,15 +4771,26 @@ public Resolved resolve(Assigner assigner,
47634771 Assigner .Typing typing ,
47644772 TypeDescription instrumentedType ,
47654773 MethodDescription instrumentedMethod ) {
4766- return new Resolved .ForStackManipulation (new JavaConstantValue (new JavaConstant .Dynamic (
4767- name ,
4768- typeDescription ,
4769- new JavaConstant .MethodHandle (bootstrapType ,
4770- bootstrapOwner .represents (void .class ) ? instrumentedType : bootstrapOwner ,
4771- bootstrapName ,
4772- bootstrapReturnType ,
4773- bootstrapParameterTypes ),
4774- arguments )));
4774+ if (invokedynamic ) {
4775+ return new Resolved .ForStackManipulation (new Invokedynamic (name ,
4776+ JavaConstant .MethodType .of (typeDescription ),
4777+ new JavaConstant .MethodHandle (bootstrapType ,
4778+ bootstrapOwner .represents (void .class ) ? instrumentedType : bootstrapOwner ,
4779+ bootstrapName ,
4780+ bootstrapReturnType ,
4781+ bootstrapParameterTypes ),
4782+ arguments ));
4783+ } else {
4784+ return new Resolved .ForStackManipulation (new JavaConstantValue (new JavaConstant .Dynamic (
4785+ name ,
4786+ typeDescription ,
4787+ new JavaConstant .MethodHandle (bootstrapType ,
4788+ bootstrapOwner .represents (void .class ) ? instrumentedType : bootstrapOwner ,
4789+ bootstrapName ,
4790+ bootstrapReturnType ,
4791+ bootstrapParameterTypes ),
4792+ arguments )));
4793+ }
47754794 }
47764795
47774796 /**
@@ -4814,6 +4833,11 @@ protected enum Factory implements OffsetMapping.Factory<DynamicConstant> {
48144833 */
48154834 private static final MethodDescription .InDefinedShape BOOTSTRAP_PARAMETER_TYPES ;
48164835
4836+ /**
4837+ * The {@link DynamicConstant#invokedynamic()} method.
4838+ */
4839+ private static final MethodDescription .InDefinedShape INVOKEDYNAMIC ;
4840+
48174841 /*
48184842 * Resolves all annotation properties.
48194843 */
@@ -4825,6 +4849,7 @@ protected enum Factory implements OffsetMapping.Factory<DynamicConstant> {
48254849 BOOTSTRAP_NAME = methods .filter (named ("bootstrapName" )).getOnly ();
48264850 BOOTSTRAP_RETURN_TYPE = methods .filter (named ("bootstrapReturnType" )).getOnly ();
48274851 BOOTSTRAP_PARAMETER_TYPES = methods .filter (named ("bootstrapParameterTypes" )).getOnly ();
4852+ INVOKEDYNAMIC = methods .filter (named ("invokedynamic" )).getOnly ();
48284853 }
48294854
48304855 /**
@@ -4853,7 +4878,8 @@ public OffsetMapping make(ParameterDescription.InDefinedShape target, Annotation
48534878 annotation .getValue (BOOTSTRAP_NAME ).resolve (String .class ),
48544879 annotation .getValue (BOOTSTRAP_RETURN_TYPE ).resolve (TypeDescription .class ),
48554880 Arrays .asList (annotation .getValue (BOOTSTRAP_PARAMETER_TYPES ).resolve (TypeDescription [].class )),
4856- Collections .<JavaConstant >emptyList ());
4881+ Collections .<JavaConstant >emptyList (),
4882+ annotation .getValue (INVOKEDYNAMIC ).resolve (Boolean .class ));
48574883 }
48584884 }
48594885 }
0 commit comments