groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 02/03: Revert "GROOVY-9111: Reduce the cost of transforming meta method(closes #925)"
Date Fri, 10 May 2019 14:53:30 GMT
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 b8a5567ead17d90f2951a08b27a76fb3ad52d444
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Fri May 10 22:43:44 2019 +0800

    Revert "GROOVY-9111: Reduce the cost of transforming meta method(closes #925)"
    
    This reverts commit 7753124d
---
 src/main/groovy/groovy/lang/MetaClassImpl.java                     | 2 +-
 .../java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java  | 7 +------
 src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java           | 7 ++-----
 src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java           | 7 +++++++
 src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java           | 5 +----
 5 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/src/main/groovy/groovy/lang/MetaClassImpl.java b/src/main/groovy/groovy/lang/MetaClassImpl.java
index 84c806e..171bf7c 100644
--- a/src/main/groovy/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/groovy/lang/MetaClassImpl.java
@@ -1276,7 +1276,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
         }
 
         if (method != null) {
-            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
() -> MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+            MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method,
MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
             return transformedMetaMethod.doMethodInvoke(object, arguments);
         } else {
             return invokePropertyOrMissing(object, methodName, originalArguments, fromInsideClass,
isCallToSuper);
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
index 1d6cdef..016c537 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
@@ -23,16 +23,11 @@ import groovy.lang.MetaMethod;
 import org.codehaus.groovy.vmplugin.VMPlugin;
 import org.codehaus.groovy.vmplugin.VMPluginFactory;
 
-import java.util.function.Supplier;
-
 public class CallSiteHelper {
     private static final VMPlugin VM_PLUGIN = VMPluginFactory.getPlugin();
 
     public static MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod,
Class<?>[] params, Class<?> caller) {
-        return transformMetaMethod(metaClass, metaMethod, () -> params, caller);
+        return VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, params, caller);
     }
 
-    public static MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod,
Supplier<Class<?>[]> paramsSupplier, Class<?> caller) {
-        return VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, paramsSupplier, caller);
-    }
 }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index 170d5a1..2848615 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -26,7 +26,6 @@ import org.codehaus.groovy.ast.CompileUnit;
 
 import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Method;
-import java.util.function.Supplier;
 
 /**
  * Interface to access VM version based actions.
@@ -89,11 +88,9 @@ public interface VMPlugin {
      *
      * @param metaClass meta class
      * @param metaMethod the original meta method
-     * @param paramsSupplier parameter types supplier
+     * @param params parameter types
      * @param caller caller type
      * @return the transformed meta method
      */
-    default MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Supplier<Class<?>[]>
paramsSupplier, Class<?> caller) {
-        return metaMethod;
-    }
+    MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params, Class<?> caller);
 }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index 58c6ea3..b8182d1 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -18,6 +18,8 @@
  */
 package org.codehaus.groovy.vmplugin.v5;
 
+import groovy.lang.MetaClass;
+import groovy.lang.MetaMethod;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.ast.AnnotatedNode;
 import org.codehaus.groovy.ast.AnnotationNode;
@@ -582,6 +584,11 @@ public class Java5 implements VMPlugin {
         }
     }
 
+    @Override
+    public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params, Class<?> caller) {
+        return metaMethod;
+    }
+
     private static final Permission ACCESS_PERMISSION = new ReflectPermission("suppressAccessChecks");
 }
 
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index c348121..882d900 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -50,7 +50,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
-import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 /**
@@ -173,7 +172,7 @@ public class Java9 extends Java8 {
     }
 
     @Override
-    public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Supplier<Class<?>[]>
paramsSupplier, Class<?> caller) {
+    public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[]
params, Class<?> caller) {
         if (!(metaMethod instanceof CachedMethod)) {
             return metaMethod;
         }
@@ -204,7 +203,6 @@ public class Java9 extends Java8 {
             classList.add(theClass);
             classList.addAll(superclassList);
 
-            Class<?>[] params = paramsSupplier.get();
             for (Class<?> sc : classList) {
                 Optional<MetaMethod> optionalMetaMethod = getAccessibleMetaMethod(metaMethod,
params, caller, sc);
                 if (optionalMetaMethod.isPresent()) {
@@ -221,7 +219,6 @@ public class Java9 extends Java8 {
         // e.g. StringBuilder sb = new StringBuilder(); sb.setLength(0);
         // `setLength` is the method of `AbstractStringBuilder`, which is `package-private`
         if (declaringClass.isAssignableFrom(theClass)) {
-            Class<?>[] params = paramsSupplier.get();
             Optional<MetaMethod> optionalMetaMethod = getAccessibleMetaMethod(metaMethod,
params, caller, theClass);
             if (optionalMetaMethod.isPresent()) {
                 return optionalMetaMethod.get();


Mime
View raw message