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/12/31 16:08:21 UTC

[groovy] branch GROOVY_3_0_X updated (b53ad0d -> d45538e)

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 b53ad0d  GROOVY-9356: Bump javaparser to 3.15.8
     new 81a5966  Trivial refactoring: Rename `CALL_TYPES` to `CallType`
     new d45538e  Minor refactoring: simplify code for getting CallType

The 2 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:
 .../classgen/asm/indy/InvokeDynamicWriter.java     |  8 +--
 .../codehaus/groovy/vmplugin/v7/IndyInterface.java | 81 ++++++++++++++--------
 .../org/codehaus/groovy/vmplugin/v7/Selector.java  | 18 ++---
 3 files changed, 67 insertions(+), 40 deletions(-)


[groovy] 01/02: Trivial refactoring: Rename `CALL_TYPES` to `CallType`

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 81a5966e4a90d0cdfb7c26ccd675ea9c06bbe3bd
Author: Daniel Sun <su...@apache.org>
AuthorDate: Tue Dec 31 22:34:36 2019 +0800

    Trivial refactoring: Rename `CALL_TYPES` to `CallType`
    
    (cherry picked from commit f6b91fd4db82ed7897fdefcd834fef2902aeb7d9)
---
 .../classgen/asm/indy/InvokeDynamicWriter.java     |  8 +--
 .../codehaus/groovy/vmplugin/v7/IndyInterface.java | 63 +++++++++++++++-------
 .../org/codehaus/groovy/vmplugin/v7/Selector.java  | 18 +++----
 3 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
index d156570..a1c2876 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/indy/InvokeDynamicWriter.java
@@ -44,10 +44,10 @@ import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
 
 import static org.codehaus.groovy.classgen.asm.BytecodeHelper.getTypeDescription;
