You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/12/04 08:32:15 UTC
[groovy] 01/02: GROOVY-10772: Possible memory leak, CacheableCallSite retains objects across invocations (thanks to Kyle Moore and Sterling Greene)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit d037841e092e70f487463e77144f313636e54671
Author: Paul King <pa...@asert.com.au>
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);
}
}