@@ -152,9 +152,23 @@ static Object doVarArgs(Node node, SingleMethod method, Object obj, Object[] arg
152
152
@ Exclusive @ Cached InlinedExactClassProfile receiverProfile ,
153
153
@ Shared ("errorBranch" ) @ Cached InlinedBranchProfile errorBranch ,
154
154
@ 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 ,
156
158
@ Cached (value = "hostContext.getGuestToHostCache()" , allowUncached = true ) GuestToHostCodeCache cache ) throws ArityException , UnsupportedTypeException {
159
+ boolean asVarArgs ;
157
160
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
+ }
158
172
int minArity = parameterCount - 1 ;
159
173
if (args .length < minArity ) {
160
174
errorBranch .enter (node );
@@ -244,19 +258,35 @@ static Object doSingleUncached(Node node, SingleMethod method, Object obj, Objec
244
258
// Note: checkArgTypes must be evaluated after selectOverload.
245
259
@ SuppressWarnings ({"unused" , "static-method" , "truffle-static-method" })
246
260
@ 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" )
248
262
static final Object doOverloadedCached (Node node , OverloadedMethod method , Object obj , Object [] args , HostContext hostContext ,
249
263
@ Cached ("method" ) OverloadedMethod cachedMethod ,
250
264
@ Exclusive @ Cached HostToTypeNode toJavaNode ,
251
265
@ Exclusive @ Cached ToGuestValueNode toGuest ,
252
266
@ CachedLibrary (limit = "LIMIT" ) InteropLibrary interop ,
253
267
@ Cached ("createArgTypesArray(args)" ) TypeCheckNode [] cachedArgTypes ,
254
268
@ Cached ("selectOverload(node, method, args, hostContext, cachedArgTypes)" ) SingleMethod overload ,
255
- @ Cached ("asVarArgs(args, overload, hostContext)" ) boolean asVarArgs ,
256
269
@ Exclusive @ Cached InlinedExactClassProfile receiverProfile ,
257
270
@ Shared ("errorBranch" ) @ Cached InlinedBranchProfile errorBranch ,
258
271
@ Shared ("seenScope" ) @ Cached InlinedBranchProfile seenVariableScope ,
272
+ @ Shared @ Cached InlinedBranchProfile seenVargArgs ,
273
+ @ Exclusive @ Cached HostTargetMappingNode varArgsMappingNode ,
274
+ @ Exclusive @ CachedLibrary (limit = "3" ) InteropLibrary varArgsMappingInterop ,
259
275
@ 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
+
260
290
assert overload == selectOverload (node , method , args , hostContext );
261
291
Class <?>[] types = overload .getParameterTypes ();
262
292
Type [] genericTypes = overload .getGenericParameterTypes ();
@@ -267,7 +297,6 @@ static final Object doOverloadedCached(Node node, OverloadedMethod method, Objec
267
297
try {
268
298
if (asVarArgs ) {
269
299
assert overload .isVarArgs ();
270
- int parameterCount = overload .getParameterCount ();
271
300
for (int i = 0 ; i < cachedArgTypes .length ; i ++) {
272
301
Class <?> expectedType = i < parameterCount - 1 ? types [i ] : types [parameterCount - 1 ].getComponentType ();
273
302
Type expectedGenericType = i < parameterCount - 1 ? genericTypes [i ] : getGenericComponentType (genericTypes [parameterCount - 1 ]);
@@ -417,7 +446,7 @@ private static void fillArgTypesArray(Node node, Object[] args, TypeCheckNode[]
417
446
cachedArgTypes [i ] = node .insert (argType );
418
447
}
419
448
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 );
421
450
}
422
451
423
452
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
454
483
}
455
484
456
485
@ 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 ) {
458
487
if (args .length != argTypes .length ) {
459
488
return false ;
460
489
}
0 commit comments