|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * The Universal Permissive License (UPL), Version 1.0
|
@@ -152,14 +152,14 @@ 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 |
| - @Shared @Cached InlinedBranchProfile seenVargArgs, |
| 155 | + @Shared @Cached InlinedBranchProfile seenVarArgs, |
156 | 156 | @Exclusive @Cached HostTargetMappingNode varArgsMappingNode,
|
157 | 157 | @Exclusive @CachedLibrary(limit = "3") InteropLibrary varArgsMappingInterop,
|
158 | 158 | @Cached(value = "hostContext.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws ArityException, UnsupportedTypeException {
|
159 | 159 | boolean asVarArgs;
|
160 | 160 | int parameterCount = cachedMethod.getParameterCount();
|
161 | 161 | if (args.length == parameterCount) {
|
162 |
| - seenVargArgs.enter(node); |
| 162 | + seenVarArgs.enter(node); |
163 | 163 | Class<?> varArgParamType = cachedMethod.getParameterTypes()[parameterCount - 1];
|
164 | 164 | asVarArgs = !HostToTypeNode.canConvert(node, args[parameterCount - 1], varArgParamType,
|
165 | 165 | cachedMethod.getGenericParameterTypes()[parameterCount - 1],
|
@@ -256,33 +256,37 @@ static Object doSingleUncached(Node node, SingleMethod method, Object obj, Objec
|
256 | 256 | }
|
257 | 257 |
|
258 | 258 | // Note: checkArgTypes must be evaluated after selectOverload.
|
259 |
| - @SuppressWarnings({"unused", "static-method", "truffle-static-method"}) |
260 | 259 | @ExplodeLoop
|
261 |
| - @Specialization(guards = {"method == cachedMethod", "checkArgTypes(args, cachedArgTypes, interop, hostContext)"}, limit = "LIMIT") |
| 260 | + @Specialization(guards = {"method == cachedMethod", "checkArgTypes(args, cachedArgTypes, interop, hostContext, overload)"}, limit = "LIMIT") |
262 | 261 | static final Object doOverloadedCached(Node node, OverloadedMethod method, Object obj, Object[] args, HostContext hostContext,
|
263 |
| - @Cached("method") OverloadedMethod cachedMethod, |
| 262 | + @Cached("method") @SuppressWarnings("unused") OverloadedMethod cachedMethod, |
264 | 263 | @Exclusive @Cached HostToTypeNode toJavaNode,
|
265 | 264 | @Exclusive @Cached ToGuestValueNode toGuest,
|
266 |
| - @CachedLibrary(limit = "LIMIT") InteropLibrary interop, |
| 265 | + @CachedLibrary(limit = "LIMIT") @SuppressWarnings("unused") InteropLibrary interop, |
267 | 266 | @Cached("createArgTypesArray(args)") TypeCheckNode[] cachedArgTypes,
|
268 | 267 | @Cached("selectOverload(node, method, args, hostContext, cachedArgTypes)") SingleMethod overload,
|
269 | 268 | @Exclusive @Cached InlinedExactClassProfile receiverProfile,
|
270 | 269 | @Shared("errorBranch") @Cached InlinedBranchProfile errorBranch,
|
271 | 270 | @Shared("seenScope") @Cached InlinedBranchProfile seenVariableScope,
|
272 |
| - @Shared @Cached InlinedBranchProfile seenVargArgs, |
| 271 | + @Shared @Cached InlinedBranchProfile seenVarArgs, |
273 | 272 | @Exclusive @Cached HostTargetMappingNode varArgsMappingNode,
|
274 | 273 | @Exclusive @CachedLibrary(limit = "3") InteropLibrary varArgsMappingInterop,
|
275 | 274 | @Cached(value = "hostContext.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws ArityException, UnsupportedTypeException {
|
| 275 | + assert args.length == cachedArgTypes.length; |
276 | 276 |
|
277 | 277 | boolean asVarArgs;
|
278 |
| - int parameterCount = cachedArgTypes.length; |
| 278 | + int parameterCount = overload.getParameterCount(); |
279 | 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); |
| 280 | + seenVarArgs.enter(node); |
| 281 | + if (cachedArgTypes.length == parameterCount) { |
| 282 | + Class<?> varArgParamType = overload.getParameterTypes()[parameterCount - 1]; |
| 283 | + asVarArgs = !HostToTypeNode.canConvert(node, args[parameterCount - 1], varArgParamType, |
| 284 | + overload.getGenericParameterTypes()[parameterCount - 1], |
| 285 | + null, hostContext, HostToTypeNode.COERCE, |
| 286 | + varArgsMappingInterop, varArgsMappingNode); |
| 287 | + } else { |
| 288 | + asVarArgs = true; |
| 289 | + } |
286 | 290 | } else {
|
287 | 291 | asVarArgs = false;
|
288 | 292 | }
|
@@ -323,7 +327,6 @@ static final Object doOverloadedCached(Node node, OverloadedMethod method, Objec
|
323 | 327 | }
|
324 | 328 | }
|
325 | 329 |
|
326 |
| - @SuppressWarnings("static-method") |
327 | 330 | @Specialization(replaces = "doOverloadedCached")
|
328 | 331 | static final Object doOverloadedUncached(Node node, OverloadedMethod method, Object obj, Object[] args, HostContext hostContext,
|
329 | 332 | @Shared("toHost") @Cached HostToTypeNode toJavaNode,
|
@@ -446,7 +449,7 @@ private static void fillArgTypesArray(Node node, Object[] args, TypeCheckNode[]
|
446 | 449 | cachedArgTypes[i] = node.insert(argType);
|
447 | 450 | }
|
448 | 451 |
|
449 |
| - assert checkArgTypes(args, cachedArgTypes, InteropLibrary.getFactory().getUncached(), context) : Arrays.toString(cachedArgTypes); |
| 452 | + assert checkArgTypes(args, cachedArgTypes, InteropLibrary.getFactory().getUncached(), context, selected) : Arrays.toString(cachedArgTypes); |
450 | 453 | }
|
451 | 454 |
|
452 | 455 | private static TypeCheckNode createPrimitiveTargetCheck(List<SingleMethod> applicable, SingleMethod selected, Object arg, Class<?> targetType, int parameterIndex, int priority, boolean varArgs,
|
@@ -482,8 +485,13 @@ private static TypeCheckNode createPrimitiveTargetCheck(List<SingleMethod> appli
|
482 | 485 | return new PrimitiveType(currentTargetType, otherPossibleTypes.toArray(EMPTY_CLASS_ARRAY), priority);
|
483 | 486 | }
|
484 | 487 |
|
| 488 | + /** |
| 489 | + * @param overload dummy argument used to ensure this guard is not evaluated until |
| 490 | + * {@link #fillArgTypesArray} has been called by {@link #selectOverload}. |
| 491 | + * @see #doOverloadedCached |
| 492 | + */ |
485 | 493 | @ExplodeLoop
|
486 |
| - static boolean checkArgTypes(Object[] args, TypeCheckNode[] argTypes, InteropLibrary interop, HostContext context) { |
| 494 | + static boolean checkArgTypes(Object[] args, TypeCheckNode[] argTypes, InteropLibrary interop, HostContext context, SingleMethod overload) { |
487 | 495 | if (args.length != argTypes.length) {
|
488 | 496 | return false;
|
489 | 497 | }
|
|
0 commit comments