This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_4_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 8c268970a35dd18718701c70d82f8a6f7d5ba60c Author: Paul King <[email protected]> AuthorDate: Wed Nov 16 16:29:32 2022 +1000 GROOVY-10772: Possible memory leak, CacheableCallSite retains objects across invocations (thanks to Kyle Moore and Sterling Greene) --- .../org/codehaus/groovy/vmplugin/v8/Selector.java | 47 +++++++++------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java index 856df001fa..9dde46177e 100644 --- a/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java +++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/Selector.java @@ -932,35 +932,26 @@ public abstract class Selector { // guards for receiver and parameter Class<?>[] pt = handle.type().parameterArray(); - if (Arrays.stream(args).anyMatch(arg -> null == arg)) { - for (int i = 0; i < args.length; i++) { - Object arg = args[i]; - Class<?> paramType = pt[i]; - MethodHandle test; - - if (arg == null) { - test = IS_NULL.asType(MethodType.methodType(boolean.class, paramType)); - if (LOG_ENABLED) LOG.info("added null argument check at pos " + i); - } else { - if (Modifier.isFinal(paramType.getModifiers())) { - // primitive types are also `final` - continue; - } - test = SAME_CLASS. - bindTo(arg.getClass()). - asType(MethodType.methodType(boolean.class, paramType)); - if (LOG_ENABLED) LOG.info("added same class check at pos " + i); - } - Class<?>[] drops = new Class[i]; - System.arraycopy(pt, 0, drops, 0, drops.length); - test = MethodHandles.dropArguments(test, 0, drops); - handle = MethodHandles.guardWithTest(test, handle, fallback); + for (int i = 0; i < args.length; i++) { + Object arg = args[i]; + Class<?> paramType = pt[i]; + MethodHandle test; + + if (arg == null) { + test = IS_NULL.asType(MethodType.methodType(boolean.class, paramType)); + if (LOG_ENABLED) LOG.info("added null argument check at pos " + i); + } else { + Class<?> argClass = arg.getClass(); + if (paramType.isPrimitive()) continue; + //if (Modifier.isFinal(argClass.getModifiers()) && TypeHelper.argumentClassIsParameterClass(argClass,pt[i])) continue; + test = SAME_CLASS. + bindTo(argClass). + asType(MethodType.methodType(boolean.class, paramType)); + if (LOG_ENABLED) LOG.info("added same class check at pos " + i); } - } else if (Arrays.stream(pt).anyMatch(paramType -> !Modifier.isFinal(paramType.getModifiers()))) { - // Avoid guards as possible as we could - MethodHandle test = SAME_CLASSES.bindTo(args) - .asCollector(Object[].class, pt.length) - .asType(MethodType.methodType(boolean.class, pt)); + Class<?>[] drops = new Class[i]; + System.arraycopy(pt, 0, drops, 0, drops.length); + test = MethodHandles.dropArguments(test, 0, drops); handle = MethodHandles.guardWithTest(test, handle, fallback); } }
