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 2019/11/23 11:15:14 UTC

[groovy] branch GROOVY_3_0_X updated (d781350 -> 18945d8)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from d781350  deprecate unused class
     new d96f767  Trivial refactoring: create call site array with stream and trivial edits
     new b0f4c6e  Avoid method calls as possible as we could
     new 18945d8  GROOVY-9314: Bump picocli to 4.1.0

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 build.gradle                                       |  2 +-
 .../groovy/runtime/callsite/CallSiteArray.java     | 83 +++++++++++-----------
 .../org/codehaus/groovy/vmplugin/v9/Java9.java     | 32 +++++----
 3 files changed, 59 insertions(+), 58 deletions(-)


[groovy] 02/03: Avoid method calls as possible as we could

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit b0f4c6e4855425fa6072428a7b1baf4a67f87660
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Nov 23 18:40:44 2019 +0800

    Avoid method calls as possible as we could
    
    (cherry picked from commit 585d4d67aece5878cb8b511b3bcfe9bee513d838)
---
 .../org/codehaus/groovy/vmplugin/v9/Java9.java     | 32 ++++++++++++----------
 1 file changed, 18 insertions(+), 14 deletions(-)

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 9337e5a..d482e89 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -177,7 +177,6 @@ public class Java9 extends Java8 {
         }
 
         Class<?> declaringClass = methodDeclaringClass.getTheClass();
-        Class<?> theClass = metaClass.getTheClass();
 
         int methodModifiers = cachedMethod.getModifiers();
 
@@ -191,10 +190,13 @@ public class Java9 extends Java8 {
             return metaMethod;
         }
 
