@@ -4726,6 +4726,11 @@ class ForDynamicConstant implements OffsetMapping {
4726
4726
*/
4727
4727
private final List <JavaConstant > arguments ;
4728
4728
4729
+ /**
4730
+ * {@code true} if invokedynamic should be used to bind the constant.
4731
+ */
4732
+ private final boolean invokedynamic ;
4733
+
4729
4734
/**
4730
4735
* Creates an offset mapping for a dynamic constant.
4731
4736
*
@@ -4737,6 +4742,7 @@ class ForDynamicConstant implements OffsetMapping {
4737
4742
* @param bootstrapReturnType The return type of the boostrap method.
4738
4743
* @param bootstrapParameterTypes The parameter types of the boostrap method.
4739
4744
* @param arguments The constant arguments to the bootstrap method.
4745
+ * @param invokedynamic {@code true} if invokedynamic should be used to bind the constant.
4740
4746
*/
4741
4747
public ForDynamicConstant (String name ,
4742
4748
TypeDescription typeDescription ,
@@ -4745,7 +4751,8 @@ public ForDynamicConstant(String name,
4745
4751
String bootstrapName ,
4746
4752
TypeDescription bootstrapReturnType ,
4747
4753
List <? extends TypeDescription > bootstrapParameterTypes ,
4748
- List <JavaConstant > arguments ) {
4754
+ List <JavaConstant > arguments ,
4755
+ boolean invokedynamic ) {
4749
4756
this .name = name ;
4750
4757
this .typeDescription = typeDescription ;
4751
4758
this .bootstrapType = bootstrapType ;
@@ -4754,6 +4761,7 @@ public ForDynamicConstant(String name,
4754
4761
this .bootstrapReturnType = bootstrapReturnType ;
4755
4762
this .bootstrapParameterTypes = bootstrapParameterTypes ;
4756
4763
this .arguments = arguments ;
4764
+ this .invokedynamic = invokedynamic ;
4757
4765
}
4758
4766
4759
4767
/**
@@ -4763,15 +4771,26 @@ public Resolved resolve(Assigner assigner,
4763
4771
Assigner .Typing typing ,
4764
4772
TypeDescription instrumentedType ,
4765
4773
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
+ }
4775
4794
}
4776
4795
4777
4796
/**
@@ -4814,6 +4833,11 @@ protected enum Factory implements OffsetMapping.Factory<DynamicConstant> {
4814
4833
*/
4815
4834
private static final MethodDescription .InDefinedShape BOOTSTRAP_PARAMETER_TYPES ;
4816
4835
4836
+ /**
4837
+ * The {@link DynamicConstant#invokedynamic()} method.
4838
+ */
4839
+ private static final MethodDescription .InDefinedShape INVOKEDYNAMIC ;
4840
+
4817
4841
/*
4818
4842
* Resolves all annotation properties.
4819
4843
*/
@@ -4825,6 +4849,7 @@ protected enum Factory implements OffsetMapping.Factory<DynamicConstant> {
4825
4849
BOOTSTRAP_NAME = methods .filter (named ("bootstrapName" )).getOnly ();
4826
4850
BOOTSTRAP_RETURN_TYPE = methods .filter (named ("bootstrapReturnType" )).getOnly ();
4827
4851
BOOTSTRAP_PARAMETER_TYPES = methods .filter (named ("bootstrapParameterTypes" )).getOnly ();
4852
+ INVOKEDYNAMIC = methods .filter (named ("invokedynamic" )).getOnly ();
4828
4853
}
4829
4854
4830
4855
/**
@@ -4853,7 +4878,8 @@ public OffsetMapping make(ParameterDescription.InDefinedShape target, Annotation
4853
4878
annotation .getValue (BOOTSTRAP_NAME ).resolve (String .class ),
4854
4879
annotation .getValue (BOOTSTRAP_RETURN_TYPE ).resolve (TypeDescription .class ),
4855
4880
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 ));
4857
4883
}
4858
4884
}
4859
4885
}
0 commit comments