-import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CALL_TYPES.CAST;
-import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CALL_TYPES.GET;
-import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CALL_TYPES.INIT;
-import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CALL_TYPES.METHOD;
+import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CallType.CAST;
+import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CallType.GET;
+import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CallType.INIT;
+import static org.codehaus.groovy.vmplugin.v7.IndyInterface.CallType.METHOD;
 import static org.codehaus.groovy.vmplugin.v7.IndyInterface.GROOVY_OBJECT;
 import static org.codehaus.groovy.vmplugin.v7.IndyInterface.IMPLICIT_THIS;
 import static org.codehaus.groovy.vmplugin.v7.IndyInterface.SAFE_NAVIGATION;
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
index 866b45e..75c2dcd 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
@@ -52,19 +52,42 @@ public class IndyInterface {
         /**
          * Enum for easy differentiation between call types
          */
-        public enum CALL_TYPES {
-            /**Method invocation type*/         METHOD("invoke"), 
-            /**Constructor invocation type*/    INIT("init"), 
-            /**Get property invocation type*/   GET("getProperty"), 
-            /**Set property invocation type*/   SET("setProperty"),
-            /**Cast invocation type*/           CAST("cast");
-            /**The name of the call site type*/
+        public enum CallType {
+            /**
+             * Method invocation type
+             */
+            METHOD("invoke"),
+            /**
+             * Constructor invocation type
+             */
+            INIT("init"),
+            /**
+             * Get property invocation type
+             */
+            GET("getProperty"),
+            /**
+             * Set property invocation type
+             */
+            SET("setProperty"),
+            /**
+             * Cast invocation type
+             */
+            CAST("cast");
+            /**
+             * The name of the call site type
+             */
             private final String name;
-            CALL_TYPES(String callSiteName) {
+
+            CallType(String callSiteName) {
                 this.name = callSiteName;
             }
-            /** Returns the name of the call site type */
-            public String getCallSiteName(){ return name; }
+
+            /**
+             * Returns the name of the call site type
+             */
+            public String getCallSiteName() {
+                return name;
+            }
         }
 
         /** Logger */
@@ -140,16 +163,16 @@ public class IndyInterface {
             boolean thisCall = (flags&THIS_CALL)!=0;
             boolean spreadCall = (flags&SPREAD_CALL)!=0;
             int callID;
-            if (callType.equals(CALL_TYPES.METHOD.getCallSiteName())) {
-                callID = CALL_TYPES.METHOD.ordinal();
-            } else if (callType.equals(CALL_TYPES.INIT.getCallSiteName())) {
-                callID = CALL_TYPES.INIT.ordinal();
-            } else if (callType.equals(CALL_TYPES.GET.getCallSiteName())) {
-                callID = CALL_TYPES.GET.ordinal();
-            } else if (callType.equals(CALL_TYPES.SET.getCallSiteName())) {
-                callID = CALL_TYPES.SET.ordinal();
-            } else if (callType.equals(CALL_TYPES.CAST.getCallSiteName())) {
-                callID = CALL_TYPES.CAST.ordinal();
+            if (callType.equals(CallType.METHOD.getCallSiteName())) {
+                callID = CallType.METHOD.ordinal();
+            } else if (callType.equals(CallType.INIT.getCallSiteName())) {
+                callID = CallType.INIT.ordinal();
+            } else if (callType.equals(CallType.GET.getCallSiteName())) {
+                callID = CallType.GET.ordinal();
+            } else if (callType.equals(CallType.SET.getCallSiteName())) {
+                callID = CallType.SET.ordinal();
+            } else if (callType.equals(CallType.CAST.getCallSiteName())) {
+                callID = CallType.CAST.ordinal();
             }else {
                 throw new GroovyBugError("Unknown call type: "+callType);
             }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
index a505580..55d4ee1 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/Selector.java
@@ -51,7 +51,7 @@ import org.codehaus.groovy.runtime.metaclass.NewStaticMetaMethod;
 import org.codehaus.groovy.runtime.metaclass.ReflectionMetaMethod;
 import org.codehaus.groovy.runtime.wrappers.Wrapper;
 import org.codehaus.groovy.vmplugin.VMPluginFactory;
-import org.codehaus.groovy.vmplugin.v7.IndyInterface.CALL_TYPES;
+import org.codehaus.groovy.vmplugin.v7.IndyInterface.CallType;
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
@@ -113,16 +113,16 @@ public abstract class Selector {
     public boolean thisCall;
     public Class selectionBase;
     public boolean catchException = true;
-    public CALL_TYPES callType;
+    public CallType callType;
 
     /** Cache values for read-only access */
-    private static final CALL_TYPES[] CALL_TYPES_VALUES = CALL_TYPES.values();
+    private static final CallType[] CALL_TYPE_VALUES = CallType.values();
 
     /**
      * Returns the Selector
      */
     public static Selector getSelector(MutableCallSite callSite, Class sender, String methodName, int callID, boolean safeNavigation, boolean thisCall, boolean spreadCall, Object[] arguments) {
-        CALL_TYPES callType = CALL_TYPES_VALUES[callID];
+        CallType callType = CALL_TYPE_VALUES[callID];
         switch (callType) {
             case INIT: return new InitSelector(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
             case METHOD: return new MethodSelector(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
@@ -156,7 +156,7 @@ public abstract class Selector {
         private final Class<?> staticSourceType, staticTargetType;
 
         public CastSelector(MutableCallSite callSite, Object[] arguments) {
-            super(callSite, Selector.class, "", CALL_TYPES.CAST, false, false, false, arguments);
+            super(callSite, Selector.class, "", CallType.CAST, false, false, false, arguments);
             this.staticSourceType = callSite.type().parameterType(0);
             this.staticTargetType = callSite.type().returnType();
         }
@@ -279,7 +279,7 @@ public abstract class Selector {
     private static class PropertySelector extends MethodSelector {
         private boolean insertName = false;
 
-        public PropertySelector(MutableCallSite callSite, Class sender, String methodName, CALL_TYPES callType, boolean safeNavigation, boolean thisCall, boolean spreadCall, Object[] arguments) {
+        public PropertySelector(MutableCallSite callSite, Class sender, String methodName, CallType callType, boolean safeNavigation, boolean thisCall, boolean spreadCall, Object[] arguments) {
             super(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
         }
 
@@ -380,7 +380,7 @@ public abstract class Selector {
     private static class InitSelector extends MethodSelector {
         private boolean beanConstructor;
 
-        public InitSelector(MutableCallSite callSite, Class sender, String methodName, CALL_TYPES callType, boolean safeNavigation, boolean thisCall, boolean spreadCall, Object[] arguments) {
+        public InitSelector(MutableCallSite callSite, Class sender, String methodName, CallType callType, boolean safeNavigation, boolean thisCall, boolean spreadCall, Object[] arguments) {
             super(callSite, sender, methodName, callType, safeNavigation, thisCall, spreadCall, arguments);
         }
 
@@ -504,7 +504,7 @@ public abstract class Selector {
         private static final Object[] SINGLE_NULL_ARRAY = { null };
         protected MetaClass mc;
         private boolean isCategoryMethod;
-        public MethodSelector(MutableCallSite callSite, Class sender, String methodName, CALL_TYPES callType, Boolean safeNavigation, Boolean thisCall, Boolean spreadCall, Object[] arguments) {
+        public MethodSelector(MutableCallSite callSite, Class sender, String methodName, CallType callType, Boolean safeNavigation, Boolean thisCall, Boolean spreadCall, Object[] arguments) {
             this.callType = callType;
             this.targetType = callSite.type();
             this.name = methodName;
@@ -989,7 +989,7 @@ public abstract class Selector {
                 getMetaClass();
                 if (LOG_ENABLED) LOG.info("meta class is "+mc);
                 setSelectionBase();
-                MetaClassImpl mci = getMetaClassImpl(mc, callType != CALL_TYPES.GET);
+                MetaClassImpl mci = getMetaClassImpl(mc, callType != CallType.GET);
                 chooseMeta(mci);
                 setHandleForMetaMethod();
                 setMetaClassCallHandleIfNedded(mci!=null);


[groovy] 02/02: Minor refactoring: simplify code for getting CallType

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 d45538e9d0bccd66a271ebb614312b94fd187072
Author: Daniel Sun <su...@apache.org>
AuthorDate: Tue Dec 31 23:17:17 2019 +0800

    Minor refactoring: simplify code for getting CallType
    
    (cherry picked from commit 722e6afbac60494d7d0ad6aa5e3f26752186065c)
---
 .../codehaus/groovy/vmplugin/v7/IndyInterface.java | 38 ++++++++++++----------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
index 75c2dcd..b545f65 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v7/IndyInterface.java
@@ -29,8 +29,12 @@ import java.lang.invoke.MethodHandles.Lookup;
 import java.lang.invoke.MethodType;
 import java.lang.invoke.MutableCallSite;
 import java.lang.invoke.SwitchPoint;
+import java.util.Map;
+import java.util.function.Function;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * Bytecode level interface for bootstrap methods used by invokedynamic.
@@ -73,6 +77,10 @@ public class IndyInterface {
              * Cast invocation type
              */
             CAST("cast");
+
+            private static final Map<String, CallType> NAME_CALLTYPE_MAP =
+                    Stream.of(CallType.values()).collect(Collectors.toMap(CallType::getCallSiteName, Function.identity()));
+
             /**
              * The name of the call site type
              */
@@ -88,6 +96,10 @@ public class IndyInterface {
             public String getCallSiteName() {
                 return name;
             }
+
+            public static CallType fromCallSiteName(String callSiteName) {
+                return NAME_CALLTYPE_MAP.get(callSiteName);
+            }
         }
 
         /** Logger */
@@ -159,23 +171,15 @@ public class IndyInterface {
          * @since Groovy 2.1.0
          */
         public static CallSite bootstrap(Lookup caller, String callType, MethodType type, String name, int flags) {
-            boolean safe = (flags&SAFE_NAVIGATION)!=0;
-            boolean thisCall = (flags&THIS_CALL)!=0;
-            boolean spreadCall = (flags&SPREAD_CALL)!=0;
-            int callID;
-            if (callType.equals(CallType.METHOD.getCallSiteName())) {
-                callID = CallType.METHOD.ordinal();
-            } else if (callType.equals(CallType.INIT.getCallSiteName())) {
-                callID = CallType.INIT.ordinal();
-            } else if (callType.equals(CallType.GET.getCallSiteName())) {
-                callID = CallType.GET.ordinal();
-            } else if (callType.equals(CallType.SET.getCallSiteName())) {
-                callID = CallType.SET.ordinal();
-            } else if (callType.equals(CallType.CAST.getCallSiteName())) {
-                callID = CallType.CAST.ordinal();
-            }else {
-                throw new GroovyBugError("Unknown call type: "+callType);
-            }
+            boolean safe = (flags & SAFE_NAVIGATION) != 0;
+            boolean thisCall = (flags & THIS_CALL) != 0;
+            boolean spreadCall = (flags & SPREAD_CALL) != 0;
+
+            CallType ct = CallType.fromCallSiteName(callType);
+            if (null == ct) throw new GroovyBugError("Unknown call type: " + callType);
+
+            int callID = ct.ordinal();
+
             return realBootstrap(caller, name, callID, type, safe, thisCall, spreadCall);
         }