+        Class<?> theClass = metaClass.getTheClass();
         if (declaringClass == theClass) {
-            MetaMethod bigIntegerMetaMethod = transformBigIntegerMetaMethod(metaMethod, params, theClass);
-            if (bigIntegerMetaMethod != metaMethod) {
-                return bigIntegerMetaMethod;
+            if (BigInteger.class == theClass) {
+                MetaMethod bigIntegerMetaMethod = transformBigIntegerMetaMethod(metaMethod, params);
+                if (bigIntegerMetaMethod != metaMethod) {
+                    return bigIntegerMetaMethod;
+                }
             }
 
             // GROOVY-9081 "3) Access public members of private class", e.g. Collections.unmodifiableMap([:]).toString()
@@ -227,21 +229,13 @@ public class Java9 extends Java8 {
         return metaMethod;
     }
 
-    private static MetaMethod transformBigIntegerMetaMethod(MetaMethod metaMethod, Class<?>[] params, Class<?> theClass) {
-        if (BigInteger.class != theClass) {
-            return metaMethod;
-        }
-
+    private static MetaMethod transformBigIntegerMetaMethod(MetaMethod metaMethod, Class<?>[] params) {
         if (1 == params.length && MULTIPLY.equals(metaMethod.getName())) {
             Class<?> param = params[0];
             if (Long.class == param || long.class == param
                     || Integer.class == param || int.class == param
                     || Short.class == param || short.class == param) {
-                try {
-                    return new CachedMethod(BigInteger.class.getDeclaredMethod(MULTIPLY, BigInteger.class));
-                } catch (NoSuchMethodException e) {
-                    throw new GroovyBugError("Failed to transform " + MULTIPLY + " method of BigInteger", e);
-                }
+                return new CachedMethod(BigIntegerMultiplyMethodHolder.MULTIPLY_METHOD);
             }
         }
 
@@ -384,6 +378,16 @@ public class Java9 extends Java8 {
     }
 
     private static final String MULTIPLY = "multiply";
+    private static class BigIntegerMultiplyMethodHolder {
+        private static final Method MULTIPLY_METHOD;
+        static {
+            try {
+                MULTIPLY_METHOD = BigInteger.class.getDeclaredMethod(MULTIPLY, BigInteger.class);
+            } catch (NoSuchMethodException | SecurityException e) {
+                throw new GroovyBugError("Failed to find " + MULTIPLY + " method of BigInteger", e);
+            }
+        }
+    }
 
     private static String[] JAVA8_PACKAGES() {
         return new String[] {


[groovy] 03/03: GROOVY-9314: Bump picocli to 4.1.0

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 18945d85296ba7a7b8e924c8724537ddb64274d9
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Nov 23 19:02:16 2019 +0800

    GROOVY-9314: Bump picocli to 4.1.0
    
    (cherry picked from commit 344b74c3272f3f9030dadaf01d91ed8504915357)
---
 build.gradle | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index 67bd25a..386739d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -148,7 +148,7 @@ ext {
     log4jVersion = '1.2.17'
     log4j2Version = '2.8'
     openbeansVersion = '1.0'
-    picocliVersion = '4.0.4'
+    picocliVersion = '4.1.0'
     qdoxVersion = '1.12.1'
     slf4jVersion = '1.7.25'
     xmlunitVersion = '1.6'


[groovy] 01/03: Trivial refactoring: create call site array with stream and trivial edits

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit d96f767f22e8e1e4b9af3517f6807e292b9afcba
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Nov 23 18:03:09 2019 +0800

    Trivial refactoring: create call site array with stream and trivial edits
    
    (cherry picked from commit 1f3ae864a9217fb86e63d85ea3e7ff968bfcbbff)
---
 .../groovy/runtime/callsite/CallSiteArray.java     | 83 +++++++++++-----------
 1 file changed, 40 insertions(+), 43 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteArray.java b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteArray.java
index 86005cf..5fe58fb 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteArray.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteArray.java
@@ -28,19 +28,19 @@ import org.codehaus.groovy.runtime.InvokerHelper;
 
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.util.stream.IntStream;
 
 
 public final class CallSiteArray {
-    public final CallSite[] array;
     public static final Object[] NOPARAM = new Object[0];
+    public final CallSite[] array;
     public final Class owner;
 
-    public CallSiteArray(Class owner, String [] names) {
+    public CallSiteArray(Class owner, final String[] names) {
         this.owner = owner;
-        array = new CallSite[names.length];
-        for (int i = 0; i < array.length; i++) {
-            array[i] = new AbstractCallSite(this, i, names[i]);
-        }
+        this.array = IntStream.range(0, names.length)
+                        .mapToObj(i -> new AbstractCallSite(this, i, names[i]))
+                        .toArray(CallSite[]::new);
     }
 
     public static Object defaultCall(CallSite callSite, Object receiver, Object[] args) throws Throwable {
@@ -60,7 +60,6 @@ public final class CallSiteArray {
     }
 
     private static CallSite createCallStaticSite(CallSite callSite, final Class receiver, Object[] args) {
-        CallSite site;
         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
             try {
                 Class.forName(receiver.getName(), true, receiver.getClassLoader());
@@ -70,25 +69,21 @@ public final class CallSiteArray {
             return null;
         });
         MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
-        if (metaClass instanceof MetaClassImpl) {
-            site = ((MetaClassImpl)metaClass).createStaticSite(callSite, args);
-        }
-        else
-          site = new StaticMetaClassSite(callSite, metaClass);
+        CallSite site =
+                metaClass instanceof MetaClassImpl
+                        ? ((MetaClassImpl) metaClass).createStaticSite(callSite, args)
+                        : new StaticMetaClassSite(callSite, metaClass);
 
         replaceCallSite(callSite, site);
         return site;
     }
 
     private static CallSite createCallConstructorSite(CallSite callSite, Class receiver, Object[] args) {
-       MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
-
-       CallSite site;
-       if (metaClass instanceof MetaClassImpl) {
-           site = ((MetaClassImpl)metaClass).createConstructorSite(callSite, args);
-       }
-       else
-         site = new MetaClassConstructorSite(callSite, metaClass);
+        MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
+        CallSite site =
+                metaClass instanceof MetaClassImpl
+                        ? ((MetaClassImpl) metaClass).createConstructorSite(callSite, args)
+                        : new MetaClassConstructorSite(callSite, metaClass);
 
         replaceCallSite(callSite, site);
         return site;
@@ -96,19 +91,18 @@ public final class CallSiteArray {
 
     private static CallSite createCallCurrentSite(CallSite callSite, GroovyObject receiver, Object[] args, Class sender) {
         CallSite site;
-        if (receiver instanceof GroovyInterceptable)
-          site = new PogoInterceptableSite(callSite);
-        else {
+        if (receiver instanceof GroovyInterceptable) {
+            site = new PogoInterceptableSite(callSite);
+        } else {
             MetaClass metaClass = receiver.getMetaClass();
-            if (receiver.getClass() != metaClass.getTheClass() && !metaClass.getTheClass().isInterface()) {
+            Class theClass = metaClass.getTheClass();
+            if (receiver.getClass() != theClass && !theClass.isInterface()) {
                 site = new PogoInterceptableSite(callSite);
+            } else if (metaClass instanceof MetaClassImpl) {
+                site = ((MetaClassImpl) metaClass).createPogoCallCurrentSite(callSite, sender, args);
+            } else {
+                site = new PogoMetaClassSite(callSite, metaClass);
             }
-            else
-                if (metaClass instanceof MetaClassImpl) {
-                    site = ((MetaClassImpl)metaClass).createPogoCallCurrentSite(callSite, sender, args);
-                }
-                else
-                  site = new PogoMetaClassSite(callSite, metaClass);
         }
 
         replaceCallSite(callSite, site);
@@ -131,15 +125,17 @@ public final class CallSiteArray {
         }
 
         ClassInfo info = ClassInfo.getClassInfo(klazz);
-        if (info.hasPerInstanceMetaClasses())
-          return new PerInstancePojoMetaClassSite(callSite, info);
-        else
-          return new PojoMetaClassSite(callSite, metaClass);
+        if (info.hasPerInstanceMetaClasses()) {
+            return new PerInstancePojoMetaClassSite(callSite, info);
+        } else {
+            return new PojoMetaClassSite(callSite, metaClass);
+        }
     }
 
     private static CallSite createPogoSite(CallSite callSite, Object receiver, Object[] args) {
-        if (receiver instanceof GroovyInterceptable)
-          return new PogoInterceptableSite(callSite);
+        if (receiver instanceof GroovyInterceptable) {
+            return new PogoInterceptableSite(callSite);
+        }
 
         MetaClass metaClass = ((GroovyObject)receiver).getMetaClass();
 
@@ -151,13 +147,14 @@ public final class CallSiteArray {
     }
 
     private static CallSite createCallSite(CallSite callSite, Object receiver, Object[] args) {
-        CallSite site;
-        if (receiver == null)
-          return new NullCallSite(callSite);
+        if (receiver == null) {
+            return new NullCallSite(callSite);
+        }
 
-        if (receiver instanceof Class)
-          site = createCallStaticSite(callSite, (Class) receiver, args);
-        else if (receiver instanceof GroovyObject) {
+        CallSite site;
+        if (receiver instanceof Class) {
+            site = createCallStaticSite(callSite, (Class) receiver, args);
+        } else if (receiver instanceof GroovyObject) {
             site = createPogoSite(callSite, receiver, args);
         } else {
             site = createPojoSite(callSite, receiver, args);
@@ -168,6 +165,6 @@ public final class CallSiteArray {
     }
 
     private static void replaceCallSite(CallSite oldSite, CallSite newSite) {
-        oldSite.getArray().array [oldSite.getIndex()] = newSite;
+        oldSite.getArray().array[oldSite.getIndex()] = newSite;
     }
 }