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 2020/04/19 11:33:40 UTC

[groovy] branch GROOVY-9513 updated (c5d774e -> fe653dd)

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

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


 discard c5d774e  MethodHandle with spread args should not be cached
     new fe653dd  MethodHandle with spread args should not be cached

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (c5d774e)
            \
             N -- N -- N   refs/heads/GROOVY-9513 (fe653dd)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 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:
 src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java | 4 ----
 1 file changed, 4 deletions(-)


[groovy] 01/01: MethodHandle with spread args should not be cached

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

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

commit fe653dd4e3adb26436f04fdc60416f569006444c
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Apr 19 19:33:07 2020 +0800

    MethodHandle with spread args should not be cached
---
 .../org/codehaus/groovy/vmplugin/v8/IndyInterface.java  | 17 ++++++++++++++++-
 .../groovy/vmplugin/v8/MethodHandleWrapper.java         | 12 ++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java
index 967cc5f..fca5159 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/IndyInterface.java
@@ -34,6 +34,7 @@ import java.lang.invoke.SwitchPoint;
 import java.util.Map;
 import java.util.function.BiFunction;
 import java.util.function.Function;
+import java.util.function.Supplier;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.stream.Collectors;
@@ -57,6 +58,7 @@ public class IndyInterface {
             SAFE_NAVIGATION = 1, THIS_CALL = 2,
             GROOVY_OBJECT = 4, IMPLICIT_THIS = 8,
             SPREAD_CALL = 16, UNCACHED_CALL = 32;
+    private static final MethodHandleWrapper NULL_METHOD_HANDLE_WRAPPER = MethodHandleWrapper.getNullMethodHandleWrapper();
 
     /**
      * Enum for easy differentiation between call types
@@ -255,16 +257,29 @@ public class IndyInterface {
      * Get the cached methodhandle. if the related methodhandle is not found in the inline cache, cache and return it.
      */
     public static Object fromCache(MutableCallSite callSite, Class<?> sender, String methodName, int callID, Boolean safeNavigation, Boolean thisCall, Boolean spreadCall, Object dummyReceiver, Object[] arguments) throws Throwable {
+        Supplier<MethodHandleWrapper> fallbackSupplier = () -> fallback(callSite, sender, methodName, callID, safeNavigation, thisCall, spreadCall, dummyReceiver, arguments);
+
         MethodHandleWrapper mhw =
                 doWithCallSite(
                         callSite, arguments,
                         (cs, receiver) ->
                                 cs.getAndPut(
                                         receiver.getClass().getName(),
-                                        c -> fallback(callSite, sender, methodName, callID, safeNavigation, thisCall, spreadCall, dummyReceiver, arguments)
+                                        c -> {
+                                            MethodHandleWrapper fbMhw = fallbackSupplier.get();
+                                            return fbMhw.isCanSetTarget() ? fbMhw : NULL_METHOD_HANDLE_WRAPPER;
+                                        }
                                 )
                 );
 
+        if (NULL_METHOD_HANDLE_WRAPPER == mhw) {
+            final MethodHandleWrapper fbMhw = fallbackSupplier.get();
+            if (fbMhw.isCanSetTarget()) {
+                doWithCallSite(callSite, arguments, (cs, receiver) -> cs.put(receiver.getClass().getName(), fbMhw));
+            }
+            mhw = fbMhw;
+        }
+
         if (mhw.isCanSetTarget() && (callSite.getTarget() != mhw.getTargetMethodHandle()) && (mhw.getLatestHitCount() > INDY_OPTIMIZE_THRESHOLD)) {
             callSite.setTarget(mhw.getTargetMethodHandle());
             if (LOG_ENABLED) LOG.info("call site target set, preparing outside invocation");
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/MethodHandleWrapper.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/MethodHandleWrapper.java
index 8849fe6..b858464 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/MethodHandleWrapper.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/MethodHandleWrapper.java
@@ -61,4 +61,16 @@ class MethodHandleWrapper {
     public long getLatestHitCount() {
         return latestHitCount.get();
     }
+
+    public static MethodHandleWrapper getNullMethodHandleWrapper() {
+        return NullMethodHandleWrapper.INSTANCE;
+    }
+
+    private static class NullMethodHandleWrapper extends MethodHandleWrapper {
+        public static final NullMethodHandleWrapper INSTANCE = new NullMethodHandleWrapper(null, null, false);
+
+        private NullMethodHandleWrapper(MethodHandle cachedMethodHandle, MethodHandle targetMethodHandle, boolean canSetTarget) {
+            super(cachedMethodHandle, targetMethodHandle, canSetTarget);
+        }
+    }
 }