@@ -152,9 +152,23 @@ static Object doVarArgs(Node node, SingleMethod method, Object obj, Object[] arg
152152 @ Exclusive @ Cached InlinedExactClassProfile receiverProfile ,
153153 @ Shared ("errorBranch" ) @ Cached InlinedBranchProfile errorBranch ,
154154 @ Shared ("seenScope" ) @ Cached InlinedBranchProfile seenDynamicScope ,
155- @ Cached ("asVarArgs(args, cachedMethod, hostContext)" ) boolean asVarArgs ,
155+ @ Shared @ Cached InlinedBranchProfile seenVargArgs ,
156+ @ Exclusive @ Cached HostTargetMappingNode varArgsMappingNode ,
157+ @ Exclusive @ CachedLibrary (limit = "3" ) InteropLibrary varArgsMappingInterop ,
156158 @ Cached (value = "hostContext.getGuestToHostCache()" , allowUncached = true ) GuestToHostCodeCache cache ) throws ArityException , UnsupportedTypeException {
159+ boolean asVarArgs ;
157160 int parameterCount = cachedMethod .getParameterCount ();
161+ if (args .length == parameterCount ) {
162+ seenVargArgs .enter (node );
163+ Class <?> varArgParamType = cachedMethod .getParameterTypes ()[parameterCount - 1 ];
164+ asVarArgs = !HostToTypeNode .canConvert (node , args [parameterCount - 1 ], varArgParamType ,
165+ cachedMethod .getGenericParameterTypes ()[parameterCount - 1 ],
166+ null , hostContext , HostToTypeNode .COERCE ,
167+ varArgsMappingInterop , varArgsMappingNode );
168+ } else {
169+ assert args .length != parameterCount ;
170+ asVarArgs = true ;
171+ }
158172 int minArity = parameterCount - 1 ;
159173 if (args .length < minArity ) {
160174 errorBranch .enter (node );
@@ -244,19 +258,35 @@ static Object doSingleUncached(Node node, SingleMethod method, Object obj, Objec
244258 // Note: checkArgTypes must be evaluated after selectOverload.
245259 @ SuppressWarnings ({"unused" , "static-method" , "truffle-static-method" })
246260 @ ExplodeLoop
247- @ Specialization (guards = {"method == cachedMethod" , "checkArgTypes(args, cachedArgTypes, interop, hostContext, asVarArgs )" }, limit = "LIMIT" )
261+ @ Specialization (guards = {"method == cachedMethod" , "checkArgTypes(args, cachedArgTypes, interop, hostContext)" }, limit = "LIMIT" )
248262 static final Object doOverloadedCached (Node node , OverloadedMethod method , Object obj , Object [] args , HostContext hostContext ,
249263 @ Cached ("method" ) OverloadedMethod cachedMethod ,
250264 @ Exclusive @ Cached HostToTypeNode toJavaNode ,
251265 @ Exclusive @ Cached ToGuestValueNode toGuest ,
252266 @ CachedLibrary (limit = "LIMIT" ) InteropLibrary interop ,
253267 @ Cached ("createArgTypesArray(args)" ) TypeCheckNode [] cachedArgTypes ,
254268 @ Cached ("selectOverload(node, method, args, hostContext, cachedArgTypes)" ) SingleMethod overload ,
255- @ Cached ("asVarArgs(args, overload, hostContext)" ) boolean asVarArgs ,
256269 @ Exclusive @ Cached InlinedExactClassProfile receiverProfile ,
257270 @ Shared ("errorBranch" ) @ Cached InlinedBranchProfile errorBranch ,
258271 @ Shared ("seenScope" ) @ Cached InlinedBranchProfile seenVariableScope ,
272+ @ Shared @ Cached InlinedBranchProfile seenVargArgs ,
273+ @ Exclusive @ Cached HostTargetMappingNode varArgsMappingNode ,
274+ @ Exclusive @ CachedLibrary (limit = "3" ) InteropLibrary varArgsMappingInterop ,
259275 @ Cached (value = "hostContext.getGuestToHostCache()" , allowUncached = true ) GuestToHostCodeCache cache ) throws ArityException , UnsupportedTypeException {
276+
277+ boolean asVarArgs ;
278+ int parameterCount = cachedArgTypes .length ;
279+ if (overload .isVarArgs ()) {
280+ seenVargArgs .enter (node );
281+ Class <?> varArgParamType = overload .getParameterTypes ()[parameterCount - 1 ];
282+ asVarArgs = !HostToTypeNode .canConvert (node , args [parameterCount - 1 ], varArgParamType ,
283+ overload .getGenericParameterTypes ()[parameterCount - 1 ],
284+ null , hostContext , HostToTypeNode .COERCE ,
285+ varArgsMappingInterop , varArgsMappingNode );
286+ } else {
287+ asVarArgs = false ;
288+ }
289+
260290 assert overload == selectOverload (node , method , args , hostContext );
261291 Class <?>[] types = overload .getParameterTypes ();
262292 Type [] genericTypes = overload .getGenericParameterTypes ();
@@ -267,7 +297,6 @@ static final Object doOverloadedCached(Node node, OverloadedMethod method, Objec
267297 try {
268298 if (asVarArgs ) {
269299 assert overload .isVarArgs ();
270- int parameterCount = overload .getParameterCount ();
271300 for (int i = 0 ; i < cachedArgTypes .length ; i ++) {
272301 Class <?> expectedType = i < parameterCount - 1 ? types [i ] : types [parameterCount - 1 ].getComponentType ();
273302 Type expectedGenericType = i < parameterCount - 1 ? genericTypes [i ] : getGenericComponentType (genericTypes [parameterCount - 1 ]);
@@ -417,7 +446,7 @@ private static void fillArgTypesArray(Node node, Object[] args, TypeCheckNode[]
417446 cachedArgTypes [i ] = node .insert (argType );
418447 }
419448
420- assert checkArgTypes (args , cachedArgTypes , InteropLibrary .getFactory ().getUncached (), context , false ) : Arrays .toString (cachedArgTypes );
449+ assert checkArgTypes (args , cachedArgTypes , InteropLibrary .getFactory ().getUncached (), context ) : Arrays .toString (cachedArgTypes );
421450 }
422451
423452 private static TypeCheckNode createPrimitiveTargetCheck (List <SingleMethod > applicable , SingleMethod selected , Object arg , Class <?> targetType , int parameterIndex , int priority , boolean varArgs ,
@@ -454,7 +483,7 @@ private static TypeCheckNode createPrimitiveTargetCheck(List<SingleMethod> appli
454483 }
455484
456485 @ ExplodeLoop
457- static boolean checkArgTypes (Object [] args , TypeCheckNode [] argTypes , InteropLibrary interop , HostContext context , @ SuppressWarnings ( "unused" ) boolean dummy ) {
486+ static boolean checkArgTypes (Object [] args , TypeCheckNode [] argTypes , InteropLibrary interop , HostContext context ) {
458487 if (args .length != argTypes .length ) {
459488 return false ;
460489 }
0 commit comments